Skip to content

Commit

Permalink
Merge pull request #143 from nori-dongsan/view_product/#142
Browse files Browse the repository at this point in the history
[ ViewProduct ] ๋“œ๋กญ๋‹ค์šด ์„น์…˜ ์ˆœ์„œ ๋ณ€๊ฒฝ
  • Loading branch information
say-young516 authored Jul 21, 2022
2 parents 52b35e5 + 0a5a757 commit 86c9c61
Show file tree
Hide file tree
Showing 20 changed files with 238 additions and 125 deletions.
4 changes: 3 additions & 1 deletion components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export default function Header() {
onChange={handleInputValue}
/>
<Link href="/viewProduct">
<IcSearchIcon onClick={handleClick} />
<a>
<IcSearchIcon onClick={handleClick} />
</a>
</Link>
</StSearchBar>
<StMenu>
Expand Down
74 changes: 64 additions & 10 deletions components/common/WriteHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import styled from '@emotion/styled';
import { IcWriteHeaderLogo } from '../../public/assets/icons';
import Link from 'next/link';
import { useRecoilState } from 'recoil';
import { newPostInfoState } from '../../core/atom';
import { postCommunity } from '../../core/api/community';
import { isChangeInfoState, newPostInfoState } from '../../core/atom';
import { postCommunity, putCommunity } from '../../core/api/community';
import { useRouter } from 'next/router';
import { PutCommunityBody } from '../../types/community';

export default function WriteHeader() {
const [newPostInfo, setNewPostInfo] = useRecoilState(newPostInfoState);
const [isChangeCommunity, setIsChangeCommunity] =
useRecoilState(isChangeInfoState);
const router = useRouter();
const { pathname } = useRouter();
const { pathname, query } = useRouter();

const handleRegister = async () => {
const { title, content } = newPostInfo;
Expand All @@ -27,20 +30,71 @@ export default function WriteHeader() {
router.push(`/community/${data.id}`);
};

const handleCancel = () => {
const val = confirm(
'์ˆ˜์ •์„ ์ทจ์†Œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? ์ž‘์„ฑํ•˜๋˜ ๋‚ด์šฉ์€ ๋ชจ๋‘ ์‚ญ์ œ๋ฉ๋‹ˆ๋‹ค.',
);

if (val) {
router.push(`/community/${query.cid}`);
}
};

const handleUpdate = async () => {
const { category, title, content, imageList } = newPostInfo;
const {
isChangeCategory,
isChangeTitle,
isChangeContent,
isChangeImageList,
} = isChangeCommunity;
const updatePostInfo: PutCommunityBody = {};

if (isChangeCategory) updatePostInfo.category = category;
if (isChangeTitle) updatePostInfo.title = title;
if (isChangeContent) updatePostInfo.content = content;
if (isChangeImageList) updatePostInfo.imageList = imageList;

if (updatePostInfo.title === '' || updatePostInfo.content === '') {
alert('๋‚ด์šฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.');
return;
}

const data = await putCommunity(String(query.cid), updatePostInfo);
setNewPostInfo({
category: 'ํ›„๊ธฐ',
title: '',
content: '',
});
setIsChangeCommunity({
isChangeCategory: false,
isChangeTitle: false,
isChangeContent: false,
isChangeImageList: false,
});
router.push(`/community/${data.id}`);
};

return (
<StWriteHeaderWrapper>
<Link href="/community">
<a>
<IcWriteHeaderLogo />
</a>
</Link>
{pathname === '/community' ? (
{pathname === '/write/[cid]' ? (
<StModifyBlock>
<StCancleBtn>์ทจ์†Œ</StCancleBtn>
<StWriteBtn>์ˆ˜์ •์™„๋ฃŒ</StWriteBtn>
<StCancleBtn isMargin={false} onClick={handleCancel}>
์ทจ์†Œ
</StCancleBtn>
<StWriteBtn isMargin={false} onClick={handleUpdate}>
์ˆ˜์ •์™„๋ฃŒ
</StWriteBtn>
</StModifyBlock>
) : (
<StWriteBtn>๋“ฑ๋กํ•˜๊ธฐ</StWriteBtn>
<StWriteBtn isMargin={true} onClick={handleRegister}>
๋“ฑ๋กํ•˜๊ธฐ
</StWriteBtn>
)}
</StWriteHeaderWrapper>
);
Expand All @@ -53,7 +107,7 @@ const StWriteHeaderWrapper = styled.section`
position: sticky;
top: -3.2em;
width: 192rem;
width: 100%;
height: 11.4rem;
padding-top: 4.2rem;
Expand All @@ -63,12 +117,12 @@ const StWriteHeaderWrapper = styled.section`
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.08);
`;
const StWriteBtn = styled.a`
const StWriteBtn = styled.a<{ isMargin: boolean }>`
display: flex;
justify-content: center;
align-items: center;
margin-left: 11.4rem;
margin-left: ${({ isMargin }) => (isMargin ? '11.4rem' : '0rem')};
width: 10rem;
height: 4.2rem;
Expand Down
1 change: 0 additions & 1 deletion components/community/CommunityFloatingBtn.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import Link from 'next/link';
import { IcWriteBtn, IcTopBtn } from '../../public/assets/icons';
Expand Down
1 change: 0 additions & 1 deletion components/main/ToyPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { MainToyData } from '../../types/toy';
export default function ToyPreview(props: MainToyData) {
const { image, month, price, siteName, siteUrl, title } = props;
const [isMark, setIsMark] = useState(false);
console.log(image);
const handleToySite = (e: React.MouseEvent<HTMLElement>) => {
if (!(e.target instanceof SVGElement)) window.open(siteUrl);
};
Expand Down
2 changes: 1 addition & 1 deletion components/viewProduct/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function FilterDropdown(props: FilterDropdownProps) {
isDrop ? 'slide-fade-in-dropdown' : 'slide-fade-out-dropdown'
}`}
>
{categoryKey === '์žฅ๋‚œ๊ฐ ์ข…๋ฅ˜' && toyKindList.length !== 0
{categoryKey === '์ข…๋ฅ˜' && toyKindList.length !== 0
? toyKindList.map((tagText: string, elementIdx: number) => {
return (
<StLabel
Expand Down
2 changes: 1 addition & 1 deletion components/viewProduct/ProductFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function ProductFilter() {
categoryInfo={filterListData[idx]}
categoryIdx={idx}
isExcept={
idx == 3 || (idx == 4 && toyKindList.length !== 0)
idx == 3 || (idx == 0 && toyKindList.length !== 0)
? true
: false
}
Expand Down
18 changes: 17 additions & 1 deletion core/api/community.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import useSWR from 'swr';
import { PostCommentBody, PostCommunityBody } from '../../types/community';
import {
PostCommunityBody,
PutCommunityBody,
PostCommentBody,
} from '../../types/community';
import { baseInstance } from '../axios';

export const useGetCollectionProduct = (key: string) => {
const { data } = useSWR(`/collection?sort=${key}`, baseInstance.get);
console.log(data);
return data;
};

export const getCollectionProduct = (key: string) => {
return baseInstance.get(`/collection?sort=${key}`);
};
Expand All @@ -27,6 +32,7 @@ export const postCommunity = async (body: PostCommunityBody) => {
console.log(e);
}
};

export const getCommunityDetail = async (id: string) => {
try {
// const { data } = await axios.get(
Expand All @@ -38,6 +44,7 @@ export const getCommunityDetail = async (id: string) => {
console.log(e);
}
};

export const deleteCommunity = async (id: string) => {
try {
const { status } = await baseInstance.delete(`/board/${id}`);
Expand All @@ -47,6 +54,15 @@ export const deleteCommunity = async (id: string) => {
}
};

export const putCommunity = async (id: string, body: PutCommunityBody) => {
try {
const { data } = await baseInstance.put(`/board/${id}`, body);
return data;
} catch (e) {
console.log(e);
}
};

export const postReply = async (body: PostCommentBody) => {
try {
const { data } = await baseInstance.post('/board/comment', body);
Expand Down
21 changes: 11 additions & 10 deletions core/api/user.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import LocalStorage from '../localStorage';
import { baseInstance } from '../axios';
import {
PostLoginBody,
PostSignUpBody,
ResponseLoginDto,
} from '../../types/user';
import { PostLoginBody, SignUpBody, ResponseLoginDto } from '../../types/user';

export const loginUser = async (userLoginData: PostLoginBody) => {
const data = (await baseInstance.post(
'/auth/login',
userLoginData,
)) as ResponseLoginDto;

console.log(userLoginData);
if (data) {
LocalStorage.setUserSession(data.data.accessToken, data.data.refreshToken);
if (data.status === 200) {
LocalStorage.setUserSession(
data.data.data.accessToken,
data.data.data.refreshToken,
);
return data.data.data.isSignup;
}
return data.data.isSignup;
};
export const getRefreshToken = () => {
return baseInstance.get('/auth/refresh');
};
export const putSignup = (signUpBody: PostSignUpBody) => {
export const postNickname = (nicknameBody: SignUpBody) => {
return baseInstance.post('/auth/nickname', nicknameBody);
};
export const putSignup = (signUpBody: SignUpBody) => {
return baseInstance.put('/auth/signup', signUpBody);
};
71 changes: 41 additions & 30 deletions core/atom.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { atom, selector, selectorFamily } from 'recoil';
import { atom } from 'recoil';
import { recoilPersist } from 'recoil-persist'; //ํŽ˜์ด์ง€๊ฐ€ ๋ณ€๊ฒฝ๋˜๋”๋ผ๋„ ์ƒํƒœ๊ด€๋ฆฌ๋ฅผ ์œ ์ง€
import { PostCommunityBody } from '../types/community';
import { PostLoginBody, UserData } from '../types/user';
import { FilterDropdownProps, FilterTagProps } from '../types/viewProduct';

import { PostCommunityBody, IsChangeCommunity } from '../types/community';
import { PostLoginBody } from '../types/user';
import { FilterTagProps } from '../types/viewProduct';

const { persistAtom } = recoilPersist();

Expand All @@ -18,7 +17,6 @@ export const userInfoState = atom<PostLoginBody>({
effects_UNSTABLE: [persistAtom],
});


export const newPostInfoState = atom<PostCommunityBody>({
key: 'newPostInfo',
default: {
Expand All @@ -29,34 +27,22 @@ export const newPostInfoState = atom<PostCommunityBody>({
effects_UNSTABLE: [persistAtom],
});

export const isChangeInfoState = atom<IsChangeCommunity>({
key: 'isChangeInfo',
default: {
isChangeCategory: false,
isChangeTitle: false,
isChangeContent: false,
isChangeImageList: false,
},
effects_UNSTABLE: [persistAtom],
});

export const filterListState = atom({
key: 'filterListState',
default: {
filterList: {
์Šคํ† ์–ด: [
'๊ตญ๋ฏผ์žฅ๋‚œ๊ฐ',
'๊ทธ๋ฆฐํ‚ค๋“œ',
'๋Ÿฌ๋ธŒ๋กœ',
'๋ฆฌํ‹€๋ฒ ์ด๋น„',
'๋นŒ๋ฆฌ๋ฐ”๋ฐ”',
'์–ดํ…์…˜ํ™ˆ์ด๋ฒคํŠธ',
'์žฅ๋‚œ๊ฐ์ ๋นต',
'์ ค๋ฆฌ๋ฐ”์šด์Šค',
'ํ•ดํ”ผ์žฅ๋‚œ๊ฐ',
],
'์‚ฌ์šฉ ์—ฐ๋ น': [
'0~5๊ฐœ์›”',
'6~11๊ฐœ์›”',
'12~17๊ฐœ์›”',
'18~23๊ฐœ์›”',
'24~35๊ฐœ์›”',
'36~47๊ฐœ์›”',
'48~60๊ฐœ์›”',
'๊ธฐํƒ€',
],
๊ฐ€๊ฒฉ: ['1๋งŒ์› ๋ฏธ๋งŒ', '1-3๋งŒ์›', '3-5๋งŒ์›', '5-8๋งŒ์›', '8๋งŒ์›์ด์ƒ'],
ํŠน์„ฑ: ['ํƒ€๊ณ  ๋…ธ๋Š”', '๋งŒ์ง€๊ณ  ๋…ธ๋Š”', '๊ธฐํƒ€'],
'์žฅ๋‚œ๊ฐ ์ข…๋ฅ˜': [
์ข…๋ฅ˜: [
'์•„๊ธฐ์ฒด์œก๊ด€',
'๋ชจ๋นŒ',
'๋ฐ”์šด์„œ',
Expand All @@ -78,9 +64,33 @@ export const filterListState = atom({
'์—ญํ• ๋†€์ด',
'๊ธฐํƒ€',
],
'์‚ฌ์šฉ ์—ฐ๋ น': [
'0~5๊ฐœ์›”',
'6~11๊ฐœ์›”',
'12~17๊ฐœ์›”',
'18~23๊ฐœ์›”',
'24~35๊ฐœ์›”',
'36~47๊ฐœ์›”',
'48~60๊ฐœ์›”',
'๊ธฐํƒ€',
],
๊ฐ€๊ฒฉ: ['1๋งŒ์› ๋ฏธ๋งŒ', '1-3๋งŒ์›', '3-5๋งŒ์›', '5-8๋งŒ์›', '8๋งŒ์›์ด์ƒ'],
ํŠน์„ฑ: ['ํƒ€๊ณ  ๋…ธ๋Š”', '๋งŒ์ง€๊ณ  ๋…ธ๋Š”', '๊ธฐํƒ€'],
์Šคํ† ์–ด: [
'๊ตญ๋ฏผ์žฅ๋‚œ๊ฐ',
'๊ทธ๋ฆฐํ‚ค๋“œ',
'๋Ÿฌ๋ธŒ๋กœ',
'๋ฆฌํ‹€๋ฒ ์ด๋น„',
'๋นŒ๋ฆฌ๋ฐ”๋ฐ”',
'์–ดํ…์…˜ํ™ˆ์ด๋ฒคํŠธ',
'์žฅ๋‚œ๊ฐ์ ๋นต',
'์ ค๋ฆฌ๋ฐ”์šด์Šค',
'ํ•ดํ”ผ์žฅ๋‚œ๊ฐ',
],
},
},
});

export const filterTagState = atom<FilterTagProps[]>({
key: 'filterTagState',
default: [],
Expand All @@ -96,6 +106,7 @@ export const checkedItemsState = atom<Set<number>[]>({
new Set<number>(),
],
});

export const toyKindState = atom<string[]>({
key: 'toyKindState',
default: [],
Expand Down
6 changes: 4 additions & 2 deletions core/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ const baseInstance = axios.create({
baseInstance.interceptors.request.use((config) => {
const headers = {
...config.headers,
accessToken: LocalStorage.getItem('accessToken'),
refreshToken: LocalStorage.getItem('refreshToken'),
accessToken:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzAsImlhdCI6MTY1ODM4NDEwMCwiZXhwIjoxNjU4MzkxMzAwLCJpc3MiOiJub3JpIn0.ZNRxtGPFJpVCHJzlK0HdcgPcZWvkkCt3FZ_VHu8sz7M',
refreshToken:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzAsImlhdCI6MTY1ODM4NDEwMCwiZXhwIjoxNjU5NTkzNzAwLCJpc3MiOiJub3JpIn0.AeuhSmM1ZqItojeM3O0SwrELog-Qfq91r_ii0EMgPig',
};

return { ...config, headers };
Expand Down
Loading

0 comments on commit 86c9c61

Please sign in to comment.