diff --git a/src/components/feed/upload/Category/CategorySelector/CategorySelectOptions.tsx b/src/components/feed/upload/Category/CategorySelector/CategorySelectOptions.tsx index d781cfe52..ea28fb9a6 100644 --- a/src/components/feed/upload/Category/CategorySelector/CategorySelectOptions.tsx +++ b/src/components/feed/upload/Category/CategorySelector/CategorySelectOptions.tsx @@ -8,15 +8,13 @@ import { UploadFeedDataType } from '@/components/feed/upload/types'; import { textStyles } from '@/styles/typography'; interface CategorySelectOptionsProp { - onNext: () => void; onSave: (categoryId: number) => void; feedData: UploadFeedDataType; } -export default function CategorySelectOptions({ onSave, onNext, feedData }: CategorySelectOptionsProp) { +export default function CategorySelectOptions({ onSave, feedData }: CategorySelectOptionsProp) { const handleSelectCategory = (categoryId: number) => { onSave(categoryId); - onNext(); }; const { data: categories } = useQuery({ diff --git a/src/components/feed/upload/Category/CategorySelector/index.stories.tsx b/src/components/feed/upload/Category/CategorySelector/index.stories.tsx index 0c8fdebf1..c637eed64 100644 --- a/src/components/feed/upload/Category/CategorySelector/index.stories.tsx +++ b/src/components/feed/upload/Category/CategorySelector/index.stories.tsx @@ -17,9 +17,8 @@ export const Default = { void; onClose: () => void; - onSave: (categoryId: number) => void; + onSelect: (categoryId: number) => void; feedData: UploadFeedDataType; } -export default function CategorySelector({ isOpen, onNext, onClose, onSave, feedData }: CategorySelectorProps) { +export default function CategorySelector({ isOpen, onClose, onSelect, feedData }: CategorySelectorProps) { return ( <> 어디에 올릴까요?}> - + @@ -31,7 +30,7 @@ export default function CategorySelector({ isOpen, onNext, onClose, onSave, feed className='category-drop' header={어디에 올릴까요?} > - + diff --git a/src/components/feed/upload/Category/index.tsx b/src/components/feed/upload/Category/index.tsx index 0237a297a..f45e62495 100644 --- a/src/components/feed/upload/Category/index.tsx +++ b/src/components/feed/upload/Category/index.tsx @@ -1,5 +1,8 @@ -import { useEffect } from 'react'; +import { useQuery } from '@tanstack/react-query'; +import { useMemo } from 'react'; +import { getCategory } from '@/api/endpoint/feed/getCategory'; +import { useGetMemberProfileOfMe } from '@/api/endpoint_LEGACY/hooks'; import CategoryHeader from '@/components/feed/upload/Category/CategoryHeader'; import CategorySelector from '@/components/feed/upload/Category/CategorySelector'; import TagSelector from '@/components/feed/upload/Category/TagSelector'; @@ -24,30 +27,65 @@ export default function Category({ openCategory, openTag, openUsingRules, - checkIsOpenCategorys, }: CateogryProps) { - useEffect(() => { - if (feedData.categoryId === 0) return; - if (checkIsOpenCategorys) return; - if (feedData.categoryId === 1) { - openUsingRules(); - } else { - openTag(); + const { data: categories } = useQuery({ + queryKey: getCategory.cacheKey(), + queryFn: getCategory.request, + }); + + const { data: myProfile } = useGetMemberProfileOfMe(); + + const latestSoptPart = useMemo(() => { + if (!myProfile?.soptActivities || myProfile.soptActivities.length === 0) { + return null; } - }, [feedData]); + + return myProfile.soptActivities.reduce((latestActivity, activity) => { + if (latestActivity.generation < activity.generation) { + return activity; + } + return latestActivity; + }, myProfile.soptActivities[0]).part; + }, [myProfile?.soptActivities]); const handleSaveMainCategory = (categoryId: number) => { - onSaveCategory(categoryId); + const selectedMainCategory = categories?.find((category) => category.id === categoryId); + + if (selectedMainCategory == null) { + return; + } + onSaveMainCategory(categoryId); + + if (selectedMainCategory.children.length === 0) { + onSaveCategory(categoryId); + return; + } + + openTag(); + + if (selectedMainCategory.hasAll) { + onSaveCategory(categoryId); + return; + } + + if (selectedMainCategory.name === '파트') { + onSaveCategory( + selectedMainCategory.children.find((category) => category.name === latestSoptPart)?.id ?? + selectedMainCategory.children[0].id, + ); + return; + } + + onSaveCategory(selectedMainCategory.children[0].id); }; return ( <>