Skip to content

Commit fe72d04

Browse files
committed
chore: add refresh icon to tokens that can refresh
1 parent 4b2558b commit fe72d04

File tree

3 files changed

+50
-25
lines changed

3 files changed

+50
-25
lines changed

site/src/pages/UserSettingsPage/ExternalAuthPage/ExternalAuthPageView.stories.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Meta, StoryObj } from "@storybook/react";
22
import {
33
MockGithubAuthLink,
44
MockGithubExternalProvider,
5-
MockGithubValidateErrorAuthLink,
65
} from "testHelpers/entities";
76
import { ExternalAuthPageView } from "./ExternalAuthPageView";
87

@@ -69,7 +68,23 @@ export const Failed: Story = {
6968
providers: [MockGithubExternalProvider],
7069
links: [
7170
{
72-
...MockGithubValidateErrorAuthLink,
71+
...MockGithubAuthLink,
72+
validate_error: "Failed to refresh token",
73+
},
74+
],
75+
},
76+
},
77+
};
78+
79+
export const NoRefresh: Story = {
80+
args: {
81+
...meta.args,
82+
auths: {
83+
providers: [MockGithubExternalProvider],
84+
links: [
85+
{
86+
...MockGithubAuthLink,
87+
has_refresh_token: false,
7388
},
7489
],
7590
},

site/src/pages/UserSettingsPage/ExternalAuthPage/ExternalAuthPageView.tsx

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import CachedIcon from "@mui/icons-material/Cached";
12
import LoadingButton from "@mui/lab/LoadingButton";
3+
import Badge from "@mui/material/Badge";
24
import Divider from "@mui/material/Divider";
35
import Table from "@mui/material/Table";
46
import TableBody from "@mui/material/TableBody";
57
import TableCell from "@mui/material/TableCell";
68
import TableContainer from "@mui/material/TableContainer";
79
import TableHead from "@mui/material/TableHead";
810
import TableRow from "@mui/material/TableRow";
11+
import Tooltip from "@mui/material/Tooltip";
912
import visuallyHidden from "@mui/utils/visuallyHidden";
1013
import { type FC, useState, useCallback, useEffect } from "react";
1114
import { useQuery } from "react-query";
@@ -125,22 +128,39 @@ const ExternalAuthRow: FC<ExternalAuthRowProps> = ({
125128
? externalAuth.authenticated
126129
: link?.authenticated ?? false;
127130

131+
let avatar = app.display_icon ? (
132+
<Avatar src={app.display_icon} variant="square" fitImage size="sm" />
133+
) : (
134+
<Avatar>{name}</Avatar>
135+
);
136+
137+
// If the link is authenticated and has a refresh token, show that it will automatically
138+
// attempt to authenticate when the token expires.
139+
if (link?.has_refresh_token && authenticated) {
140+
avatar = (
141+
<Badge
142+
anchorOrigin={{
143+
vertical: "bottom",
144+
horizontal: "right",
145+
}}
146+
badgeContent={
147+
<Tooltip
148+
title="Authentication token will automatically refresh when expired."
149+
placement="right"
150+
>
151+
<CachedIcon fontSize="small" />
152+
</Tooltip>
153+
}
154+
>
155+
{avatar}
156+
</Badge>
157+
);
158+
}
159+
128160
return (
129161
<TableRow key={app.id}>
130162
<TableCell>
131-
<AvatarData
132-
title={name}
133-
avatar={
134-
app.display_icon && (
135-
<Avatar
136-
src={app.display_icon}
137-
variant="square"
138-
fitImage
139-
size="sm"
140-
/>
141-
)
142-
}
143-
/>
163+
<AvatarData title={name} avatar={avatar} />
144164
{/* TODO: Style this! */}
145165
{link?.validate_error}
146166
</TableCell>

site/src/testHelpers/entities.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3455,16 +3455,6 @@ export const MockGithubAuthLink: TypesGen.ExternalAuthLink = {
34553455
validate_error: "",
34563456
};
34573457

3458-
export const MockGithubValidateErrorAuthLink: TypesGen.ExternalAuthLink = {
3459-
provider_id: "github",
3460-
created_at: "",
3461-
updated_at: "",
3462-
has_refresh_token: true,
3463-
expires: "",
3464-
authenticated: false,
3465-
validate_error: "Failed to refresh token.",
3466-
};
3467-
34683458
export const MockOAuth2ProviderApps: TypesGen.OAuth2ProviderApp[] = [
34693459
{
34703460
id: "1",

0 commit comments

Comments
 (0)