@@ -13,28 +13,22 @@ import PlaceholderLoader from '../UI/PlaceholderLoader';
13
13
import { getGravatarUrl } from '../UI/GravatarUrl' ;
14
14
import Text from '../UI/Text' ;
15
15
import { I18n } from '@lingui/react' ;
16
- import PlaceholderError from '../UI/PlaceholderError' ;
17
16
import RaisedButton from '../UI/RaisedButton' ;
18
- import { type Achievement } from '../Utils/GDevelopServices/Badge' ;
19
17
import Window from '../Utils/Window' ;
20
18
import { GDevelopGamesPlatform } from '../Utils/GDevelopServices/ApiConfigs' ;
21
19
import FlatButton from '../UI/FlatButton' ;
22
20
import ShareExternal from '../UI/CustomSvgIcons/ShareExternal' ;
23
21
import {
24
22
communityLinksConfig ,
25
- type CommunityLinks ,
26
23
syncDiscordUsername ,
27
24
} from '../Utils/GDevelopServices/User' ;
28
- import AuthenticatedUserContext from './AuthenticatedUserContext' ;
25
+ import { type AuthenticatedUser } from './AuthenticatedUserContext' ;
29
26
import IconButton from '../UI/IconButton' ;
30
27
import Refresh from '../UI/CustomSvgIcons/Refresh' ;
31
28
import Check from '../UI/CustomSvgIcons/Check' ;
32
29
import { MarkdownText } from '../UI/MarkdownText' ;
33
30
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' ;
38
32
import { extractGDevelopApiErrorStatusAndCode } from '../Utils/GDevelopServices/Errors' ;
39
33
40
34
const CommunityLinksLines = ( {
@@ -60,39 +54,36 @@ const CommunityLinksLines = ({
60
54
</ ColumnStackLayout >
61
55
) ;
62
56
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
-
75
57
type Props = { |
76
- profile : ?DisplayedProfile ,
77
- subscription ?: ?Subscription ,
78
- achievements : ?Array < Achievement > ,
79
- error ?: ?Error ,
80
- onRetry ?: ( ) => void ,
58
+ authenticatedUser : AuthenticatedUser ,
81
59
onOpenChangeEmailDialog ?: ( ) => void ,
82
60
onOpenEditProfileDialog ?: ( ) => void ,
83
- hideSocials ? : boolean ,
84
61
| } ;
85
62
86
63
const ProfileDetails = ( {
87
- profile,
88
- subscription,
89
- achievements,
90
- error,
91
- onRetry,
64
+ authenticatedUser,
92
65
onOpenChangeEmailDialog,
93
66
onOpenEditProfileDialog,
94
- hideSocials,
95
67
} : 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 ;
96
87
const email = profile ? profile . email : null ;
97
88
const donateLink = profile ? profile . donateLink : null ;
98
89
const discordUsername = profile ? profile . discordUsername : null ;
@@ -112,26 +103,34 @@ const ProfileDetails = ({
112
103
const redditUsername = profile ? communityLinks . redditUsername : null ;
113
104
const snapchatUsername = profile ? communityLinks . snapchatUsername : null ;
114
105
const discordServerLink = profile ? communityLinks . discordServerLink : null ;
115
- const { getAuthorizationHeader } = React . useContext ( AuthenticatedUserContext ) ;
116
106
const { showAlert } = useAlertDialog ( ) ;
117
107
const githubStarAchievement =
118
108
( achievements &&
119
109
achievements . find ( achievement => achievement . id === 'github-star' ) ) ||
120
110
null ;
111
+ const hasGithubBadge =
112
+ ! ! badges && badges . some ( badge => badge . achievementId === 'github-star' ) ;
121
113
const tiktokFollowAchievement =
122
114
( achievements &&
123
115
achievements . find ( achievement => achievement . id === 'tiktok-follow' ) ) ||
124
116
null ;
117
+ const hasTiktokBadge =
118
+ ! ! badges && badges . some ( badge => badge . achievementId === 'tiktok-follow' ) ;
125
119
const twitterFollowAchievement =
126
120
( achievements &&
127
121
achievements . find ( achievement => achievement . id === 'twitter-follow' ) ) ||
128
122
null ;
123
+ const hasTwitterBadge =
124
+ ! ! badges && badges . some ( badge => badge . achievementId === 'twitter-follow' ) ;
129
125
const youtubeSubscriptionAchievement =
130
126
( achievements &&
131
127
achievements . find (
132
128
achievement => achievement . id === 'youtube-subscription'
133
129
) ) ||
134
130
null ;
131
+ const hasYoutubeBadge =
132
+ ! ! badges &&
133
+ badges . some ( badge => badge . achievementId === 'youtube-subscription' ) ;
135
134
136
135
const [
137
136
discordUsernameSyncStatus ,
@@ -176,16 +175,6 @@ const ProfileDetails = ({
176
175
177
176
const canUserBenefitFromDiscordRole = canBenefitFromDiscordRole ( subscription ) ;
178
177
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
-
189
178
if ( ! profile ) {
190
179
return < PlaceholderLoader /> ;
191
180
}
@@ -280,70 +269,74 @@ const ProfileDetails = ({
280
269
< CommunityLinksLines
281
270
communityLinks = { [
282
271
{
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
+ ) ,
296
286
isNotFilled : ! githubUsername ,
297
287
icon : communityLinksConfig . githubUsername . icon ,
298
288
} ,
299
289
{
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
+ ) ,
313
304
isNotFilled : ! twitterUsername ,
314
305
icon : communityLinksConfig . twitterUsername . icon ,
315
306
} ,
316
307
{
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
+ ) ,
330
322
isNotFilled : ! youtubeUsername ,
331
323
icon : communityLinksConfig . youtubeUsername . icon ,
332
324
} ,
333
325
{
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
+ ) ,
347
340
isNotFilled : ! tiktokUsername ,
348
341
icon : communityLinksConfig . tiktokUsername . icon ,
349
342
} ,
0 commit comments