mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 03:02:03 +00:00
27 lines
952 B
TypeScript
27 lines
952 B
TypeScript
import { useMutation, useQueryClient, type UseMutationResult } from "@tanstack/react-query";
|
|
import { toast } from "react-toastify";
|
|
import { dropdownOptionsApi } from "@/domain/settings/dropdown-options/api/dropdown-options-api";
|
|
import type {
|
|
CreateDropdownOptionInput,
|
|
DropdownOption,
|
|
} from "@/domain/settings/dropdown-options/types/dropdown-option";
|
|
import { queryKeys } from "@/infra/query-key/query-key";
|
|
|
|
export function useCreateDropdownOption(): UseMutationResult<
|
|
DropdownOption,
|
|
Error,
|
|
CreateDropdownOptionInput
|
|
> {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (input: CreateDropdownOptionInput) => dropdownOptionsApi.create(input),
|
|
onSuccess: () => {
|
|
void queryClient.invalidateQueries({ queryKey: queryKeys.dropdownOptions.all });
|
|
toast.success("Option added");
|
|
},
|
|
onError: (error: Error) => {
|
|
toast.error(error.message || "Failed to add option");
|
|
},
|
|
});
|
|
}
|