Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add title of community and characterType of user on complete step of creating id card #257

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/api/domain/idCard.api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useMutation, UseMutationOptions, useQuery, useQueryClient } from '@tanstack/react-query';
import {
useMutation,
UseMutationOptions,
useQuery,
useQueryClient,
UseQueryOptions,
} from '@tanstack/react-query';
import { AxiosError } from 'axios';

import privateApi from '~/api/config/privateApi';
Expand All @@ -18,6 +24,16 @@ export const idCardQueryKey = {
export const getIdCardDetail = (idCardId: number) =>
privateApi.get<IdCardDetailResponse>(`/id-cards/${idCardId}`);

export const useGetIdCardDetail = (
idCardId: number,
options?: UseQueryOptions<IdCardDetailResponse>,
) =>
useQuery<IdCardDetailResponse>(
idCardQueryKey.idCards(idCardId),
() => getIdCardDetail(idCardId),
options,
);

export const getCommunityMyIdCardDetail = (communityId: number) =>
privateApi.get<CommunityMyIdCardDetailResponse>(`/communities/${communityId}/users/idCards`);

Expand Down
6 changes: 3 additions & 3 deletions src/modules/IdCardCreation/IdCardCreationSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ export const IdCardCreationSteps = ({ communityId }: IdCardCreationStepsProps) =
mode: 'onChange',
resolver: yupResolver(schema),
});
const [userId, setUserId] = useState<number>();
const [idCardId, setIdCardId] = useState<number>();

const [stepOrder, setStepOrder] = useState<number>(INIT_STEP);
const onNext = () => setStepOrder(stepOrder + 1);
const onPrev = () => setStepOrder(stepOrder - 1);

const { mutateAsync } = usePostIdCardCreate({
onSuccess: data => {
setUserId(data.id);
setIdCardId(data.id);
},
onError: error => {
errorToast(error.message);
Expand Down Expand Up @@ -88,7 +88,7 @@ export const IdCardCreationSteps = ({ communityId }: IdCardCreationStepsProps) =
onSubmit={onSubmit}
/>
)}
{steps[stepOrder] === 'COMPLETE' && userId && <CompleteStep userId={userId} />}
{steps[stepOrder] === 'COMPLETE' && idCardId && <CompleteStep idCardId={idCardId} />}
</div>
</FormProvider>
);
Expand Down
34 changes: 19 additions & 15 deletions src/modules/IdCardCreation/Step/CompleteStep.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,46 @@ import Link from 'next/link';
import { useParams, useRouter } from 'next/navigation';
import { useFormContext } from 'react-hook-form';

import { useGetCommunityDetail } from '~/api/domain/community.api';
import { useGetIdCardDetail } from '~/api/domain/idCard.api';
import { Button } from '~/components/Button';
import { IdCard } from '~/modules/IdCard/IdCard.client';
import { IdCardCreationFormModel } from '~/types/idCard';

const title = 'planet이름';

type CompleteStepProps = {
userId: number;
idCardId: number;
};

export const CompleteStep = ({ userId }: CompleteStepProps) => {
export const CompleteStep = ({ idCardId }: CompleteStepProps) => {
const { getValues } = useFormContext<IdCardCreationFormModel>();
const values = getValues();
const { nickname, aboutMe, keywords } = values;
const keywordTitles = keywords.map(keyword => keyword.title);
const router = useRouter();
const { communityId } = useParams();
const { data: idCardDetail } = useGetIdCardDetail(idCardId);
const { data: communityDetail } = useGetCommunityDetail(Number(communityId));

const onMoveToCommunity = () => {
router.push(`/planet/${communityId}`);
};

return (
// TODO: 지금은 커뮤니티 정보가 없는데 나중에 커뮤니티 타이틀 추가
<div className="flex min-h-[calc(100vh-50px)] flex-col px-layout-sm ">
<h2 className="text-h1 text-grey-900">{`짜잔!${title} \n주민증이 발급되었어요!`}</h2>
<h2 className="text-h1 text-grey-900">{`짜잔!${
communityDetail?.communityDetailsDto.title || ''
} \n주민증이 발급되었어요!`}</h2>
<div className="mt-24pxr flex flex-1 flex-col">
<IdCard
idCardId={userId}
aboutMe={aboutMe}
keywordTitles={keywordTitles}
nickname={nickname}
// TODO: 로그인 할때 캐릭터 타입 정보 넣어서 가져오기
characterType="TOBBY"
/>
<Link href={`/planet/${communityId}/id-card/${userId}`}>
{idCardDetail && (
<IdCard
idCardId={idCardId}
aboutMe={aboutMe}
keywordTitles={keywordTitles}
nickname={nickname}
characterType={idCardDetail.idCardDetailsDto.characterType}
/>
)}
<Link href={`/planet/${communityId}/id-card/${idCardId}`}>
<p className="my-52px flex w-full flex-1 items-center justify-center text-center text-b1 text-primary-500">
주민증을 눌러보세요!
</p>
Expand Down