fix(dashboard): RMAs shipping pricing (#8848)
* wip: allow unsetting price * fix: use non return shipping for outbound * fix: claims shipping * fix: refactor * fix: checks * feat: polish
This commit is contained in:
@@ -2450,6 +2450,7 @@
|
|||||||
"handle": "Handle",
|
"handle": "Handle",
|
||||||
"subtitle": "Subtitle",
|
"subtitle": "Subtitle",
|
||||||
"item": "Item",
|
"item": "Item",
|
||||||
|
"qty": "qty.",
|
||||||
"limit": "Limit",
|
"limit": "Limit",
|
||||||
"tags": "Tags",
|
"tags": "Tags",
|
||||||
"type": "Type",
|
"type": "Type",
|
||||||
|
|||||||
+28
-25
@@ -79,7 +79,9 @@ export const ClaimCreateForm = ({
|
|||||||
*/
|
*/
|
||||||
const { setIsOpen } = useStackedModal()
|
const { setIsOpen } = useStackedModal()
|
||||||
const [isShippingPriceEdit, setIsShippingPriceEdit] = useState(false)
|
const [isShippingPriceEdit, setIsShippingPriceEdit] = useState(false)
|
||||||
const [customShippingAmount, setCustomShippingAmount] = useState(0)
|
const [customShippingAmount, setCustomShippingAmount] = useState<
|
||||||
|
number | string
|
||||||
|
>(0)
|
||||||
const [inventoryMap, setInventoryMap] = useState<
|
const [inventoryMap, setInventoryMap] = useState<
|
||||||
Record<string, InventoryLevelDTO[]>
|
Record<string, InventoryLevelDTO[]>
|
||||||
>({})
|
>({})
|
||||||
@@ -166,15 +168,15 @@ export const ClaimCreateForm = ({
|
|||||||
const form = useForm<CreateClaimSchemaType>({
|
const form = useForm<CreateClaimSchemaType>({
|
||||||
defaultValues: () => {
|
defaultValues: () => {
|
||||||
const inboundShippingMethod = preview.shipping_methods.find((s) => {
|
const inboundShippingMethod = preview.shipping_methods.find((s) => {
|
||||||
const action = s.actions?.find((a) => a.action === "SHIPPING_ADD")
|
return !!s.actions?.find(
|
||||||
|
(a) => a.action === "SHIPPING_ADD" && !!a.return_id
|
||||||
return !!action?.return?.id
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const outboundShippingMethod = preview.shipping_methods.find((s) => {
|
const outboundShippingMethod = preview.shipping_methods.find((s) => {
|
||||||
const action = s.actions?.find((a) => a.action === "SHIPPING_ADD")
|
return !!s.actions?.find(
|
||||||
|
(a) => a.action === "SHIPPING_ADD" && !a.return_id
|
||||||
return action && !!!action?.return?.id
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
@@ -234,9 +236,7 @@ export const ClaimCreateForm = ({
|
|||||||
)
|
)
|
||||||
|
|
||||||
const outboundShipping = preview.shipping_methods.find((s) => {
|
const outboundShipping = preview.shipping_methods.find((s) => {
|
||||||
const action = s.actions?.find((a) => a.action === "SHIPPING_ADD")
|
return !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
|
||||||
|
|
||||||
return action && !!!action?.return?.id
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -292,7 +292,8 @@ export const ClaimCreateForm = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const method = preview.shipping_methods.find(
|
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) {
|
if (method) {
|
||||||
@@ -474,16 +475,15 @@ export const ClaimCreateForm = ({
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const shippingTotal = useMemo(() => {
|
const inboundShippingTotal = useMemo(() => {
|
||||||
const method = preview.shipping_methods.find(
|
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
|
return (method?.total as number) || 0
|
||||||
}, [preview.shipping_methods])
|
}, [preview.shipping_methods])
|
||||||
|
|
||||||
const returnTotal = preview.return_requested_total
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RouteFocusModal.Form form={form}>
|
<RouteFocusModal.Form form={form}>
|
||||||
<form onSubmit={handleSubmit} className="flex h-full flex-col">
|
<form onSubmit={handleSubmit} className="flex h-full flex-col">
|
||||||
@@ -774,22 +774,27 @@ export const ClaimCreateForm = ({
|
|||||||
|
|
||||||
preview.shipping_methods.forEach((s) => {
|
preview.shipping_methods.forEach((s) => {
|
||||||
if (s.actions) {
|
if (s.actions) {
|
||||||
for (let a of s.actions) {
|
for (const a of s.actions) {
|
||||||
if (a.action === "SHIPPING_ADD") {
|
if (
|
||||||
|
a.action === "SHIPPING_ADD" &&
|
||||||
|
!!a.return_id
|
||||||
|
) {
|
||||||
actionId = a.id
|
actionId = a.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const customPrice =
|
||||||
|
customShippingAmount === ""
|
||||||
|
? null
|
||||||
|
: parseInt(customShippingAmount)
|
||||||
|
|
||||||
if (actionId) {
|
if (actionId) {
|
||||||
updateInboundShipping(
|
updateInboundShipping(
|
||||||
{
|
{
|
||||||
actionId,
|
actionId,
|
||||||
custom_price:
|
custom_price: customPrice,
|
||||||
typeof customShippingAmount === "string"
|
|
||||||
? null
|
|
||||||
: customShippingAmount,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
@@ -805,14 +810,12 @@ export const ClaimCreateForm = ({
|
|||||||
.symbol_native
|
.symbol_native
|
||||||
}
|
}
|
||||||
code={order.currency_code}
|
code={order.currency_code}
|
||||||
onValueChange={(value) =>
|
onValueChange={setCustomShippingAmount}
|
||||||
value && setCustomShippingAmount(parseInt(value))
|
|
||||||
}
|
|
||||||
value={customShippingAmount}
|
value={customShippingAmount}
|
||||||
disabled={showInboundItemsPlaceholder}
|
disabled={showInboundItemsPlaceholder}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
getStylizedAmount(shippingTotal, order.currency_code)
|
getStylizedAmount(inboundShippingTotal, order.currency_code)
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+26
-22
@@ -55,7 +55,9 @@ export const ExchangeCreateForm = ({
|
|||||||
* STATE
|
* STATE
|
||||||
*/
|
*/
|
||||||
const [isShippingPriceEdit, setIsShippingPriceEdit] = useState(false)
|
const [isShippingPriceEdit, setIsShippingPriceEdit] = useState(false)
|
||||||
const [customShippingAmount, setCustomShippingAmount] = useState(0)
|
const [customShippingAmount, setCustomShippingAmount] = useState<
|
||||||
|
number | string
|
||||||
|
>(0)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MUTATIONS
|
* MUTATIONS
|
||||||
@@ -99,15 +101,15 @@ export const ExchangeCreateForm = ({
|
|||||||
const form = useForm<CreateExchangeSchemaType>({
|
const form = useForm<CreateExchangeSchemaType>({
|
||||||
defaultValues: () => {
|
defaultValues: () => {
|
||||||
const inboundShippingMethod = preview.shipping_methods.find((s) => {
|
const inboundShippingMethod = preview.shipping_methods.find((s) => {
|
||||||
const action = s.actions?.find((a) => a.action === "SHIPPING_ADD")
|
return !!s.actions?.find(
|
||||||
|
(a) => a.action === "SHIPPING_ADD" && !!a.return_id
|
||||||
return !!action?.return?.id
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
const outboundShippingMethod = preview.shipping_methods.find((s) => {
|
const outboundShippingMethod = preview.shipping_methods.find((s) => {
|
||||||
const action = s.actions?.find((a) => a.action === "SHIPPING_ADD")
|
return !!s.actions?.find(
|
||||||
|
(a) => a.action === "SHIPPING_ADD" && !a.return_id
|
||||||
return action && !!!action?.return?.id
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
@@ -143,9 +145,7 @@ export const ExchangeCreateForm = ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const outboundShipping = preview.shipping_methods.find((s) => {
|
const outboundShipping = preview.shipping_methods.find((s) => {
|
||||||
const action = s.actions?.find((a) => a.action === "SHIPPING_ADD")
|
return !!s.actions?.find((a) => a.action === "SHIPPING_ADD" && !a.return_id)
|
||||||
|
|
||||||
return action && !!!action?.return?.id
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const shippingOptionId = form.watch("inbound_option_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(
|
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
|
return (method?.total as number) || 0
|
||||||
@@ -304,22 +305,27 @@ export const ExchangeCreateForm = ({
|
|||||||
|
|
||||||
preview.shipping_methods.forEach((s) => {
|
preview.shipping_methods.forEach((s) => {
|
||||||
if (s.actions) {
|
if (s.actions) {
|
||||||
for (let a of s.actions) {
|
for (const a of s.actions) {
|
||||||
if (a.action === "SHIPPING_ADD") {
|
if (
|
||||||
|
a.action === "SHIPPING_ADD" &&
|
||||||
|
!!a.return_id
|
||||||
|
) {
|
||||||
actionId = a.id
|
actionId = a.id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const customPrice =
|
||||||
|
customShippingAmount === ""
|
||||||
|
? null
|
||||||
|
: parseInt(customShippingAmount)
|
||||||
|
|
||||||
if (actionId) {
|
if (actionId) {
|
||||||
updateInboundShipping(
|
updateInboundShipping(
|
||||||
{
|
{
|
||||||
actionId,
|
actionId,
|
||||||
custom_price:
|
custom_price: customPrice,
|
||||||
typeof customShippingAmount === "string"
|
|
||||||
? null
|
|
||||||
: customShippingAmount,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
@@ -335,14 +341,12 @@ export const ExchangeCreateForm = ({
|
|||||||
.symbol_native
|
.symbol_native
|
||||||
}
|
}
|
||||||
code={order.currency_code}
|
code={order.currency_code}
|
||||||
onValueChange={(value) =>
|
onValueChange={setCustomShippingAmount}
|
||||||
value && setCustomShippingAmount(parseInt(value))
|
|
||||||
}
|
|
||||||
value={customShippingAmount}
|
value={customShippingAmount}
|
||||||
disabled={!inboundPreviewItems?.length}
|
disabled={!inboundPreviewItems?.length}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
getStylizedAmount(shippingTotal, order.currency_code)
|
getStylizedAmount(inboundShippingTotal, order.currency_code)
|
||||||
)}
|
)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
+1
-1
@@ -192,7 +192,7 @@ export const ExchangeOutboundSection = ({
|
|||||||
const outboundShippingMethods = preview.shipping_methods.filter((s) => {
|
const outboundShippingMethods = preview.shipping_methods.filter((s) => {
|
||||||
const action = s.actions?.find((a) => a.action === "SHIPPING_ADD")
|
const action = s.actions?.find((a) => a.action === "SHIPPING_ADD")
|
||||||
|
|
||||||
return action && !!!action?.return?.id
|
return !action?.return_id
|
||||||
})
|
})
|
||||||
|
|
||||||
const promises = outboundShippingMethods
|
const promises = outboundShippingMethods
|
||||||
|
|||||||
Reference in New Issue
Block a user