11"use client" ;
2- import { useState } from "react" ;
3- import { useRouter , useSearchParams } from "next/navigation" ;
2+ import { useEffect , useState } from "react" ;
3+ import { useParams , useRouter , useSearchParams } from "next/navigation" ;
44import { FormProvider , useForm } from "react-hook-form" ;
55import axios from "axios" ;
66import TabMenuDropdown from "@/app/components/button/dropdown/TabMenuDropdown" ;
77import Button from "@/app/components/button/default/Button" ;
88import { toast } from "react-hot-toast" ;
99import { useMutation } from "@tanstack/react-query" ;
1010import { useUpdateProfile } from "@/hooks/queries/user/me/useUpdateProfile" ;
11- import RecruitContentSection from "./RecruitContentSection" ;
12- import RecruitConditionSection from "./RecruitConditionSection" ;
13- import WorkConditionSection from "./WorkConditionSection" ;
11+ import RecruitContentSection from "./section/RecruitContentSection" ;
12+ import RecruitConditionSection from "./section/RecruitConditionSection" ;
13+ import WorkConditionSection from "./section/WorkConditionSection" ;
14+ import useEditing from "@/hooks/useEditing" ;
15+ import { SubmitFormDataType } from "@/types/addform" ;
1416
15- interface SubmitFormDataType {
16- isPublic : boolean ;
17- hourlyWage : number ;
18- isNegotiableWorkDays : boolean ;
19- workDays : string [ ] ;
20- workEndTime : string ;
21- workStartTime : string ;
22- workEndDate : string ;
23- workStartDate : string ;
24- location : string ;
25- preferred : string ;
26- age : string ;
27- education : string ;
28- gender : string ;
29- numberOfPositions : number ;
30- imageUrls : string [ ] ;
31- recruitmentEndDate : string | undefined ;
32- recruitmentStartDate : string | undefined ;
33- description : string ;
34- title : string ;
35- imageFiles : File [ ] ;
36- }
3717export default function AddFormPage ( ) {
3818 const router = useRouter ( ) ;
39-
19+ const formId = useParams ( ) . formId ;
4020 // ๋ฆฌ์กํธ ํ
ํผ์์ ๊ด๋ฆฌํ ๋ฐ์ดํฐ ํ์
์ง์ ๋ฐ ๋ฉ์๋ ํธ์ถ (์์ ์ปดํฌ๋ํธ = useForm ์ฌ์ฉ)
4121 const methods = useForm < SubmitFormDataType > ( {
4222 mode : "onChange" ,
4323 defaultValues : {
4424 isPublic : false ,
45- hourlyWage : 0 ,
25+ hourlyWage : 10030 ,
4626 isNegotiableWorkDays : false ,
4727 workDays : [ ] ,
4828 workEndTime : "" ,
@@ -75,7 +55,7 @@ export default function AddFormPage() {
7555
7656 // ์ด๋ฏธ์ง ์
๋ก๋ api ์ฒ๋ฆฌ๋ฅผ ์ํด ๋ณ๋ ๋ณ์์ ํ ๋น
7757 const imageFiles = currentValues . imageFiles ;
78- const [ selectedOption , setSelectedOption ] = useState ( "๋ชจ์ง ๋ด์ฉ ") ;
58+ const [ , setSelectedOption ] = useState < string > ( " ") ;
7959
8060 // ํผ ์ ์ถ ๋ฆฌ์กํธ์ฟผ๋ฆฌ
8161 const mutation = useMutation ( {
@@ -91,24 +71,20 @@ export default function AddFormPage() {
9171 acc [ key ] = Number ( value ) ;
9272 } else if ( key === "hourlyWage" ) {
9373 // hourlyWage๋ ์ผํ๋ฅผ ์ ๊ฑฐํ๊ณ ์ซ์ํ์ผ๋ก ๋ณํ
94- acc [ key ] = Number ( value . replaceAll ( / , / g, "" ) ) ; // ์ผํ ์ ๊ฑฐ ํ ์ซ์ํ ๋ณํ
74+ if ( value . includes ( "," ) ) acc [ key ] = Number ( value . replaceAll ( / , / g, "" ) ) ; // ์ผํ ์ ๊ฑฐ ํ ์ซ์ํ ๋ณํ
9575 } else {
9676 acc [ key as keyof SubmitFormDataType ] = value ; // ๋๋จธ์ง ๊ฐ์ ๊ทธ๋๋ก ์ถ๊ฐ
9777 }
9878 return acc ;
9979 } , { } ) ;
100- await axios . post ( "/api/forms" , filteredData , {
101- headers : {
102- "Content-Type" : "application/json" ,
103- } ,
104- } ) ;
80+ await axios . post ( "/api/forms" , filteredData ) ;
10581 } ,
10682 onSuccess : ( ) => {
10783 if ( typeof window !== "undefined" ) {
10884 window . localStorage . removeItem ( "tempAddFormData" ) ;
10985 }
11086 toast . success ( "์๋ฐํผ์ ๋ฑ๋กํ์ต๋๋ค." ) ;
111- router . back ( ) ; // -> ์ถํ ์์ธ ํ์ด์ง ์ด๋์ผ๋ก ์์ ํ ๊ฒ
87+ router . push ( `/alba/ ${ formId } ` ) ;
11288 } ,
11389 onError : ( error ) => {
11490 console . error ( "์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค." , error ) ;
@@ -137,16 +113,32 @@ export default function AddFormPage() {
137113 router . push ( `/addform?tab=${ params } ` ) ;
138114 } ;
139115
116+ useEffect ( ( ) => {
117+ switch ( currentParam ) {
118+ case "recruit-content" :
119+ setSelectedOption ( "๋ชจ์ง ๋ด์ฉ" ) ;
120+ break ;
121+ case "recruit-condition" :
122+ setSelectedOption ( "๋ชจ์ง ์กฐ๊ฑด" ) ;
123+ break ;
124+ case "work-condition" :
125+ setSelectedOption ( "๊ทผ๋ฌด ์กฐ๊ฑด" ) ;
126+ break ;
127+ default :
128+ setSelectedOption ( "๋ชจ์ง ๋ด์ฉ" ) ;
129+ }
130+ } , [ currentParam ] ) ;
131+
140132 const renderChildren = ( ) => {
141- switch ( selectedOption ) {
142- case "๋ชจ์ง ๋ด์ฉ " :
133+ switch ( currentParam ) {
134+ case "recruit-content " :
143135 return < RecruitContentSection key = "recruitContent" /> ;
144- case "๋ชจ์ง ์กฐ๊ฑด " :
136+ case "recruit-condition " :
145137 return < RecruitConditionSection key = "recruitCondition" /> ;
146- case "๊ทผ๋ฌด ์กฐ๊ฑด " :
138+ case "work-condition " :
147139 return < WorkConditionSection key = "workCondition" /> ;
148140 default :
149- return < > < /> ;
141+ return < RecruitContentSection key = "recruitContent" /> ;
150142 }
151143 } ;
152144 const { uploadImageMutation } = useUpdateProfile ( ) ;
@@ -207,29 +199,11 @@ export default function AddFormPage() {
207199 } ;
208200
209201 // ๊ฐ๊ฐ์ ํญ ์์ฑ์ค ์ฌ๋ถ
210- const isEditingRecruitContent =
211- currentValues . title !== "" || currentValues . description !== "" || currentValues . recruitmentStartDate !== undefined
212- ? true
213- : false ;
214- const isEditingRecruitCondition =
215- currentValues . gender !== "" ||
216- currentValues . numberOfPositions !== 0 ||
217- currentValues . education !== "" ||
218- currentValues . age !== "" ||
219- currentValues . preferred !== ""
220- ? true
221- : false ;
222- const isEditingWorkCondition =
223- currentValues . location !== "" ||
224- currentValues . workStartTime !== "" ||
225- currentValues . workStartDate !== "" ||
226- currentValues . hourlyWage > 0
227- ? true
228- : false ;
202+ const { isEditingRecruitContent, isEditingRecruitCondition, isEditingWorkCondition } = useEditing ( currentValues ) ;
229203
230204 return (
231205 < FormProvider { ...methods } >
232- < div className = "relative" >
206+ < div className = "relative pb-10 lg:pb-0 " >
233207 < aside className = "flex flex-col items-center justify-between rounded-[24px] bg-background-200 lg:fixed lg:left-[108px] lg:top-[64px] lg:m-10 lg:h-[80vh] lg:p-10" >
234208 < TabMenuDropdown
235209 options = { [
@@ -241,8 +215,9 @@ export default function AddFormPage() {
241215 { label : "๊ทผ๋ฌด ์กฐ๊ฑด" , isEditing : isEditingWorkCondition || currentParam === "work-condition" } ,
242216 ] }
243217 onChange = { handleOptionChange }
218+ currentParam = { currentParam || "" }
244219 />
245- < div className = "absolute -bottom-[160px] flex flex-col gap-2 lg:relative lg:bottom-0" >
220+ < div className = "absolute -bottom-[160px] mb-20 flex flex-col gap-2 lg:relative lg:bottom-0 lg:mb -0" >
246221 < Button
247222 type = "button"
248223 variant = "outlined"
0 commit comments