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-08-26 13:59:32 +00:00
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
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";
|
2019-08-26 13:59:32 +00:00
|
|
|
import { commonMessages } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
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
|
|
|
|
}) => {
|
2019-08-26 13:59:32 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
const translatedVoucherTypes = translateVoucherTypes();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Card>
|
2019-08-26 13:59:32 +00:00
|
|
|
<CardTitle title={intl.formatMessage(commonMessages.summary)} />
|
2019-06-19 14:40:52 +00:00
|
|
|
<CardContent>
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage defaultMessage="Code" description="voucher 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 />
|
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage defaultMessage="Applies to" description="voucher" />
|
|
|
|
</Typography>
|
2019-06-19 14:40:52 +00:00
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() => translatedVoucherTypes[voucher.type],
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</Typography>
|
|
|
|
<FormSpacer />
|
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Value"
|
|
|
|
description="voucher value"
|
|
|
|
/>
|
|
|
|
</Typography>
|
2019-06-19 14:40:52 +00:00
|
|
|
<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 />
|
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
{intl.formatMessage(commonMessages.startDate)}
|
|
|
|
</Typography>
|
2019-06-19 14:40:52 +00:00
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() => (
|
|
|
|
<Date date={voucher.startDate} plain />
|
|
|
|
),
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</Typography>
|
|
|
|
<FormSpacer />
|
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
{intl.formatMessage(commonMessages.endDate)}
|
|
|
|
</Typography>
|
2019-06-19 14:40:52 +00:00
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() =>
|
|
|
|
voucher.endDate === null ? (
|
|
|
|
"-"
|
|
|
|
) : (
|
|
|
|
<Date date={voucher.endDate} plain />
|
|
|
|
),
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</Typography>
|
|
|
|
|
|
|
|
<CardSpacer />
|
|
|
|
<Hr />
|
|
|
|
<CardSpacer />
|
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Min. Order Value"
|
|
|
|
description="voucher value requirement"
|
|
|
|
/>
|
|
|
|
</Typography>
|
2019-06-19 14:40:52 +00:00
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() =>
|
|
|
|
voucher.minAmountSpent ? (
|
|
|
|
<Money money={voucher.minAmountSpent} />
|
|
|
|
) : (
|
|
|
|
"-"
|
|
|
|
),
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</Typography>
|
|
|
|
<FormSpacer />
|
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Usage Limit"
|
|
|
|
description="voucher value requirement"
|
|
|
|
/>
|
|
|
|
</Typography>
|
2019-06-19 14:40:52 +00:00
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() => (voucher.usageLimit === null ? "-" : voucher.usageLimit),
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</Typography>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
VoucherSummary.displayName = "VoucherSummary";
|
|
|
|
export default VoucherSummary;
|