Skip to content

Commit 3748655

Browse files
committed
Revert "feat(edit-profile): allow custom avatar (#995)"
This reverts commit 55e7f1a.
1 parent 55e7f1a commit 3748655

16 files changed

Lines changed: 72 additions & 401 deletions

File tree

netlify/functions-src/functions/modules/users/current.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ const getCurrentUserHandler: ApiHandler = async (_event: HandlerEvent, context:
5757
if (!auth0Id) {
5858
return error('Unauthorized: user not found', 401)
5959
}
60-
const currentUser = await getCurrentUser(auth0Id);
61-
62-
// Use stored avatar if exists, otherwise fallback to Auth0 picture
63-
const avatarUrl = currentUser.avatar || context.user?.picture;
64-
6560
const applicationUser = {
66-
...currentUser,
61+
...await getCurrentUser(auth0Id),
6762
email_verified: context.user?.email_verified,
68-
avatar: avatarUrl,
63+
avatar: context.user?.picture,
6964
};
65+
// TODO: remove avatar from the database
7066
return success({ data: applicationUser })
7167
}
7268

netlify/functions-src/functions/modules/users/toggleAvatar.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

netlify/functions-src/functions/modules/users/userInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ export const updateUserInfoHandler: ApiHandler<User> = async (event, context) =>
4141
data: upsertedUser,
4242
});
4343
} catch (e) {
44-
return error((e as Error).message, 400);
44+
return error(e.message, 400);
4545
}
4646
}

netlify/functions-src/functions/users.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { handler as usersCurrentHandler } from './modules/users/current'
33
import { handler as getUserInfoHandler, updateUserInfoHandler } from './modules/users/userInfo'
44
import { handler as deleteUser } from './modules/users/delete'
55
import { handler as verifyUserHandler } from './modules/users/verify'
6-
import { toggleAvatarHandler } from './modules/users/toggleAvatar'
76
import { withRouter } from './hof/withRouter';
87
import { withDB } from './hof/withDB';
98
import { withAuth } from './utils/auth';
@@ -15,7 +14,6 @@ export const handler: ApiHandler = withDB(
1514
includeFullUser: true,
1615
})],
1716
['/current', 'GET', usersCurrentHandler],
18-
['/current/avatar', 'POST', withAuth(toggleAvatarHandler)],
1917
['/verify', 'POST', withAuth(verifyUserHandler, {
2018
emailVerificationRequired: false,
2119
includeFullUser: true,

src/Me/MentorshipRequests/UsersList.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getAvatarUrl } from '../../helpers/avatar';
12
import ReqContent from './ReqContent';
23
import { Status } from '../../helpers/mentorship';
34
import { formatTimeAgo } from '../../helpers/time';
@@ -95,7 +96,7 @@ const renderList = ({
9596
<RichItem
9697
id={_id}
9798
userId={user._id}
98-
avatar={user.avatar}
99+
avatar={getAvatarUrl(user.avatar)}
99100
title={user.name}
100101
subtitle={user.title}
101102
onClick={() => {

src/Me/Routes/Home/Avatar/Avatar.tsx

Lines changed: 20 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
import React, { FC, useState } from 'react';
1+
import React, { FC } from 'react';
22
import styled from 'styled-components/macro';
33
import { useUser } from '../../../../context/userContext/UserContext';
44
import Camera from '../../../../assets/me/camera.svg';
55
import CardContainer from '../../../components/Card/index';
6-
import { isGoogleOAuthUser } from '../../../../helpers/authProvider';
6+
import { getAvatarUrl } from '../../../../helpers/avatar';
77
import { IconButton } from '../../../components/Button/IconButton';
88
import { Tooltip } from 'react-tippy';
99
import { toast } from 'react-toastify';
1010
import { 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

1513
const ShareProfile = ({ url }: { url: string }) => {
1614
const [showInput, setShowInput] = React.useState(false);
@@ -53,105 +51,41 @@ const ShareProfile = ({ url }: { url: string }) => {
5351
};
5452

5553
const 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

15791
const AvatarPlaceHolder = styled.img`
@@ -165,24 +99,8 @@ const AvatarPlaceHolder = styled.img`
16599
const 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

188106
const Container = styled.div`

src/api/index.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,6 @@ export default class ApiService {
206206
return !!response?.success;
207207
}
208208

209-
toggleAvatar = async (useGravatar: boolean) => {
210-
const response = await this.makeApiCall<User>(
211-
`${paths.USERS}/current/avatar`,
212-
{ useGravatar },
213-
'POST'
214-
);
215-
if (response?.success) {
216-
return response.data;
217-
}
218-
return null;
219-
}
220-
221209
// no need. we're using gravatar now
222210
// updateMentorAvatar = async (mentor: Mentor, value: FormData) => {
223211
// const response = await this.makeApiCall(

src/components/Card/Card.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useDeviceType } from '../../hooks/useDeviceType';
1212
import { report } from '../../ga';
1313
import messages from '../../messages';
1414
import { UnstyledList } from '../common';
15+
import { getAvatarUrl } from '../../helpers/avatar';
1516
import { languageName } from '../../helpers/languages';
1617
import { getChannelInfo } from '../../channelProvider';
1718
import { CardProps, CTAButtonProps } from './Card.types';
@@ -113,7 +114,7 @@ const Avatar = ({ mentor, id }: { mentor: Mentor; id: string }) => {
113114
<Link href={urls.user.get(mentor)} className="avatar">
114115
<i className="fa fa-user-circle" />
115116
<img
116-
src={mentor.avatar}
117+
src={getAvatarUrl(mentor.avatar)}
117118
aria-labelledby={`${id}`}
118119
alt={`${mentor.name}`}
119120
onError={(e) => e.currentTarget.classList.add('broken')}
@@ -335,14 +336,14 @@ const Card = ({ mentor, onFavMentor, isFav, appearance }: CardProps) => {
335336
data-testid="mentor-card"
336337
appearance={appearance}
337338
>
338-
<CardHeader
339+
<CardHeader
339340
mentor={mentor}
340341
onFavMentor={onFavMentor}
341342
isFav={isFav}
342343
/>
343344
<MentorInfo />
344345
<SkillsTags />
345-
<CardFooter
346+
<CardFooter
346347
mentor={mentor}
347348
availability={availability}
348349
appearance={appearance}

0 commit comments

Comments
 (0)