22
33import { usePathname , useRouter } from 'next/navigation' ;
44import { useEffect , useState } from 'react' ;
5- import { FormProvider } from 'react-hook-form' ;
5+ import { FormProvider , useWatch } from 'react-hook-form' ;
66
77import { emptySubTitle } from '@/app/my-posts/components/MyPostsTable/MyPostsTable.css' ;
88import { emptyViewLayout } from '@/app/post/[postId]/desktop/components/ExperimentPostContainer/ExperimentPostContainer.css' ;
@@ -31,12 +31,12 @@ const EditExperimentPost = ({ params }: { params: { postId: string } }) => {
3131
3232 const [ addLink , setAddLink ] = useState < boolean > ( false ) ;
3333 const [ addContact , setAddContact ] = useState < boolean > ( false ) ;
34+ const [ isOnCampus , setIsOnCampus ] = useState < boolean > ( true ) ;
3435
3536 const [ openSubmitAlertDialog , setOpenSubmitAlertDialog ] = useState < boolean > ( false ) ;
3637 const [ openUpdateAlertModal , setOpenUpdateAlertModal ] = useState < boolean > ( false ) ;
3738
3839 const [ images , setImages ] = useState < ( File | string ) [ ] > ( [ ] ) ;
39-
4040 const [ errorMessage , setErrorMessage ] = useState < string > ( '' ) ;
4141
4242 const { form, handleSubmit, isLoading, applyMethodData, isRecruitStatus, originExperimentError } =
@@ -45,17 +45,23 @@ const EditExperimentPost = ({ params }: { params: { postId: string } }) => {
4545 postId : params . postId ,
4646 addLink,
4747 addContact,
48+ isOnCampus,
4849 setOpenAlertModal : setOpenSubmitAlertDialog ,
4950 images,
5051 setImages,
5152 setErrorMessage,
5253 } ) ;
5354
5455 const isUserInputDirty = form . formState . isDirty ;
56+ const isOnCampusValue = useWatch ( { name : 'isOnCampus' , control : form . control } ) ;
5557
5658 const { isLeaveConfirmModalOpen, handleBackClick, handleCancelLeave, handleConfirmLeave } =
5759 useLeaveConfirmModal ( { isUserInputDirty } ) ;
5860
61+ useEffect ( ( ) => {
62+ setIsOnCampus ( isOnCampusValue ) ;
63+ } , [ isOnCampusValue , isUserInputDirty ] ) ;
64+
5965 useEffect ( ( ) => {
6066 if ( originExperimentError ) {
6167 setOpenUpdateAlertModal ( true ) ;
@@ -101,6 +107,7 @@ const EditExperimentPost = ({ params }: { params: { postId: string } }) => {
101107 experimentDateChecked = { experimentDateChecked }
102108 durationChecked = { durationChecked }
103109 isRecruitStatus = { isRecruitStatus }
110+ setIsOnCampus = { setIsOnCampus }
104111 />
105112 < ApplyMethodSection
106113 addLink = { addLink }
0 commit comments