"use client"; import { Dispatch, SetStateAction, useActionState, useEffect } from "react"; import { updateTenantName } from "@/actions/users/tenants"; import { useToast } from "@/components/ui"; import { CustomServerInput } from "@/components/ui/custom"; import { FormButtons } from "@/components/ui/form"; export const EditTenantForm = ({ tenantId, tenantName, setIsOpen, }: { tenantId: string; tenantName?: string; setIsOpen: Dispatch>; }) => { const [state, formAction] = useActionState(updateTenantName, null); const { toast } = useToast(); useEffect(() => { if (state && "success" in state) { toast({ title: "Changed successfully", description: state.success, }); setIsOpen(false); } else if (state && "error" in state) { toast({ variant: "destructive", title: "Oops! Something went wrong", description: state.error, }); } }, [state, toast, setIsOpen]); return (
Current name: {tenantName}
{/* Hidden inputs for Server Action */} ); };