import { makeStyles } from "@material-ui/core/styles"; 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 Checkbox from "@saleor/components/Checkbox"; import Date from "@saleor/components/Date"; import Money from "@saleor/components/Money"; import Percent from "@saleor/components/Percent"; import ResponsiveTable from "@saleor/components/ResponsiveTable"; import Skeleton from "@saleor/components/Skeleton"; import TableCellHeader from "@saleor/components/TableCellHeader"; import TableHead from "@saleor/components/TableHead"; import TablePagination from "@saleor/components/TablePagination"; import { VoucherListUrlSortField } from "@saleor/discounts/urls"; import { maybe, renderCollection } from "@saleor/misc"; import { ListActions, ListProps, SortPage } from "@saleor/types"; import { DiscountValueTypeEnum } from "@saleor/types/globalTypes"; import { getArrowDirection } from "@saleor/utils/sort"; import React from "react"; import { FormattedMessage } from "react-intl"; import { VoucherList_vouchers_edges_node } from "../../types/VoucherList"; export interface VoucherListProps extends ListProps, ListActions, SortPage { defaultCurrency: string; vouchers: VoucherList_vouchers_edges_node[]; } const useStyles = makeStyles( theme => ({ [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: { paddingLeft: 0 }, colStart: { textAlign: "right" }, colUses: { textAlign: "right" }, colValue: { textAlign: "right" }, tableRow: { cursor: "pointer" }, textRight: { textAlign: "right" } }), { name: "VoucherList" } ); const numberOfColumns = 7; const VoucherList: React.FC = props => { const { settings, defaultCurrency, disabled, onNextPage, onPreviousPage, onUpdateListSettings, onRowClick, onSort, pageInfo, vouchers, isChecked, selected, sort, toggle, toggleAll, toolbar } = props; const classes = useStyles(props); return ( onSort(VoucherListUrlSortField.code)} className={classes.colName} > onSort(VoucherListUrlSortField.minSpent)} className={classes.colMinSpent} > onSort(VoucherListUrlSortField.startDate)} className={classes.colStart} > onSort(VoucherListUrlSortField.endDate)} className={classes.colEnd} > onSort(VoucherListUrlSortField.value)} className={classes.colValue} > onSort(VoucherListUrlSortField.limit)} className={classes.colUses} > {renderCollection( vouchers, voucher => { const isSelected = voucher ? isChecked(voucher.id) : false; return ( toggle(voucher.id)} /> {maybe(() => voucher.code, )} {voucher && voucher.minSpent ? ( ) : voucher && voucher.minSpent === null ? ( "-" ) : ( )} {voucher && voucher.startDate ? ( ) : ( )} {voucher && voucher.endDate ? ( ) : voucher && voucher.endDate === null ? ( "-" ) : ( )} {voucher && voucher.discountValueType && voucher.discountValue ? ( voucher.discountValueType === DiscountValueTypeEnum.FIXED ? ( ) : ( ) ) : ( )} {maybe( () => voucher.usageLimit === null ? "-" : voucher.usageLimit, )} ); }, () => ( ) )} ); }; VoucherList.displayName = "VoucherList"; export default VoucherList;