1
- import Box from "@mui/material/Box"
2
- import { makeStyles } from "@mui/styles"
1
+ import Box , { BoxProps } from "@mui/material/Box"
2
+ import { makeStyles , useTheme } from "@mui/styles"
3
3
import TableCell from "@mui/material/TableCell"
4
4
import TableRow from "@mui/material/TableRow"
5
5
import { ChooseOne , Cond } from "components/Conditionals/ChooseOne"
6
- import { LastUsed } from "components/LastUsed/LastUsed"
7
6
import { Pill } from "components/Pill/Pill"
8
7
import { FC } from "react"
9
8
import { useTranslation } from "react-i18next"
@@ -16,6 +15,8 @@ import { TableRowMenu } from "../TableRowMenu/TableRowMenu"
16
15
import { EditRolesButton } from "components/EditRolesButton/EditRolesButton"
17
16
import { Stack } from "components/Stack/Stack"
18
17
import { EnterpriseBadge } from "components/DeploySettingsLayout/Badges"
18
+ import dayjs from "dayjs"
19
+ import { Theme } from "@mui/material/styles"
19
20
20
21
const isOwnerRole = ( role : TypesGen . Role ) : boolean => {
21
22
return role . name === "owner"
@@ -166,11 +167,10 @@ export const UsersTableBody: FC<
166
167
: undefined ,
167
168
] ) }
168
169
>
169
- { user . status }
170
- </ TableCell >
171
- < TableCell >
172
- < LastUsed lastUsedAt = { user . last_seen_at } />
170
+ < Box > { user . status } </ Box >
171
+ < LastSeen value = { user . last_seen_at } sx = { { fontSize : 12 } } />
173
172
</ TableCell >
173
+
174
174
{ canEditUsers && (
175
175
< TableCell >
176
176
< TableRowMenu
@@ -236,6 +236,44 @@ export const UsersTableBody: FC<
236
236
)
237
237
}
238
238
239
+ export const LastSeen = ( {
240
+ value,
241
+ ...boxProps
242
+ } : { value : string } & BoxProps ) => {
243
+ const theme : Theme = useTheme ( )
244
+ const t = dayjs ( value )
245
+ const now = dayjs ( )
246
+
247
+ let message = t . fromNow ( )
248
+ let color = theme . palette . text . secondary
249
+
250
+ if ( t . isAfter ( now . subtract ( 1 , "hour" ) ) ) {
251
+ color = theme . palette . success . light
252
+ // Since the agent reports on a 10m interval,
253
+ // the last_used_at can be inaccurate when recent.
254
+ message = "Now"
255
+ } else if ( t . isAfter ( now . subtract ( 3 , "day" ) ) ) {
256
+ color = theme . palette . text . secondary
257
+ } else if ( t . isAfter ( now . subtract ( 1 , "month" ) ) ) {
258
+ color = theme . palette . warning . light
259
+ } else if ( t . isAfter ( now . subtract ( 100 , "year" ) ) ) {
260
+ color = theme . palette . error . light
261
+ } else {
262
+ message = "Never"
263
+ }
264
+
265
+ return (
266
+ < Box
267
+ component = "span"
268
+ data-chromatic = "ignore"
269
+ { ...boxProps }
270
+ sx = { { color, ...boxProps . sx } }
271
+ >
272
+ { message }
273
+ </ Box >
274
+ )
275
+ }
276
+
239
277
const useStyles = makeStyles ( ( theme ) => ( {
240
278
status : {
241
279
textTransform : "capitalize" ,
0 commit comments