Skip to content

Commit

Permalink
Fix typos and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch committed Oct 30, 2023
1 parent 9d9907d commit af65064
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
6 changes: 3 additions & 3 deletions locale/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -7373,6 +7373,9 @@
"context": "Add filter button text",
"string": "+ Add filter"
},
"o/4OCR": {
"string": "Shipping has already been refunded"
},
"o5KXAN": {
"context": "delete webhook",
"string": "Are you sure you want to delete {name}?"
Expand Down Expand Up @@ -7515,9 +7518,6 @@
"context": "status",
"string": "Deactivated"
},
"pNP2pn": {
"string": "Shipping has been already refunded"
},
"pOUOnw": {
"context": "tab name",
"string": "All vouchers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export const ShippingIncluded = ({
{!canRefundShipping && (
<Text variant="caption" color="textNeutralDisabled">
<FormattedMessage
defaultMessage="Shipping has been already refunded"
id="pNP2pn"
defaultMessage="Shipping has already been refunded"
id="o/4OCR"
/>
</Text>
)}
Expand Down
17 changes: 8 additions & 9 deletions src/orders/components/OrderGrantRefundPage/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,19 @@ function createToGrantRefundLineMap(
| OrderDetailsGrantRefundFragment["fulfillments"][0]["lines"][0],
): GrantRefundLineKeyValue => {
const initialQuantity =
grantedRefund?.lines?.find(
initLine => (initLine as any).orderLine.id === line.id,
)?.quantity ?? 0;
grantedRefund?.lines?.find(initLine => initLine.orderLine.id === line.id)
?.quantity ?? 0;

return [
line.id,
{
isDirty: false,
availableQuantity: getLineAvailableQuantity(
line.id,
line.quantity,
order?.grantedRefunds,
grantedRefund?.id,
),
availableQuantity: getLineAvailableQuantity({
lineId: line.id,
lineQuntity: line.quantity,
grantRefunds: order?.grantedRefunds,
grantRefundId: grantedRefund?.id,
}),
unitPrice:
"orderLine" in line
? line.orderLine.unitPrice.gross.amount
Expand Down
19 changes: 12 additions & 7 deletions src/orders/components/OrderGrantRefundPage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,21 @@ export const prepareLineData = (lines: Map<string, ReducerOrderLine>): Line[] =>
quantity: line.selectedQuantity,
}));

export const getLineAvailableQuantity = (
lineId: string,
lineQuntity: number,
grantRefunds: OrderDetailsGrantRefundFragment["grantedRefunds"],
grandRefundId?: string,
) => {
export const getLineAvailableQuantity = ({
lineId,
lineQuntity,
grantRefunds,
grantRefundId,
}: {
lineId: string;
lineQuntity: number;
grantRefunds: OrderDetailsGrantRefundFragment["grantedRefunds"];
grantRefundId?: string;
}) => {
let refundedQuantity = 0;

grantRefunds.forEach(refund => {
if (grandRefundId && refund.id === grandRefundId) {
if (grantRefundId && refund.id === grantRefundId) {
return;
}

Expand Down

0 comments on commit af65064

Please sign in to comment.