File tree Expand file tree Collapse file tree 4 files changed +55
-18
lines changed
components/Profile/MyProfile Expand file tree Collapse file tree 4 files changed +55
-18
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export const userApi = {
1515 } ,
1616
1717 // 프로필 이미지 업데이트
18- updateProfileImage : async ( profileImageUrl : string ) => {
18+ updateProfileImage : async ( profileImageUrl : string | null ) => {
1919 const { data } = await instance . patch ( `users/me/profile-image` , {
2020 profileImageUrl,
2121 } ) ;
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ export const Header = styled.div`
2020 justify-content: space-between;
2121` ;
2222
23+ export const ProfileImageContainer = styled . div `
24+ position: relative;
25+ ` ;
26+
2327export const ProfileImage = styled . img < { $onClick : boolean } > `
2428 width: 64px;
2529 height: 64px;
@@ -32,6 +36,25 @@ export const ProfileImage = styled.img<{ $onClick: boolean }>`
3236 }
3337` ;
3438
39+ export const ProfileImageResetButton = styled . button `
40+ position: absolute;
41+ top: -6px;
42+ left: -6px;
43+ background-color: var(--palette-background-normal-alternative);
44+ display: flex;
45+ align-items: center;
46+ justify-content: center;
47+ border: 1px solid var(--palette-line-normal-neutral);
48+ cursor: pointer;
49+ border-radius: 50%;
50+ padding: 8px;
51+
52+ & > img {
53+ width: 8px;
54+ height: 8px;
55+ }
56+ ` ;
57+
3558export const HeaderButtonContainer = styled . div `
3659 display: flex;
3760 gap: 8px;
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ import {
1313 StateMessageInput ,
1414 StateMessagePlus ,
1515 ErrorMessage ,
16+ ProfileImageResetButton ,
17+ ProfileImageContainer ,
1618} from './index.css' ;
1719
1820import Edit from '@/assets/img/Edit.svg' ;
@@ -99,25 +101,37 @@ export const MyProfile = () => {
99101 }
100102 } ;
101103
104+ const handleImageReset = async ( ) => {
105+ const updateUser = await updateProfileImage ( null ) ;
106+ console . log ( 'image reset' , updateUser ) ;
107+ } ;
108+
102109 return (
103110 < Container >
104111 < Profile >
105112 < Header >
106- < ProfileImage
107- src = { user . profileImageUrl ?? DefaultProfile }
108- onClick = { handleImageClick }
109- $onClick = { isEditMode }
110- onError = { e => {
111- e . currentTarget . src = DefaultProfile ;
112- } }
113- />
114- < input
115- type = "file"
116- ref = { fileInputRef }
117- onChange = { handleImageChange }
118- style = { { display : 'none' } }
119- accept = "image/*"
120- />
113+ < ProfileImageContainer >
114+ < ProfileImage
115+ src = { user . profileImageUrl ?? DefaultProfile }
116+ onClick = { handleImageClick }
117+ $onClick = { isEditMode }
118+ onError = { e => {
119+ e . currentTarget . src = DefaultProfile ;
120+ } }
121+ />
122+ < input
123+ type = "file"
124+ ref = { fileInputRef }
125+ onChange = { handleImageChange }
126+ style = { { display : 'none' } }
127+ accept = "image/*"
128+ />
129+ { isEditMode && (
130+ < ProfileImageResetButton onClick = { handleImageReset } >
131+ < img src = { Cancel } alt = "cancel" />
132+ </ ProfileImageResetButton >
133+ ) }
134+ </ ProfileImageContainer >
121135 < HeaderButtonContainer >
122136 < IconButton
123137 beforeImgUrl = { isEditMode ? Check : Edit }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ interface UserStore {
1010 updateMyProfile : (
1111 updateUserRequestDto : UpdateUserRequestDto ,
1212 ) => Promise < UserResponseDto | undefined > ;
13- updateProfileImage : ( profileImageUrl : string ) => Promise < UserResponseDto | undefined > ;
13+ updateProfileImage : ( profileImageUrl : string | null ) => Promise < UserResponseDto | undefined > ;
1414 clearProfile : ( ) => void ;
1515}
1616
@@ -34,7 +34,7 @@ export const useUserStore = create(
3434 set ( { user : data } ) ;
3535 return data ;
3636 } ,
37- updateProfileImage : async ( profileImageUrl : string ) => {
37+ updateProfileImage : async ( profileImageUrl : string | null ) => {
3838 try {
3939 const data = await userApi . updateProfileImage ( profileImageUrl ) ;
4040 set ( { user : data } ) ;
You can’t perform that action at this time.
0 commit comments