diff --git a/src/api/domain/community.api.server.ts b/src/api/domain/community.api.server.ts index 3722b64e..fd3f2e7b 100644 --- a/src/api/domain/community.api.server.ts +++ b/src/api/domain/community.api.server.ts @@ -2,6 +2,7 @@ import { CommunityDetailResponse, CommunityIdCardsRequest, CommunityIdCardsResponse, + CommunityListResponse, } from '~/types/community'; import { privateApi } from '../config/privateApi.server'; @@ -20,3 +21,6 @@ export const getCommunityIdCardsServer = ({ privateApi.get( `/communities/${communityId}/idCards?page=${pageParam}&size=10`, ); + +export const getCommunityListServer = (userId: number) => + privateApi.get(`/communities/users/${userId}`); diff --git a/src/api/domain/user.api.server.ts b/src/api/domain/user.api.server.ts new file mode 100644 index 00000000..10709942 --- /dev/null +++ b/src/api/domain/user.api.server.ts @@ -0,0 +1,4 @@ +import { privateApi } from '~/api/config/privateApi.server'; +import { UserInfoResponse } from '~/types/user'; + +export const getUserInfoServer = () => privateApi.get(`/user/profile`); diff --git a/src/app/my-page/[communityId]/layout.tsx b/src/app/my-page/[communityId]/layout.tsx new file mode 100644 index 00000000..e52eccff --- /dev/null +++ b/src/app/my-page/[communityId]/layout.tsx @@ -0,0 +1,33 @@ +'use client'; +import { useRouter } from 'next/navigation'; +import { PropsWithChildren } from 'react'; + +import { BottomNavigation } from '~/components/BottomNavigation'; +import { GearFillIcon } from '~/components/Icon'; +import { TopNavigation } from '~/components/TopNavigation'; +import { PlanetSelector } from '~/modules/PlanetSelector'; + +const Layout = ({ children }: PropsWithChildren) => { + const router = useRouter(); + + const onClickGearFill = () => { + router.push('/my-page/config'); + }; + return ( +
+ + + + + + + + + + {children} + +
+ ); +}; + +export default Layout; diff --git a/src/app/my-page/config/layout.tsx b/src/app/my-page/config/layout.tsx new file mode 100644 index 00000000..d7af42e0 --- /dev/null +++ b/src/app/my-page/config/layout.tsx @@ -0,0 +1,24 @@ +import { PropsWithChildren } from 'react'; + +import { BottomNavigation } from '~/components/BottomNavigation'; +import { TopNavigation } from '~/components/TopNavigation'; + +const Layout = ({ children }: PropsWithChildren) => { + return ( +
+ + + + + +

설정

+
+ +
+ {children} + +
+ ); +}; + +export default Layout; diff --git a/src/app/my-page/config/page.tsx b/src/app/my-page/config/page.tsx index 91eee444..090760aa 100644 --- a/src/app/my-page/config/page.tsx +++ b/src/app/my-page/config/page.tsx @@ -1,31 +1,22 @@ import 'server-only'; -import { getCommunityList } from '~/api/domain/community.api'; +import { getCommunityListServer } from '~/api/domain/community.api.server'; +import { getUserInfoServer } from '~/api/domain/user.api.server'; import { Divider } from '~/components/Divider'; -import { TopNavigation } from '~/components/TopNavigation'; import { PlanetMenu } from '~/modules/PlanetMenu'; import { UserMenu } from '~/modules/UserMenu'; export const dynamic = 'force-dynamic'; const MyPageConfig = async () => { - // TODO: userId 수정 필요 - const userId = 1; + const { userProfileDto } = await getUserInfoServer(); - const { communityListDtos } = await getCommunityList(userId); + const { communityListDtos } = await getCommunityListServer(userProfileDto.userId); const isBelongToCommunity = communityListDtos.length !== 0; return (
- - - - - -

설정

-
-
{isBelongToCommunity && ( <> diff --git a/src/app/my-page/layout.tsx b/src/app/my-page/layout.tsx index e52eccff..d15755ae 100644 --- a/src/app/my-page/layout.tsx +++ b/src/app/my-page/layout.tsx @@ -1,29 +1,10 @@ -'use client'; -import { useRouter } from 'next/navigation'; import { PropsWithChildren } from 'react'; import { BottomNavigation } from '~/components/BottomNavigation'; -import { GearFillIcon } from '~/components/Icon'; -import { TopNavigation } from '~/components/TopNavigation'; -import { PlanetSelector } from '~/modules/PlanetSelector'; const Layout = ({ children }: PropsWithChildren) => { - const router = useRouter(); - - const onClickGearFill = () => { - router.push('/my-page/config'); - }; return (
- - - - - - - - - {children}
diff --git a/src/modules/IdCard/IdCard.client.tsx b/src/modules/IdCard/IdCard.client.tsx index 719e88b7..13229858 100644 --- a/src/modules/IdCard/IdCard.client.tsx +++ b/src/modules/IdCard/IdCard.client.tsx @@ -36,7 +36,8 @@ export const IdCard = ({ const pathname = usePathname(); const handleClickIdCard = () => { - router.push(`${pathname}/id-card/${idCardId}`); + const planetIdPathname = pathname.replace('/id-card/create', ''); + router.push(`${planetIdPathname}/id-card/${idCardId}`); }; return ( diff --git a/src/modules/IdCardCreation/IdCardCreationSteps.tsx b/src/modules/IdCardCreation/IdCardCreationSteps.tsx index e4cb0508..8851a8b6 100644 --- a/src/modules/IdCardCreation/IdCardCreationSteps.tsx +++ b/src/modules/IdCardCreation/IdCardCreationSteps.tsx @@ -1,17 +1,22 @@ 'use client'; import { yupResolver } from '@hookform/resolvers/yup'; +import { usePathname, useRouter } from 'next/navigation'; import { useState } from 'react'; import { FormProvider, useForm } from 'react-hook-form'; import * as yup from 'yup'; import { usePostIdCardCreate } from '~/api/domain/idCard.api'; +import { useGetUserInfo } from '~/api/domain/user.api'; import { IdCardCreationForm } from '~/modules/IdCardCreation/Form'; import { BoardingStep, CompleteStep } from '~/modules/IdCardCreation/Step'; +import { useToastMessageStore } from '~/stores/toastMessage.store'; import { IdCardCreationFormModel } from '~/types/idCard'; import { CreationSteps } from './IdCardCreation.type'; +const INIT_STEP = 0; + const steps: CreationSteps[] = ['BOARDING', 'PROFILE', 'KEYWORD', 'KEYWORD_CONTENT', 'COMPLETE']; const schema = yup.object({ @@ -27,10 +32,15 @@ type IdCardCreationStepsProps = { }; export const IdCardCreationSteps = ({ communityId }: IdCardCreationStepsProps) => { + const { errorToast } = useToastMessageStore(); + const { data } = useGetUserInfo(); + const profileImageUrl = data?.userProfileDto.profileImageUrl; + const router = useRouter(); + const pathname = usePathname(); const methods = useForm({ defaultValues: { communityId, - profileImageUrl: '', + profileImageUrl, nickname: '', aboutMe: '', keywords: [], @@ -40,7 +50,7 @@ export const IdCardCreationSteps = ({ communityId }: IdCardCreationStepsProps) = }); const [userId, setUserId] = useState(); - const [stepOrder, setStepOrder] = useState(0); + const [stepOrder, setStepOrder] = useState(INIT_STEP); const onNext = () => setStepOrder(stepOrder + 1); const onPrev = () => setStepOrder(stepOrder - 1); @@ -48,6 +58,13 @@ export const IdCardCreationSteps = ({ communityId }: IdCardCreationStepsProps) = onSuccess: data => { setUserId(data.id); }, + onError: error => { + errorToast(error.message); + setTimeout(() => { + const planetIdPathname = pathname.replace('/id-card/create', ''); + router.push(`${planetIdPathname}`); + }, 2000); + }, }); const onSubmit = () => {