|
1 | | -import type { Metadata } from 'next' |
2 | | -import Link from 'next/link' |
3 | | -import { notFound } from 'next/navigation' |
4 | | -import { DocumentPencilIcon, DocumentDiamondIcon } from '@/assets/icons' |
| 1 | +'use client' |
5 | 2 |
|
6 | | -const validKinds = ['paper', 'interview', 'activity'] as const |
| 3 | +import { Suspense, useEffect, useState } from 'react' |
| 4 | +import { notFound, redirect } from 'next/navigation' |
| 5 | +import { |
| 6 | + FormFactory, |
| 7 | + isValidFormKind, |
| 8 | + type FormKind, |
| 9 | +} from '@/components/pages/review/new/forms' |
| 10 | +import AppPath from '@/shared/configs/appPath' |
| 11 | +import { useAuth } from '@/shared/providers/auth-provider' |
7 | 12 |
|
8 | | -export async function generateMetadata({ |
9 | | - params, |
10 | | -}: { |
| 13 | +interface PageProps { |
11 | 14 | params: Promise<{ kind: string }> |
12 | | -}): Promise<Metadata> { |
13 | | - const { kind } = await params |
14 | | - const isValidKind = (validKinds as readonly string[]).includes(kind) |
| 15 | +} |
15 | 16 |
|
16 | | - if (!isValidKind) { |
17 | | - return { |
18 | | - title: '페이지를 찾을 수 없습니다', |
19 | | - } |
20 | | - } |
| 17 | +export default function Page({ params }: PageProps) { |
| 18 | + const { user, isLoading } = useAuth() |
| 19 | + const [formKind, setFormKind] = useState<FormKind | null>(null) |
21 | 20 |
|
22 | | - const getKindDisplayName = (kind: string) => { |
23 | | - switch (kind) { |
24 | | - case 'paper': |
25 | | - return '서류' |
26 | | - case 'interview': |
27 | | - return '인터뷰/면접' |
28 | | - case 'activity': |
29 | | - return '활동' |
30 | | - default: |
31 | | - return kind |
32 | | - } |
33 | | - } |
| 21 | + useEffect(() => { |
| 22 | + async function loadParams() { |
| 23 | + const { kind } = await params |
34 | 24 |
|
35 | | - const kindName = getKindDisplayName(kind) |
| 25 | + if (!isValidFormKind(kind)) { |
| 26 | + notFound() |
| 27 | + } |
36 | 28 |
|
37 | | - return { |
38 | | - title: `${kindName} 후기 작성`, |
39 | | - description: `IT 동아리 ${kindName} 후기를 작성해보세요. 일반 후기와 프리미엄 후기 중 선택하여 경험을 공유하고 다른 분들에게 도움을 주세요.`, |
40 | | - keywords: [`IT 동아리 ${kindName} 후기`, '동아리 후기 작성', '경험 공유'], |
41 | | - openGraph: { |
42 | | - title: `${kindName} 후기 작성 | 모여잇`, |
43 | | - description: `IT 동아리 ${kindName} 후기를 작성해보세요. 일반 후기와 프리미엄 후기 중 선택하여 경험을 공유하고 다른 분들에게 도움을 주세요.`, |
44 | | - }, |
45 | | - } |
46 | | -} |
| 29 | + setFormKind(kind as FormKind) |
| 30 | + } |
47 | 31 |
|
48 | | -export default async function Page({ |
49 | | - params, |
50 | | -}: { |
51 | | - params: Promise<{ kind: string }> |
52 | | -}) { |
53 | | - const { kind } = await params |
54 | | - const isValidKind = (validKinds as readonly string[]).includes(kind) |
55 | | - if (!isValidKind) { |
56 | | - notFound() |
57 | | - } |
| 32 | + loadParams() |
| 33 | + }, [params]) |
58 | 34 |
|
59 | | - const getKindDisplayName = (kind: string) => { |
60 | | - switch (kind) { |
61 | | - case 'paper': |
62 | | - return '서류' |
63 | | - case 'interview': |
64 | | - return '인터뷰/면접' |
65 | | - case 'activity': |
66 | | - return '활동' |
67 | | - default: |
68 | | - return kind |
| 35 | + useEffect(() => { |
| 36 | + if (!isLoading && !user) { |
| 37 | + redirect(AppPath.login()) |
69 | 38 | } |
70 | | - } |
| 39 | + }, [user, isLoading]) |
71 | 40 |
|
72 | | - return ( |
73 | | - <main className="w-full h-full"> |
74 | | - <div className="max-w-[530px] h-full mx-auto flex flex-col items-center justify-center"> |
75 | | - {/* 제목 */} |
76 | | - <div className="text-center mb-8"> |
77 | | - <h2 className="typo-title-1 text-black-color mb-8"> |
78 | | - {getKindDisplayName(kind)} 후기 작성 |
79 | | - </h2> |
| 41 | + if (isLoading || !user) { |
| 42 | + return ( |
| 43 | + <main className=""> |
| 44 | + <div className="max-w-[800px] mx-auto pt-20"> |
| 45 | + <div className="text-center"> |
| 46 | + <p className="typo-body-2-r text-grey-color-4">로딩 중...</p> |
| 47 | + </div> |
80 | 48 | </div> |
| 49 | + </main> |
| 50 | + ) |
| 51 | + } |
81 | 52 |
|
82 | | - {/* 카드 컨테이너 */} |
83 | | - <div className="p-6 rounded-2xl bg-white-color flex flex-col gap-8 items-center w-[530px] shadow-sm"> |
84 | | - <p className="typo-body-2-sb text-grey-color-4"> |
85 | | - 작성하실 후기 스타일을 선택해주세요 |
86 | | - </p> |
87 | | - <div className="w-full flex flex-col gap-4"> |
88 | | - {/* 일반 후기 카드 */} |
89 | | - <Link href={`/review/new/${kind}/normal`}> |
90 | | - <div className="w-full p-6 border border-gray-200 rounded-xl cursor-pointer group"> |
91 | | - <div className="flex items-center space-x-4"> |
92 | | - <div className="flex-shrink-0"> |
93 | | - <DocumentPencilIcon role="img" aria-label="일반 후기" /> |
94 | | - </div> |
95 | | - <div className="flex-1"> |
96 | | - <h3 className="typo-body-3-b text-black-color mb-1"> |
97 | | - 일반 후기 |
98 | | - </h3> |
99 | | - <p className="typo-button-m text-grey-color-3"> |
100 | | - 짧고 간단한 3분 후기 작성하기 |
101 | | - </p> |
102 | | - </div> |
103 | | - </div> |
104 | | - </div> |
105 | | - </Link> |
106 | | - {/* 프리미엄 후기 카드 */} |
107 | | - <Link href={`/review/new/${kind}/premium`}> |
108 | | - <div className="w-full p-6 border border-gray-200 rounded-xl cursor-pointer group"> |
109 | | - <div className="flex items-center space-x-4"> |
110 | | - <div className="flex-shrink-0"> |
111 | | - <DocumentDiamondIcon |
112 | | - role="img" |
113 | | - aria-label="프리미엄 후기" |
114 | | - /> |
115 | | - </div> |
116 | | - <div className="flex-1"> |
117 | | - <h3 className="typo-body-3-b text-black-color mb-1"> |
118 | | - 프리미엄 후기 |
119 | | - </h3> |
120 | | - <p className="typo-button-m text-grey-color-3"> |
121 | | - 가이드 따라 상세 후기 작성하고 기프티콘 혜택 받기 |
122 | | - </p> |
123 | | - </div> |
124 | | - </div> |
125 | | - </div> |
126 | | - </Link> |
| 53 | + if (!formKind) { |
| 54 | + return ( |
| 55 | + <main className=""> |
| 56 | + <div className="max-w-[800px] mx-auto pt-20"> |
| 57 | + <div className="text-center"> |
| 58 | + <p className="typo-body-2-r text-grey-color-4">로딩 중...</p> |
127 | 59 | </div> |
128 | 60 | </div> |
129 | | - </div> |
| 61 | + </main> |
| 62 | + ) |
| 63 | + } |
| 64 | + |
| 65 | + return ( |
| 66 | + <main className=""> |
| 67 | + <Suspense> |
| 68 | + <div className="max-w-[800px] mx-auto pt-20 pb-20"> |
| 69 | + <FormFactory kind={formKind} /> |
| 70 | + </div> |
| 71 | + </Suspense> |
130 | 72 | </main> |
131 | 73 | ) |
132 | 74 | } |
0 commit comments