-
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.
Merge pull request #50 from team-crews/feat/goonco
[Fix] Fix left trivial issues
- Loading branch information
Showing
9 changed files
with
138 additions
and
125 deletions.
There are no files selected for viewing
64 changes: 34 additions & 30 deletions
64
src/app/apply/[recruitmentCode]/_hooks/use-choice-map.tsx
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
113 changes: 55 additions & 58 deletions
113
src/app/apply/[recruitmentCode]/_hooks/use-section-selection.tsx
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,58 +1,55 @@ | ||
import { UseFormClearErrors } from 'react-hook-form'; | ||
import { useEffect, useState } from 'react'; | ||
import { getInitialSectionSelection } from '../_utils/utils'; | ||
import { SHARED_SECTION_INDEX } from '../page'; | ||
import { z } from 'zod'; | ||
import { RecruitmentSchema } from '../../../../lib/types/schemas/recruitment-schema.ts'; | ||
import { ApplicationDetailSchema } from '../../../../lib/types/schemas/application-schema.ts'; | ||
|
||
type UseSectionSelectionParams = { | ||
recruitment?: z.infer<typeof RecruitmentSchema>; | ||
application?: z.infer<typeof ApplicationDetailSchema>; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
clearErrors: UseFormClearErrors<any>; | ||
}; | ||
|
||
export const useSectionSelection = ({ | ||
recruitment, | ||
application, | ||
clearErrors, | ||
}: UseSectionSelectionParams) => { | ||
// 공통 섹션 | ||
const sharedSection = recruitment?.sections[SHARED_SECTION_INDEX]; | ||
|
||
// 초기 focus 섹션 index | ||
const initialSectionSelections = getInitialSectionSelection( | ||
application?.sections, | ||
recruitment?.sections, | ||
); | ||
|
||
// 선택된 섹션 index | ||
const [selectedSectionIndex, setSelectedSectionIndex] = useState<number>( | ||
initialSectionSelections, | ||
); | ||
|
||
// 선택된 섹션 | ||
const selectedSection = recruitment?.sections[selectedSectionIndex]; | ||
const isOnlySharedSection = recruitment?.sections.length === 1; | ||
|
||
useEffect(() => { | ||
setSelectedSectionIndex(initialSectionSelections); | ||
}, [initialSectionSelections]); | ||
|
||
const handleSectionSelectionChange = (index: number) => { | ||
setSelectedSectionIndex(index); | ||
|
||
// 선택된 섹션 변경 시, 에러 메시지 초기화 | ||
clearErrors(`sections.${selectedSectionIndex}.answers`); | ||
}; | ||
|
||
return { | ||
sharedSection, | ||
selectedSectionIndex, | ||
selectedSection, | ||
isOnlySharedSection, | ||
handleSectionSelectionChange, | ||
}; | ||
}; | ||
/* | ||
FixMe | ||
- 필요없다고 완전히 판단되면 제거 | ||
*/ | ||
|
||
// type UseSectionSelectionParams = { | ||
// recruitment?: z.infer<typeof RecruitmentSchema>; | ||
// application?: z.infer<typeof ApplicationDetailSchema>; | ||
// | ||
// // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
// clearErrors: UseFormClearErrors<any>; | ||
// }; | ||
|
||
// export const useSectionSelection = ({ | ||
// recruitment, | ||
// application, | ||
// clearErrors, | ||
// }: UseSectionSelectionParams) => { | ||
// // 공통 섹션 | ||
// const sharedSection = recruitment?.sections[SHARED_SECTION_INDEX]; | ||
// | ||
// // 초기 focus 섹션 index | ||
// const initialSectionSelections = getInitialSectionSelection( | ||
// application?.sections, | ||
// recruitment?.sections, | ||
// ); | ||
// | ||
// // 선택된 섹션 index | ||
// const [selectedSectionIndex, setSelectedSectionIndex] = useState<number>( | ||
// initialSectionSelections, | ||
// ); | ||
// | ||
// // 선택된 섹션 | ||
// const selectedSection = recruitment?.sections[selectedSectionIndex]; | ||
// const isOnlySharedSection = recruitment?.sections.length === 1; | ||
// | ||
// useEffect(() => { | ||
// setSelectedSectionIndex(initialSectionSelections); | ||
// }, [initialSectionSelections]); | ||
// | ||
// const handleSectionSelectionChange = (index: number) => { | ||
// setSelectedSectionIndex(index); | ||
// | ||
// // 선택된 섹션 변경 시, 에러 메시지 초기화 | ||
// clearErrors(`sections.${selectedSectionIndex}.answers`); | ||
// }; | ||
// | ||
// return { | ||
// sharedSection, | ||
// selectedSectionIndex, | ||
// selectedSection, | ||
// isOnlySharedSection, | ||
// handleSectionSelectionChange, | ||
// }; | ||
// }; |
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
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