|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useParams } from "next/navigation"; |
| 4 | +import { useUserFormDetail } from "@/hooks/queries/form/userFormDetail"; |
| 5 | +import React, { useEffect, useState } from "react"; |
| 6 | +import CardChipIcon from "@/app/components/card/cardList/CardChipIcon"; |
| 7 | +import Chip from "@/app/components/chip/Chip"; |
| 8 | + |
| 9 | +export default function AlbaFormDetailPage() { |
| 10 | + const { formId } = useParams(); // useParams๋ก formId ์ถ์ถ |
| 11 | + const [formIdState, setFormIdState] = useState<number>(0); |
| 12 | + |
| 13 | + useEffect(() => { |
| 14 | + // formId๊ฐ ๋ฌธ์์ด๋ก ์ ๋ฌ๋๋ฏ๋ก ์ซ์๋ก ๋ณํํ์ฌ ์ํ์ ์ ์ฅ |
| 15 | + if (formId) { |
| 16 | + setFormIdState(Number(formId)); // formId๋ฅผ ์ซ์๋ก ๋ณํํ์ฌ ์ํ์ ์ ์ฅ |
| 17 | + } |
| 18 | + }, [formId]); |
| 19 | + |
| 20 | + // formId๊ฐ ์ค์ ๋๋ฉด useUserFormDetail ํธ์ถ |
| 21 | + const { data, isLoading, error } = useUserFormDetail({ formId: formIdState }); |
| 22 | + |
| 23 | + if (isLoading) { |
| 24 | + return <div>Loading...</div>; |
| 25 | + } |
| 26 | + |
| 27 | + if (error) { |
| 28 | + return <div>Error: ๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ค๋๋ฐ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค.</div>; |
| 29 | + } |
| 30 | + |
| 31 | + if (!data) { |
| 32 | + return <div>๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค.</div>; |
| 33 | + } |
| 34 | + |
| 35 | + // ๋ชจ์ง ์ํ ๊ณ์ฐ |
| 36 | + const recruitmentStatus = new Date(data.recruitmentEndDate) > new Date() ? "๋ชจ์ง์ค" : "๋ชจ์ง์๋ฃ"; |
| 37 | + |
| 38 | + return ( |
| 39 | + <div className="container flex min-h-screen flex-col"> |
| 40 | + <div className="h-[562px] bg-black-100">์ฌ์ง์์ญ</div> |
| 41 | + <div> |
| 42 | + <div className="mt-20 w-[770px] space-y-10"> |
| 43 | + <div className="flex items-center"> |
| 44 | + <Chip label={data.isPublic ? "๊ณต๊ฐ" : "๋น๊ณต๊ฐ"} variant={data.isPublic ? "positive" : "negative"} /> |
| 45 | + <Chip label={recruitmentStatus} variant="positive" /> |
| 46 | + <p className="text-sm text-grayscale-500">{new Date(data.createdAt).toLocaleString()} ๋ฑ๋ก</p> |
| 47 | + </div> |
| 48 | + <div className="mb-4 flex gap-4"> |
| 49 | + <span className="text-base text-black-400 underline">{data.storeName || "๊ฐ๊ฒ๋ช
"}</span> |
| 50 | + <span className="text-grayscale-500"> |
| 51 | + {data.location || "์์น"} ใป {"๊ฒฝ๋ ฅ ์ ๋ณด ์์"} |
| 52 | + </span> |
| 53 | + </div> |
| 54 | + <p className="text-3xl font-bold">{data.title}</p> |
| 55 | + <CardChipIcon |
| 56 | + formData={{ |
| 57 | + updatedAt: new Date(data.updatedAt), |
| 58 | + createdAt: new Date(data.createdAt), |
| 59 | + isPublic: data.isPublic, |
| 60 | + scrapCount: data.scrapCount, |
| 61 | + applyCount: data.applyCount, |
| 62 | + imageUrls: data.imageUrls, |
| 63 | + recruitmentEndDate: new Date(data.recruitmentEndDate), |
| 64 | + recruitmentStartDate: new Date(data.recruitmentStartDate), |
| 65 | + title: data.title, |
| 66 | + id: data.id, |
| 67 | + }} |
| 68 | + /> |
| 69 | + <div className="text-2xl">{data.description}</div> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + ); |
| 74 | +} |
0 commit comments