import Card from "@material-ui/core/Card"; import { createStyles, Theme, WithStyles, withStyles } from "@material-ui/core/styles"; import Table from "@material-ui/core/Table"; import TableBody from "@material-ui/core/TableBody"; import TableCell from "@material-ui/core/TableCell"; import TableFooter from "@material-ui/core/TableFooter"; import TableRow from "@material-ui/core/TableRow"; import React from "react"; import Checkbox from "@saleor/components/Checkbox"; import Date from "@saleor/components/Date"; import Money from "@saleor/components/Money"; import Percent from "@saleor/components/Percent"; import Skeleton from "@saleor/components/Skeleton"; import TableHead from "@saleor/components/TableHead"; import TablePagination from "@saleor/components/TablePagination"; import i18n from "../../../i18n"; import { maybe, renderCollection } from "../../../misc"; import { ListActions, ListProps } from "../../../types"; import { VoucherDiscountValueType } from "../../../types/globalTypes"; import { VoucherList_vouchers_edges_node } from "../../types/VoucherList"; export interface VoucherListProps extends ListProps, ListActions { defaultCurrency: string; vouchers: VoucherList_vouchers_edges_node[]; } const styles = (theme: Theme) => createStyles({ [theme.breakpoints.up("lg")]: { colEnd: { width: 180 }, colMinSpent: { width: 150 }, colName: {}, colStart: { width: 180 }, colUses: { width: 150 }, colValue: { width: 150 } }, colEnd: { textAlign: "right" }, colMinSpent: { textAlign: "right" }, colName: {}, colStart: { textAlign: "right" }, colUses: { textAlign: "right" }, colValue: { textAlign: "right" }, tableRow: { cursor: "pointer" }, textRight: { textAlign: "right" } }); const VoucherList = withStyles(styles, { name: "VoucherList" })( ({ classes, defaultCurrency, disabled, onNextPage, onPreviousPage, onRowClick, pageInfo, vouchers, isChecked, selected, toggle, toggleAll, toolbar }: VoucherListProps & WithStyles) => ( {i18n.t("Name", { context: "voucher list table header" })} {i18n.t("Min. Spent", { context: "voucher list table header" })} {i18n.t("Starts", { context: "voucher list table header" })} {i18n.t("Ends", { context: "voucher list table header" })} {i18n.t("Value", { context: "voucher list table header" })} {i18n.t("Uses", { context: "voucher list table header" })} {renderCollection( vouchers, voucher => { const isSelected = voucher ? isChecked(voucher.id) : false; return ( toggle(voucher.id)} /> {maybe(() => voucher.name, )} {voucher && voucher.minAmountSpent ? ( ) : voucher && voucher.minAmountSpent === null ? ( "-" ) : ( )} {voucher && voucher.startDate ? ( ) : ( )} {voucher && voucher.endDate ? ( ) : voucher && voucher.endDate === null ? ( "-" ) : ( )} {voucher && voucher.discountValueType && voucher.discountValue ? ( voucher.discountValueType === VoucherDiscountValueType.FIXED ? ( ) : ( ) ) : ( )} {voucher && voucher.usageLimit ? ( voucher.usageLimit ) : voucher && voucher.usageLimit === null ? ( "-" ) : ( )} ); }, () => ( {i18n.t("No vouchers found")} ) )}
) ); VoucherList.displayName = "VoucherList"; export default VoucherList;