Skip to content

Commit 7612a98

Browse files
authored
Merge pull request #120 from FE9-2/feat/albaform/edit
Feat : alba/edit ์•Œ๋ฐ”ํผ ์ˆ˜์ • ํŽ˜์ด์ง€
2 parents 41134eb + a3c1e67 commit 7612a98

File tree

26 files changed

+424
-147
lines changed

26 files changed

+424
-147
lines changed

โ€Žsrc/app/(pages)/(albaform)/addform/page.tsxโ€Ž

Lines changed: 38 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,28 @@
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";
44
import { FormProvider, useForm } from "react-hook-form";
55
import axios from "axios";
66
import TabMenuDropdown from "@/app/components/button/dropdown/TabMenuDropdown";
77
import Button from "@/app/components/button/default/Button";
88
import { toast } from "react-hot-toast";
99
import { useMutation } from "@tanstack/react-query";
1010
import { 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-
}
3717
export 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"

src/app/(pages)/(albaform)/addform/RecruitConditionSection.tsx renamed to src/app/(pages)/(albaform)/addform/section/RecruitConditionSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22
import { useFormContext } from "react-hook-form";
3-
import Label from "../Label";
43
import InputDropdown from "@/app/components/button/dropdown/InputDropdown";
4+
import Label from "../../component/Label";
55

66
// ์•Œ๋ฐ”ํผ ๋งŒ๋“ค๊ธฐ - ์‚ฌ์žฅ๋‹˜- 2-๋ชจ์ง‘์กฐ๊ฑด
77
export default function RecruitConditionSection() {

src/app/(pages)/(albaform)/addform/RecruitContentSection.tsx renamed to src/app/(pages)/(albaform)/addform/section/RecruitContentSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
"use client";
2-
import Label from "../Label";
32
import BaseInput from "@/app/components/input/text/BaseInput";
43
import BaseTextArea from "@/app/components/input/textarea/BaseTextArea";
54
import ImageInput from "@/app/components/input/file/ImageInput/ImageInput";
65
import DatePickerInput from "@/app/components/input/dateTimeDaypicker/DatePickerInput";
76
import { cn } from "@/lib/tailwindUtil";
87
import { useFormContext } from "react-hook-form";
98
import { useEffect, useState } from "react";
9+
import Label from "../../component/Label";
1010

1111
// ์•Œ๋ฐ”ํผ ๋งŒ๋“ค๊ธฐ - ์‚ฌ์žฅ๋‹˜ - 1-๋ชจ์ง‘๋‚ด์šฉ
1212

src/app/(pages)/(albaform)/addform/WorkConditionSection.tsx renamed to src/app/(pages)/(albaform)/addform/section/WorkConditionSection.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import { useFormContext } from "react-hook-form";
44
import { useState, ChangeEvent, MouseEvent, useEffect } from "react";
5-
import Label from "../Label";
65
import { cn } from "@/lib/tailwindUtil";
76
import DatePickerInput from "@/app/components/input/dateTimeDaypicker/DatePickerInput";
87
import LocationInput from "@/app/components/input/text/LocationInput";
98
import TimePickerInput from "@/app/components/input/dateTimeDaypicker/TimePickerInput";
109
import DayPickerList from "@/app/components/input/dateTimeDaypicker/DayPickerList";
1110
import BaseInput from "@/app/components/input/text/BaseInput";
1211
import CheckBtn from "@/app/components/button/default/CheckBtn";
12+
import formatMoney from "@/utils/formatMoney";
13+
import Label from "../../component/Label";
1314

1415
// ์•Œ๋ฐ”ํผ ๋งŒ๋“ค๊ธฐ - ์‚ฌ์žฅ๋‹˜ - 3-๊ทผ๋ฌด์กฐ๊ฑด
1516
export default function WorkConditionSection() {
@@ -56,15 +57,6 @@ export default function WorkConditionSection() {
5657
// ์‹œ๊ธ‰ ์ƒํƒœ ์ถ”๊ฐ€
5758
const [displayWage, setDisplayWage] = useState<string>("");
5859

59-
const formatNumber = (value: string) => {
60-
let numericValue = value.replaceAll(/,/g, "");
61-
if (numericValue.startsWith("0")) {
62-
numericValue = numericValue.slice(1);
63-
}
64-
const formatNumber = numericValue.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
65-
return formatNumber;
66-
};
67-
6860
// ๋ฆฌ์•กํŠธ ํ›…ํผ ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ€์ ธ์™€์„œ ๋ Œ๋”๋ง
6961
useEffect(() => {
7062
const selectedDays = getValues("workDays") || [];
@@ -150,7 +142,7 @@ export default function WorkConditionSection() {
150142
const value = e.target.value;
151143
const numericValue = Number(value.replace(/,/g, ""));
152144
setValue("hourlyWage", numericValue); // ์ฝค๋งˆ ์ œ๊ฑฐํ•˜๊ณ  ์ˆซ์žํ˜•์œผ๋กœ ์ €์žฅ
153-
setDisplayWage(formatNumber(value));
145+
setDisplayWage(formatMoney(value));
154146
}}
155147
variant="white"
156148
afterString="์›"

0 commit comments

Comments
ย (0)