@@ -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,21 @@ function EditNickName({
4352 } ) ,
4453 } ) ;
4554 await setIsOpen ( false ) ;
55+ toastSuccess ( '닉네임이 저장되었습니다.' ) ;
4656 } ;
4757
4858 const handleChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
4959 setEditNickName ( e . target . value ) ;
5060 } ;
5161
62+ const handleDefaultNickname = ( ) => {
63+ setEditNickName ( defaultNickname ) ;
64+ } ;
65+
5266 return (
5367 < ModalLayout
54- title = "닉네임 수정 "
55- description = "닉네임을 수정해주세요 ."
68+ title = "닉네임 변경 "
69+ description = "닉네임을 변경해주세요 ."
5670 open = { open }
5771 onClose = { onClose }
5872 buttons = {
@@ -67,11 +81,12 @@ function EditNickName({
6781 </ label >
6882 < Input
6983 onChange = { ( e ) => handleChange ( e ) }
70- placeholder = "8글자 이내로 입력해주세요"
84+ placeholder = "닉네임을 2글자 이상 8글자 이내로 입력해주세요"
7185 id = "editNickName"
86+ value = { editNickName }
7287 className = "w-full"
7388 />
74- < TextButton onClick = { onClose } > 기존 이름으로 돌아가기</ TextButton >
89+ < TextButton onClick = { handleDefaultNickname } > 전 닉네임으로 돌아가기</ TextButton >
7590 </ div >
7691 </ ModalLayout >
7792 ) ;
0 commit comments