@@ -96,7 +96,8 @@ function ProfileEditForm({
9696
9797 const handleSubmit = async ( ) => {
9898 const file = fileInputRef . current ?. files ?. [ 0 ] ;
99- const profileImageExtension = file ?. name . split ( '.' ) . pop ( ) ;
99+ const profileImageExtension =
100+ image === DEFAULT_PROFILE_IMAGE_URL ? 'jpg' : file ?. name . split ( '.' ) . pop ( ) ;
100101
101102 const rawFormData : UpdateUserProfileRequest = {
102103 name : profileForm . name ,
@@ -116,36 +117,22 @@ function ProfileEditForm({
116117
117118 const updatedProfile = await updateProfile ( formData ) ;
118119
119- // todo: 서버 측에서 api 수정되면, 리팩토링
120- // 기본 프로필 이미지를 선택할 경우, 기본 프로필 이미지 전송 -> 서버 측에서 나중에 리팩토링 예정
121- // public 폴더의 profile-default.jpg 파일을 fetch해서 FormData에 추가
122- // profile-default.jpg를 추가한 이유는 서버에서 프로필 이미지 확장자에 svg 파일을 고려하지 못함 -> 서버 측에서 리팩토링 예정
123- if ( image === DEFAULT_PROFILE_IMAGE_URL ) {
124- try {
120+ if ( updatedProfile . profileImageUploadUrl ) {
121+ const imageFormData = new FormData ( ) ;
122+
123+ if ( file ) imageFormData . append ( 'file' , file ) ;
124+
125+ // 기본 프로필 이미지를 선택할 경우, public 폴더의 profile-default.jpg로 서버 api에게 기본 프로필 이미지 전송 -> 서버 측에서 나중에 리팩토링 예정
126+ // profile-default.jpg를 추가한 이유는 서버에서 프로필 이미지 확장자에 svg 파일을 고려하지 못함 -> 서버 측에서 리팩토링 예정
127+ if ( ! file && image === DEFAULT_PROFILE_IMAGE_URL ) {
125128 const defaultProfileImage = 'profile-default.jpg' ;
126129 const response = await fetch ( defaultProfileImage ) ;
127130 const blob = await response . blob ( ) ;
128- const defaultFile = new File ( [ blob ] , defaultProfileImage , {
129- type : 'image/jpeg ' ,
131+ const defaultProfileFile = new File ( [ blob ] , defaultProfileImage , {
132+ type : 'image/jpg ' ,
130133 } ) ;
131- const imageFormData = new FormData ( ) ;
132- imageFormData . append ( 'file' , defaultFile ) ;
133-
134- await uploadProfileImage ( {
135- memberId,
136- filename : defaultProfileImage ,
137- file : imageFormData ,
138- } ) ;
139- } catch ( error ) {
140- console . error ( '기본 프로필 이미지 업로드 실패:' , error ) ;
141- alert ( '기본 프로필 이미지 업로드에 실패했습니다.' ) ;
134+ imageFormData . append ( 'file' , defaultProfileFile ) ;
142135 }
143- }
144-
145- // 폴더에서 이미지를 선택한 경우
146- if ( file && updatedProfile . profileImageUploadUrl ) {
147- const imageFormData = new FormData ( ) ;
148- imageFormData . append ( 'file' , file ) ;
149136
150137 const filename = updatedProfile . profileImageUploadUrl . split ( '/' ) . pop ( ) ;
151138 if ( ! filename ) return ;
0 commit comments