@@ -16,7 +16,7 @@ import { twMerge } from 'tailwind-merge';
1616type ProfileFormType = {
1717 password : string ;
1818 nickName : string ;
19- spotifyId : string ;
19+ spotifyId : string | - 1 ;
2020 title : string ;
2121 artist : string ;
2222 albumImage : string ;
@@ -52,11 +52,19 @@ function ProfileEditForm() {
5252 if ( nickname !== prevNickname . current ) {
5353 updatedData . nickName = nickname ;
5454 }
55+ // 현재 프로필 뮤직이랑 이전 프로필 뮤직이 다를때만 업데이트
5556 if ( selectedProfileMusic !== prevProfileMusic . current ) {
56- updatedData . spotifyId = selectedProfileMusic ?. spotifyId ;
57- updatedData . title = selectedProfileMusic ?. title ;
58- updatedData . artist = selectedProfileMusic ?. artist ;
59- updatedData . albumImage = selectedProfileMusic ?. album ;
57+ // 프로필 뮤직이 선택되어있을 경우
58+ if ( selectedProfileMusic ) {
59+ updatedData . spotifyId = selectedProfileMusic . spotifyId ;
60+ updatedData . title = selectedProfileMusic . title ;
61+ updatedData . artist = selectedProfileMusic . artist ;
62+ updatedData . albumImage = selectedProfileMusic . album ;
63+ }
64+ // 프로필 뮤직이 선택되지않아서 삭제하는 로직
65+ else {
66+ updatedData . spotifyId = - 1 ;
67+ }
6068 }
6169
6270 console . log ( '전송 데이터:' , updatedData ) ;
@@ -121,12 +129,14 @@ function ProfileEditForm() {
121129
122130 useEffect ( ( ) => {
123131 const loadMyProfile = async ( ) => {
124- const data = await getMyProfile ( ) ;
125- prevNickname . current = data . data . nickname ; // 이전 닉네임 저장하기
126- prevProfileMusic . current = data . data . profileMusic ; // 이전 음악 저장하기
132+ const { data } = await getMyProfile ( ) ;
133+ const { nickname, profileMusic } = data ;
127134
128- setNickname ( data . data . nickname ) ;
129- selectProfileMusic ( data . data . profileMusic ) ;
135+ prevNickname . current = nickname ; // 이전 닉네임 저장
136+ prevProfileMusic . current = profileMusic ?. spotifyId ? profileMusic : null ; // 이전 음악저장
137+
138+ setNickname ( nickname ) ;
139+ selectProfileMusic ( prevProfileMusic . current ) ;
130140 } ;
131141 loadMyProfile ( ) ;
132142
0 commit comments