|
| 1 | +import { useTheme } from "@material-ui/core/styles" |
| 2 | +import Table from "@material-ui/core/Table" |
| 3 | +import TableBody from "@material-ui/core/TableBody" |
| 4 | +import TableCell from "@material-ui/core/TableCell" |
| 5 | +import TableContainer from "@material-ui/core/TableContainer" |
| 6 | +import TableHead from "@material-ui/core/TableHead" |
| 7 | +import TableRow from "@material-ui/core/TableRow" |
| 8 | +import { APIKey } from "api/typesGenerated" |
| 9 | +import { ChooseOne, Cond } from "components/Conditionals/ChooseOne" |
| 10 | +import { Maybe } from "components/Conditionals/Maybe" |
| 11 | +import { Stack } from "components/Stack/Stack" |
| 12 | +import { TableEmpty } from "components/TableEmpty/TableEmpty" |
| 13 | +import { TableLoader } from "components/TableLoader/TableLoader" |
| 14 | +import { FC } from "react" |
| 15 | + |
| 16 | +export const Language = { |
| 17 | + idLabel: "ID", |
| 18 | + createdAtLabel: "Created At", |
| 19 | + lastUsedLabel: "Last Used", |
| 20 | + expiresAtLabel: "Expires At", |
| 21 | + emptyMessage: "No tokens found", |
| 22 | +} |
| 23 | + |
| 24 | +export interface TokensPageViewProps { |
| 25 | + tokens?: APIKey[] |
| 26 | + getTokensError?: Error | unknown |
| 27 | +} |
| 28 | + |
| 29 | +export const TokensPageView: FC< |
| 30 | + React.PropsWithChildren<TokensPageViewProps> |
| 31 | +> = ({ |
| 32 | + tokens, |
| 33 | +}) => { |
| 34 | + const theme = useTheme() |
| 35 | + |
| 36 | + return ( |
| 37 | + <Stack> |
| 38 | + <TableContainer> |
| 39 | + <Table> |
| 40 | + <TableHead> |
| 41 | + <TableRow> |
| 42 | + <TableCell width="34%">{Language.idLabel}</TableCell> |
| 43 | + <TableCell width="16%">{Language.createdAtLabel}</TableCell> |
| 44 | + <TableCell width="16%">{Language.lastUsedLabel}</TableCell> |
| 45 | + <TableCell width="16%">{Language.expiresAtLabel}</TableCell> |
| 46 | + <TableCell width="1%"></TableCell> |
| 47 | + </TableRow> |
| 48 | + </TableHead> |
| 49 | + <TableBody> |
| 50 | + <Maybe condition={tokens === undefined}> |
| 51 | + <TableLoader /> |
| 52 | + </Maybe> |
| 53 | + |
| 54 | + <ChooseOne> |
| 55 | + <Cond condition={Boolean(tokens?.length)}> |
| 56 | + <TableEmpty |
| 57 | + message={Language.emptyMessage} |
| 58 | + /> |
| 59 | + </Cond> |
| 60 | + <Cond> |
| 61 | + {tokens?.map((token) => { |
| 62 | + |
| 63 | + return ( |
| 64 | + <TableRow |
| 65 | + key={token.id} |
| 66 | + hover |
| 67 | + data-testid={`token-${token.id}`} |
| 68 | + tabIndex={0} |
| 69 | + > |
| 70 | + <TableCell> |
| 71 | + <span |
| 72 | + style={{ color: theme.palette.text.secondary }} |
| 73 | + > |
| 74 | + {token.id} |
| 75 | + </span> |
| 76 | + </TableCell> |
| 77 | + |
| 78 | + <TableCell> |
| 79 | + <span |
| 80 | + style={{ color: theme.palette.text.secondary }} |
| 81 | + > |
| 82 | + {token.created_at} |
| 83 | + </span> |
| 84 | + </TableCell> |
| 85 | + |
| 86 | + |
| 87 | + <TableCell> |
| 88 | + <span |
| 89 | + style={{ color: theme.palette.text.secondary }} |
| 90 | + > |
| 91 | + {token.last_used} |
| 92 | + </span> |
| 93 | + </TableCell> |
| 94 | + |
| 95 | + <TableCell> |
| 96 | + <span |
| 97 | + style={{ color: theme.palette.text.secondary }} |
| 98 | + > |
| 99 | + {token.expires_at} |
| 100 | + </span> |
| 101 | + </TableCell> |
| 102 | + </TableRow> |
| 103 | + ) |
| 104 | + })} |
| 105 | + </Cond> |
| 106 | + </ChooseOne> |
| 107 | + </TableBody> |
| 108 | + </Table> |
| 109 | + </TableContainer> |
| 110 | + </Stack> |
| 111 | + ) |
| 112 | +} |
0 commit comments