-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MERX-53] Implement refunds datagrid (#4681)
* Basic implementation of refunds datagrid * Extract messages * Add changeset * Fix failing test * Translate strings * Move onRowClick to menuItems * Refactor ternary * Remove test label * Refactor to hooks & fix test * Group grid opts into hook * Fix flag * Fix test names --------- Co-authored-by: Paweł Chyła <[email protected]>
- Loading branch information
Showing
13 changed files
with
534 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": minor | ||
--- | ||
|
||
Implement refunds datagrid on order details |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
name: improved_refunds | ||
displayName: Improved refunds | ||
enabled: false | ||
payload: "default" | ||
visible: false | ||
--- | ||
|
||
Experience new refund flow supporting multiple transactions. | ||
|
||
<!-- TODO: add image later on --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/orders/components/OrderRefundDatagrid/OrderRefundDatagrid.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { DashboardCard } from "@dashboard/components/Card"; | ||
import { ColumnPicker } from "@dashboard/components/Datagrid/ColumnPicker/ColumnPicker"; | ||
import { useColumns } from "@dashboard/components/Datagrid/ColumnPicker/useColumns"; | ||
import Datagrid from "@dashboard/components/Datagrid/Datagrid"; | ||
import { DatagridChangeStateContext } from "@dashboard/components/Datagrid/hooks/useDatagridChange"; | ||
import { OrderDetailsFragment } from "@dashboard/graphql"; | ||
import { orderGrantRefundEditUrl } from "@dashboard/orders/urls"; | ||
import { ListViews } from "@dashboard/types"; | ||
import { Box, Button, EditIcon, PlusIcon, Text } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
import { FormattedMessage } from "react-intl"; | ||
import { Link } from "react-router-dom"; | ||
|
||
import { | ||
createGetCellContent, | ||
useDatagridOpts, | ||
useOrderRefundStaticColumns, | ||
} from "./datagrid"; | ||
import { refundGridMessages } from "./messages"; | ||
|
||
interface OrderRefundDatagridProps { | ||
grantedRefunds: OrderDetailsFragment["grantedRefunds"]; | ||
orderId: string; | ||
} | ||
|
||
export const OrderRefundDatagrid: React.FC<OrderRefundDatagridProps> = ({ | ||
grantedRefunds, | ||
orderId, | ||
}) => { | ||
const { datagrid, currentTheme, settings, handleColumnChange } = | ||
useDatagridOpts(ListViews.ORDER_REFUNDS); | ||
|
||
const orderDraftDetailsStaticColumns = useOrderRefundStaticColumns(); | ||
|
||
const { | ||
handlers, | ||
visibleColumns, | ||
staticColumns, | ||
selectedColumns, | ||
recentlyAddedColumn, | ||
} = useColumns({ | ||
staticColumns: orderDraftDetailsStaticColumns, | ||
selectedColumns: settings?.columns ?? [], | ||
onSave: handleColumnChange, | ||
}); | ||
|
||
const getCellContent = createGetCellContent({ | ||
columns: visibleColumns, | ||
refunds: grantedRefunds, | ||
currentTheme, | ||
}); | ||
|
||
const getMenuItems = React.useCallback( | ||
index => [ | ||
{ | ||
label: "", | ||
Icon: ( | ||
<Link to={orderGrantRefundEditUrl(orderId, grantedRefunds[index].id)}> | ||
<EditIcon /> | ||
</Link> | ||
), | ||
onSelect: () => false, | ||
}, | ||
], | ||
[], | ||
); | ||
|
||
return ( | ||
<DashboardCard> | ||
<Box | ||
paddingX={6} | ||
paddingTop={6} | ||
display="flex" | ||
justifyContent="space-between" | ||
> | ||
<Text variant="heading"> | ||
<FormattedMessage {...refundGridMessages.refundSection} /> | ||
</Text> | ||
{/** TODO: Add modal */} | ||
<Button variant="secondary"> | ||
<PlusIcon /> | ||
<FormattedMessage {...refundGridMessages.addNewRefund} /> | ||
</Button> | ||
</Box> | ||
<DatagridChangeStateContext.Provider value={datagrid}> | ||
<Datagrid | ||
readonly | ||
hasRowHover | ||
rowMarkers="none" | ||
columnSelect="none" | ||
freezeColumns={2} | ||
menuItems={getMenuItems} | ||
verticalBorder={col => col > 1} | ||
availableColumns={visibleColumns} | ||
emptyText={""} | ||
getCellContent={getCellContent} | ||
getCellError={() => false} | ||
rows={grantedRefunds.length} | ||
selectionActions={() => null} | ||
onColumnResize={handlers.onResize} | ||
onColumnMoved={handlers.onMove} | ||
recentlyAddedColumn={recentlyAddedColumn} | ||
renderColumnPicker={() => ( | ||
<ColumnPicker | ||
selectedColumns={selectedColumns} | ||
staticColumns={staticColumns} | ||
onToggle={handlers.onToggle} | ||
/> | ||
)} | ||
/> | ||
</DatagridChangeStateContext.Provider> | ||
</DashboardCard> | ||
); | ||
}; |
Oops, something went wrong.