From 71622bd76820476f46c734cbb8fb387b4349687c Mon Sep 17 00:00:00 2001
From: Savien/Woo Jun Han <49388937+MrMirror21@users.noreply.github.com>
Date: Sat, 26 Oct 2024 17:42:00 +0900
Subject: [PATCH] =?UTF-8?q?:sparkles:=20feat:=20=EC=9E=91=EC=84=B1?=
=?UTF-8?q?=EB=90=9C=20=EB=AC=B8=EC=84=9C=20=EC=88=98=EC=A0=95=20=EA=B8=B0?=
=?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84=20#54?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/document.ts | 1 -
.../IntegratedApplicationWriteForm.tsx | 33 +++++++++++--------
.../WriteDocuments/LaborContractWriteForm.tsx | 33 ++++++++++++-------
.../PartTimePermitWriteForm.tsx | 31 +++++++++++------
4 files changed, 63 insertions(+), 35 deletions(-)
diff --git a/src/api/document.ts b/src/api/document.ts
index ea014e6d..a8dae3cd 100644
--- a/src/api/document.ts
+++ b/src/api/document.ts
@@ -5,7 +5,6 @@ import {
SearchSchoolResponse,
} from '@/types/api/document';
import { api } from '.';
-import { PartTimePermitFormRequest } from '../types/api/document';
//시간제 취업허가서 작성 api 통신 함수
export const postPartTimeEmployPermit = async ({
diff --git a/src/components/WriteDocuments/IntegratedApplicationWriteForm.tsx b/src/components/WriteDocuments/IntegratedApplicationWriteForm.tsx
index d9c062a9..6fc287e3 100644
--- a/src/components/WriteDocuments/IntegratedApplicationWriteForm.tsx
+++ b/src/components/WriteDocuments/IntegratedApplicationWriteForm.tsx
@@ -70,8 +70,8 @@ const IntegratedApplicationWriteForm = ({
const { searchAddress } = useSearchAddress({
onSuccess: (data) => setAddressSearchResult(data),
});
- const { mutate } = usePostIntegratedApplicants(); // 통합신청서 생성 훅
-
+ const { mutate: postDocument } = usePostIntegratedApplicants(); // 통합신청서 생성 훅
+ const { mutate: updateDocument } = usePostIntegratedApplicants(); // 통합신청서 수정 훅
// 문서 편집일 시 페이지 진입과 동시에 기존 내용 자동 입력
useEffect(() => {
if (isEdit && document) {
@@ -155,16 +155,23 @@ const IntegratedApplicationWriteForm = ({
// 문서 작성 완료 핸들러 함수
const handleNext = () => {
- mutate({
+ const finalDocument = {
+ ...newDocumentData,
+ birth: newDocumentData.birth.replace(/\//g, '.'),
+ tele_phone_number: formatPhoneNumber(phoneNum),
+ cell_phone_number: formatPhoneNumber(cellPhoneNum),
+ school_phone_number: formatPhoneNumber(schoolPhoneNum),
+ };
+ const payload = {
id: 1,
- document: {
- ...newDocumentData,
- birth: newDocumentData.birth.replace(/\//g, '.'),
- tele_phone_number: formatPhoneNumber(phoneNum),
- cell_phone_number: formatPhoneNumber(cellPhoneNum),
- school_phone_number: formatPhoneNumber(schoolPhoneNum),
- },
- }); // TODO: 로그인 연결 후 userId를 넣어야 하는 것으로 추정
+ document: finalDocument, // TODO: 로그인 연결 후 userId를 넣어야 하는 것으로 추정
+ };
+
+ if (isEdit) {
+ updateDocument(payload);
+ return;
+ }
+ postDocument(payload);
};
return (
@@ -581,7 +588,7 @@ const IntegratedApplicationWriteForm = ({
bgColor="bg-[#fef387]"
fontColor="text-[#222]"
isBorder={false}
- title="Create"
+ title={isEdit ? 'Modify' : 'Create'}
onClick={handleNext}
/>
) : (
@@ -590,7 +597,7 @@ const IntegratedApplicationWriteForm = ({
bgColor="bg-[#F4F4F9]"
fontColor=""
isBorder={false}
- title="Create"
+ title={isEdit ? 'Modify' : 'Create'}
/>
)}
diff --git a/src/components/WriteDocuments/LaborContractWriteForm.tsx b/src/components/WriteDocuments/LaborContractWriteForm.tsx
index c30fe435..2a92ad75 100644
--- a/src/components/WriteDocuments/LaborContractWriteForm.tsx
+++ b/src/components/WriteDocuments/LaborContractWriteForm.tsx
@@ -19,7 +19,10 @@ import BottomButtonPanel from '@/components/Common/BottomButtonPanel';
import Button from '@/components/Common/Button';
import SignaturePad from '@/components/Document/write/SignaturePad';
import EmployerInfoSection from '@/components/Document/write/EmployerInfoSection';
-import { usePostStandardLaborContracts } from '@/hooks/api/useDocument';
+import {
+ usePostStandardLaborContracts,
+ usePutStandardLaborContracts,
+} from '@/hooks/api/useDocument';
type LaborContractFormProps = {
document?: LaborContractDataResponse;
@@ -55,8 +58,9 @@ const LaborContractWriteForm = ({
const { searchAddress } = useSearchAddress({
onSuccess: (data) => setAddressSearchResult(data),
});
- // 작성된 근로계약서 제출 훅
- const { mutate } = usePostStandardLaborContracts();
+
+ const { mutate: postDocument } = usePostStandardLaborContracts(); // 작성된 근로계약서 제출 훅
+ const { mutate: updateDocument } = usePutStandardLaborContracts(); // 수정된 근로계약서 제출 훅
// 문서 편집일 시 페이지 진입과 동시에 기존 내용 자동 입력
useEffect(() => {
if (isEdit && document) {
@@ -147,13 +151,20 @@ const LaborContractWriteForm = ({
// 문서 작성 완료 핸들러 함수
const handleNext = () => {
- mutate({
+ const finalDocument = {
+ ...newDocumentData,
+ phone_number: formatPhoneNumber(phoneNum),
+ };
+ const payload = {
id: 1,
- document: {
- ...newDocumentData,
- phone_number: formatPhoneNumber(phoneNum),
- },
- }); // TODO: 로그인 연결 후 userId를 넣어야 하는 것으로 추정
+ document: finalDocument, // TODO: 로그인 연결 후 userId를 넣어야 하는 것으로 추정
+ };
+
+ if (isEdit) {
+ updateDocument(payload);
+ return;
+ }
+ postDocument(payload);
};
return (
@@ -348,7 +359,7 @@ const LaborContractWriteForm = ({
bgColor="bg-[#fef387]"
fontColor="text-[#222]"
isBorder={false}
- title="Next"
+ title={isEdit ? 'Modify' : 'Create'}
onClick={handleNext}
/>
) : (
@@ -357,7 +368,7 @@ const LaborContractWriteForm = ({
bgColor="bg-[#F4F4F9]"
fontColor=""
isBorder={false}
- title="Next"
+ title={isEdit ? 'Modify' : 'Create'}
/>
)}
diff --git a/src/components/WriteDocuments/PartTimePermitWriteForm.tsx b/src/components/WriteDocuments/PartTimePermitWriteForm.tsx
index 1ac418b4..199d8de2 100644
--- a/src/components/WriteDocuments/PartTimePermitWriteForm.tsx
+++ b/src/components/WriteDocuments/PartTimePermitWriteForm.tsx
@@ -14,7 +14,10 @@ import BottomButtonPanel from '@/components/Common/BottomButtonPanel';
import Button from '@/components/Common/Button';
import { isNotEmpty } from '@/utils/document';
import { formatPhoneNumber } from '@/utils/information';
-import { usePostPartTimeEmployPermit } from '@/hooks/api/useDocument';
+import {
+ usePostPartTimeEmployPermit,
+ usePutPartTimeEmployPermit,
+} from '@/hooks/api/useDocument';
type PartTimePermitFormProps = {
document?: PartTimePermitData;
@@ -27,7 +30,8 @@ const PartTimePermitWriteForm = ({
}: PartTimePermitFormProps) => {
const [newDocumentData, setNewDocumentData] =
useState
(initialPartTimePermitForm);
- const { mutate } = usePostPartTimeEmployPermit();
+ const { mutate: postDocument } = usePostPartTimeEmployPermit(); // 작성된 문서 제출 훅
+ const { mutate: updateDocument } = usePutPartTimeEmployPermit(); // 수정된 문서 제출 훅
// 세 부분으로 나누어 입력받는 방식을 위해 전화번호만 별도의 state로 분리, 추후 유효성 검사 단에서 통합
const [phoneNum, setPhoneNum] = useState({
start: '',
@@ -50,13 +54,20 @@ const PartTimePermitWriteForm = ({
// 문서 작성 완료 핸들러 함수
const handleNext = () => {
- mutate({
+ const finalDocument = {
+ ...newDocumentData,
+ phone_number: formatPhoneNumber(phoneNum),
+ };
+ const payload = {
id: 1,
- document: {
- ...newDocumentData,
- phone_number: formatPhoneNumber(phoneNum),
- },
- }); // TODO: 로그인 연결 후 userId를 넣어야 하는 것으로 추정
+ document: finalDocument, // TODO: 로그인 연결 후 userId를 넣어야 하는 것으로 추정
+ };
+
+ if (isEdit) {
+ updateDocument(payload);
+ return;
+ }
+ postDocument(payload);
};
return (
@@ -214,7 +225,7 @@ const PartTimePermitWriteForm = ({
bgColor="bg-[#fef387]"
fontColor="text-[#222]"
isBorder={false}
- title="Next"
+ title={isEdit ? 'Modify' : 'Create'}
onClick={handleNext}
/>
) : (
@@ -223,7 +234,7 @@ const PartTimePermitWriteForm = ({
bgColor="bg-[#F4F4F9]"
fontColor=""
isBorder={false}
- title="Next"
+ title={isEdit ? 'Modify' : 'Create'}
/>
)}