diff --git a/packages/admin-next/dashboard/src/i18n/translations/en.json b/packages/admin-next/dashboard/src/i18n/translations/en.json index 7ea7629760..b2f4ddf713 100644 --- a/packages/admin-next/dashboard/src/i18n/translations/en.json +++ b/packages/admin-next/dashboard/src/i18n/translations/en.json @@ -2450,6 +2450,7 @@ "handle": "Handle", "subtitle": "Subtitle", "item": "Item", + "qty": "qty.", "limit": "Limit", "tags": "Tags", "type": "Type", diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx index c297896da4..5fe63c9566 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-claim/components/claim-create-form/claim-create-form.tsx @@ -79,7 +79,9 @@ export const ClaimCreateForm = ({ */ const { setIsOpen } = useStackedModal() const [isShippingPriceEdit, setIsShippingPriceEdit] = useState(false) - const [customShippingAmount, setCustomShippingAmount] = useState(0) + const [customShippingAmount, setCustomShippingAmount] = useState< + number | string + >(0) const [inventoryMap, setInventoryMap] = useState< Record >({}) @@ -166,15 +168,15 @@ export const ClaimCreateForm = ({ const form = useForm({ defaultValues: () => { const inboundShippingMethod = preview.shipping_methods.find((s) => { - const action = s.actions?.find((a) => a.action === "SHIPPING_ADD") - - return !!action?.return?.id + return !!s.actions?.find( + (a) => a.action === "SHIPPING_ADD" && !!a.return_id + ) }) const outboundShippingMethod = preview.shipping_methods.find((s) => { - const action = s.actions?.find((a) => a.action === "SHIPPING_ADD") - - return action && !!!action?.return?.id + return !!s.actions?.find( + (a) => a.action === "SHIPPING_ADD" && !a.return_id + ) }) return Promise.resolve({ @@ -234,9 +236,7 @@ export const ClaimCreateForm = ({ ) const outboundShipping = preview.shipping_methods.find((s) => { - const action = s.actions?.find((a) => a.action === "SHIPPING_ADD") - - return action && !!!action?.return?.id + return !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id) }) const { @@ -292,7 +292,8 @@ export const ClaimCreateForm = ({ useEffect(() => { const method = preview.shipping_methods.find( - (s) => !!s.actions?.find((a) => a.action === "SHIPPING_ADD") + (s) => + !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id) ) if (method) { @@ -474,16 +475,15 @@ export const ClaimCreateForm = ({ } }, []) - const shippingTotal = useMemo(() => { + const inboundShippingTotal = useMemo(() => { const method = preview.shipping_methods.find( - (sm) => !!sm.actions?.find((a) => a.action === "SHIPPING_ADD") + (sm) => + !!sm.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id) ) return (method?.total as number) || 0 }, [preview.shipping_methods]) - const returnTotal = preview.return_requested_total - return (
@@ -774,22 +774,27 @@ export const ClaimCreateForm = ({ preview.shipping_methods.forEach((s) => { if (s.actions) { - for (let a of s.actions) { - if (a.action === "SHIPPING_ADD") { + for (const a of s.actions) { + if ( + a.action === "SHIPPING_ADD" && + !!a.return_id + ) { actionId = a.id } } } }) + const customPrice = + customShippingAmount === "" + ? null + : parseInt(customShippingAmount) + if (actionId) { updateInboundShipping( { actionId, - custom_price: - typeof customShippingAmount === "string" - ? null - : customShippingAmount, + custom_price: customPrice, }, { onError: (error) => { @@ -805,14 +810,12 @@ export const ClaimCreateForm = ({ .symbol_native } code={order.currency_code} - onValueChange={(value) => - value && setCustomShippingAmount(parseInt(value)) - } + onValueChange={setCustomShippingAmount} value={customShippingAmount} disabled={showInboundItemsPlaceholder} /> ) : ( - getStylizedAmount(shippingTotal, order.currency_code) + getStylizedAmount(inboundShippingTotal, order.currency_code) )} diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx index 337f2030f6..44c447a4c0 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-create-form.tsx @@ -55,7 +55,9 @@ export const ExchangeCreateForm = ({ * STATE */ const [isShippingPriceEdit, setIsShippingPriceEdit] = useState(false) - const [customShippingAmount, setCustomShippingAmount] = useState(0) + const [customShippingAmount, setCustomShippingAmount] = useState< + number | string + >(0) /** * MUTATIONS @@ -99,15 +101,15 @@ export const ExchangeCreateForm = ({ const form = useForm({ defaultValues: () => { const inboundShippingMethod = preview.shipping_methods.find((s) => { - const action = s.actions?.find((a) => a.action === "SHIPPING_ADD") - - return !!action?.return?.id + return !!s.actions?.find( + (a) => a.action === "SHIPPING_ADD" && !!a.return_id + ) }) const outboundShippingMethod = preview.shipping_methods.find((s) => { - const action = s.actions?.find((a) => a.action === "SHIPPING_ADD") - - return action && !!!action?.return?.id + return !!s.actions?.find( + (a) => a.action === "SHIPPING_ADD" && !a.return_id + ) }) return Promise.resolve({ @@ -143,9 +145,7 @@ export const ExchangeCreateForm = ({ }) const outboundShipping = preview.shipping_methods.find((s) => { - const action = s.actions?.find((a) => a.action === "SHIPPING_ADD") - - return action && !!!action?.return?.id + return !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id) }) const shippingOptionId = form.watch("inbound_option_id") @@ -203,9 +203,10 @@ export const ExchangeCreateForm = ({ } }, []) - const shippingTotal = useMemo(() => { + const inboundShippingTotal = useMemo(() => { const method = preview.shipping_methods.find( - (sm) => !!sm.actions?.find((a) => a.action === "SHIPPING_ADD") + (sm) => + !!sm.actions?.find((a) => a.action === "SHIPPING_ADD" && !!a.return_id) ) return (method?.total as number) || 0 @@ -304,22 +305,27 @@ export const ExchangeCreateForm = ({ preview.shipping_methods.forEach((s) => { if (s.actions) { - for (let a of s.actions) { - if (a.action === "SHIPPING_ADD") { + for (const a of s.actions) { + if ( + a.action === "SHIPPING_ADD" && + !!a.return_id + ) { actionId = a.id } } } }) + const customPrice = + customShippingAmount === "" + ? null + : parseInt(customShippingAmount) + if (actionId) { updateInboundShipping( { actionId, - custom_price: - typeof customShippingAmount === "string" - ? null - : customShippingAmount, + custom_price: customPrice, }, { onError: (error) => { @@ -335,14 +341,12 @@ export const ExchangeCreateForm = ({ .symbol_native } code={order.currency_code} - onValueChange={(value) => - value && setCustomShippingAmount(parseInt(value)) - } + onValueChange={setCustomShippingAmount} value={customShippingAmount} disabled={!inboundPreviewItems?.length} /> ) : ( - getStylizedAmount(shippingTotal, order.currency_code) + getStylizedAmount(inboundShippingTotal, order.currency_code) )} diff --git a/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx b/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx index f3f0459c1a..d21f9909cf 100644 --- a/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx +++ b/packages/admin-next/dashboard/src/routes/orders/order-create-exchange/components/exchange-create-form/exchange-outbound-section.tsx @@ -192,7 +192,7 @@ export const ExchangeOutboundSection = ({ const outboundShippingMethods = preview.shipping_methods.filter((s) => { const action = s.actions?.find((a) => a.action === "SHIPPING_ADD") - return action && !!!action?.return?.id + return !action?.return_id }) const promises = outboundShippingMethods