fix(dashboard,types,js-sdk): Locations & Shipping fixes and cleanup (#7715)
This commit is contained in:
committed by
GitHub
parent
bc0c65c6b3
commit
2e8e7b27b6
@@ -1,21 +1,28 @@
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { QueryKey, useQuery, UseQueryOptions } from "@tanstack/react-query"
|
||||
import { client } from "../../lib/client"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
|
||||
const FULFILLMENT_PROVIDERS_QUERY_KEY = "f_providers" as const
|
||||
const FULFILLMENT_PROVIDERS_QUERY_KEY = "fulfillment_providers" as const
|
||||
export const fulfillmentProvidersQueryKeys = queryKeysFactory(
|
||||
FULFILLMENT_PROVIDERS_QUERY_KEY
|
||||
)
|
||||
|
||||
export const useFulfillmentProviders = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminFulfillmentProviderListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<any, Error, any, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminFulfillmentProviderListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminFulfillmentProviderListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.fulfillmentProviders.list(query),
|
||||
queryFn: () => sdk.admin.fulfillmentProvider.list(query),
|
||||
queryKey: fulfillmentProvidersQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
|
||||
180
packages/admin-next/dashboard/src/hooks/api/fulfillment-sets.tsx
Normal file
180
packages/admin-next/dashboard/src/hooks/api/fulfillment-sets.tsx
Normal file
@@ -0,0 +1,180 @@
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import {
|
||||
QueryKey,
|
||||
UseMutationOptions,
|
||||
UseQueryOptions,
|
||||
useMutation,
|
||||
useQuery,
|
||||
} from "@tanstack/react-query"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { shippingOptionsQueryKeys } from "./shipping-options"
|
||||
import { stockLocationsQueryKeys } from "./stock-locations"
|
||||
|
||||
const FULFILLMENT_SETS_QUERY_KEY = "fulfillment_sets" as const
|
||||
export const fulfillmentSetsQueryKeys = queryKeysFactory(
|
||||
FULFILLMENT_SETS_QUERY_KEY
|
||||
)
|
||||
|
||||
export const useDeleteFulfillmentSet = (
|
||||
id: string,
|
||||
options?: Omit<
|
||||
UseMutationOptions<
|
||||
HttpTypes.AdminFulfillmentSetDeleteResponse,
|
||||
FetchError,
|
||||
void
|
||||
>,
|
||||
"mutationFn"
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => sdk.admin.fulfillmentSet.delete(id),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: fulfillmentSetsQueryKeys.detail(id),
|
||||
})
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: fulfillmentSetsQueryKeys.lists(),
|
||||
})
|
||||
|
||||
// We need to invalidate all related entities. We invalidate using `all` keys to ensure that all relevant entities are invalidated.
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
})
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: shippingOptionsQueryKeys.all,
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useFulfillmentSetServiceZone = (
|
||||
fulfillmentSetId: string,
|
||||
serviceZoneId: string,
|
||||
query?: HttpTypes.SelectParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminServiceZoneResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminServiceZoneResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () =>
|
||||
sdk.admin.fulfillmentSet.retrieveServiceZone(
|
||||
fulfillmentSetId,
|
||||
serviceZoneId,
|
||||
query
|
||||
),
|
||||
queryKey: fulfillmentSetsQueryKeys.detail(fulfillmentSetId, query),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useCreateFulfillmentSetServiceZone = (
|
||||
fulfillmentSetId: string,
|
||||
options?: Omit<
|
||||
UseMutationOptions<
|
||||
HttpTypes.AdminFulfillmentSetResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateFulfillmentSetServiceZone,
|
||||
QueryKey
|
||||
>,
|
||||
"mutationFn"
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
sdk.admin.fulfillmentSet.createServiceZone(fulfillmentSetId, payload),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: fulfillmentSetsQueryKeys.lists(),
|
||||
})
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useUpdateFulfillmentSetServiceZone = (
|
||||
fulfillmentSetId: string,
|
||||
serviceZoneId: string,
|
||||
options?: Omit<
|
||||
UseMutationOptions<
|
||||
HttpTypes.AdminFulfillmentSetResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdateFulfillmentSetServiceZone,
|
||||
QueryKey
|
||||
>,
|
||||
"mutationFn"
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
sdk.admin.fulfillmentSet.updateServiceZone(
|
||||
fulfillmentSetId,
|
||||
serviceZoneId,
|
||||
payload
|
||||
),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: fulfillmentSetsQueryKeys.lists(),
|
||||
})
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteFulfillmentServiceZone = (
|
||||
fulfillmentSetId: string,
|
||||
serviceZoneId: string,
|
||||
options?: Omit<
|
||||
UseMutationOptions<
|
||||
HttpTypes.AdminServiceZoneDeleteResponse,
|
||||
FetchError,
|
||||
void
|
||||
>,
|
||||
"mutationFn"
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () =>
|
||||
sdk.admin.fulfillmentSet.deleteServiceZone(
|
||||
fulfillmentSetId,
|
||||
serviceZoneId
|
||||
),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: fulfillmentSetsQueryKeys.lists(),
|
||||
})
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: shippingOptionsQueryKeys.lists(),
|
||||
})
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
@@ -6,33 +6,51 @@ import {
|
||||
UseQueryOptions,
|
||||
} from "@tanstack/react-query"
|
||||
|
||||
import { client } from "../../lib/client"
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import {
|
||||
CreateShippingOptionReq,
|
||||
UpdateShippingOptionReq,
|
||||
} from "../../types/api-payloads"
|
||||
import {
|
||||
ShippingOptionDeleteRes,
|
||||
ShippingOptionRes,
|
||||
} from "../../types/api-responses"
|
||||
import { stockLocationsQueryKeys } from "./stock-locations"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import { stockLocationsQueryKeys } from "./stock-locations"
|
||||
|
||||
const SHIPPING_OPTIONS_QUERY_KEY = "shipping_options" as const
|
||||
export const shippingOptionsQueryKeys = queryKeysFactory(
|
||||
SHIPPING_OPTIONS_QUERY_KEY
|
||||
)
|
||||
|
||||
// TODO: Endpoint is not implemented yet
|
||||
// export const useShippingOption = (
|
||||
// id: string,
|
||||
// options?: UseQueryOptions<
|
||||
// HttpTypes.AdminShippingOptionResponse,
|
||||
// Error,
|
||||
// HttpTypes.AdminShippingOptionResponse,
|
||||
// QueryKey
|
||||
// >
|
||||
// ) => {
|
||||
// const { data, ...rest } = useQuery({
|
||||
// queryFn: () => sdk.admin.shippingOption.retrieve(id),
|
||||
// queryKey: shippingOptionsQueryKeys.retrieve(id),
|
||||
// ...options,
|
||||
// })
|
||||
|
||||
// return { ...data, ...rest }
|
||||
// }
|
||||
|
||||
export const useShippingOptions = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminShippingOptionListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<any, Error, any, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminShippingOptionListResponse,
|
||||
Error,
|
||||
HttpTypes.AdminShippingOptionListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.shippingOptions.list(query),
|
||||
queryFn: () => sdk.admin.shippingOption.list(query),
|
||||
queryKey: shippingOptionsQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
@@ -42,13 +60,13 @@ export const useShippingOptions = (
|
||||
|
||||
export const useCreateShippingOptions = (
|
||||
options?: UseMutationOptions<
|
||||
ShippingOptionRes,
|
||||
Error,
|
||||
CreateShippingOptionReq
|
||||
HttpTypes.AdminShippingOptionResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateShippingOption
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.shippingOptions.create(payload),
|
||||
mutationFn: (payload) => sdk.admin.shippingOption.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
@@ -65,13 +83,13 @@ export const useCreateShippingOptions = (
|
||||
export const useUpdateShippingOptions = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
ShippingOptionRes,
|
||||
Error,
|
||||
UpdateShippingOptionReq
|
||||
HttpTypes.AdminShippingOptionResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdateShippingOption
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.shippingOptions.update(id, payload),
|
||||
mutationFn: (payload) => sdk.admin.shippingOption.update(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
@@ -87,11 +105,15 @@ export const useUpdateShippingOptions = (
|
||||
|
||||
export const useDeleteShippingOption = (
|
||||
optionId: string,
|
||||
options?: UseMutationOptions<ShippingOptionDeleteRes, Error, void>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminShippingOptionDeleteResponse,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.shippingOptions.delete(optionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
mutationFn: () => sdk.admin.shippingOption.delete(optionId),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.all,
|
||||
})
|
||||
|
||||
@@ -5,14 +5,10 @@ import {
|
||||
useQuery,
|
||||
UseQueryOptions,
|
||||
} from "@tanstack/react-query"
|
||||
import { CreateShippingProfileReq } from "../../types/api-payloads"
|
||||
import {
|
||||
ShippingProfileListRes,
|
||||
ShippingProfileRes,
|
||||
} from "../../types/api-responses"
|
||||
|
||||
import { DeleteResponse } from "@medusajs/types"
|
||||
import { client } from "../../lib/client"
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
|
||||
@@ -23,13 +19,13 @@ export const shippingProfileQueryKeys = queryKeysFactory(
|
||||
|
||||
export const useCreateShippingProfile = (
|
||||
options?: UseMutationOptions<
|
||||
ShippingProfileRes,
|
||||
Error,
|
||||
CreateShippingProfileReq
|
||||
HttpTypes.AdminShippingProfileResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateShippingProfile
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.shippingProfiles.create(payload),
|
||||
mutationFn: (payload) => sdk.admin.shippingProfile.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: shippingProfileQueryKeys.lists(),
|
||||
@@ -45,14 +41,14 @@ export const useShippingProfile = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
options?: UseQueryOptions<
|
||||
ShippingProfileRes,
|
||||
Error,
|
||||
ShippingProfileRes,
|
||||
HttpTypes.AdminShippingProfileResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminShippingProfileResponse,
|
||||
QueryKey
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.shippingProfiles.retrieve(id, query),
|
||||
queryFn: () => sdk.admin.shippingProfile.retrieve(id, query),
|
||||
queryKey: shippingProfileQueryKeys.detail(id, query),
|
||||
...options,
|
||||
})
|
||||
@@ -61,19 +57,19 @@ export const useShippingProfile = (
|
||||
}
|
||||
|
||||
export const useShippingProfiles = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminShippingProfileListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
ShippingProfileListRes,
|
||||
Error,
|
||||
ShippingProfileListRes,
|
||||
HttpTypes.AdminShippingProfileListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminShippingProfileListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.shippingProfiles.list(query),
|
||||
queryFn: () => sdk.admin.shippingProfile.list(query),
|
||||
queryKey: shippingProfileQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
@@ -82,12 +78,19 @@ export const useShippingProfiles = (
|
||||
}
|
||||
|
||||
export const useDeleteShippingProfile = (
|
||||
profileId: string,
|
||||
options?: UseMutationOptions<DeleteResponse, Error, void>
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminShippingProfileDeleteResponse,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.shippingProfiles.delete(profileId),
|
||||
mutationFn: () => sdk.admin.shippingProfile.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: shippingProfileQueryKeys.detail(id),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: shippingProfileQueryKeys.lists(),
|
||||
})
|
||||
|
||||
@@ -6,24 +6,11 @@ import {
|
||||
useQuery,
|
||||
} from "@tanstack/react-query"
|
||||
|
||||
import { client } from "../../lib/client"
|
||||
import { FetchError } from "@medusajs/js-sdk"
|
||||
import { HttpTypes } from "@medusajs/types"
|
||||
import { sdk } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/query-client"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import {
|
||||
CreateFulfillmentSetReq,
|
||||
CreateServiceZoneReq,
|
||||
CreateStockLocationReq,
|
||||
UpdateServiceZoneReq,
|
||||
UpdateStockLocationReq,
|
||||
UpdateStockLocationSalesChannelsReq,
|
||||
} from "../../types/api-payloads"
|
||||
import {
|
||||
FulfillmentSetDeleteRes,
|
||||
ServiceZoneDeleteRes,
|
||||
StockLocationDeleteRes,
|
||||
StockLocationListRes,
|
||||
StockLocationRes,
|
||||
} from "../../types/api-responses"
|
||||
|
||||
const STOCK_LOCATIONS_QUERY_KEY = "stock_locations" as const
|
||||
export const stockLocationsQueryKeys = queryKeysFactory(
|
||||
@@ -32,14 +19,19 @@ export const stockLocationsQueryKeys = queryKeysFactory(
|
||||
|
||||
export const useStockLocation = (
|
||||
id: string,
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.SelectParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<StockLocationRes, Error, StockLocationRes, QueryKey>,
|
||||
UseQueryOptions<
|
||||
HttpTypes.AdminStockLocationResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminStockLocationResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.stockLocations.retrieve(id, query),
|
||||
queryFn: () => sdk.admin.stockLocation.retrieve(id, query),
|
||||
queryKey: stockLocationsQueryKeys.detail(id, query),
|
||||
...options,
|
||||
})
|
||||
@@ -48,19 +40,19 @@ export const useStockLocation = (
|
||||
}
|
||||
|
||||
export const useStockLocations = (
|
||||
query?: Record<string, any>,
|
||||
query?: HttpTypes.AdminStockLocationListParams,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
StockLocationListRes,
|
||||
Error,
|
||||
StockLocationListRes,
|
||||
HttpTypes.AdminStockLocationListResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminStockLocationListResponse,
|
||||
QueryKey
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.stockLocations.list(query),
|
||||
queryFn: () => sdk.admin.stockLocation.list(query),
|
||||
queryKey: stockLocationsQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
@@ -69,12 +61,16 @@ export const useStockLocations = (
|
||||
}
|
||||
|
||||
export const useCreateStockLocation = (
|
||||
options?: UseMutationOptions<StockLocationRes, Error, CreateStockLocationReq>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminStockLocationResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateStockLocation
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.stockLocations.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
mutationFn: (payload) => sdk.admin.stockLocation.create(payload),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
|
||||
@@ -86,15 +82,19 @@ export const useCreateStockLocation = (
|
||||
|
||||
export const useUpdateStockLocation = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<StockLocationRes, Error, UpdateStockLocationReq>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminStockLocationResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdateStockLocation
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.stockLocations.update(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
mutationFn: (payload) => sdk.admin.stockLocation.update(id, payload),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
|
||||
@@ -107,21 +107,22 @@ export const useUpdateStockLocation = (
|
||||
export const useUpdateStockLocationSalesChannels = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<
|
||||
StockLocationRes,
|
||||
Error,
|
||||
UpdateStockLocationSalesChannelsReq
|
||||
HttpTypes.AdminStockLocationResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminUpdateStockLocationSalesChannels
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.stockLocations.updateSalesChannels(id, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
sdk.admin.stockLocation.updateSalesChannels(id, payload),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
@@ -130,15 +131,19 @@ export const useUpdateStockLocationSalesChannels = (
|
||||
|
||||
export const useDeleteStockLocation = (
|
||||
id: string,
|
||||
options?: UseMutationOptions<StockLocationDeleteRes, Error, void>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminStockLocationDeleteResponse,
|
||||
FetchError,
|
||||
void
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.stockLocations.delete(id),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
mutationFn: () => sdk.admin.stockLocation.delete(id),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.detail(id),
|
||||
})
|
||||
|
||||
@@ -148,105 +153,22 @@ export const useDeleteStockLocation = (
|
||||
})
|
||||
}
|
||||
|
||||
export const useCreateFulfillmentSet = (
|
||||
export const useCreateStockLocationFulfillmentSet = (
|
||||
locationId: string,
|
||||
options?: UseMutationOptions<StockLocationRes, Error, CreateFulfillmentSetReq>
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminStockLocationResponse,
|
||||
FetchError,
|
||||
HttpTypes.AdminCreateStockLocationFulfillmentSet
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.stockLocations.createFulfillmentSet(locationId, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
sdk.admin.stockLocation.createFulfillmentSet(locationId, payload),
|
||||
onSuccess: async (data, variables, context) => {
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.details(),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useCreateServiceZone = (
|
||||
locationId: string,
|
||||
fulfillmentSetId: string,
|
||||
options?: UseMutationOptions<StockLocationRes, Error, CreateServiceZoneReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.stockLocations.createServiceZone(fulfillmentSetId, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useUpdateServiceZone = (
|
||||
fulfillmentSetId: string,
|
||||
serviceZoneId: string,
|
||||
locationId: string,
|
||||
options?: UseMutationOptions<StockLocationRes, Error, UpdateServiceZoneReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.stockLocations.updateServiceZone(
|
||||
fulfillmentSetId,
|
||||
serviceZoneId,
|
||||
payload
|
||||
),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.details(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteFulfillmentSet = (
|
||||
setId: string,
|
||||
options?: UseMutationOptions<FulfillmentSetDeleteRes, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.stockLocations.deleteFulfillmentSet(setId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.details(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteServiceZone = (
|
||||
setId: string,
|
||||
zoneId: string,
|
||||
options?: UseMutationOptions<ServiceZoneDeleteRes, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.stockLocations.deleteServiceZone(setId, zoneId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.details(),
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user