"use client"; import { useRef } from "react"; import { addProvider } from "@/actions"; import { useToast } from "../ui/toast"; import { ButtonAddProvider } from "./ButtonAddProvider"; export const AddProvider = () => { const ref = useRef(null); const { toast } = useToast(); async function clientAction(formData: FormData) { // reset the form ref.current?.reset(); // client-side validation const data = await addProvider(formData); if (data?.errors) { data.errors.forEach((error: { detail: string }) => { const errorMessage = `${error.detail}`; // show error toast({ variant: "destructive", title: "Ups! Something went wrong", description: errorMessage, }); }); } else { toast({ title: "Success!", description: "The provider was added successfully.", }); } } return (
); };