2022-10-27 10:58:17 +00:00
|
|
|
import { Card, TableBody, TableCell, Typography } from "@material-ui/core";
|
2022-05-06 08:59:55 +00:00
|
|
|
import { customAppAddUrl } from "@saleor/apps/urls";
|
|
|
|
import { Button } from "@saleor/components/Button";
|
2022-01-28 12:34:20 +00:00
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
2022-05-13 11:04:16 +00:00
|
|
|
import { TableButtonWrapper } from "@saleor/components/TableButtonWrapper/TableButtonWrapper";
|
2022-05-06 08:59:55 +00:00
|
|
|
import TableRowLink from "@saleor/components/TableRowLink";
|
2022-03-09 08:56:55 +00:00
|
|
|
import { AppsListQuery } from "@saleor/graphql";
|
2020-07-22 10:54:15 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2022-05-06 08:59:55 +00:00
|
|
|
import { DeleteIcon, IconButton, ResponsiveTable } from "@saleor/macaw-ui";
|
2022-05-13 11:04:16 +00:00
|
|
|
import { renderCollection } from "@saleor/misc";
|
2020-07-22 10:54:15 +00:00
|
|
|
import React from "react";
|
2022-03-09 08:56:55 +00:00
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
|
|
|
import { useStyles } from "../../styles";
|
|
|
|
import AppsSkeleton from "../AppsSkeleton";
|
|
|
|
import DeactivatedText from "../DeactivatedText";
|
|
|
|
|
|
|
|
export interface CustomAppsProps {
|
2022-03-09 08:56:55 +00:00
|
|
|
appsList: AppsListQuery["apps"]["edges"];
|
2022-05-06 08:59:55 +00:00
|
|
|
getCustomAppHref: (id: string) => string;
|
2020-07-22 10:54:15 +00:00
|
|
|
onRemove: (id: string) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const CustomApps: React.FC<CustomAppsProps> = ({
|
|
|
|
appsList,
|
|
|
|
onRemove,
|
2022-06-21 09:36:55 +00:00
|
|
|
getCustomAppHref,
|
2020-07-22 10:54:15 +00:00
|
|
|
}) => {
|
2022-01-28 12:34:20 +00:00
|
|
|
const intl = useIntl();
|
2020-07-22 10:54:15 +00:00
|
|
|
const classes = useStyles({});
|
|
|
|
|
|
|
|
return (
|
2022-01-28 12:34:20 +00:00
|
|
|
<Card className={classes.customApps}>
|
|
|
|
<CardTitle
|
|
|
|
toolbar={
|
2022-05-06 08:59:55 +00:00
|
|
|
<Button
|
|
|
|
variant="secondary"
|
|
|
|
href={customAppAddUrl}
|
|
|
|
data-test-id="create-app"
|
|
|
|
>
|
|
|
|
<FormattedMessage
|
|
|
|
id="XB2Jj9"
|
|
|
|
defaultMessage="Create App"
|
|
|
|
description="create app button"
|
|
|
|
/>
|
|
|
|
</Button>
|
2022-01-28 12:34:20 +00:00
|
|
|
}
|
|
|
|
title={intl.formatMessage(commonMessages.customApps)}
|
|
|
|
/>
|
|
|
|
<ResponsiveTable>
|
|
|
|
<TableBody>
|
|
|
|
{renderCollection(
|
|
|
|
appsList,
|
|
|
|
(app, index) =>
|
|
|
|
app ? (
|
2022-05-06 08:59:55 +00:00
|
|
|
<TableRowLink
|
2022-01-28 12:34:20 +00:00
|
|
|
key={app.node.id}
|
|
|
|
className={classes.tableRow}
|
2022-05-06 08:59:55 +00:00
|
|
|
href={getCustomAppHref(app.node.id)}
|
2021-07-15 10:27:07 +00:00
|
|
|
>
|
2022-01-28 12:34:20 +00:00
|
|
|
<TableCell className={classes.colName}>
|
|
|
|
<span data-tc="name" className={classes.appName}>
|
|
|
|
{app.node.name}
|
|
|
|
</span>
|
|
|
|
{!app.node.isActive && (
|
|
|
|
<div className={classes.statusWrapper}>
|
|
|
|
<DeactivatedText />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</TableCell>
|
|
|
|
<TableCell className={classes.colAction}>
|
2022-05-13 11:04:16 +00:00
|
|
|
<TableButtonWrapper>
|
|
|
|
<IconButton
|
|
|
|
variant="secondary"
|
|
|
|
color="primary"
|
|
|
|
onClick={() => onRemove(app.node.id)}
|
|
|
|
>
|
|
|
|
<DeleteIcon />
|
|
|
|
</IconButton>
|
|
|
|
</TableButtonWrapper>
|
2022-01-28 12:34:20 +00:00
|
|
|
</TableCell>
|
2022-05-06 08:59:55 +00:00
|
|
|
</TableRowLink>
|
2022-01-28 12:34:20 +00:00
|
|
|
) : (
|
|
|
|
<AppsSkeleton key={index} />
|
|
|
|
),
|
|
|
|
() => (
|
2022-10-27 10:58:17 +00:00
|
|
|
<TableRowLink className={classes.tableRow}>
|
2020-07-22 10:54:15 +00:00
|
|
|
<TableCell className={classes.colName}>
|
2022-01-28 12:34:20 +00:00
|
|
|
<Typography className={classes.text} variant="body2">
|
|
|
|
<FormattedMessage
|
2022-05-05 07:54:28 +00:00
|
|
|
id="voRaz3"
|
2022-01-28 12:34:20 +00:00
|
|
|
defaultMessage="Your custom-created apps will be shown here."
|
|
|
|
description="custom apps content"
|
|
|
|
/>
|
|
|
|
</Typography>
|
2020-07-22 10:54:15 +00:00
|
|
|
</TableCell>
|
2022-10-27 10:58:17 +00:00
|
|
|
</TableRowLink>
|
2022-06-21 09:36:55 +00:00
|
|
|
),
|
2022-01-28 12:34:20 +00:00
|
|
|
)}
|
|
|
|
</TableBody>
|
|
|
|
</ResponsiveTable>
|
|
|
|
</Card>
|
2020-07-22 10:54:15 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
CustomApps.displayName = "CustomApps";
|
|
|
|
export default CustomApps;
|