Skip to content

Commit 4235d33

Browse files
authored
Merge pull request #973 from mapswipe/fix/username-display
Fix username display on user group dashboard table
2 parents 75e6750 + 5faf645 commit 4235d33

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

community-dashboard/app/components/ItemSelectInput/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
IoPeople,
77
IoSearch,
88
} from 'react-icons/io5';
9-
import { _cs } from '@togglecorp/fujs';
9+
import { isFalsyString, _cs } from '@togglecorp/fujs';
1010
import {
1111
useQuery,
1212
gql,
@@ -192,7 +192,7 @@ function ItemSelectInput<Name extends string>(props: ItemSelectInputProps<Name>)
192192
() => ([
193193
...(usersData?.map((user) => ({
194194
id: user.userId,
195-
name: user.username ?? 'Unknown',
195+
name: (isFalsyString(user.username) ? user.userId : user.username),
196196
type: 'user' as const,
197197
})) ?? []),
198198
...(userGroupsData?.map((userGroup) => ({

community-dashboard/app/components/MemberItem/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { Link, generatePath } from 'react-router-dom';
3-
import { isDefined } from '@togglecorp/fujs';
3+
import { isDefined, isFalsyString } from '@togglecorp/fujs';
44

55
import NumberOutput from '#components/NumberOutput';
66
import routes from '#base/configs/routes';
@@ -27,14 +27,17 @@ function MemberItem(props: Props) {
2727
{ userId: member.userId },
2828
);
2929

30+
// NOTE: OSM user does not have username stored
31+
const memberName = isFalsyString(member.username) ? member.userId : member.username;
32+
3033
return (
3134
<div className={styles.member}>
3235
<div className={styles.memberName}>
3336
<Link
3437
className={styles.link}
3538
to={path}
3639
>
37-
{member.username}
40+
{memberName}
3841
</Link>
3942
{!member.isActive && (
4043
<div className={styles.inactive}>

community-dashboard/app/views/UserDashboard/index.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react';
1+
import React, { useMemo } from 'react';
22
import { gql, useQuery } from '@apollo/client';
3-
import { encodeDate } from '@togglecorp/fujs';
3+
import { encodeDate, isDefined, isFalsyString } from '@togglecorp/fujs';
44
import { useParams, generatePath, Link } from 'react-router-dom';
55

66
import useUrlState from '#hooks/useUrlState';
@@ -181,11 +181,22 @@ function UserDashboard(props: Props) {
181181

182182
const filteredStats = filteredUserStats?.userStats?.filteredStats;
183183

184+
// NOTE: OSM user does not have username stored
185+
const userName = useMemo(() => {
186+
if (isDefined(userStats) && isDefined(userStats.user)) {
187+
return isFalsyString(userStats.user.username)
188+
? userStats.user.userId
189+
: userStats.user.username;
190+
}
191+
192+
return null;
193+
}, [userStats]);
194+
184195
return (
185196
<Page
186197
className={className}
187198
variant="user"
188-
heading={userStats?.user.username}
199+
heading={userName}
189200
totalSwipes={totalSwipes}
190201
totalSwipesLastMonth={totalSwipesLastMonth}
191202
totalTimeSpent={totalSwipeTime}

community-dashboard/app/views/UserGroupDashboard/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useCallback, useMemo, useState } from 'react';
22
import { gql, useQuery, useLazyQuery } from '@apollo/client';
3-
import { encodeDate } from '@togglecorp/fujs';
3+
import { encodeDate, isFalsyString } from '@togglecorp/fujs';
44
import { useParams } from 'react-router-dom';
55

66
import StatsBoard from '#views/StatsBoard';
@@ -137,7 +137,7 @@ const USER_MEMBERSHIPS_EXPORT = gql`
137137
type UserGroupMember = NonNullable<NonNullable<NonNullable<UserGroupStatsQuery['userGroup']>['userMemberships']>['items']>[number];
138138

139139
function memberKeySelector(member: UserGroupMember) {
140-
return member.username;
140+
return member.userId;
141141
}
142142

143143
interface DateRangeValue {
@@ -239,7 +239,7 @@ function UserGroupDashboard(props: Props) {
239239
['User', 'Total swipes', 'Project contributed', 'Time spent(mins)'],
240240
...(newUserMembershipsData?.map((user) => (
241241
[
242-
user.username,
242+
isFalsyString(user.username) ? user.userId : user.username,
243243
user.totalSwipes,
244244
user.totalMappingProjects,
245245
user.totalSwipeTime,

0 commit comments

Comments
 (0)