1- import React , { FC , useState } from 'react' ;
1+ import React , { FC } from 'react' ;
22import styled from 'styled-components/macro' ;
33import { useUser } from '../../../../context/userContext/UserContext' ;
44import Camera from '../../../../assets/me/camera.svg' ;
55import CardContainer from '../../../components/Card/index' ;
6- import { isGoogleOAuthUser } from '../../../../helpers/authProvider ' ;
6+ import { getAvatarUrl } from '../../../../helpers/avatar ' ;
77import { IconButton } from '../../../components/Button/IconButton' ;
88import { Tooltip } from 'react-tippy' ;
99import { toast } from 'react-toastify' ;
1010import { report } from '../../../../ga' ;
11- import { useApi } from '../../../../context/apiContext/ApiContext' ;
12- import messages from '../../../../messages' ;
13- import Switch from '../../../../components/Switch/Switch' ;
11+ import { RedirectToGravatar } from '../../../Modals/RedirectToGravatar' ;
1412
1513const ShareProfile = ( { url } : { url : string } ) => {
1614 const [ showInput , setShowInput ] = React . useState ( false ) ;
@@ -53,105 +51,41 @@ const ShareProfile = ({ url }: { url: string }) => {
5351} ;
5452
5553const Avatar : FC = ( ) => {
56- const { currentUser, updateCurrentUser } = useUser < true > ( ) ;
57- const api = useApi ( ) ;
58- const [ isSaving , setIsSaving ] = useState ( false ) ;
54+ const { currentUser } = useUser < true > ( ) ;
5955
6056 if ( ! currentUser ) {
6157 return null ;
6258 }
6359
64- const isUsingGravatar = currentUser . avatar ?. includes ( 'gravatar.com' ) || false ;
65-
66- const handleToggleGravatar = async ( newValue : boolean ) => {
67- setIsSaving ( true ) ;
68- try {
69- report ( 'Avatar' , newValue ? 'use gravatar' : 'use google profile picture' ) ;
70- const updatedUser = await api . toggleAvatar ( newValue ) ;
71- if ( updatedUser ) {
72- api . clearCurrentUser ( ) ;
73- updateCurrentUser ( updatedUser ) ;
74- toast . success ( 'Avatar updated successfully' , { toastId : 'avatar-updated' } ) ;
75- } else {
76- toast . error ( messages . GENERIC_ERROR ) ;
77- }
78- } catch ( error ) {
79- toast . error ( messages . GENERIC_ERROR ) ;
80- } finally {
81- setIsSaving ( false ) ;
82- }
83- } ;
84-
85- const isGoogleUser = isGoogleOAuthUser ( currentUser . auth0Id ) ;
86-
8760 return (
8861 < CardContainer >
8962 < Container >
9063 < ShareProfile
9164 url = { `${ process . env . NEXT_PUBLIC_AUTH_CALLBACK } /u/${ currentUser . _id } ` }
9265 />
93- < AvatarContainer >
94- < AvatarWrapper >
95- { currentUser . avatar ? (
96- < UserImage
97- alt = { currentUser . email }
98- src = { currentUser . avatar }
99- />
100- ) : (
101- < AvatarPlaceHolder alt = "No profile picture" src = { Camera } />
102- ) }
103- </ AvatarWrapper >
104- </ AvatarContainer >
105-
106- { isGoogleUser && (
107- < >
108- < Tooltip
109- title = "Use Gravatar for a different avatar from your Google photo"
110- size = "regular"
111- arrow = { true }
112- position = "bottom"
113- >
114- < i className = "fa fa-info-circle" > </ i >
115- </ Tooltip > { " " }
116- < ToggleLabel >
117- < Switch
118- label = "Use Gravatar"
119- isChecked = { isUsingGravatar }
120- onToggle = { handleToggleGravatar }
121- size = "small"
122- />
123- </ ToggleLabel >
124- < ToggleDescription >
125- Update your avatar picture at{ " " }
126- { isUsingGravatar
127- ? < a href = "https://gravatar.com/profile/avatars" target = "_blank" rel = "noopener noreferrer" > Gravatar</ a >
128- : < a href = "https://myaccount.google.com/profile" target = "_blank" rel = "noopener noreferrer" > Google Profile</ a >
129- }
130- </ ToggleDescription >
131- </ >
132- ) }
66+ < div >
67+ { currentUser && currentUser . avatar ? (
68+ < UserImage
69+ alt = { currentUser . email }
70+ src = { getAvatarUrl ( currentUser . avatar ) }
71+ />
72+ ) : (
73+ < AvatarPlaceHolder alt = "No profile picture" src = { Camera } />
74+ ) }
75+ < ChangeAvatarSection >
76+ Change your avatar on < RedirectToGravatar />
77+ </ ChangeAvatarSection >
78+ </ div >
13379 < h1 > { currentUser ? currentUser . name : '' } </ h1 >
13480 < p > { currentUser ? currentUser . title : '' } </ p >
13581 </ Container >
13682 </ CardContainer >
13783 ) ;
13884} ;
13985
140- // Styled components
141- const AvatarContainer = styled . div `
142- display: flex;
143- flex-direction: column;
144- align-items: center;
145- gap: 8px;
146- ` ;
147-
148- const AvatarWrapper = styled . div `
149- position: relative;
150- display: inline-block;
151-
152- &:hover img {
153- opacity: 0.9;
154- }
86+ // Styled components for the updated UI elements
87+ const ChangeAvatarSection = styled . div `
88+ margin: auto auto 10px;
15589` ;
15690
15791const AvatarPlaceHolder = styled . img `
@@ -165,24 +99,8 @@ const AvatarPlaceHolder = styled.img`
16599const UserImage = styled . img `
166100 width: 100px;
167101 height: 100px;
168- display: block;
169102 object-fit: cover;
170103 border-radius: 8px;
171- border: 2px solid #e0e0e0;
172- transition: opacity 0.2s ease;
173- ` ;
174-
175- const ToggleLabel = styled . div `
176- display: inline-flex;
177- align-items: center;
178- gap: 12px;
179- ` ;
180-
181- const ToggleDescription = styled . div `
182- font-size: 13px;
183- color: #666;
184- margin: 0 0 12px 0;
185- line-height: 1.5;
186104` ;
187105
188106const Container = styled . div `
0 commit comments