Skip to content

Commit f99d7bf

Browse files
committed
Show user's last activity
1 parent 4ca1c98 commit f99d7bf

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
lines changed

src/lib/helpers/date.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
export const toLocaleDate = (datetime: string) => {
22
const date = new Date(datetime);
3+
4+
if (isNaN(date.getTime())) {
5+
return 'n/a';
6+
}
7+
38
const options: Intl.DateTimeFormatOptions = {
49
year: 'numeric',
510
month: 'short',
@@ -11,6 +16,11 @@ export const toLocaleDate = (datetime: string) => {
1116

1217
export const toLocaleDateTime = (datetime: string | number) => {
1318
const date = new Date(datetime);
19+
20+
if (isNaN(date.getTime())) {
21+
return 'n/a';
22+
}
23+
1424
const options: Intl.DateTimeFormatOptions = {
1525
year: 'numeric',
1626
month: 'short',

src/routes/console/project-[project]/auth/+page.svelte

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
TableRowLink
2020
} from '$lib/elements/table';
2121
import { Pill } from '$lib/elements';
22-
import { toLocaleDateTime } from '$lib/helpers/date';
22+
import { toLocaleDate, toLocaleDateTime } from '$lib/helpers/date';
2323
import { Container } from '$lib/layout';
2424
import { base } from '$app/paths';
2525
import { goto } from '$app/navigation';
@@ -29,6 +29,13 @@
2929
3030
export let data: PageData;
3131
32+
// TODO: Remove this when the console SDK is updated
33+
const users = data.users.users.map((user) => {
34+
const labels: string[] = [];
35+
const accessedAt = '';
36+
return { accessedAt, labels, ...user };
37+
});
38+
3239
let showCreate = false;
3340
const projectId = $page.params.project;
3441
async function userCreated(event: CustomEvent<Models.User<Record<string, unknown>>>) {
@@ -50,9 +57,10 @@
5057
<TableCellHead onlyDesktop width={130}>Status</TableCellHead>
5158
<TableCellHead onlyDesktop width={100}>ID</TableCellHead>
5259
<TableCellHead onlyDesktop>Joined</TableCellHead>
60+
<TableCellHead onlyDesktop>Last Activity</TableCellHead>
5361
</TableHeader>
5462
<TableBody>
55-
{#each data.users.users as user}
63+
{#each users as user}
5664
<TableRowLink
5765
href={`${base}/console/project-${projectId}/auth/user-${user.$id}`}>
5866
<TableCell title="Name">
@@ -105,6 +113,9 @@
105113
<TableCellText onlyDesktop title="Joined">
106114
{toLocaleDateTime(user.registration)}
107115
</TableCellText>
116+
<TableCellText onlyDesktop title="Last Activity">
117+
{toLocaleDate(user.accessedAt)}
118+
</TableCellText>
108119
</TableRowLink>
109120
{/each}
110121
</TableBody>

src/routes/console/project-[project]/auth/user-[user]/dangerZone.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<script lang="ts">
22
import { CardGrid, Box, Heading, AvatarInitials } from '$lib/components';
33
import { Button } from '$lib/elements/forms';
4+
import { toLocaleDate } from '$lib/helpers/date';
45
import DeleteUser from './deleteUser.svelte';
56
import { user } from './store';
67
78
let showDelete = false;
9+
10+
// TODO: Remove this when the console SDK is updated
11+
$: accessedAt = ($user as unknown as { accessedAt: string }).accessedAt;
812
</script>
913

1014
<CardGrid danger>
@@ -42,6 +46,7 @@
4246
? [$user.email, $user.phone].join(',')
4347
: $user.email || $user.phone}
4448
</p>
49+
<p>Last activity: {toLocaleDate(accessedAt)}</p>
4550
</Box>
4651
</svelte:fragment>
4752

src/routes/console/project-[project]/auth/user-[user]/updateStatus.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { Dependencies } from '$lib/constants';
66
import { Pill } from '$lib/elements';
77
import { Button } from '$lib/elements/forms';
8-
import { toLocaleDateTime } from '$lib/helpers/date';
8+
import { toLocaleDate, toLocaleDateTime } from '$lib/helpers/date';
99
import { addNotification } from '$lib/stores/notifications';
1010
import { sdk } from '$lib/stores/sdk';
1111
import { user } from './store';
@@ -71,6 +71,9 @@
7171
trackError(error, Submit.UserUpdateStatus);
7272
}
7373
}
74+
75+
// TODO: Remove this when the console SDK is updated
76+
$: accessedAt = ($user as unknown as { accessedAt: string }).accessedAt;
7477
</script>
7578

7679
<CardGrid>
@@ -100,6 +103,7 @@
100103
<p class="title">{$user.phone}</p>
101104
{/if}
102105
<p>Joined: {toLocaleDateTime($user.registration)}</p>
106+
<p>Last activity: {toLocaleDate(accessedAt)}</p>
103107
</div>
104108
{#if !$user.status}
105109
<Pill danger>blocked</Pill>

tests/unit/helpers/date.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ describe('local date', () => {
1616
expect(toLocaleDate(value)).toBe(expected);
1717
});
1818
});
19+
20+
it('invalid date', () => {
21+
expect(toLocaleDate('')).toBe('n/a');
22+
});
1923
});
2024

2125
describe('local date time', () => {
@@ -27,6 +31,10 @@ describe('local date time', () => {
2731
expect(toLocaleDateTime(value)).toBe(expected);
2832
});
2933
});
34+
35+
it('invalid date', () => {
36+
expect(toLocaleDateTime('')).toBe('n/a');
37+
});
3038
});
3139

3240
describe('is same day', () => {

0 commit comments

Comments
 (0)