mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
import { useMutation, useQueryClient, type UseMutationResult } from "@tanstack/react-query";
|
|
import { toast } from "react-toastify";
|
|
import { vendorsApi } from "@/domain/vendors/api/vendors-api";
|
|
import type { VendorFormValues } from "@/domain/vendors/schemas/vendor-schema";
|
|
import type { Vendor } from "@/domain/vendors/types/vendor";
|
|
import { queryKeys } from "@/infra/query-key/query-key";
|
|
|
|
interface UpdateVendorInput {
|
|
id: string | number;
|
|
values: VendorFormValues;
|
|
}
|
|
|
|
export function useUpdateVendor(): UseMutationResult<Vendor, Error, UpdateVendorInput> {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ id, values }: UpdateVendorInput) => vendorsApi.update(id, values),
|
|
onSuccess: (_data, variables) => {
|
|
void queryClient.invalidateQueries({ queryKey: queryKeys.vendors.all });
|
|
void queryClient.invalidateQueries({ queryKey: queryKeys.vendors.detail(variables.id) });
|
|
toast.success("Vendor updated");
|
|
},
|
|
onError: (error: Error) => {
|
|
toast.error(error.message || "Failed to update vendor");
|
|
},
|
|
});
|
|
}
|