saleor-dashboard/src/orders/components/OrderDraftList/OrderDraftList.tsx
Dominik Żegleń f8254fd11b
Bump macaw to 0.3 (#1807)
* Update to new design theme (#1631)

* Update macaw to 0.3.0 (#1623)

* Update macaw to 0.3

* Use proper pagination component

* Fix type errors

* Remove leftover import

* Remove variant and color from confirm button

* Remove alias

* Update macaw

* Fix button type

* Random fixes (#1633)

* Improve layout components

* Use colored svgs

* Minor fixes

* Fix autocomplete loaders

* Fix padding

* Fix button variant

* Remove codegen file

* Fixes after bumping macaw to 0.3 part 2 (#1638)

* Fix various visual bugs

* Fix type errors

* Bump macaw

* Random fixes part 3 (#1647)

* wip

* Fix mismatched paddings

* Fix actions container padding

* Put story in the right directory

* Fix shipping zone picker

* Fix minor visual bugs

* Remove unused imports

* Move styles to separate file

* Random fixes part 4 (#1641)

* Fix various visual bugs

* Fix type errors

* Fix last table item padding

* Add outline on hover

* Fix spaces

* Fix spaces

* Remove dead code

* Fix elevation

* Remove dead code

* Fix shadows

* Add outline to expand button

* Fix spacing

* Fix spacings

* Fix selectable tables hover

* Use proper delete icon

* Fix ConfirmButtonTransitionState imports

* Update src/apps/components/CustomApps/CustomApps.tsx

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>

* Rework error page (#1670)

* Remake error page

* Fix types

* Update error id styles

* Fix types

* Login page rework (#1703)

* Rework login page

* Remove outline

* Fix logo and footer placement

* Sort imports

* Random fixes part 5 (#1669)

* Fix text color in dark mode

* Update password reset pages (#1714)

* Update password reset pages

* Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx

Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

* Fix collection page

* Update dark mode logo

* Bring back "create app" button

* Fix spacings

* Fix selects

* Fix login e2e test

* Fix not found page displaying

* Update selector

* Add missing package

* Let dropdown overflow through card

* Fix scroll

* Fix scroll

* Fix overflow on grid element

* Fix e2e tests

* Fix data-test-id

* Update snapshots

* Update messages

* Update macaw

* Update snapshots

* Use stable macaw version

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

* Update to new design theme (#1631)

* Update macaw to 0.3.0 (#1623)

* Update macaw to 0.3

* Use proper pagination component

* Fix type errors

* Remove leftover import

* Remove variant and color from confirm button

* Remove alias

* Update macaw

* Fix button type

* Random fixes (#1633)

* Improve layout components

* Use colored svgs

* Minor fixes

* Fix autocomplete loaders

* Fix padding

* Fix button variant

* Remove codegen file

* Fixes after bumping macaw to 0.3 part 2 (#1638)

* Fix various visual bugs

* Fix type errors

* Bump macaw

* Random fixes part 3 (#1647)

* wip

* Fix mismatched paddings

* Fix actions container padding

* Put story in the right directory

* Fix shipping zone picker

* Fix minor visual bugs

* Remove unused imports

* Move styles to separate file

* Random fixes part 4 (#1641)

* Fix various visual bugs

* Fix type errors

* Fix last table item padding

* Add outline on hover

* Fix spaces

* Fix spaces

* Remove dead code

* Fix elevation

* Remove dead code

* Fix shadows

* Add outline to expand button

* Fix spacing

* Fix spacings

* Fix selectable tables hover

* Use proper delete icon

* Fix ConfirmButtonTransitionState imports

* Update src/apps/components/CustomApps/CustomApps.tsx

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>

* Rework error page (#1670)

* Remake error page

* Fix types

* Update error id styles

* Fix types

* Login page rework (#1703)

* Rework login page

* Remove outline

* Fix logo and footer placement

* Sort imports

* Random fixes part 5 (#1669)

* Fix text color in dark mode

* Update password reset pages (#1714)

* Update password reset pages

* Update src/auth/components/ResetPasswordPage/ResetPasswordPage.tsx

Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

* Fix collection page

* Update dark mode logo

* Bring back "create app" button

* Fix spacings

* Fix selects

* Fix login e2e test

* Fix not found page displaying

* Update selector

* Add missing package

* Let dropdown overflow through card

* Fix scroll

* Fix scroll

* Fix overflow on grid element

* Fix e2e tests

* Fix data-test-id

* Update snapshots

* Update messages

* Update macaw

* Update snapshots

* Use stable macaw version

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>

* Fix visual bugs and artifacts

* Fix dropdown menus being clipped (#1762)

* wip

* Fix clipped select menus

* Remove unused import

* Fix spacing

* Fix tests

* Fix select content appearing under dialogs (#1777)

* Fix type errors

* Fix bulk delete button placement

* Fix filter arrow buttons

* Fix messages

* Remove backling from pages list

* Move status above events

* Update messages and snapshots

Co-authored-by: Wojciech Mista <wojciech.mista@saleor.io>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-01-28 13:34:20 +01:00

236 lines
7 KiB
TypeScript

import { TableBody, TableCell, TableFooter, TableRow } from "@material-ui/core";
import Checkbox from "@saleor/components/Checkbox";
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 TableCellHeader from "@saleor/components/TableCellHeader";
import TableHead from "@saleor/components/TableHead";
import TablePagination from "@saleor/components/TablePagination";
import { makeStyles } from "@saleor/macaw-ui";
import {
maybe,
renderCollection,
transformOrderStatus,
transformPaymentStatus
} from "@saleor/misc";
import { OrderDraftListUrlSortField } from "@saleor/orders/urls";
import { ListActions, ListProps, SortPage } from "@saleor/types";
import { getArrowDirection } from "@saleor/utils/sort";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
import { OrderDraftList_draftOrders_edges_node } from "../../types/OrderDraftList";
const useStyles = makeStyles(
theme => ({
[theme.breakpoints.up("lg")]: {
colCustomer: {
width: 300
},
colDate: {
width: 300
},
colNumber: {
width: 160
},
colTotal: {}
},
colCustomer: {},
colDate: {},
colNumber: {
paddingLeft: 0
},
colTotal: {
textAlign: "right"
},
link: {
cursor: "pointer"
}
}),
{ name: "OrderDraftList" }
);
interface OrderDraftListProps
extends ListProps,
ListActions,
SortPage<OrderDraftListUrlSortField> {
orders: OrderDraftList_draftOrders_edges_node[];
}
export const OrderDraftList: React.FC<OrderDraftListProps> = props => {
const {
disabled,
settings,
orders,
pageInfo,
onPreviousPage,
onNextPage,
onUpdateListSettings,
onRowClick,
onSort,
isChecked,
selected,
sort,
toggle,
toggleAll,
toolbar
} = props;
const classes = useStyles(props);
const intl = useIntl();
const orderDraftList = orders
? orders.map(order => ({
...order,
paymentStatus: transformPaymentStatus(order.paymentStatus, intl),
status: transformOrderStatus(order.status, intl)
}))
: undefined;
const numberOfColumns = orderDraftList?.length === 0 ? 4 : 5;
return (
<ResponsiveTable>
<TableHead
colSpan={numberOfColumns}
selected={selected}
disabled={disabled}
items={orders}
toggleAll={toggleAll}
toolbar={toolbar}
>
<TableCellHeader
direction={
sort.sort === OrderDraftListUrlSortField.number
? getArrowDirection(sort.asc)
: undefined
}
arrowPosition="right"
onClick={() => onSort(OrderDraftListUrlSortField.number)}
className={classes.colNumber}
>
<FormattedMessage defaultMessage="No. of Order" />
</TableCellHeader>
<TableCellHeader
direction={
sort.sort === OrderDraftListUrlSortField.date
? getArrowDirection(sort.asc)
: undefined
}
onClick={() => onSort(OrderDraftListUrlSortField.date)}
className={classes.colDate}
>
<FormattedMessage
defaultMessage="Date"
description="order draft creation date"
/>
</TableCellHeader>
<TableCellHeader
direction={
sort.sort === OrderDraftListUrlSortField.customer
? getArrowDirection(sort.asc)
: undefined
}
onClick={() => onSort(OrderDraftListUrlSortField.customer)}
className={classes.colCustomer}
>
<FormattedMessage defaultMessage="Customer" />
</TableCellHeader>
<TableCellHeader textAlign="right" className={classes.colTotal}>
<FormattedMessage
defaultMessage="Total"
description="order draft total price"
/>
</TableCellHeader>
</TableHead>
<TableFooter>
<TableRow>
<TablePagination
colSpan={numberOfColumns}
settings={settings}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
onUpdateListSettings={onUpdateListSettings}
hasPreviousPage={
pageInfo && !disabled ? pageInfo.hasPreviousPage : false
}
onPreviousPage={onPreviousPage}
/>
</TableRow>
</TableFooter>
<TableBody>
{renderCollection(
orderDraftList,
order => {
const isSelected = order ? isChecked(order.id) : false;
return (
<TableRow
data-test-id="draft-order-table-row"
hover={!!order}
className={!!order ? classes.link : undefined}
onClick={order ? onRowClick(order.id) : undefined}
key={order ? order.id : "skeleton"}
selected={isSelected}
>
<TableCell padding="checkbox">
<Checkbox
checked={isSelected}
disabled={disabled}
disableClickPropagation
onChange={() => toggle(order.id)}
/>
</TableCell>
<TableCell className={classes.colNumber}>
{maybe(() => order.number) ? (
"#" + order.number
) : (
<Skeleton />
)}
</TableCell>
<TableCell className={classes.colDate}>
{maybe(() => order.created) ? (
<DateTime date={order.created} />
) : (
<Skeleton />
)}
</TableCell>
<TableCell className={classes.colCustomer}>
{maybe(() => order.billingAddress) ? (
<>
{order.billingAddress.firstName}
&nbsp;
{order.billingAddress.lastName}
</>
) : maybe(() => order.userEmail) !== undefined ? (
order.userEmail
) : (
<Skeleton />
)}
</TableCell>
<TableCell className={classes.colTotal} align="right">
{maybe(() => order.total.gross) ? (
<Money money={order.total.gross} />
) : (
<Skeleton />
)}
</TableCell>
</TableRow>
);
},
() => (
<TableRow>
<TableCell colSpan={numberOfColumns}>
<FormattedMessage defaultMessage="No draft orders found" />
</TableCell>
</TableRow>
)
)}
</TableBody>
</ResponsiveTable>
);
};
OrderDraftList.displayName = "OrderDraftList";
export default OrderDraftList;