
* Minor fixes for intl messages * Add esbuild-loader * switch from babel to esbuild-loader * use formatjs enforce-id linter * Generate ids for intl messages * id format defined by idInterpolationPattern * Modify intl messages extraction * remove react-intl-translations-manager * remove transpile-tx.js * use formatjs cli * Modify defaultMessages.json * modify ids in defaultMessages.json with defined idInterpolationPattern * Fix errors * Fix page crash * Use babel to transpile tests * Fix useStateFromProps * Improve render count * Add test to useStateFromProps * Fix reloading state buh * Do not check if form with channels is dirty * Stop blocking save if form has not changed * Remove debug code * Fix form disabling * Fix variant selection checkbox onClick * Update translations * Update messages * Use esbuild to build storybook Co-authored-by: Bartłomiej Wiaduch <tukan2can@gmail.com> Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
165 lines
4.8 KiB
TypeScript
165 lines
4.8 KiB
TypeScript
import {
|
|
Card,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableRow
|
|
} from "@material-ui/core";
|
|
import CardTitle from "@saleor/components/CardTitle";
|
|
import { DateTime } from "@saleor/components/Date";
|
|
import Money from "@saleor/components/Money";
|
|
import ResponsiveTable from "@saleor/components/ResponsiveTable";
|
|
import Skeleton from "@saleor/components/Skeleton";
|
|
import { CustomerDetailsQuery } from "@saleor/graphql";
|
|
import { Button, makeStyles, Pill } from "@saleor/macaw-ui";
|
|
import { RelayToFlat } from "@saleor/types";
|
|
import React from "react";
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
|
|
import { maybe, renderCollection, transformPaymentStatus } from "../../../misc";
|
|
|
|
const useStyles = makeStyles(
|
|
{
|
|
link: {
|
|
cursor: "pointer"
|
|
},
|
|
textRight: {
|
|
textAlign: "right"
|
|
}
|
|
},
|
|
{ name: "CustomerOrders" }
|
|
);
|
|
|
|
export interface CustomerOrdersProps {
|
|
orders: RelayToFlat<CustomerDetailsQuery["user"]["orders"]>;
|
|
onViewAllOrdersClick: () => void;
|
|
onRowClick: (id: string) => void;
|
|
}
|
|
|
|
const CustomerOrders: React.FC<CustomerOrdersProps> = props => {
|
|
const { orders, onRowClick, onViewAllOrdersClick } = props;
|
|
const classes = useStyles(props);
|
|
|
|
const intl = useIntl();
|
|
|
|
const orderList = orders
|
|
? orders.map(order => ({
|
|
...order,
|
|
paymentStatus: transformPaymentStatus(order.paymentStatus, intl)
|
|
}))
|
|
: undefined;
|
|
return (
|
|
<Card>
|
|
<CardTitle
|
|
title={intl.formatMessage({
|
|
id: "1LiVhv",
|
|
defaultMessage: "Recent Orders",
|
|
description: "section header"
|
|
})}
|
|
toolbar={
|
|
<Button variant="tertiary" onClick={onViewAllOrdersClick}>
|
|
<FormattedMessage
|
|
id="3+990c"
|
|
defaultMessage="View all orders"
|
|
description="button"
|
|
/>
|
|
</Button>
|
|
}
|
|
/>
|
|
<ResponsiveTable>
|
|
<TableHead>
|
|
<TableRow>
|
|
<TableCell>
|
|
<FormattedMessage
|
|
id="nTF6tG"
|
|
defaultMessage="No. of Order"
|
|
description="number of order"
|
|
/>
|
|
</TableCell>
|
|
<TableCell>
|
|
<FormattedMessage
|
|
id="ri3kK9"
|
|
defaultMessage="Date"
|
|
description="order placement date"
|
|
/>
|
|
</TableCell>
|
|
<TableCell>
|
|
<FormattedMessage
|
|
id="pURrk1"
|
|
defaultMessage="Status"
|
|
description="order status"
|
|
/>
|
|
</TableCell>
|
|
<TableCell className={classes.textRight}>
|
|
<FormattedMessage
|
|
id="taX/V3"
|
|
defaultMessage="Total"
|
|
description="order total amount"
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
</TableHead>
|
|
<TableBody>
|
|
{renderCollection(
|
|
orderList,
|
|
order => (
|
|
<TableRow
|
|
hover={!!order}
|
|
className={!!order ? classes.link : undefined}
|
|
onClick={order ? () => onRowClick(order.id) : undefined}
|
|
key={order ? order.id : "skeleton"}
|
|
>
|
|
<TableCell>
|
|
{maybe(() => order.number) ? (
|
|
"#" + order.number
|
|
) : (
|
|
<Skeleton />
|
|
)}
|
|
</TableCell>
|
|
<TableCell>
|
|
{maybe(() => order.created) ? (
|
|
<DateTime date={order.created} />
|
|
) : (
|
|
<Skeleton />
|
|
)}
|
|
</TableCell>
|
|
<TableCell>
|
|
{maybe(() => order.paymentStatus.status) !== undefined ? (
|
|
order.paymentStatus.status === null ? null : (
|
|
<Pill
|
|
color={order.paymentStatus.status}
|
|
label={order.paymentStatus.localized}
|
|
/>
|
|
)
|
|
) : (
|
|
<Skeleton />
|
|
)}
|
|
</TableCell>
|
|
<TableCell className={classes.textRight} align="right">
|
|
{maybe(() => order.total.gross) ? (
|
|
<Money money={order.total.gross} />
|
|
) : (
|
|
<Skeleton />
|
|
)}
|
|
</TableCell>
|
|
</TableRow>
|
|
),
|
|
() => (
|
|
<TableRow>
|
|
<TableCell colSpan={6}>
|
|
<FormattedMessage
|
|
id="RlfqSV"
|
|
defaultMessage="No orders found"
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
)
|
|
)}
|
|
</TableBody>
|
|
</ResponsiveTable>
|
|
</Card>
|
|
);
|
|
};
|
|
|
|
CustomerOrders.displayName = "CustomerOrders";
|
|
export default CustomerOrders;
|