feat: update return request (#8302)
This commit is contained in:
@@ -151,6 +151,29 @@ export const useRemoveReturnItem = (
|
||||
})
|
||||
}
|
||||
|
||||
export const useUpdateReturn = (
|
||||
id: string,
|
||||
orderId: string,
|
||||
options?: UseMutationOptions<
|
||||
HttpTypes.AdminReturnResponse,
|
||||
Error,
|
||||
HttpTypes.AdminUpdateReturnRequest
|
||||
>
|
||||
) => {
|
||||
return useMutation({
|
||||
mutationFn: (payload: HttpTypes.AdminUpdateReturnRequest) => {
|
||||
return sdk.admin.return.updateRequest(id, payload)
|
||||
},
|
||||
onSuccess: (data: any, variables: any, context: any) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ordersQueryKeys.preview(orderId),
|
||||
})
|
||||
options?.onSuccess?.(data, variables, context)
|
||||
},
|
||||
...options,
|
||||
})
|
||||
}
|
||||
|
||||
export const useAddReturnShipping = (
|
||||
id: string,
|
||||
orderId: string,
|
||||
|
||||
@@ -37,6 +37,7 @@ import {
|
||||
useConfirmReturnRequest,
|
||||
useDeleteReturnShipping,
|
||||
useRemoveReturnItem,
|
||||
useUpdateReturn,
|
||||
useUpdateReturnItem,
|
||||
useUpdateReturnShipping,
|
||||
} from "../../../../../hooks/api/returns"
|
||||
@@ -91,6 +92,8 @@ export const ReturnCreateForm = ({
|
||||
|
||||
const { mutateAsync: cancelReturnRequest, isPending: isCanceling } =
|
||||
useCancelReturnRequest(activeReturn.id, order.id)
|
||||
const { mutateAsync: updateReturnRequest, isPending: isUpdating } =
|
||||
useUpdateReturn(activeReturn.id, order.id)
|
||||
|
||||
const { mutateAsync: addReturnShipping, isPending: isAddingReturnShipping } =
|
||||
useAddReturnShipping(activeReturn.id, order.id)
|
||||
@@ -122,7 +125,8 @@ export const ReturnCreateForm = ({
|
||||
isDeletingReturnShipping ||
|
||||
isAddingReturnItem ||
|
||||
isRemovingReturnItem ||
|
||||
isUpdatingReturnItem
|
||||
isUpdatingReturnItem ||
|
||||
isUpdating
|
||||
|
||||
/**
|
||||
* FORM
|
||||
@@ -254,6 +258,10 @@ export const ReturnCreateForm = ({
|
||||
setIsOpen("items", false)
|
||||
}
|
||||
|
||||
const onLocationChange = async (selectedLocationId: string) => {
|
||||
await updateReturnRequest({ location_id: selectedLocationId })
|
||||
}
|
||||
|
||||
const onShippingOptionChange = async (selectedOptionId: string) => {
|
||||
const promises = preview.shipping_methods
|
||||
.map((s) => s.actions?.find((a) => a.action === "SHIPPING_ADD")?.id)
|
||||
@@ -477,6 +485,7 @@ export const ReturnCreateForm = ({
|
||||
value={value}
|
||||
onChange={(v) => {
|
||||
onChange(v)
|
||||
onLocationChange(v)
|
||||
}}
|
||||
{...field}
|
||||
options={(stock_locations ?? []).map(
|
||||
|
||||
Reference in New Issue
Block a user