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

feat-fe: 공고폼 임시 저장 기능 구현 #954

Merged
merged 15 commits into from
Dec 28, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: 기능 구현 스코프 정리 및 마킹
lurgi committed Dec 17, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 782e262898b7bfde05460814282e1866dd4a5b85
2 changes: 2 additions & 0 deletions frontend/src/components/recruitmentPost/ApplyForm/index.tsx
Original file line number Diff line number Diff line change
@@ -27,13 +27,15 @@ export default function ApplyForm({ questions, isClosed }: ApplyFormProps) {
const { data: recruitmentPost } = applyQueries.useGetRecruitmentPost({ applyFormId: applyFormId ?? '' });
const { mutate: apply } = applyMutations.useApply(applyFormId, recruitmentPost?.title ?? '');

// TODO: useForm은 input으로 initialValues제공해야 한다. 따라서 SideEffect를 피하기 위해선 useForm외부에서 localStorage를 별도로 저장해야 한다.
const {
formData: applicant,
register,
hasErrors,
} = useForm<ApplicantData>({
initialValues: { name: '', email: '', phone: '' },
});

const { answers, changeHandler, isRequiredFieldsIncomplete } = useAnswers(questions);
const [personalDataCollection, setPersonalDataCollection] = useState(false);

28 changes: 16 additions & 12 deletions frontend/src/components/recruitmentPost/ApplyForm/useAnswers.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { Question } from '@customTypes/apply';
import { useEffect, useState } from 'react';
import { useState } from 'react';

interface AnswerFormData {
[key: string]: string[];
}

export const useAnswers = (questions: Question[]) => {
const [answers, setAnswers] = useState<AnswerFormData>({});

useEffect(() => {
if (questions.length > 0) {
const initialAnswers = questions.reduce(
(acc, question) => ({ ...acc, [question.questionId]: [] }),
{} as AnswerFormData,
);
setAnswers(initialAnswers);
}
}, [questions]);
// const [answers, setAnswers] = useState<AnswerFormData>({});
// TODO: useLocalStorageState() 사용하기
const [answers, setAnswers] = useState<AnswerFormData>(
questions.reduce((acc, question) => ({ ...acc, [question.questionId]: [] }), {} as AnswerFormData),
);

// useEffect(() => {
// if (questions.length > 0) {
// const initialAnswers = questions.reduce(
// (acc, question) => ({ ...acc, [question.questionId]: [] }),
// {} as AnswerFormData,
// );
// setAnswers(initialAnswers);
// }
// }, [questions]);

const handleText = (id: string, value: string) => {
setAnswers((prev) => ({ ...prev, [id]: [value] }));
1 change: 1 addition & 0 deletions frontend/src/hooks/useDashboardCreateForm/index.tsx
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@ const initialRecruitmentInfoState: RecruitmentInfoState = {
};

export default function useDashboardCreateForm(): UseDashboardCreateFormReturn {
// TODO: useLocalStorageState() 사용하기
const [stepState, setStepState] = useState<StepState>('recruitmentForm');
const [recruitmentInfoState, setRecruitmentInfoState] = useState<RecruitmentInfoState>(initialRecruitmentInfoState);
const [applyState, setApplyState] = useState<Question[]>(DEFAULT_QUESTIONS);