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";
|
|
|
|
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";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import { maybe } from "../../../misc";
|
|
|
|
import { SaleType } from "../../../types/globalTypes";
|
|
|
|
import { SaleDetails_sale } from "../../types/SaleDetails";
|
|
|
|
|
|
|
|
export interface SaleSummaryProps {
|
|
|
|
defaultCurrency: string;
|
|
|
|
sale: SaleDetails_sale;
|
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const SaleSummary: React.FC<SaleSummaryProps> = ({ defaultCurrency, sale }) => {
|
2019-08-26 13:59:32 +00:00
|
|
|
const intl = useIntl();
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
return (
|
|
|
|
<Card>
|
|
|
|
<CardTitle title={intl.formatMessage(commonMessages.summary)} />
|
|
|
|
<CardContent>
|
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage defaultMessage="Name" description="sale name" />
|
|
|
|
</Typography>
|
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(() => sale.name, <Skeleton />)}
|
|
|
|
</Typography>
|
|
|
|
<FormSpacer />
|
|
|
|
|
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage defaultMessage="Value" description="sale value" />
|
|
|
|
</Typography>
|
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() =>
|
|
|
|
sale.type === SaleType.FIXED ? (
|
|
|
|
<Money
|
|
|
|
money={{
|
|
|
|
amount: sale.value,
|
|
|
|
currency: defaultCurrency
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<Percent amount={sale.value} />
|
|
|
|
),
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</Typography>
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<CardSpacer />
|
|
|
|
<Hr />
|
|
|
|
<CardSpacer />
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage {...commonMessages.startDate} />
|
|
|
|
</Typography>
|
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() => (
|
|
|
|
<Date date={sale.startDate} plain />
|
|
|
|
),
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</Typography>
|
|
|
|
<FormSpacer />
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
<Typography variant="caption">
|
|
|
|
<FormattedMessage {...commonMessages.endDate} />
|
|
|
|
</Typography>
|
|
|
|
<Typography>
|
|
|
|
{maybe<React.ReactNode>(
|
|
|
|
() =>
|
|
|
|
sale.endDate === null ? "-" : <Date date={sale.endDate} plain />,
|
|
|
|
<Skeleton />
|
|
|
|
)}
|
|
|
|
</Typography>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
SaleSummary.displayName = "SaleSummary";
|
|
|
|
export default SaleSummary;
|