Skip to content

Commit

Permalink
✨ feat: 작성된 문서 수정 기능 구현 #54
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMirror21 committed Oct 26, 2024
1 parent d8a95d7 commit 71622bd
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 35 deletions.
1 change: 0 additions & 1 deletion src/api/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
SearchSchoolResponse,
} from '@/types/api/document';
import { api } from '.';
import { PartTimePermitFormRequest } from '../types/api/document';

//시간제 취업허가서 작성 api 통신 함수
export const postPartTimeEmployPermit = async ({
Expand Down
33 changes: 20 additions & 13 deletions src/components/WriteDocuments/IntegratedApplicationWriteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 (
<div className="w-full p-6 flex flex-col">
Expand Down Expand Up @@ -581,7 +588,7 @@ const IntegratedApplicationWriteForm = ({
bgColor="bg-[#fef387]"
fontColor="text-[#222]"
isBorder={false}
title="Create"
title={isEdit ? 'Modify' : 'Create'}
onClick={handleNext}
/>
) : (
Expand All @@ -590,7 +597,7 @@ const IntegratedApplicationWriteForm = ({
bgColor="bg-[#F4F4F9]"
fontColor=""
isBorder={false}
title="Create"
title={isEdit ? 'Modify' : 'Create'}
/>
)}
</BottomButtonPanel>
Expand Down
33 changes: 22 additions & 11 deletions src/components/WriteDocuments/LaborContractWriteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 (
<div className="w-full p-6 flex flex-col">
Expand Down Expand Up @@ -348,7 +359,7 @@ const LaborContractWriteForm = ({
bgColor="bg-[#fef387]"
fontColor="text-[#222]"
isBorder={false}
title="Next"
title={isEdit ? 'Modify' : 'Create'}
onClick={handleNext}
/>
) : (
Expand All @@ -357,7 +368,7 @@ const LaborContractWriteForm = ({
bgColor="bg-[#F4F4F9]"
fontColor=""
isBorder={false}
title="Next"
title={isEdit ? 'Modify' : 'Create'}
/>
)}
</BottomButtonPanel>
Expand Down
31 changes: 21 additions & 10 deletions src/components/WriteDocuments/PartTimePermitWriteForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +30,8 @@ const PartTimePermitWriteForm = ({
}: PartTimePermitFormProps) => {
const [newDocumentData, setNewDocumentData] =
useState<PartTimePermitFormRequest>(initialPartTimePermitForm);
const { mutate } = usePostPartTimeEmployPermit();
const { mutate: postDocument } = usePostPartTimeEmployPermit(); // 작성된 문서 제출 훅
const { mutate: updateDocument } = usePutPartTimeEmployPermit(); // 수정된 문서 제출 훅
// 세 부분으로 나누어 입력받는 방식을 위해 전화번호만 별도의 state로 분리, 추후 유효성 검사 단에서 통합
const [phoneNum, setPhoneNum] = useState({
start: '',
Expand All @@ -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 (
<div className="w-full p-6 flex flex-col">
Expand Down Expand Up @@ -214,7 +225,7 @@ const PartTimePermitWriteForm = ({
bgColor="bg-[#fef387]"
fontColor="text-[#222]"
isBorder={false}
title="Next"
title={isEdit ? 'Modify' : 'Create'}
onClick={handleNext}
/>
) : (
Expand All @@ -223,7 +234,7 @@ const PartTimePermitWriteForm = ({
bgColor="bg-[#F4F4F9]"
fontColor=""
isBorder={false}
title="Next"
title={isEdit ? 'Modify' : 'Create'}
/>
)}
</BottomButtonPanel>
Expand Down

0 comments on commit 71622bd

Please sign in to comment.