@@ -5,6 +5,7 @@ import Input from '@/shared/components/Input-box/Input';
55import ModalLayout from '@/shared/components/modal-pop/ModalLayout' ;
66import { useToast } from '@/shared/hook/useToast' ;
77import { Dispatch , SetStateAction , useEffect , useState } from 'react' ;
8+ import useFetchProfile from '../api/fetchProfile' ;
89
910interface Props {
1011 open : boolean ;
@@ -27,33 +28,26 @@ function EditNickName({
2728} : Props ) {
2829 const [ defaultNickname , setDefaultNickname ] = useState ( nickname ) ;
2930 const { toastSuccess, toastError } = useToast ( ) ;
30-
31+ const { patchNickName } = useFetchProfile ( )
32+
3133 useEffect ( ( ) => {
3234 setEditNickName ( nickname ) ;
3335 setDefaultNickname ( nickname ) ;
3436 } , [ nickname , setEditNickName ] ) ;
3537
3638 const handlesave = async ( ) => {
37- if ( editNickName . length <= 1 || editNickName . length >= 8 ) {
38- toastError ( '닉네임은 2글자 이상 입력해야합니다' ) ;
39- return ;
40- }
39+ if ( editNickName . length <= 1 || editNickName . length >= 8 ) {
40+ toastError ( '닉네임은 2글자 이상 8글자 이내로 입력해야합니다' ) ;
41+ return ;
42+ }
4143
42- await setNickName ( editNickName ) ;
44+ await setNickName ( editNickName ) ;
45+ // CRUD중 CUD를 관리하는 메서드
46+ await patchNickName . mutateAsync ( editNickName )
4347
44- await fetch ( `${ getApi } /me/profile` , {
45- method : 'PATCH' ,
46- credentials : 'include' ,
47- headers : {
48- 'Content-Type' : 'application/json' ,
49- } ,
50- body : JSON . stringify ( {
51- nickname : editNickName ,
52- } ) ,
53- } ) ;
54- await setIsOpen ( false ) ;
55- toastSuccess ( '닉네임이 저장되었습니다.' ) ;
56- } ;
48+ await setIsOpen ( false ) ;
49+ toastSuccess ( '닉네임이 저장되었습니다.' ) ;
50+ }
5751
5852 const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
5953 setEditNickName ( e . target . value ) ;
0 commit comments