import React, { useEffect } from "react"; import { Controller, useFieldArray, useForm } from "react-hook-form"; import { Dialog, Transition } from "@headlessui/react"; // ui import { Button, CustomSelect, Input } from "@plane/ui"; // icons import { Plus, X } from "lucide-react"; // types import { IWorkspaceBulkInviteFormData, TUserWorkspaceRole } from "types"; // constants import { ROLE } from "constants/workspace"; type Props = { isOpen: boolean; onClose: () => void; onSubmit: (data: IWorkspaceBulkInviteFormData) => Promise | undefined; }; type EmailRole = { email: string; role: TUserWorkspaceRole; }; type FormValues = { emails: EmailRole[]; }; const defaultValues: FormValues = { emails: [ { email: "", role: 15, }, ], }; export const SendWorkspaceInvitationModal: React.FC = (props) => { const { isOpen, onClose, onSubmit } = props; // form info const { control, reset, handleSubmit, formState: { isSubmitting, errors }, } = useForm(); const { fields, append, remove } = useFieldArray({ control, name: "emails", }); const handleClose = () => { onClose(); const timeout = setTimeout(() => { reset(defaultValues); clearTimeout(timeout); }, 350); }; // const onSubmit = async (formData: FormValues) => { // if (!workspaceSlug) return; // return workspaceService // .inviteWorkspace(workspaceSlug, formData, user) // .then(async () => { // if (onSuccess) await onSuccess(); // handleClose(); // setToastAlert({ // type: "success", // title: "Success!", // message: "Invitations sent successfully.", // }); // }) // .catch((err) => // setToastAlert({ // type: "error", // title: "Error!", // message: `${err.error ?? "Something went wrong. Please try again."}`, // }) // ); // }; const appendField = () => { append({ email: "", role: 15 }); }; useEffect(() => { if (fields.length === 0) append([{ email: "", role: 15 }]); }, [fields, append]); return (
{ if (e.code === "Enter") e.preventDefault(); }} >
Invite people to collaborate

Invite members to work on your workspace.

{fields.map((field, index) => (
( <> {errors.emails?.[index]?.email && ( {errors.emails?.[index]?.email?.message} )} )} />
( {ROLE[value]}} onChange={onChange} width="w-full" input > {Object.entries(ROLE).map(([key, value]) => ( {value} ))} )} />
{fields.length > 1 && ( )}
))}
); };