-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 게시글 수정 버튼을 클릭하면, state의 mode를 변경하는 방식으로 설정.같은 /posting 경로에서 State를 create모드와 modify 모드로 분리. - 게시글 수정 시 postId를 기반으로 postData를 호출해오는 API 함수 getPostById 작성 -Posting.jsx 에서 게시글을 수정하는 useEffect작성 ref : #18
- Loading branch information
1 parent
a7ade43
commit 13267ae
Showing
5 changed files
with
117 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
// utils/validationHelper.js | ||
export const validateForm = (payload, formData) => { | ||
const requiredFields = { | ||
"제목": payload.postData.title, | ||
"하는 일": payload.postData.workType, | ||
"일하는 기간": formData.workPeriod, | ||
"일하는 요일": formData.workDays, | ||
"일하는 시간": formData.workTime?.start && formData.workTime?.end, | ||
"급여": formData.pay, | ||
"일하는 장소": formData.workLocation, | ||
"업체명": payload.storeName, | ||
"연락처": payload.postData.applyNumber, | ||
}; | ||
|
||
for (const [label, value] of Object.entries(requiredFields)) { | ||
if ( | ||
value === undefined || | ||
value === null || | ||
(typeof value === "string" && value.trim() === "") || | ||
(Array.isArray(value) && value.length === 0) || | ||
value === false | ||
) { | ||
alert(`${label}을(를) 입력해주세요.`); | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
const requiredFields = { | ||
"제목": payload.postData.title, | ||
"하는 일": payload.postData.workType, | ||
"일하는 기간": formData.workPeriod, | ||
"일하는 요일": formData.workDays, | ||
"일하는 시간": formData.workTime?.start && formData.workTime?.end, | ||
"급여": formData.pay, | ||
"일하는 장소": formData.workLocation, | ||
"업체명": payload.storeName, | ||
"연락처": payload.postData.applyNumber, | ||
}; | ||
|
||
const missingFields = Object.entries(requiredFields) | ||
.filter(([_, value]) => | ||
value === undefined || | ||
value === null || | ||
(typeof value === "string" && value.trim() === "") || | ||
(Array.isArray(value) && value.length === 0) || | ||
value === false | ||
) | ||
.map(([label]) => label); | ||
|
||
if (missingFields.length > 0) { | ||
alert(`다음 항목을 입력해주세요: ${missingFields.join(", ")}`); | ||
return false; // 유효성 검증 실패 | ||
} | ||
|
||
return true; // 유효성 검증 성공 | ||
}; |