saleor-dashboard/src/discounts/components/VoucherSummary/VoucherSummary.tsx

127 lines
3.7 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import Typography from "@material-ui/core/Typography";
2019-08-09 10:26:22 +00:00
import React from "react";
2019-06-19 14:40:52 +00:00
import CardSpacer from "@saleor/components/CardSpacer";
import CardTitle from "@saleor/components/CardTitle";
import Date from "@saleor/components/Date";
import FormSpacer from "@saleor/components/FormSpacer";
import Hr from "@saleor/components/Hr";
import Money from "@saleor/components/Money";
import Percent from "@saleor/components/Percent";
import Skeleton from "@saleor/components/Skeleton";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
2019-08-09 11:14:35 +00:00
import { DiscountValueTypeEnum } from "../../../types/globalTypes";
2019-06-19 14:40:52 +00:00
import { translateVoucherTypes } from "../../translations";
import { VoucherDetails_voucher } from "../../types/VoucherDetails";
export interface VoucherSummaryProps {
defaultCurrency: string;
voucher: VoucherDetails_voucher;
}
const VoucherSummary: React.StatelessComponent<VoucherSummaryProps> = ({
defaultCurrency,
voucher
}) => {
const translatedVoucherTypes = translateVoucherTypes();
return (
<Card>
<CardTitle title={i18n.t("Summary")} />
<CardContent>
2019-08-09 11:14:35 +00:00
<Typography variant="caption">{i18n.t("Code")}</Typography>
2019-06-19 14:40:52 +00:00
<Typography>
2019-08-09 11:14:35 +00:00
{maybe<React.ReactNode>(() => voucher.code, <Skeleton />)}
2019-06-19 14:40:52 +00:00
</Typography>
<FormSpacer />
<Typography variant="caption">{i18n.t("Applies to")}</Typography>
<Typography>
{maybe<React.ReactNode>(
() => translatedVoucherTypes[voucher.type],
<Skeleton />
)}
</Typography>
<FormSpacer />
<Typography variant="caption">{i18n.t("Value")}</Typography>
<Typography>
{maybe<React.ReactNode>(
() =>
2019-08-09 11:14:35 +00:00
voucher.discountValueType === DiscountValueTypeEnum.FIXED ? (
2019-06-19 14:40:52 +00:00
<Money
money={{
amount: voucher.discountValue,
currency: defaultCurrency
}}
/>
) : (
<Percent amount={voucher.discountValue} />
),
<Skeleton />
)}
</Typography>
<CardSpacer />
<Hr />
<CardSpacer />
<Typography variant="caption">{i18n.t("Start Date")}</Typography>
<Typography>
{maybe<React.ReactNode>(
() => (
<Date date={voucher.startDate} plain />
),
<Skeleton />
)}
</Typography>
<FormSpacer />
<Typography variant="caption">{i18n.t("End Date")}</Typography>
<Typography>
{maybe<React.ReactNode>(
() =>
voucher.endDate === null ? (
"-"
) : (
<Date date={voucher.endDate} plain />
),
<Skeleton />
)}
</Typography>
<CardSpacer />
<Hr />
<CardSpacer />
<Typography variant="caption">{i18n.t("Min. Order Value")}</Typography>
<Typography>
{maybe<React.ReactNode>(
() =>
voucher.minAmountSpent ? (
<Money money={voucher.minAmountSpent} />
) : (
"-"
),
<Skeleton />
)}
</Typography>
<FormSpacer />
<Typography variant="caption">{i18n.t("Usage Limit")}</Typography>
<Typography>
{maybe<React.ReactNode>(
() => (voucher.usageLimit === null ? "-" : voucher.usageLimit),
<Skeleton />
)}
</Typography>
</CardContent>
</Card>
);
};
VoucherSummary.displayName = "VoucherSummary";
export default VoucherSummary;