import Button from "@material-ui/core/Button"; import Card from "@material-ui/core/Card"; import TableBody from "@material-ui/core/TableBody"; import TableCell from "@material-ui/core/TableCell"; import TableHead from "@material-ui/core/TableHead"; import TableRow from "@material-ui/core/TableRow"; import DeleteIcon from "@material-ui/icons/Delete"; import EditIcon from "@material-ui/icons/Edit"; import CardTitle from "@saleor/components/CardTitle"; import IconButtonTableCell from "@saleor/components/IconButtonTableCell"; import Money from "@saleor/components/Money"; import MoneyRange from "@saleor/components/MoneyRange"; import ResponsiveTable from "@saleor/components/ResponsiveTable"; import Skeleton from "@saleor/components/Skeleton"; import WeightRange from "@saleor/components/WeightRange"; import { ShippingZoneDetailsFragment_shippingMethods } from "@saleor/fragments/types/ShippingZoneDetailsFragment"; import { makeStyles } from "@saleor/theme"; import { ChannelProps } from "@saleor/types"; import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; import { maybe, renderCollection } from "../../../misc"; import { ICONBUTTON_SIZE } from "../../../theme"; export interface ShippingZoneRatesProps extends ChannelProps { disabled: boolean; rates: ShippingZoneDetailsFragment_shippingMethods[]; variant: "price" | "weight"; testId?: string; onRateAdd: () => void; onRateEdit: (id: string) => void; onRateRemove: (id: string) => void; } const useStyles = makeStyles( theme => ({ alignRight: { paddingRight: 24, width: ICONBUTTON_SIZE + theme.spacing(0.5) }, buttonColumn: { padding: "4px 0", width: "62px" }, nameColumn: { width: "auto" }, valueColumn: { width: "auto" } }), { name: "ShippingZoneRates" } ); const ShippingZoneRates: React.FC = props => { const { disabled, onRateAdd, onRateEdit, onRateRemove, rates, selectedChannelId, variant, testId } = props; const classes = useStyles(props); const intl = useIntl(); return ( } /> {variant === "price" ? intl.formatMessage({ defaultMessage: "Value Range", description: "shipping method price range" }) : intl.formatMessage({ defaultMessage: "Weight Range", description: "shipping method weight range" })} {renderCollection( rates, rate => { const channel = rate?.channelListings?.find( listing => listing.channel.id === selectedChannelId ); return ( onRateEdit(rate.id) : undefined} > {maybe(() => rate.name, )} {maybe( () => rate && !channel ? ( "-" ) : variant === "price" ? ( ) : ( ), )} {maybe( () => rate && !channel ? ( "-" ) : ( ), )} onRateEdit(rate.id)} className={classes.buttonColumn} > onRateRemove(rate.id)} className={classes.buttonColumn} > ); }, () => ( ) )} ); }; ShippingZoneRates.displayName = "ShippingZoneRates"; export default ShippingZoneRates;