feat(dashboard): shipping management (#6995)
**What** - shipping flow - shipping profile pages - delete fulfillment set endpoint - delete shipping profile endpoint
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { useMutation, UseMutationOptions } from "@tanstack/react-query"
|
||||
|
||||
import {
|
||||
ShippingOptionDeleteRes,
|
||||
ShippingOptionRes,
|
||||
} from "../../types/api-responses"
|
||||
import { CreateShippingOptionReq } from "../../types/api-payloads"
|
||||
import { stockLocationsQueryKeys } from "./stock-locations"
|
||||
import { queryClient } from "../../lib/medusa"
|
||||
import { client } from "../../lib/client"
|
||||
|
||||
export const useCreateShippingOptions = (
|
||||
options?: UseMutationOptions<
|
||||
ShippingOptionRes,
|
||||
Error,
|
||||
CreateShippingOptionReq
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.shippingOptions.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useDeleteShippingOption = (
|
||||
optionId: string,
|
||||
options?: UseMutationOptions<ShippingOptionDeleteRes, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.shippingOptions.delete(optionId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
QueryKey,
|
||||
useMutation,
|
||||
UseMutationOptions,
|
||||
useQuery,
|
||||
UseQueryOptions,
|
||||
} from "@tanstack/react-query"
|
||||
import { CreateShippingProfileReq } from "../../types/api-payloads"
|
||||
import {
|
||||
ShippingProfileDeleteRes,
|
||||
ShippingProfileListRes,
|
||||
ShippingProfileRes,
|
||||
} from "../../types/api-responses"
|
||||
|
||||
import { client } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/medusa"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
|
||||
const SHIPPING_PROFILE_QUERY_KEY = "shipping_profile" as const
|
||||
export const shippingProfileQueryKeys = queryKeysFactory(
|
||||
SHIPPING_PROFILE_QUERY_KEY
|
||||
)
|
||||
|
||||
export const useCreateShippingProfile = (
|
||||
options?: UseMutationOptions<
|
||||
ShippingProfileRes,
|
||||
Error,
|
||||
CreateShippingProfileReq
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) => client.shippingProfiles.create(payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: shippingProfileQueryKeys.lists(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useShippingProfiles = (
|
||||
query?: Record<string, any>,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
ShippingProfileListRes,
|
||||
Error,
|
||||
ShippingProfileListRes,
|
||||
QueryKey
|
||||
>,
|
||||
"queryFn" | "queryKey"
|
||||
>
|
||||
) => {
|
||||
const { data, ...rest } = useQuery({
|
||||
queryFn: () => client.shippingProfiles.list(query),
|
||||
queryKey: shippingProfileQueryKeys.list(query),
|
||||
...options,
|
||||
})
|
||||
|
||||
return { ...data, ...rest }
|
||||
}
|
||||
|
||||
export const useDeleteShippingProfile = (
|
||||
profileId: string,
|
||||
options?: UseMutationOptions<ShippingProfileDeleteRes, Error, void>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: () => client.shippingProfiles.delete(profileId),
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: shippingProfileQueryKeys.lists(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
@@ -10,17 +10,23 @@ import { client } from "../../lib/client"
|
||||
import { queryClient } from "../../lib/medusa"
|
||||
import { queryKeysFactory } from "../../lib/query-key-factory"
|
||||
import {
|
||||
CreateFulfillmentSetReq,
|
||||
CreateServiceZoneReq,
|
||||
CreateStockLocationReq,
|
||||
UpdateStockLocationReq,
|
||||
} from "../../types/api-payloads"
|
||||
import {
|
||||
FulfillmentSetDeleteRes,
|
||||
ServiceZoneDeleteRes,
|
||||
StockLocationDeleteRes,
|
||||
StockLocationListRes,
|
||||
StockLocationRes,
|
||||
} from "../../types/api-responses"
|
||||
|
||||
const STOCK_LOCATIONS_QUERY_KEY = "stock_locations" as const
|
||||
const stockLocationsQueryKeys = queryKeysFactory(STOCK_LOCATIONS_QUERY_KEY)
|
||||
export const stockLocationsQueryKeys = queryKeysFactory(
|
||||
STOCK_LOCATIONS_QUERY_KEY
|
||||
)
|
||||
|
||||
export const useStockLocation = (
|
||||
id: string,
|
||||
@@ -115,3 +121,79 @@ export const useDeleteStockLocation = (
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useCreateFulfillmentSet = (
|
||||
locationId: string,
|
||||
options?: UseMutationOptions<StockLocationRes, Error, CreateFulfillmentSetReq>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload) =>
|
||||
client.stockLocations.createFulfillmentSet(locationId, payload),
|
||||
onSuccess: (data, variables, context) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.lists(),
|
||||
})
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: stockLocationsQueryKeys.detail(locationId),
|
||||
})
|
||||
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.detail(locationId),
|
||||
})
|
||||
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(),
|
||||
})
|
||||
|
||||
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(),
|
||||
})
|
||||
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user