2021-05-14 08:15:15 +00:00
|
|
|
import {
|
|
|
|
Card,
|
|
|
|
TableBody,
|
|
|
|
TableCell,
|
|
|
|
TableHead,
|
|
|
|
TableRow
|
|
|
|
} from "@material-ui/core";
|
2019-09-26 15:33:44 +00:00
|
|
|
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";
|
2022-01-28 12:34:20 +00:00
|
|
|
import { Button, DeleteIcon, IconButton } from "@saleor/macaw-ui";
|
2020-07-22 10:54:15 +00:00
|
|
|
import { renderCollection } from "@saleor/misc";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2019-09-26 15:33:44 +00:00
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
import { AppUpdate_appUpdate_app_tokens } from "../../types/AppUpdate";
|
|
|
|
import { useStyles } from "./styles";
|
|
|
|
|
|
|
|
export interface CustomAppTokensProps {
|
|
|
|
tokens: Array<AppUpdate_appUpdate_app_tokens | null> | null;
|
2019-09-26 15:33:44 +00:00
|
|
|
onCreate: () => void;
|
|
|
|
onDelete: (id: string) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const numberOfColumns = 3;
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
const CustomAppTokens: React.FC<CustomAppTokensProps> = props => {
|
2019-09-26 15:33:44 +00:00
|
|
|
const { tokens, onCreate, onDelete } = props;
|
|
|
|
const classes = useStyles(props);
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardTitle
|
|
|
|
title={intl.formatMessage({
|
2020-07-22 10:54:15 +00:00
|
|
|
defaultMessage: "Tokens",
|
2019-09-26 15:33:44 +00:00
|
|
|
description: "header"
|
|
|
|
})}
|
|
|
|
toolbar={
|
2022-01-28 12:34:20 +00:00
|
|
|
<Button
|
|
|
|
variant="secondary"
|
|
|
|
onClick={onCreate}
|
2022-02-11 11:28:55 +00:00
|
|
|
data-test-id="create-token"
|
2022-01-28 12:34:20 +00:00
|
|
|
>
|
2019-09-26 15:33:44 +00:00
|
|
|
<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"
|
2020-07-22 10:54:15 +00:00
|
|
|
description="custom app token key"
|
2019-09-26 15:33:44 +00:00
|
|
|
/>
|
|
|
|
</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}>
|
2020-07-22 10:54:15 +00:00
|
|
|
{token?.name || <Skeleton />}
|
2019-09-26 15:33:44 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.colKey}>
|
2020-07-22 10:54:15 +00:00
|
|
|
{token?.authToken ? `**** ${token.authToken}` : <Skeleton />}
|
2019-09-26 15:33:44 +00:00
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.colActions}>
|
|
|
|
<IconButton
|
2022-01-28 12:34:20 +00:00
|
|
|
variant="secondary"
|
2019-09-26 15:33:44 +00:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-07-22 10:54:15 +00:00
|
|
|
CustomAppTokens.displayName = "CustomAppTokens";
|
|
|
|
export default CustomAppTokens;
|