@@ -7,6 +7,8 @@ import { firestore } from "../../config/firebase_configure";
7
7
import { toast } from "react-toastify" ;
8
8
import { getAuth , updateProfile } from "firebase/auth" ;
9
9
import "react-toastify/dist/ReactToastify.css" ;
10
+ import { PiUploadSimpleLight } from "react-icons/pi" ;
11
+ import { PiCheckSquareOffsetLight } from "react-icons/pi" ;
10
12
import {
11
13
ref ,
12
14
getDownloadURL ,
@@ -36,7 +38,6 @@ const ProfilePage = () => {
36
38
const userData = doc . data ( ) ;
37
39
setUser ( userData ) ;
38
40
setUserData ( userData ) ;
39
- // console.log("this is current user",currentUser);
40
41
} else {
41
42
console . log ( "No such document!" ) ;
42
43
}
@@ -51,6 +52,7 @@ const ProfilePage = () => {
51
52
return unsubscribe ;
52
53
} , [ ] ) ;
53
54
55
+ //get the profile picture url
54
56
useEffect ( ( ) => {
55
57
const fetchurl = ( ) => {
56
58
if ( user && user . uid ) {
@@ -69,32 +71,35 @@ const ProfilePage = () => {
69
71
fetchurl ( ) ;
70
72
} , [ user ] ) ;
71
73
74
+ //handle input profile picture and set it to the state
72
75
const handleInputPic = ( e ) => {
73
76
if ( e . target . files [ 0 ] ) {
74
77
setProfilePic ( e . target . files [ 0 ] ) ;
78
+ toast . success ( "Please Click Upload button to update profile picture" ) ;
75
79
}
76
80
} ;
77
81
78
82
//prpofile pic upload
79
83
const uploadpic = ( ) => {
80
84
const imageRef = ref ( storage , `profile_pictures/${ user . uid } ` ) ;
81
85
const desertRef = ref ( storage , `profile_pictures/${ user . uid } ` ) ;
86
+ //file selection
82
87
if ( profilePic === null ) {
83
88
toast . error ( "Please select a profile picture" ) ;
84
89
return ;
85
90
} else {
91
+ //if already exist profile picture delete it
86
92
if ( `profile_pictures/${ user . uid } ` ) {
87
93
deleteObject ( desertRef )
88
94
. then ( ( ) => {
89
- // toast.success("Profile Picture Deleted Successfully");
90
95
console . log ( "File deleted successfully" ) ;
91
96
} )
92
97
. catch ( ( error ) => {
93
98
console . log ( "Error in deleting" , error . message ) ;
94
99
toast . error ( "Error in deleting exist profile picture" ) ;
95
100
} ) ;
96
101
}
97
-
102
+ //upload new profile picture
98
103
uploadBytes ( imageRef , profilePic )
99
104
. then ( ( ) => {
100
105
getDownloadURL ( imageRef )
@@ -159,81 +164,55 @@ const ProfilePage = () => {
159
164
< div className = " text-black w-64 h-full p-4" > </ div >
160
165
</ div >
161
166
162
- { /* new profile feature */ }
163
- < div className = "p-2 flex flex-col" >
167
+ { /* profile picture section */ }
168
+ < div className = "p-2 flex flex-col w-full mx-5 " >
164
169
{ user ? (
165
- < div >
166
- < h1 className = "text-[#4743E0] text-lg lg:text- 6xl font-extrabold mb-3 lg:mb-8 mt-5 lg:mt-10" >
167
- Welcome, { user . userName }
170
+ < div className = "flex flex-row items-center justify-between gap-5" >
171
+ < h1 className = "text-[#4743E0] text-6xl font-extrabold mb-3 lg:mb-8 mt-5 lg:mt-10" >
172
+ { user . userName }
168
173
</ h1 >
169
- { /* Profile Picture */ }
170
- < div className = "flex flex-col lg:flex-row items-center justify-center" >
171
- < div
172
- className = "flex flex-col justify-between"
173
- style = { {
174
- borderRadius : "50%" ,
175
- overflow : "hidden" ,
176
- width : 200 ,
177
- height : 200 ,
178
- } }
179
- >
180
- { url ? (
181
- < div className = "relative w-44 h-44 lg:w-60 lg:h-60 mb-6 lg:mb-0 mr-0 lg:mr-12" >
182
- < img
183
- src = { url }
184
- alt = { "profile pic" }
185
- className = "w-full h-full object-cover rounded-full shadow-lg"
186
- />
187
- < div className = "absolute inset-0 flex items-center justify-center opacity-0 hover:opacity-100 transition-opacity duration-300 bg-gray-900 bg-opacity-75 rounded-full" >
188
- < input
189
- type = "file"
190
- onChange = { handleInputPic }
191
- className = "absolute inset-0 opacity-0 cursor-pointer w-full h-full"
192
- />
193
- < span className = "text-white text-sm lg:text-base font-semibold" >
194
- Change Picture
195
- </ span >
196
- </ div >
197
- </ div >
198
- ) : (
199
- < div className = "relative w-44 h-44" >
200
- < img
201
- src = { default_profile }
202
- alt = { "profile pic" }
203
- className = "w-full h-full object-cover rounded-full shadow-lg"
204
- />
205
- < div className = "absolute inset-0 flex items-center justify-center opacity-0 hover:opacity-100 transition-opacity duration-300 bg-gray-900 bg-opacity-75 rounded-full" >
206
- < input
207
- type = "file"
208
- onChange = { handleInputPic }
209
- className = "absolute opacity-0 cursor-pointer w-full h-full"
210
- />
211
- < span className = "text-white text-sm lg:text-base font-semibold" >
212
- Change Picture
213
- </ span >
214
- </ div >
215
- </ div >
216
- ) }
174
+ < div className = "flex flex-col lg:flex-col items-center justify-center " >
175
+ { /* Profile Picture */ }
176
+ < div className = "flex-shrink-0 relative w-32 h-32 m-2 justify-center items-center lg:w-44 lg:h-44 mb-6 lg:mb-0 mr-0 lg:mr-12" >
177
+ < img
178
+ src = { url || default_profile }
179
+ alt = "profile pic"
180
+ className = "justify-center items-center w-full h-full object-cover rounded-full shadow-lg"
181
+ />
182
+ < div className = "absolute inset-0 flex items-center justify-center opacity-0 hover:opacity-100 transition-opacity duration-300 bg-gray-900 bg-opacity-75 rounded-full" >
183
+ < input
184
+ type = "file"
185
+ onChange = { handleInputPic }
186
+ className = "absolute justify-center inset-0 opacity-0 cursor-pointer w-full h-full"
187
+ />
188
+ < span className = "text-white text-sm justify-center lg:justify-center font-normal" >
189
+ < PiCheckSquareOffsetLight className = "justify-center w-6 h-6 ml-10" />
190
+ Change Picture
191
+ </ span >
192
+ </ div >
217
193
</ div >
218
- < div >
194
+ < div className = "flex flex-row justify-center items-center lg:mr-10 mt-2 " >
219
195
< button
220
- className = "cursor-pointer bg-[#4743E0] text-white px-8 py-2 rounded-full ease-in-out hover:bg-opacity-80 "
196
+ className = "cursor-pointer flex flex-row justify-center border-2 text-gray-800 px-4 py-1 rounded-full ease-in-out hover:underline hover: bg-slate-100 "
221
197
onClick = { uploadpic }
222
198
>
199
+ < PiUploadSimpleLight className = "m-1" />
223
200
Upload
224
201
</ button >
225
202
</ div >
226
203
</ div >
227
204
</ div >
228
205
) : (
229
- < div > user not found</ div >
230
- ) }
206
+ < div className = " text-lg lg:text-2xl font-thin mt-5" >
207
+ User not found
208
+ </ div >
209
+ ) }
231
210
211
+ { /* profile details section */ }
232
212
< div >
233
213
{ userData ? (
234
214
< >
235
- < div > </ div >
236
- < hr className = "mx-auto border-dashed rounded-md w-[1000%] lg:w-[1000px] mt-12 mb-5" />
215
+ < hr className = "mx-auto border-dashed rounded-md lg:w-full mt-12 mb-5" />
237
216
< div >
238
217
< div >
239
218
< label htmlFor = "userName" className = "lg:ml-2 mb-2" >
@@ -286,7 +265,7 @@ const ProfilePage = () => {
286
265
< select
287
266
className = "border rounded-full py-2 px-3 mb-4 text-grey-darker w-72"
288
267
defaultValue = { userData . role }
289
- // onChange={onChangeHandler}
268
+ onChange = { onChangeHandler }
290
269
id = "role"
291
270
type = "select"
292
271
name = "role"
@@ -321,9 +300,10 @@ const ProfilePage = () => {
321
300
Save Changes
322
301
</ button >
323
302
</ div >
324
- < hr className = "mx-auto border-dashed rounded-md w-[1000%] lg:w-[1000px] mt-12 mb-5" />
303
+ < hr className = "mx-auto border-dashed rounded-md lg:w-full mt-12 mb-5" />
304
+ { /* Password section */ }
325
305
< div >
326
- < h1 className = "font-semibold text-lg" > Change Password</ h1 >
306
+ < h1 className = "font-semibold text-lg m-2 " > Change Password</ h1 >
327
307
< div >
328
308
< label htmlFor = "password" className = "lg:ml-2 mb-2" >
329
309
New Password
@@ -334,6 +314,7 @@ const ProfilePage = () => {
334
314
placeholder = "********"
335
315
name = "password"
336
316
className = "border rounded-full py-2 px-3 mb-4 text-grey-darker w-72"
317
+ // onChange={passwordHandler}
337
318
/>
338
319
</ div >
339
320
< div >
@@ -346,6 +327,7 @@ const ProfilePage = () => {
346
327
placeholder = "******"
347
328
name = "confirmPassword"
348
329
className = "border rounded-full py-2 px-3 mb-4 text-grey-darker w-72"
330
+ // onChange={confirmPasswordHandler}
349
331
/>
350
332
</ div >
351
333
</ div >
0 commit comments