-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of github.com:picktoss/pick-toss-next into dev…
…elop
- Loading branch information
Showing
7 changed files
with
277 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
src/app/(routes)/collections/edit-info/[id]/@header/default.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import GoBackButton from '@/shared/components/custom/go-back-button' | ||
import Text from '@/shared/components/ui/text' | ||
|
||
const Header = () => { | ||
return ( | ||
<header className="fixed top-0 z-50 flex h-[54px] w-full max-w-mobile shrink-0 items-center bg-white px-[16px]"> | ||
<GoBackButton /> | ||
<div className="absolute right-1/2 translate-x-1/2"> | ||
<Text as="h1" typography="subtitle2-medium"> | ||
컬렉션 정보수정 | ||
</Text> | ||
</div> | ||
</header> | ||
) | ||
} | ||
|
||
export default Header |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { FunctionComponent, PropsWithChildren } from 'react' | ||
import type { Metadata } from 'next' | ||
|
||
export const metadata: Metadata = {} | ||
|
||
interface LayoutProps extends PropsWithChildren { | ||
header: React.ReactNode | ||
} | ||
|
||
const Layout: FunctionComponent<LayoutProps> = ({ header, children }) => { | ||
return ( | ||
<main> | ||
{header} | ||
<div className="pt-[54px]">{children}</div> | ||
</main> | ||
) | ||
} | ||
|
||
export default Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import EditCollectionInfoForm from '@/features/collection/components/edit-collection-info-form' | ||
|
||
const EditCollectionInfoPage = () => { | ||
return ( | ||
<div className="px-[20px]"> | ||
<EditCollectionInfoForm /> | ||
</div> | ||
) | ||
} | ||
|
||
export default EditCollectionInfoPage |
166 changes: 166 additions & 0 deletions
166
src/features/collection/components/edit-collection-info-form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
'use client' | ||
|
||
import { CATEGORIES } from '@/features/category/config' | ||
import { useCollectionInfo, useUpdateCollectionInfo } from '@/requests/collection/hooks' | ||
import CategoryTag from '@/shared/components/custom/category-tag' | ||
import FixedBottom from '@/shared/components/custom/fixed-bottom' | ||
import Loading from '@/shared/components/custom/loading' | ||
import { Button } from '@/shared/components/ui/button' | ||
import { | ||
Drawer, | ||
DrawerClose, | ||
DrawerContent, | ||
DrawerHeader, | ||
DrawerTitle, | ||
DrawerTrigger, | ||
} from '@/shared/components/ui/drawer' | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuTrigger, | ||
} from '@/shared/components/ui/dropdown-menu' | ||
import Text from '@/shared/components/ui/text' | ||
import { Textarea } from '@/shared/components/ui/textarea' | ||
import EmojiPicker from 'emoji-picker-react' | ||
import { useParams, useRouter } from 'next/navigation' | ||
import { useEffect, useState } from 'react' | ||
|
||
const EditCollectionInfoForm = () => { | ||
const router = useRouter() | ||
|
||
const { id } = useParams() | ||
const { data } = useCollectionInfo(Number(id)) | ||
|
||
const [emoji, setEmoji] = useState('') | ||
const [title, setTitle] = useState('') | ||
const [description, setDescription] = useState('') | ||
const [categoryId, setCategoryId] = useState<Collection.Field>(CATEGORIES[0]!.id) | ||
|
||
const { mutate: editCollectionInfoMutate, isPending: isEditCollectionInfoPending } = | ||
useUpdateCollectionInfo() | ||
|
||
const handleEditCollectionInfo = () => { | ||
if (isEditCollectionInfoPending) { | ||
return | ||
} | ||
|
||
editCollectionInfoMutate( | ||
{ | ||
collectionId: Number(id), | ||
payload: { | ||
name: title, | ||
emoji, | ||
description, | ||
collectionCategory: CATEGORIES.find((category) => category.id === categoryId)!.id, | ||
}, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
router.replace(`/collections/${Number(id)}`) | ||
}, | ||
} | ||
) | ||
} | ||
|
||
useEffect(() => { | ||
if (!data) return | ||
|
||
setEmoji(data.emoji) | ||
setTitle(data.name) | ||
setDescription(data.description) | ||
setCategoryId(CATEGORIES.find((category) => category.name === data.collectionCategory)!.id) | ||
}, [data]) | ||
|
||
if (!data) { | ||
return <Loading center /> | ||
} | ||
|
||
return ( | ||
<div className="mt-3"> | ||
<div> | ||
{/* 이모지 선택 및 컬렉션 이름 입력 */} | ||
<div className="flex items-center gap-[20px]"> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="outline-none"> | ||
<div className="flex-center size-[48px] rounded-[12px] bg-background-base-02 text-3xl"> | ||
{emoji} | ||
</div> | ||
</DropdownMenuTrigger> | ||
|
||
<DropdownMenuContent> | ||
<EmojiPicker | ||
skinTonesDisabled | ||
height={'60vh'} | ||
onEmojiClick={(emojiData) => { | ||
setEmoji(emojiData.emoji) | ||
}} | ||
/> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
<input | ||
value={title} | ||
onChange={(e) => setTitle(e.target.value)} | ||
placeholder="새로운 컬렉션" | ||
className="flex-1 bg-transparent text-title2 placeholder:text-text-placeholder-02 focus:outline-none" | ||
autoFocus | ||
/> | ||
</div> | ||
|
||
{/* 분야 선택 */} | ||
<div className="mt-[25px] flex items-center gap-[5px]"> | ||
<Text typography="text1-medium" color="secondary"> | ||
분야<span className="text-text-accent">*</span> | ||
</Text> | ||
<Drawer> | ||
<DrawerTrigger> | ||
<div className="rounded-full bg-background-base-02 px-[14px] py-[5px]"> | ||
<CategoryTag | ||
title={CATEGORIES.find((category) => category.id === categoryId)?.name ?? ''} | ||
/> | ||
</div> | ||
</DrawerTrigger> | ||
<DrawerContent> | ||
<DrawerHeader> | ||
<DrawerTitle>카테고리를 선택해주세요.</DrawerTitle> | ||
</DrawerHeader> | ||
<div className="flex flex-col gap-2 p-4"> | ||
{CATEGORIES.map((category) => ( | ||
<DrawerClose key={category.id}> | ||
<CategoryTag title={category.name} onClick={() => setCategoryId(category.id)} /> | ||
</DrawerClose> | ||
))} | ||
</div> | ||
</DrawerContent> | ||
</Drawer> | ||
</div> | ||
|
||
{/* 컬렉션 설명 */} | ||
<div className="mt-[27px]"> | ||
<Text typography="text1-medium" color="secondary"> | ||
컬렉션 설명<span className="text-text-accent">*</span> | ||
</Text> | ||
<Textarea | ||
value={description} | ||
onChange={(e) => setDescription(e.target.value)} | ||
className="mt-2 min-h-[130px] rounded-[8px] border-none bg-background-base-02" | ||
/> | ||
<Text typography="text2-medium" color="caption" className="mt-2"> | ||
200자 이내로 입력해주세요 ({description.length}/200) | ||
</Text> | ||
</div> | ||
</div> | ||
<FixedBottom className="flex gap-[6px]"> | ||
<Button | ||
variant={'largeRound'} | ||
className="w-full" | ||
onClick={() => handleEditCollectionInfo()} | ||
disabled={isEditCollectionInfoPending} | ||
> | ||
만들기 | ||
</Button> | ||
</FixedBottom> | ||
</div> | ||
) | ||
} | ||
|
||
export default EditCollectionInfoForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters