mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
* feat(vendors): align directory UI with prototype * fix(vendors): report the filtered total * fix(vendors): keep company input in sync * fix(vendors): scope facets to directory status
21 lines
879 B
TypeScript
21 lines
879 B
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";
|
|
|
|
export function useCreateVendor(): UseMutationResult<Vendor, Error, VendorFormValues> {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (values: VendorFormValues) => vendorsApi.create(values),
|
|
onSuccess: () => {
|
|
void queryClient.invalidateQueries({ queryKey: queryKeys.vendors.all });
|
|
toast.success("Vendor created");
|
|
},
|
|
onError: (error: Error) => {
|
|
toast.error(error.message || "Failed to create vendor");
|
|
},
|
|
});
|
|
}
|