2021-05-14 08:15:15 +00:00
|
|
|
|
import {
|
2022-01-28 12:34:20 +00:00
|
|
|
|
Card,
|
2021-05-14 08:15:15 +00:00
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableFooter,
|
|
|
|
|
TableRow,
|
|
|
|
|
Typography
|
|
|
|
|
} from "@material-ui/core";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
|
|
|
import TablePagination from "@saleor/components/TablePagination";
|
2022-01-28 12:34:20 +00:00
|
|
|
|
import { DeleteIcon, ResponsiveTable } from "@saleor/macaw-ui";
|
|
|
|
|
import { Button, IconButton } from "@saleor/macaw-ui";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
import { renderCollection, stopPropagation } from "@saleor/misc";
|
|
|
|
|
import { ListProps } from "@saleor/types";
|
|
|
|
|
import React from "react";
|
|
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
|
|
|
|
|
|
|
|
import { useStyles } from "../../styles";
|
|
|
|
|
import { AppsList_apps_edges } from "../../types/AppsList";
|
|
|
|
|
import AppsSkeleton from "../AppsSkeleton";
|
|
|
|
|
import DeactivatedText from "../DeactivatedText";
|
|
|
|
|
|
|
|
|
|
export interface InstalledAppsProps extends ListProps {
|
|
|
|
|
appsList: AppsList_apps_edges[];
|
|
|
|
|
onRemove: (id: string) => void;
|
|
|
|
|
onSettingsRowClick: (id: string) => () => void;
|
|
|
|
|
}
|
|
|
|
|
const numberOfColumns = 2;
|
|
|
|
|
|
|
|
|
|
const InstalledApps: React.FC<InstalledAppsProps> = ({
|
|
|
|
|
appsList,
|
|
|
|
|
onRemove,
|
|
|
|
|
settings,
|
|
|
|
|
disabled,
|
|
|
|
|
onNextPage,
|
|
|
|
|
onPreviousPage,
|
|
|
|
|
onRowClick,
|
|
|
|
|
onUpdateListSettings,
|
|
|
|
|
onSettingsRowClick,
|
|
|
|
|
pageInfo,
|
|
|
|
|
...props
|
|
|
|
|
}) => {
|
|
|
|
|
const intl = useIntl();
|
|
|
|
|
const classes = useStyles(props);
|
|
|
|
|
|
|
|
|
|
return (
|
2022-01-28 12:34:20 +00:00
|
|
|
|
<Card className={classes.apps}>
|
|
|
|
|
<CardTitle
|
|
|
|
|
title={intl.formatMessage({
|
|
|
|
|
defaultMessage: "Third-party Apps",
|
|
|
|
|
description: "section header"
|
|
|
|
|
})}
|
|
|
|
|
/>
|
|
|
|
|
<ResponsiveTable>
|
2020-07-22 10:54:15 +00:00
|
|
|
|
<TableFooter>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TablePagination
|
|
|
|
|
colSpan={numberOfColumns}
|
|
|
|
|
settings={settings}
|
|
|
|
|
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
|
|
|
|
|
onNextPage={onNextPage}
|
|
|
|
|
onUpdateListSettings={onUpdateListSettings}
|
|
|
|
|
hasPreviousPage={
|
|
|
|
|
pageInfo && !disabled ? pageInfo.hasPreviousPage : false
|
|
|
|
|
}
|
|
|
|
|
onPreviousPage={onPreviousPage}
|
|
|
|
|
/>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableFooter>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{renderCollection(
|
|
|
|
|
appsList,
|
|
|
|
|
(app, index) =>
|
|
|
|
|
app ? (
|
|
|
|
|
<TableRow
|
|
|
|
|
key={app.node.id}
|
|
|
|
|
className={classes.tableRow}
|
|
|
|
|
onClick={onSettingsRowClick(app.node.id)}
|
|
|
|
|
>
|
|
|
|
|
<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-01-28 12:34:20 +00:00
|
|
|
|
<Button onClick={stopPropagation(onRowClick(app.node.id))}>
|
2020-07-22 10:54:15 +00:00
|
|
|
|
<FormattedMessage
|
|
|
|
|
defaultMessage="About"
|
|
|
|
|
description="about app"
|
|
|
|
|
/>
|
|
|
|
|
</Button>
|
|
|
|
|
<IconButton
|
2022-01-28 12:34:20 +00:00
|
|
|
|
variant="secondary"
|
2020-07-22 10:54:15 +00:00
|
|
|
|
color="primary"
|
|
|
|
|
onClick={stopPropagation(() => onRemove(app.node.id))}
|
|
|
|
|
>
|
|
|
|
|
<DeleteIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
) : (
|
|
|
|
|
<AppsSkeleton key={index} />
|
|
|
|
|
),
|
|
|
|
|
() => (
|
|
|
|
|
<TableRow className={classes.tableRow}>
|
|
|
|
|
<TableCell className={classes.colName}>
|
|
|
|
|
<Typography className={classes.text} variant="body2">
|
|
|
|
|
<FormattedMessage
|
|
|
|
|
defaultMessage="You don’t have any installed apps in your dashboard"
|
|
|
|
|
description="apps content"
|
|
|
|
|
/>
|
|
|
|
|
</Typography>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
)
|
|
|
|
|
)}
|
|
|
|
|
</TableBody>
|
2022-01-28 12:34:20 +00:00
|
|
|
|
</ResponsiveTable>
|
|
|
|
|
</Card>
|
2020-07-22 10:54:15 +00:00
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
InstalledApps.displayName = "InstalledApps";
|
|
|
|
|
export default InstalledApps;
|