Skip to content

Commit

Permalink
feat: home 파트별 소개 validation 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiacho committed Dec 31, 2024
1 parent d9892c1 commit 817107e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/org/OrgAdmin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { Group } from './types';
import {
validationAboutInputs,
validationCommonInputs,
validationHomeInputs,
validationRecruitInputs,
} from './utils';

Expand Down Expand Up @@ -74,9 +75,14 @@ function OrgAdmin() {
setIntroPart(part);
};

const handleValidateHomeInputs = () =>
validationHomeInputs(getValues, setError, onChangeIntroPart);

const onSubmit: SubmitHandler<FieldValues> = (data) => {
const handleValidateCommonInputs = () =>
validationCommonInputs(getValues, setError, setGroup);
const handleValidateHomeInputs = () =>
validationHomeInputs(getValues, setError, onChangeIntroPart);
const handleValidationAboutInputs = () =>
validationAboutInputs(
getValues,
Expand All @@ -94,19 +100,27 @@ function OrgAdmin() {

const validationFlow = {
공통: [
handleValidateCommonInputs,
handleValidateHomeInputs,
handleValidationAboutInputs,
handleValidationRecruitInputs,
],
: [
handleValidateHomeInputs,
handleValidateCommonInputs,
handleValidationAboutInputs,
handleValidationRecruitInputs,
],
: [],
소개: [
handleValidationAboutInputs,
handleValidateCommonInputs,
handleValidateHomeInputs,
handleValidationRecruitInputs,
],
지원하기: [
handleValidationRecruitInputs,
handleValidateCommonInputs,
handleValidateHomeInputs,
handleValidationAboutInputs,
],
};
Expand All @@ -117,6 +131,7 @@ function OrgAdmin() {
if (validateFn === handleValidateCommonInputs) return '공통';
if (validateFn === handleValidationAboutInputs) return '소개';
if (validateFn === handleValidationRecruitInputs) return '지원하기';
if (validateFn === handleValidateHomeInputs) return '홈';
return '공통';
};

Expand Down
21 changes: 21 additions & 0 deletions src/components/org/OrgAdmin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ export const validationCommonInputs = (
return true;
};

export const validationHomeInputs = (
getValues: (payload?: string | string[]) => FieldValues,
setError: (name: string, error: { type: string; message: string }) => void,
onChangeIntroPart: (part: PART_KO) => void,
) => {
for (const part of PART_LIST) {
const name = `partIntroduction${part}`;
const data = getValues(name);
if (!data) {
console.log(part, data);
setError(name, {
type: 'required',
message: VALIDATION_CHECK.required.errorText,
});
onChangeIntroPart(part);
return false;
}
}
return true;
};

export const validationAboutInputs = (
getValues: (payload?: string | string[]) => FieldValues,
setError: (name: string, error: { type: string; message: string }) => void,
Expand Down

0 comments on commit 817107e

Please sign in to comment.