Skip to content

Commit

Permalink
주민증 생성 boadring페이지, 주민증이 없는 경우 마이페이지에 접근했을 때 처리 (#260)
Browse files Browse the repository at this point in the history
* refactor: 주민증 생성 boadring페이지에 뒤로가기 버튼

* feat: checkIdCardServer

* feat: CreateIdCardButton

* refactor: MyPage

주민증이 없는 경우 마이페이지에 접근했을 때 처리

* refactor: EmptyPlanet에서 PlanetCreationButton 분리
  • Loading branch information
kimyouknow authored Jul 6, 2023
1 parent 03ef3f7 commit 4a28344
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 91 deletions.
4 changes: 4 additions & 0 deletions src/api/domain/community.api.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
CheckIdCardResponse,
CommunityDetailResponse,
CommunityIdCardsRequest,
CommunityIdCardsResponse,
Expand All @@ -24,3 +25,6 @@ export const getCommunityIdCardsServer = ({

export const getCommunityListServer = (userId: number) =>
privateApi.get<CommunityListResponse>(`/communities/users/${userId}`);

export const checkIdCardServer = (communityId: number) =>
privateApi.get<CheckIdCardResponse>(`/communities/${communityId}/users`);
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,40 @@ import { Suspense } from 'react';
import { getCommunityMyIdCardDetailServer } from '~/api/domain/idCard.api.server';
import RetryErrorBoundary from '~/components/ErrorBoundary/RetryErrorBoundary.client';
import { IdCard } from '~/modules/IdCard';
import { IdCardEditButton } from '~/modules/IdCardEditButton';

type MyPageProps = {
id: number;
communityId: number;
};

const MyPageIdCardComponent = async ({ id }: MyPageProps) => {
const { idCardDetailsDto } = await getCommunityMyIdCardDetailServer(id);
const MyPageIdCardComponent = async ({ communityId }: MyPageProps) => {
const { idCardDetailsDto } = await getCommunityMyIdCardDetailServer(communityId);
const { idCardId, nickname, aboutMe, characterType, keywords } = idCardDetailsDto;
const keywordTitles = keywords.map(keyword => keyword.title);

return (
<IdCard
idCardId={idCardId}
nickname={nickname}
aboutMe={aboutMe}
characterType={characterType}
keywordTitles={keywordTitles}
/>
<div>
<div className="mb-16pxr flex w-full justify-between">
<h2 className="text-h3 text-grey-800">내 주민증</h2>
<IdCardEditButton />
</div>
<IdCard
idCardId={idCardId}
nickname={nickname}
aboutMe={aboutMe}
characterType={characterType}
keywordTitles={keywordTitles}
/>
</div>
);
};

export const MyPageIdCard = ({ id }: MyPageProps) => {
export const MyPageIdCard = ({ communityId }: MyPageProps) => {
return (
<RetryErrorBoundary>
<Suspense>
{/* @ts-expect-error Server Component */}
<MyPageIdCardComponent id={id} />
<MyPageIdCardComponent communityId={communityId} />
</Suspense>
</RetryErrorBoundary>
);
Expand Down
15 changes: 8 additions & 7 deletions src/app/my-page/[communityId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'server-only';

import Link from 'next/link';

import { checkIdCardServer } from '~/api/domain/community.api.server';
import { MyPageIdCard } from '~/app/my-page/[communityId]/components/MyPageIdCard';
import { BottomNavigation } from '~/components/BottomNavigation';
import { GearFillIcon } from '~/components/Icon';
import { TopNavigation } from '~/components/TopNavigation';
import { IdCardEditButton } from '~/modules/IdCardEditButton';
import { CreateIdCardButton } from '~/modules/CreateIdCardButton';
import { PlanetCreationButton } from '~/modules/PlanetCreationButton';
import { PlanetSelector } from '~/modules/PlanetSelector';

Expand All @@ -14,7 +17,9 @@ type MyPageProps = {
};
};

const MyPage = ({ params: { communityId } }: MyPageProps) => {
const MyPage = async ({ params: { communityId } }: MyPageProps) => {
const { userMakeIdCard } = await checkIdCardServer(communityId);
const isUserMakeIdCard = userMakeIdCard;
return (
<div>
<TopNavigation bottomBorderColor="bg-grey-100">
Expand All @@ -29,11 +34,7 @@ const MyPage = ({ params: { communityId } }: MyPageProps) => {
</TopNavigation>
<main className="pt-35pxr">
<div className="mx-layout-l">
<div className="mb-16pxr flex w-full justify-between">
<h2 className="text-h3 text-grey-800">내 주민증</h2>
<IdCardEditButton />
</div>
<MyPageIdCard id={communityId} />
{isUserMakeIdCard ? <MyPageIdCard communityId={communityId} /> : <CreateIdCardButton />}
</div>
<div className="mx-layout-sm mt-28pxr">
<PlanetCreationButton />
Expand Down
32 changes: 4 additions & 28 deletions src/app/my-page/empty/page.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
'use client';
import Link from 'next/link';
import { useRouter } from 'next/navigation';

import { BottomNavigation } from '~/components/BottomNavigation';
import { GearFillIcon, PlusIcon } from '~/components/Icon';
import { GearFillIcon } from '~/components/Icon';
import { TopNavigation } from '~/components/TopNavigation';
import { CreateIdCardButton } from '~/modules/CreateIdCardButton';
import { PlanetCreationButton } from '~/modules/PlanetCreationButton';
import { PlanetSelector } from '~/modules/PlanetSelector';
import { useCommunityStore } from '~/stores/community.store';

const EmptyPlanet = () => {
const { communityId } = useCommunityStore();
const router = useRouter();

// TODO: communityId가 없는 경우 에러 처리가 필요해요( ex. 홈이나 다른 페이지로 보내기)
const onClickCreateIdCardButton = () => {
router.replace(`/planet/${communityId}/id-card/create`);
};

return (
<div>
<TopNavigation bottomBorderColor="bg-grey-100">
<TopNavigation.Left>
<PlanetSelector />
</TopNavigation.Left>
<TopNavigation.Left></TopNavigation.Left>
<TopNavigation.Right>
<Link href="/my-page/config">
<GearFillIcon />
Expand All @@ -32,18 +19,7 @@ const EmptyPlanet = () => {
</TopNavigation>
<main className="pt-35pxr">
<div className="mx-layout-l">
<h1 className="text-h3 text-grey-800">내 주민증</h1>
<div className="mt-16pxr flex h-[404px] w-full items-center justify-center rounded-[16px] border border-dashed border-primary-500 bg-blue-100">
<div className="flex flex-col items-center gap-8pxr">
<button
onClick={onClickCreateIdCardButton}
className="flex h-[52px] w-[52px] items-center justify-center rounded-full bg-blue-200"
>
<PlusIcon className="fill-primary-500 stroke-2" />
</button>
<span className="text-b1 text-primary-500">주민증 만들기</span>
</div>
</div>
<CreateIdCardButton />
</div>
<div className="mx-layout-sm mt-28pxr">
<PlanetCreationButton />
Expand Down
31 changes: 31 additions & 0 deletions src/modules/CreateIdCardButton/CreateIdCardButton.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use client';
import { useRouter } from 'next/navigation';

import { PlusIcon } from '~/components/Icon';
import { useCommunityStore } from '~/stores/community.store';

export const CreateIdCardButton = () => {
const { communityId } = useCommunityStore();
const router = useRouter();

// TODO: communityId가 없는 경우 에러 처리가 필요해요( ex. 홈이나 다른 페이지로 보내기)
const onClickCreateIdCardButton = () => {
router.replace(`/planet/${communityId}/id-card/create`);
};
return (
<div>
<h1 className="text-h3 text-grey-800">내 주민증</h1>
<div className="mt-16pxr flex h-[404px] w-full items-center justify-center rounded-[16px] border border-dashed border-primary-500 bg-blue-100">
<div className="flex flex-col items-center gap-8pxr">
<button
onClick={onClickCreateIdCardButton}
className="flex h-[52px] w-[52px] items-center justify-center rounded-full bg-blue-200"
>
<PlusIcon className="fill-primary-500 stroke-2" />
</button>
<span className="text-b1 text-primary-500">주민증 만들기</span>
</div>
</div>
</div>
);
};
17 changes: 17 additions & 0 deletions src/modules/CreateIdCardButton/CreateIdCardButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Meta, StoryObj } from '@storybook/react';

import { CreateIdCardButton } from './index';

const meta: Meta<typeof CreateIdCardButton> = {
title: 'modules/CreateIdCardButton',
component: CreateIdCardButton,
args: {},
};

export default meta;

type Story = StoryObj<typeof CreateIdCardButton>;

export const Primary: Story = {
render: () => <CreateIdCardButton />,
};
1 change: 1 addition & 0 deletions src/modules/CreateIdCardButton/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CreateIdCardButton.client';
98 changes: 54 additions & 44 deletions src/modules/IdCardCreation/Step/BoardingStep.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Image from 'next/image';
import BottomSheet, { useBottomSheet } from '~/components/BottomSheet';
import { Button, TextButton } from '~/components/Button';
import { QuestionCircleIcon } from '~/components/Icon';
import { TopNavigation } from '~/components/TopNavigation';

type BoardingStepProps = {
onNext: VoidFunction;
Expand All @@ -17,56 +18,65 @@ export const BoardingStep = ({ onNext }: BoardingStepProps) => {
};

return (
<div className="px-layout-sm">
<h1 className="text-h2 text-grey-900">주민증으로 나를 소개해요!</h1>
<p className="mt-12pxr text-b1 text-grey-700">
{`주민증에 담기는 내용을 언제든지\n수정할 수 있어요.`}
</p>
<div className="pb-32pxr">
<div className="flex flex-col items-center justify-center">
<Image
src="/assets/images/id_card_creation.png"
alt="explain id card"
object-fit="contain"
object-position="center"
width={375}
height={375}
/>
<TextButton className="mt-36pxr flex gap-4pxr" onClick={() => onClickHelperText()}>
<QuestionCircleIcon />
<span className="text-b3 text-grey-600">어떻게 수정하나요?</span>
</TextButton>
</div>
</div>
<Button color="primary" size="large" onClick={onNext} className="mt-45pxr">
주민증 만들기
</Button>
<BottomSheet {...bottomSheetHandlers}>
<BottomSheet.Header>주민증 수정</BottomSheet.Header>
<BottomSheet.Content>
<div className="flex w-full flex-col items-center justify-center">
<div>
<TopNavigation>
<TopNavigation.Left>
<TopNavigation.BackButton />
</TopNavigation.Left>
</TopNavigation>
<main className="px-layout-sm">
<h1 className="text-h2 text-grey-900">주민증으로 나를 소개해요!</h1>
<p className="mt-12pxr text-b1 text-grey-700">
{`주민증에 담기는 내용을 언제든지\n수정할 수 있어요.`}
</p>
<div className="pb-32pxr">
<div className="flex flex-col items-center justify-center">
<Image
src="/assets/images/memo.png"
src="/assets/images/id_card_creation.png"
alt="explain id card"
object-fit="contain"
object-position="center"
width={160}
height={160}
width={375}
height={375}
/>
<span className="text-b1 text-grey-700">마이페이지에서 주민증을 수정할 수 있어요.</span>
<TextButton className="mt-36pxr flex gap-4pxr" onClick={() => onClickHelperText()}>
<QuestionCircleIcon />
<span className="text-b3 text-grey-600">어떻게 수정하나요?</span>
</TextButton>
</div>
</BottomSheet.Content>
<BottomSheet.Footer>
<BottomSheet.Footer.Button
onClick={bottomSheetHandlers.onClose}
size="large"
color="primary"
className="text-white"
>
확인했어요.
</BottomSheet.Footer.Button>
</BottomSheet.Footer>
</BottomSheet>
</div>
<Button color="primary" size="large" onClick={onNext} className="mt-45pxr">
주민증 만들기
</Button>
<BottomSheet {...bottomSheetHandlers}>
<BottomSheet.Header>주민증 수정</BottomSheet.Header>
<BottomSheet.Content>
<div className="flex w-full flex-col items-center justify-center">
<Image
src="/assets/images/memo.png"
alt="explain id card"
object-fit="contain"
object-position="center"
width={160}
height={160}
/>
<span className="text-b1 text-grey-700">
마이페이지에서 주민증을 수정할 수 있어요.
</span>
</div>
</BottomSheet.Content>
<BottomSheet.Footer>
<BottomSheet.Footer.Button
onClick={bottomSheetHandlers.onClose}
size="large"
color="primary"
className="text-white"
>
확인했어요.
</BottomSheet.Footer.Button>
</BottomSheet.Footer>
</BottomSheet>
</main>
</div>
);
};

0 comments on commit 4a28344

Please sign in to comment.