All files / src/application createSuggestion.ts

83.33% Statements 5/6
0% Branches 0/2
80% Functions 4/5
80% Lines 4/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                    7x   2x 1x   1x              
import { useMutation } from "@tanstack/react-query";
import { useToastStore } from "../presentation/stores/toast.store";
import { createSuggestion } from "../infrastructure/suggestion.api";
 
interface SuggestionParams {
  senderEmail: string|null;
  label: string;
}
 
export function useCreateSuggestion() {
  const addToast = useToastStore(s => s.addToast);
 
  return useMutation<void, Error, SuggestionParams>({
    mutationFn: (params) => createSuggestion(params),
    onSuccess: () => {
      addToast({ type: "success", message: "Suggestion enregistrée !" });
    },
    onError: (err) => {
      addToast({ type: "error", message: err.message || "Erreur lors de l'envoi" });
    }
  });
}