Skip to content

Commit be5cc49

Browse files
Fix discord role claim & other display issues in the profile (#7468)
1 parent 4bdf717 commit be5cc49

File tree

3 files changed

+109
-186
lines changed

3 files changed

+109
-186
lines changed

newIDE/app/src/Profile/AuthenticatedUserProfileDetails.js

+1-14
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ const AuthenticatedUserProfileDetails = ({
3232
[authenticatedUser]
3333
);
3434

35-
const hideSocials =
36-
!!authenticatedUser.limits &&
37-
!!authenticatedUser.limits.capabilities.classrooms &&
38-
authenticatedUser.limits.capabilities.classrooms.hideSocials;
39-
4035
return firebaseUser && profile ? (
4136
<ColumnStackLayout noMargin>
4237
{firebaseUser && !firebaseUser.emailVerified && (
@@ -57,17 +52,9 @@ const AuthenticatedUserProfileDetails = ({
5752
</AlertMessage>
5853
)}
5954
<ProfileDetails
60-
// The firebase user is the source of truth for the emails.
61-
profile={
62-
authenticatedUser.profile
63-
? { ...authenticatedUser.profile, email: firebaseUser.email }
64-
: null
65-
}
66-
subscription={authenticatedUser.subscription}
67-
achievements={authenticatedUser.achievements}
55+
authenticatedUser={authenticatedUser}
6856
onOpenChangeEmailDialog={onOpenChangeEmailDialog}
6957
onOpenEditProfileDialog={onOpenEditProfileDialog}
70-
hideSocials={hideSocials}
7158
/>
7259
</ColumnStackLayout>
7360
) : (

newIDE/app/src/Profile/ProfileDetails.js

+88-95
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,22 @@ import PlaceholderLoader from '../UI/PlaceholderLoader';
1313
import { getGravatarUrl } from '../UI/GravatarUrl';
1414
import Text from '../UI/Text';
1515
import { I18n } from '@lingui/react';
16-
import PlaceholderError from '../UI/PlaceholderError';
1716
import RaisedButton from '../UI/RaisedButton';
18-
import { type Achievement } from '../Utils/GDevelopServices/Badge';
1917
import Window from '../Utils/Window';
2018
import { GDevelopGamesPlatform } from '../Utils/GDevelopServices/ApiConfigs';
2119
import FlatButton from '../UI/FlatButton';
2220
import ShareExternal from '../UI/CustomSvgIcons/ShareExternal';
2321
import {
2422
communityLinksConfig,
25-
type CommunityLinks,
2623
syncDiscordUsername,
2724
} from '../Utils/GDevelopServices/User';
28-
import AuthenticatedUserContext from './AuthenticatedUserContext';
25+
import { type AuthenticatedUser } from './AuthenticatedUserContext';
2926
import IconButton from '../UI/IconButton';
3027
import Refresh from '../UI/CustomSvgIcons/Refresh';
3128
import Check from '../UI/CustomSvgIcons/Check';
3229
import { MarkdownText } from '../UI/MarkdownText';
3330
import useAlertDialog from '../UI/Alert/useAlertDialog';
34-
import {
35-
canBenefitFromDiscordRole,
36-
type Subscription,
37-
} from '../Utils/GDevelopServices/Usage';
31+
import { canBenefitFromDiscordRole } from '../Utils/GDevelopServices/Usage';
3832
import { extractGDevelopApiErrorStatusAndCode } from '../Utils/GDevelopServices/Errors';
3933

4034
const CommunityLinksLines = ({
@@ -60,39 +54,36 @@ const CommunityLinksLines = ({
6054
</ColumnStackLayout>
6155
);
6256

63-
type DisplayedProfile = {
64-
id: string,
65-
+email?: string, // the "+" allows handling both public and private profile
66-
username: ?string,
67-
description: ?string,
68-
donateLink: ?string,
69-
discordUsername: ?string,
70-
githubUsername: ?string,
71-
+isEmailAutogenerated?: boolean, // the "+" allows handling both public and private profile
72-
+communityLinks?: CommunityLinks, // the "+" allows handling both public and private profile
73-
};
74-
7557
type Props = {|
76-
profile: ?DisplayedProfile,
77-
subscription?: ?Subscription,
78-
achievements: ?Array<Achievement>,
79-
error?: ?Error,
80-
onRetry?: () => void,
58+
authenticatedUser: AuthenticatedUser,
8159
onOpenChangeEmailDialog?: () => void,
8260
onOpenEditProfileDialog?: () => void,
83-
hideSocials?: boolean,
8461
|};
8562

8663
const ProfileDetails = ({
87-
profile,
88-
subscription,
89-
achievements,
90-
error,
91-
onRetry,
64+
authenticatedUser,
9265
onOpenChangeEmailDialog,
9366
onOpenEditProfileDialog,
94-
hideSocials,
9567
}: Props) => {
68+
const {
69+
firebaseUser,
70+
achievements,
71+
badges,
72+
subscription,
73+
getAuthorizationHeader,
74+
} = authenticatedUser;
75+
const profile = React.useMemo(
76+
() =>
77+
authenticatedUser.profile && firebaseUser
78+
? // The firebase user is the source of truth for the emails.
79+
{ ...authenticatedUser.profile, email: firebaseUser.email }
80+
: null,
81+
[authenticatedUser.profile, firebaseUser]
82+
);
83+
const hideSocials =
84+
!!authenticatedUser.limits &&
85+
!!authenticatedUser.limits.capabilities.classrooms &&
86+
authenticatedUser.limits.capabilities.classrooms.hideSocials;
9687
const email = profile ? profile.email : null;
9788
const donateLink = profile ? profile.donateLink : null;
9889
const discordUsername = profile ? profile.discordUsername : null;
@@ -112,26 +103,34 @@ const ProfileDetails = ({
112103
const redditUsername = profile ? communityLinks.redditUsername : null;
113104
const snapchatUsername = profile ? communityLinks.snapchatUsername : null;
114105
const discordServerLink = profile ? communityLinks.discordServerLink : null;
115-
const { getAuthorizationHeader } = React.useContext(AuthenticatedUserContext);
116106
const { showAlert } = useAlertDialog();
117107
const githubStarAchievement =
118108
(achievements &&
119109
achievements.find(achievement => achievement.id === 'github-star')) ||
120110
null;
111+
const hasGithubBadge =
112+
!!badges && badges.some(badge => badge.achievementId === 'github-star');
121113
const tiktokFollowAchievement =
122114
(achievements &&
123115
achievements.find(achievement => achievement.id === 'tiktok-follow')) ||
124116
null;
117+
const hasTiktokBadge =
118+
!!badges && badges.some(badge => badge.achievementId === 'tiktok-follow');
125119
const twitterFollowAchievement =
126120
(achievements &&
127121
achievements.find(achievement => achievement.id === 'twitter-follow')) ||
128122
null;
123+
const hasTwitterBadge =
124+
!!badges && badges.some(badge => badge.achievementId === 'twitter-follow');
129125
const youtubeSubscriptionAchievement =
130126
(achievements &&
131127
achievements.find(
132128
achievement => achievement.id === 'youtube-subscription'
133129
)) ||
134130
null;
131+
const hasYoutubeBadge =
132+
!!badges &&
133+
badges.some(badge => badge.achievementId === 'youtube-subscription');
135134

136135
const [
137136
discordUsernameSyncStatus,
@@ -176,16 +175,6 @@ const ProfileDetails = ({
176175

177176
const canUserBenefitFromDiscordRole = canBenefitFromDiscordRole(subscription);
178177

179-
if (error)
180-
return (
181-
<PlaceholderError onRetry={onRetry}>
182-
<Trans>
183-
Unable to load the profile, please verify your internet connection or
184-
try again later.
185-
</Trans>
186-
</PlaceholderError>
187-
);
188-
189178
if (!profile) {
190179
return <PlaceholderLoader />;
191180
}
@@ -280,70 +269,74 @@ const ProfileDetails = ({
280269
<CommunityLinksLines
281270
communityLinks={[
282271
{
283-
text: !githubUsername ? (
284-
<MarkdownText
285-
translatableSource={communityLinksConfig.githubUsername.getRewardMessage(
286-
false,
287-
githubStarAchievement &&
288-
githubStarAchievement.rewardValueInCredits
289-
? githubStarAchievement.rewardValueInCredits.toString()
290-
: '-'
291-
)}
292-
/>
293-
) : (
294-
githubUsername
295-
),
272+
text:
273+
!githubUsername && !hasGithubBadge ? (
274+
<MarkdownText
275+
translatableSource={communityLinksConfig.githubUsername.getRewardMessage(
276+
false,
277+
githubStarAchievement &&
278+
githubStarAchievement.rewardValueInCredits
279+
? githubStarAchievement.rewardValueInCredits.toString()
280+
: '-'
281+
)}
282+
/>
283+
) : (
284+
githubUsername
285+
),
296286
isNotFilled: !githubUsername,
297287
icon: communityLinksConfig.githubUsername.icon,
298288
},
299289
{
300-
text: !twitterUsername ? (
301-
<MarkdownText
302-
translatableSource={communityLinksConfig.twitterUsername.getRewardMessage(
303-
false,
304-
twitterFollowAchievement &&
305-
twitterFollowAchievement.rewardValueInCredits
306-
? twitterFollowAchievement.rewardValueInCredits.toString()
307-
: '-'
308-
)}
309-
/>
310-
) : (
311-
twitterUsername
312-
),
290+
text:
291+
!twitterUsername && !hasTwitterBadge ? (
292+
<MarkdownText
293+
translatableSource={communityLinksConfig.twitterUsername.getRewardMessage(
294+
false,
295+
twitterFollowAchievement &&
296+
twitterFollowAchievement.rewardValueInCredits
297+
? twitterFollowAchievement.rewardValueInCredits.toString()
298+
: '-'
299+
)}
300+
/>
301+
) : (
302+
twitterUsername
303+
),
313304
isNotFilled: !twitterUsername,
314305
icon: communityLinksConfig.twitterUsername.icon,
315306
},
316307
{
317-
text: !youtubeUsername ? (
318-
<MarkdownText
319-
translatableSource={communityLinksConfig.youtubeUsername.getRewardMessage(
320-
false,
321-
youtubeSubscriptionAchievement &&
322-
youtubeSubscriptionAchievement.rewardValueInCredits
323-
? youtubeSubscriptionAchievement.rewardValueInCredits.toString()
324-
: '-'
325-
)}
326-
/>
327-
) : (
328-
youtubeUsername
329-
),
308+
text:
309+
!youtubeUsername && !hasYoutubeBadge ? (
310+
<MarkdownText
311+
translatableSource={communityLinksConfig.youtubeUsername.getRewardMessage(
312+
false,
313+
youtubeSubscriptionAchievement &&
314+
youtubeSubscriptionAchievement.rewardValueInCredits
315+
? youtubeSubscriptionAchievement.rewardValueInCredits.toString()
316+
: '-'
317+
)}
318+
/>
319+
) : (
320+
youtubeUsername
321+
),
330322
isNotFilled: !youtubeUsername,
331323
icon: communityLinksConfig.youtubeUsername.icon,
332324
},
333325
{
334-
text: !tiktokUsername ? (
335-
<MarkdownText
336-
translatableSource={communityLinksConfig.tiktokUsername.getRewardMessage(
337-
false,
338-
tiktokFollowAchievement &&
339-
tiktokFollowAchievement.rewardValueInCredits
340-
? tiktokFollowAchievement.rewardValueInCredits.toString()
341-
: '-'
342-
)}
343-
/>
344-
) : (
345-
tiktokUsername
346-
),
326+
text:
327+
!tiktokUsername && !hasTiktokBadge ? (
328+
<MarkdownText
329+
translatableSource={communityLinksConfig.tiktokUsername.getRewardMessage(
330+
false,
331+
tiktokFollowAchievement &&
332+
tiktokFollowAchievement.rewardValueInCredits
333+
? tiktokFollowAchievement.rewardValueInCredits.toString()
334+
: '-'
335+
)}
336+
/>
337+
) : (
338+
tiktokUsername
339+
),
347340
isNotFilled: !tiktokUsername,
348341
icon: communityLinksConfig.tiktokUsername.icon,
349342
},

0 commit comments

Comments
 (0)