Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] 홈 탭 - 파트별 소개 validation #188

Merged
merged 3 commits into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 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 @@ -77,6 +78,8 @@ function OrgAdmin() {
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 +97,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 +128,7 @@ function OrgAdmin() {
if (validateFn === handleValidateCommonInputs) return '공통';
if (validateFn === handleValidationAboutInputs) return '소개';
if (validateFn === handleValidationRecruitInputs) return '지원하기';
if (validateFn === handleValidateHomeInputs) return '홈';
return '공통';
};

Expand Down
20 changes: 20 additions & 0 deletions src/components/org/OrgAdmin/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ 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) {
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
Loading