shoc-frontend-new/src/domain/vendors/use-cases/use-create-vendor.ts
Alexandre Brandizzi 20237f8142
Some checks are pending
CI / ci (push) Waiting to run
Deploy / deploy (push) Waiting to run
feat(vendors): align directory UI with current prototype (#46)
* 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
2026-07-23 15:23:03 -03:00

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");
},
});
}