feat(dashboard, core-flows, js-sdk, types, medusa): listing order's shipping options (#13242)
* feat(dashboard, core-flows,js-sdk,types,medusa): listing order's shipping option * fix: typo * chore: migrate claim form * fix: cleanup rule logic * feat: add test case, rm params * fix: expand location name
This commit is contained in:
@@ -18,6 +18,7 @@ const _orderKeys = queryKeysFactory(ORDERS_QUERY_KEY) as TQueryKey<"orders"> & {
|
||||
preview: (orderId: string) => any
|
||||
changes: (orderId: string) => any
|
||||
lineItems: (orderId: string) => any
|
||||
shippingOptions: (orderId: string) => any
|
||||
}
|
||||
|
||||
_orderKeys.preview = function (id: string) {
|
||||
@@ -32,6 +33,10 @@ _orderKeys.lineItems = function (id: string) {
|
||||
return [this.detail(id), "lineItems"]
|
||||
}
|
||||
|
||||
_orderKeys.shippingOptions = function (id: string) {
|
||||
return [this.detail(id), "shippingOptions"]
|
||||
}
|
||||
|
||||
export const ordersQueryKeys = _orderKeys
|
||||
|
||||
export const useOrder = (
|
||||
@@ -125,6 +130,28 @@ export const useOrders = (
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useOrderShippingOptions = (
|
||||
id: string,
|
||||
query?: HttpTypes.AdminGetOrderShippingOptionList,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
{ shipping_options: HttpTypes.AdminShippingOption[] },
|
||||
FetchError,
|
||||
{ shipping_options: HttpTypes.AdminShippingOption[] },
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: async () => sdk.admin.order.listShippingOptions(id, query),
|
||||
queryKey: ordersQueryKeys.shippingOptions(id),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useOrderChanges = (
|
||||
id: string,
|
||||
query?: HttpTypes.AdminOrderChangesFilters,
|
||||
|
||||
@@ -24,13 +24,14 @@ import {
|
||||
useRemoveClaimOutboundItem,
|
||||
useUpdateClaimOutboundItems,
|
||||
} from "../../../../../hooks/api/claims"
|
||||
import { useShippingOptions } from "../../../../../hooks/api/shipping-options"
|
||||
import { sdk } from "../../../../../lib/client"
|
||||
import { OutboundShippingPlaceholder } from "../../../common/placeholders"
|
||||
import { AddClaimOutboundItemsTable } from "../add-claim-outbound-items-table"
|
||||
import { ClaimOutboundItem } from "./claim-outbound-item"
|
||||
import { ItemPlaceholder } from "./item-placeholder"
|
||||
import { CreateClaimSchemaType } from "./schema"
|
||||
import { useOrderShippingOptions } from "../../../../../hooks/api/orders"
|
||||
import { getFormattedShippingOptionLocationName } from "../../../../../lib/shipping-options"
|
||||
|
||||
type ClaimOutboundSectionProps = {
|
||||
order: AdminOrder
|
||||
@@ -58,16 +59,12 @@ export const ClaimOutboundSection = ({
|
||||
/**
|
||||
* HOOKS
|
||||
*/
|
||||
const { shipping_options = [] } = useShippingOptions({
|
||||
limit: 999,
|
||||
fields: "*prices,+service_zone.fulfillment_set.location.id",
|
||||
})
|
||||
const { shipping_options = [] } = useOrderShippingOptions(order.id)
|
||||
|
||||
// TODO: filter in the API when boolean filter is supported and fulfillment module support partial rule SO filtering
|
||||
const outboundShippingOptions = shipping_options.filter(
|
||||
(shippingOption) =>
|
||||
!!shippingOption.rules.find(
|
||||
(r) => r.attribute === "is_return" && r.value === "false"
|
||||
)
|
||||
(so) =>
|
||||
!so.rules?.find((r) => r.attribute === "is_return" && r.value === "true")
|
||||
)
|
||||
|
||||
const { mutateAsync: addOutboundShipping } = useAddClaimOutboundShipping(
|
||||
@@ -415,7 +412,7 @@ export const ClaimOutboundSection = ({
|
||||
}}
|
||||
{...field}
|
||||
options={outboundShippingOptions.map((so) => ({
|
||||
label: so.name,
|
||||
label: `${so.name} (${getFormattedShippingOptionLocationName(so)})`,
|
||||
value: so.id,
|
||||
}))}
|
||||
disabled={!outboundShippingOptions.length}
|
||||
|
||||
@@ -23,13 +23,14 @@ import {
|
||||
useRemoveExchangeOutboundItem,
|
||||
useUpdateExchangeOutboundItems,
|
||||
} from "../../../../../hooks/api/exchanges"
|
||||
import { useShippingOptions } from "../../../../../hooks/api/shipping-options"
|
||||
import { sdk } from "../../../../../lib/client"
|
||||
import { OutboundShippingPlaceholder } from "../../../common/placeholders"
|
||||
import { ItemPlaceholder } from "../../../order-create-claim/components/claim-create-form/item-placeholder"
|
||||
import { AddExchangeOutboundItemsTable } from "../add-exchange-outbound-items-table"
|
||||
import { ExchangeOutboundItem } from "./exchange-outbound-item"
|
||||
import { useOrderShippingOptions } from "../../../../../hooks/api/orders"
|
||||
import { CreateExchangeSchemaType } from "./schema"
|
||||
import { getFormattedShippingOptionLocationName } from "../../../../../lib/shipping-options"
|
||||
|
||||
type ExchangeOutboundSectionProps = {
|
||||
order: AdminOrder
|
||||
@@ -57,16 +58,12 @@ export const ExchangeOutboundSection = ({
|
||||
/**
|
||||
* HOOKS
|
||||
*/
|
||||
const { shipping_options = [] } = useShippingOptions({
|
||||
limit: 999,
|
||||
fields: "*prices,+service_zone.fulfillment_set.location.id",
|
||||
})
|
||||
const { shipping_options = [] } = useOrderShippingOptions(order.id)
|
||||
|
||||
// TODO: filter in the API when boolean filter is supported and fulfillment module support partial rule SO filtering
|
||||
const outboundShippingOptions = shipping_options.filter(
|
||||
(shippingOption) =>
|
||||
!!shippingOption.rules.find(
|
||||
(r) => r.attribute === "is_return" && r.value === "false"
|
||||
)
|
||||
(so) =>
|
||||
!so.rules?.find((r) => r.attribute === "is_return" && r.value === "true")
|
||||
)
|
||||
|
||||
const { mutateAsync: addOutboundShipping } = useAddExchangeOutboundShipping(
|
||||
@@ -424,7 +421,7 @@ export const ExchangeOutboundSection = ({
|
||||
}}
|
||||
{...field}
|
||||
options={outboundShippingOptions.map((so) => ({
|
||||
label: so.name,
|
||||
label: `${so.name} (${getFormattedShippingOptionLocationName(so)})`,
|
||||
value: so.id,
|
||||
}))}
|
||||
disabled={!outboundShippingOptions.length}
|
||||
|
||||
Reference in New Issue
Block a user