@@ -4,11 +4,12 @@ import TextButton from '@/shared/components/button/TextButton';
44import Input from '@/shared/components/Input-box/Input' ;
55import ModalLayout from '@/shared/components/modal-pop/ModalLayout' ;
66import { useToast } from '@/shared/hook/useToast' ;
7- import { Dispatch , SetStateAction } from 'react' ;
7+ import { Dispatch , SetStateAction , useEffect , useState } from 'react' ;
88
99interface Props {
1010 open : boolean ;
1111 onClose : ( ) => void ;
12+ nickname :string
1213 setNickName : ( v : string ) => void ;
1314 setIsOpen : Dispatch < SetStateAction < boolean > > ;
1415 editNickName : string ;
@@ -18,14 +19,22 @@ interface Props {
1819function EditNickName ( {
1920 open,
2021 onClose,
22+ nickname,
2123 setNickName,
2224 setIsOpen,
2325 editNickName,
2426 setEditNickName,
2527} : Props ) {
26- const { toastError } = useToast ( ) ;
28+ const [ defaultNickname , setDefaultNickname ] = useState ( nickname )
29+ const { toastSuccess, toastError } = useToast ( ) ;
30+
31+ useEffect ( ( ) => {
32+ setEditNickName ( nickname )
33+ setDefaultNickname ( nickname )
34+ } , [ nickname , setEditNickName ] )
35+
2736 const handlesave = async ( ) => {
28- if ( editNickName . length <= 1 ) {
37+ if ( editNickName . length <= 1 || editNickName . length >= 8 ) {
2938 toastError ( '닉네임은 2글자 이상 입력해야합니다' ) ;
3039 return ;
3140 }
@@ -43,16 +52,22 @@ function EditNickName({
4352 } ) ,
4453 } ) ;
4554 await setIsOpen ( false ) ;
55+ toastSuccess ( '닉네임이 저장되었습니다.' ) ;
4656 } ;
4757
4858 const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
4959 setEditNickName ( e . target . value ) ;
60+
5061 } ;
5162
63+ const handleDefaultNickname = ( ) => {
64+ setEditNickName ( defaultNickname )
65+ }
66+
5267 return (
5368 < ModalLayout
54- title = "닉네임 수정 "
55- description = "닉네임을 수정해주세요 ."
69+ title = "닉네임 변경 "
70+ description = "닉네임을 변경해주세요 ."
5671 open = { open }
5772 onClose = { onClose }
5873 buttons = {
@@ -67,11 +82,12 @@ function EditNickName({
6782 </ label >
6883 < Input
6984 onChange = { ( e ) => handleChange ( e ) }
70- placeholder = "8글자 이내로 입력해주세요"
85+ placeholder = "닉네임을 2글자 이상 8글자 이내로 입력해주세요"
7186 id = "editNickName"
87+ value = { editNickName }
7288 className = "w-full"
7389 />
74- < TextButton onClick = { onClose } > 기존 이름으로 돌아가기</ TextButton >
90+ < TextButton onClick = { handleDefaultNickname } > 전 닉네임으로 돌아가기</ TextButton >
7591 </ div >
7692 </ ModalLayout >
7793 ) ;
0 commit comments