saleor-dashboard/src/services/components/ServiceTokens/ServiceTokens.tsx

129 lines
3.8 KiB
TypeScript
Raw Normal View History

2019-09-26 15:33:44 +00:00
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import IconButton from "@material-ui/core/IconButton";
2019-10-28 16:16:49 +00:00
import makeStyles from "@material-ui/core/styles/makeStyles";
2019-09-26 15:33:44 +00:00
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import DeleteIcon from "@material-ui/icons/Delete";
import CardTitle from "@saleor/components/CardTitle";
2019-11-04 14:25:23 +00:00
import ResponsiveTable from "@saleor/components/ResponsiveTable";
2019-09-26 15:33:44 +00:00
import Skeleton from "@saleor/components/Skeleton";
import { ServiceDetailsFragment_tokens } from "@saleor/fragments/types/ServiceDetailsFragment";
2019-09-26 15:33:44 +00:00
import { maybe, renderCollection } from "@saleor/misc";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
2019-09-26 15:33:44 +00:00
export interface ServiceTokensProps {
tokens: ServiceDetailsFragment_tokens[];
onCreate: () => void;
onDelete: (id: string) => void;
}
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
[theme.breakpoints.down("md")]: {
colNote: {
width: 200
}
},
colActions: {
textAlign: "right",
width: 100
},
colKey: {
2019-09-26 15:33:44 +00:00
width: 200
2019-12-03 15:28:40 +00:00
},
colNote: {},
table: {
tableLayout: "fixed"
2019-09-26 15:33:44 +00:00
}
2019-12-03 15:28:40 +00:00
}),
{ name: "ServiceTokens" }
);
2019-09-26 15:33:44 +00:00
const numberOfColumns = 3;
const ServiceTokens: React.FC<ServiceTokensProps> = props => {
const { tokens, onCreate, onDelete } = props;
const classes = useStyles(props);
const intl = useIntl();
return (
<Card>
<CardTitle
title={intl.formatMessage({
defaultMessage: "Service Account Information",
description: "header"
})}
toolbar={
<Button color="primary" onClick={onCreate}>
<FormattedMessage
defaultMessage="Create Token"
description="button"
/>
</Button>
}
/>
2019-11-04 14:25:23 +00:00
<ResponsiveTable>
2019-09-26 15:33:44 +00:00
<TableHead>
<TableRow>
<TableCell className={classes.colNote}>
<FormattedMessage defaultMessage="Token Note" />
</TableCell>
<TableCell className={classes.colKey}>
<FormattedMessage
defaultMessage="Key"
description="service account key"
/>
</TableCell>
<TableCell className={classes.colActions}>
<FormattedMessage
defaultMessage="Actions"
description="table actions"
/>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{renderCollection(
tokens,
token => (
<TableRow key={token ? token.id : "skeleton"}>
<TableCell className={classes.colNote}>
{maybe<React.ReactNode>(() => token.name, <Skeleton />)}
</TableCell>
<TableCell className={classes.colKey}>
2019-09-30 10:32:00 +00:00
{maybe<React.ReactNode>(
() => `**** ${token.authToken}`,
<Skeleton />
)}
2019-09-26 15:33:44 +00:00
</TableCell>
<TableCell className={classes.colActions}>
<IconButton
color="primary"
onClick={() => onDelete(token.id)}
>
<DeleteIcon />
</IconButton>
</TableCell>
</TableRow>
),
() => (
<TableRow>
<TableCell colSpan={numberOfColumns}>
<FormattedMessage defaultMessage="No tokens found" />
</TableCell>
</TableRow>
)
)}
</TableBody>
2019-11-04 14:25:23 +00:00
</ResponsiveTable>
2019-09-26 15:33:44 +00:00
</Card>
);
};
ServiceTokens.displayName = "ServiceTokens";
export default ServiceTokens;