@@ -31,7 +31,7 @@ const FIELD_LABELS: Record<keyof FormType, string> = {
3131
3232export default function ProfileEditPage ( ) {
3333 const navigate = useNavigate ( ) ;
34- const { user } = useUserStore ( ) ;
34+ const { user, updateUser } = useUserStore ( ) ;
3535 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
3636 const openModal = useModalStore ( ( state ) => state . openModal ) ;
3737
@@ -43,34 +43,52 @@ export default function ProfileEditPage() {
4343 } ) ;
4444
4545 useEffect ( ( ) => {
46- async function fetchUser ( ) {
46+ if ( ! user ) {
47+ openModal ( {
48+ type : "alert" ,
49+ iconType : "warning" ,
50+ message : "로그인 후에 이용 가능한 기능입니다." ,
51+ onClose : ( ) => navigate ( ROUTES . AUTH . SIGNIN ) ,
52+ } ) ;
53+ return ;
54+ }
55+ if ( user . type === "employer" ) {
56+ openModal ( {
57+ type : "alert" ,
58+ iconType : "warning" ,
59+ message : "알바생 계정으로만 이용 가능한 기능입니다." ,
60+ onClose : ( ) => navigate ( ROUTES . SHOP . ROOT ) ,
61+ } ) ;
62+ return ;
63+ }
64+ } , [ ] ) ;
65+
66+ useEffect ( ( ) => {
67+ const fetchUser = async ( ) => {
4768 if ( ! user ?. id ) return ;
4869 const res = await getUser ( user . id ) ;
70+
71+ if ( ! res . data . item ?. name ) {
72+ navigate ( ROUTES . PROFILE . REGISTER ) ;
73+ return ;
74+ }
4975 const { name, phone, address, bio } = res . data . item ;
5076 setForm ( {
5177 name : name ?? "" ,
5278 phone : phone ?? "" ,
5379 address,
5480 bio : bio ?? "" ,
5581 } ) ;
56- }
82+ } ;
5783 fetchUser ( ) ;
58- } , [ user ?. id ] ) ;
84+ } , [ user ?. id , navigate ] ) ;
5985
6086 const handleChange = ( key : keyof FormType , value : string | SeoulDistrict ) => {
6187 setForm ( ( prev ) => ( { ...prev , [ key ] : value } ) ) ;
6288 } ;
6389
6490 const handleSubmit = async ( ) => {
65- if ( ! user ?. id ) {
66- openModal ( {
67- type : "alert" ,
68- iconType : "warning" ,
69- message : "로그인 정보가 없습니다." ,
70- } ) ;
71- return ;
72- }
73-
91+ if ( ! user ?. id ) return ;
7492 if ( isSubmitting ) return ;
7593
7694 const requiredFields : Array < keyof FormType > = [ "name" , "phone" , "address" ] ;
@@ -99,6 +117,7 @@ export default function ProfileEditPage() {
99117
100118 try {
101119 await putUser ( user . id , payload ) ;
120+ updateUser ( payload ) ;
102121 openModal ( {
103122 type : "message" ,
104123 iconType : "none" ,
@@ -120,72 +139,74 @@ export default function ProfileEditPage() {
120139 } ;
121140
122141 return (
123- < form
124- className = "w-full max-w-[964px] mx-auto px-4 py-12"
125- onSubmit = { ( e ) => {
126- e . preventDefault ( ) ;
127- handleSubmit ( ) ;
128- } }
129- >
130- < div className = "flex justify-between items-center mb-8" >
131- < h2 className = "sm:text-[1.75rem] text-[1.25rem] font-bold" >
132- 내 프로필
133- </ h2 >
134- < button type = "button" onClick = { ( ) => navigate ( "/profile" ) } >
135- < Close className = "sm:w-8 sm:h-8 w-6 h-6 cursor-pointer" />
136- </ button >
137- </ div >
138-
139- < div className = "grid md:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5 mb-6" >
140- < TextField . Input
141- label = "이름*"
142- placeholder = "입력"
143- fullWidth
144- value = { form . name }
145- onChange = { ( e ) => handleChange ( "name" , e . target . value ) }
146- maxLength = { 20 }
147- />
148- < TextField . Input
149- label = "연락처*"
150- placeholder = "입력"
151- fullWidth
152- value = { form . phone }
153- onChange = { ( e ) => {
154- const formatted = autoHyphenFormatter ( e . target . value ) ;
155- handleChange ( "phone" , formatted ) ;
156- } }
157- />
158- < Select
159- label = "선호 지역*"
160- placeholder = "선택"
161- fullWidth
162- options = { SeoulDistricts . map ( ( d ) => ( { label : d , value : d } ) ) }
163- value = { form . address }
164- onValueChange = { ( value ) => handleChange ( "address" , value ) }
165- />
166- </ div >
167- < div className = "mb-10" >
168- < TextField . TextArea
169- label = "소개 (최대 300자)"
170- placeholder = "입력"
171- fullWidth
172- rows = { 4 }
173- value = { form . bio }
174- maxLength = { 300 }
175- onChange = { ( e ) => handleChange ( "bio" , e . target . value ) }
176- />
177- </ div >
178- < div className = "text-center" >
179- < Button
180- variant = "primary"
181- textSize = "md"
182- className = "sm:w-[350px] w-full px-34 py-3.5"
183- disabled = { isSubmitting }
184- type = "submit"
185- >
186- 수정하기
187- </ Button >
188- </ div >
189- </ form >
142+ < div className = "w-full bg-gray-5 min-h-screen" >
143+ < form
144+ className = "w-full max-w-[964px] mx-auto px-4 py-12"
145+ onSubmit = { ( e ) => {
146+ e . preventDefault ( ) ;
147+ handleSubmit ( ) ;
148+ } }
149+ >
150+ < div className = "flex justify-between items-center mb-8" >
151+ < h2 className = "sm:text-[1.75rem] text-[1.25rem] font-bold" >
152+ 내 프로필
153+ </ h2 >
154+ < button type = "button" onClick = { ( ) => navigate ( "/profile" ) } >
155+ < Close className = "sm:w-8 sm:h-8 w-6 h-6 cursor-pointer" />
156+ </ button >
157+ </ div >
158+
159+ < div className = "grid lg:grid-cols-3 sm:grid-cols-2 grid-cols-1 gap-5 mb-6" >
160+ < TextField . Input
161+ label = "이름*"
162+ placeholder = "입력"
163+ fullWidth
164+ value = { form . name }
165+ onChange = { ( e ) => handleChange ( "name" , e . target . value ) }
166+ maxLength = { 20 }
167+ />
168+ < TextField . Input
169+ label = "연락처*"
170+ placeholder = "입력"
171+ fullWidth
172+ value = { form . phone }
173+ onChange = { ( e ) => {
174+ const formatted = autoHyphenFormatter ( e . target . value ) ;
175+ handleChange ( "phone" , formatted ) ;
176+ } }
177+ />
178+ < Select
179+ label = "선호 지역*"
180+ placeholder = "선택"
181+ fullWidth
182+ options = { SeoulDistricts . map ( ( d ) => ( { label : d , value : d } ) ) }
183+ value = { form . address }
184+ onValueChange = { ( value ) => handleChange ( "address" , value ) }
185+ />
186+ </ div >
187+ < div className = "mb-10" >
188+ < TextField . TextArea
189+ label = "소개 (최대 300자)"
190+ placeholder = "입력"
191+ fullWidth
192+ rows = { 4 }
193+ value = { form . bio }
194+ maxLength = { 300 }
195+ onChange = { ( e ) => handleChange ( "bio" , e . target . value ) }
196+ />
197+ </ div >
198+ < div className = "text-center" >
199+ < Button
200+ variant = "primary"
201+ textSize = "md"
202+ className = "sm:w-[350px] w-full px-34 py-3.5"
203+ disabled = { isSubmitting }
204+ type = "submit"
205+ >
206+ 수정하기
207+ </ Button >
208+ </ div >
209+ </ form >
210+ </ div >
190211 ) ;
191212}
0 commit comments