import React, { useEffect, useRef, useState } from "react"; // next import Image from "next/image"; // headless ui import { Listbox, Transition } from "@headlessui/react"; // react-hook-form import { Control, Controller, FieldArrayWithId, UseFieldArrayRemove, useFieldArray, useForm } from "react-hook-form"; // services import { WorkspaceService } from "services/workspace.service"; // hooks import useToast from "hooks/use-toast"; // ui import { Button, Input } from "@plane/ui"; // components import OnboardingStepIndicator from "components/account/step-indicator"; // hooks import useDynamicDropdownPosition from "hooks/use-dynamic-dropdown"; // icons import { Check, ChevronDown, Plus, User2, X, XCircle } from "lucide-react"; // types import { IUser, IWorkspace, TOnboardingSteps, TUserWorkspaceRole } from "types"; // constants import { ROLE } from "constants/workspace"; // assets import user1 from "public/users/user-1.png"; import user2 from "public/users/user-2.png"; type Props = { finishOnboarding: () => Promise; stepChange: (steps: Partial) => Promise; user: IUser | undefined; workspace: IWorkspace | undefined; }; type EmailRole = { email: string; role: TUserWorkspaceRole; }; type FormValues = { emails: EmailRole[]; }; type InviteMemberFormProps = { index: number; remove: UseFieldArrayRemove; control: Control; field: FieldArrayWithId; fields: FieldArrayWithId[]; errors: any; }; // services const workspaceService = new WorkspaceService(); const InviteMemberForm: React.FC = (props) => { const { control, index, fields, remove, errors } = props; const buttonRef = useRef(null); const dropdownRef = useRef(null); const [isDropdownOpen, setIsDropdownOpen] = useState(false); useDynamicDropdownPosition(isDropdownOpen, () => setIsDropdownOpen(false), buttonRef, dropdownRef); return (
( )} />
( { onChange(val); setIsDropdownOpen(false); }} className="flex-shrink-0 text-left w-full" > setIsDropdownOpen((prev) => !prev)} className="flex items-center px-2.5 h-11 py-2 text-xs justify-between gap-1 w-full rounded-md duration-300" > {ROLE[value]}
{Object.entries(ROLE).map(([key, value]) => ( `cursor-pointer select-none truncate rounded px-1 py-1.5 ${ active || selected ? "bg-onboarding-background-400/40" : "" } ${selected ? "text-onboarding-text-100" : "text-custom-text-200"}` } > {({ selected }) => (
{value}
{selected && }
)}
))}
)} />
{fields.length > 1 && ( )}
); }; export const InviteMembers: React.FC = (props) => { const { finishOnboarding, stepChange, workspace } = props; const { setToastAlert } = useToast(); const { control, handleSubmit, formState: { isSubmitting, errors, isValid }, } = useForm(); const { fields, append, remove } = useFieldArray({ control, name: "emails", }); const nextStep = async () => { const payload: Partial = { workspace_invite: true, }; await stepChange(payload); await finishOnboarding(); }; const onSubmit = async (formData: FormValues) => { if (!workspace) return; const payload = { ...formData }; await workspaceService .inviteWorkspace(workspace.slug, payload) .then(async () => { setToastAlert({ type: "success", title: "Success!", message: "Invitations sent successfully.", }); await nextStep(); }) .catch((err) => console.log(err)); }; const appendField = () => { append({ email: "", role: 15 }); }; useEffect(() => { if (fields.length === 0) { append([ { email: "", role: 15 }, { email: "", role: 15 }, { email: "", role: 15 }, ]); } }, [fields, append]); return (

Members

{Array.from({ length: 4 }).map(() => (
))}
user

Murphy cooper

murphy@plane.so

user

Else Thompson

Elsa@plane.so

{ if (e.code === "Enter") e.preventDefault(); }} >

Invite your team to work with you

{fields.map((field, index) => ( ))}
{/* */} Do this later
); };