import { ArrowRight } from "lucide-react"; import { useRouter } from "next/navigation"; import { Controller, useForm } from "react-hook-form"; import { z } from "zod"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { useRouterQuery } from "@calcom/lib/hooks/useRouterQuery"; import { MembershipRole } from "@calcom/prisma/enums"; import { trpc } from "@calcom/trpc/react"; import { Button, Form, showToast, TextAreaField } from "@calcom/ui"; const querySchema = z.object({ id: z.string().transform((val) => parseInt(val)), }); export const AddNewOrgAdminsForm = () => { const { t, i18n } = useLocale(); const router = useRouter(); const routerQuery = useRouterQuery(); const { id: orgId } = querySchema.parse(routerQuery); const newAdminsFormMethods = useForm<{ emails: string[]; }>(); const inviteMemberMutation = trpc.viewer.teams.inviteMember.useMutation({ async onSuccess(data) { if (data.sendEmailInvitation) { if (Array.isArray(data.usernameOrEmail)) { showToast( t("email_invite_team_bulk", { userCount: data.usernameOrEmail.length, }), "success" ); } else { showToast( t("email_invite_team", { email: data.usernameOrEmail, }), "success" ); } } router.push(`/settings/organizations/${orgId}/add-teams`); }, onError: (error) => { showToast(error.message, "error"); }, }); return (
{ inviteMemberMutation.mutate({ teamId: orgId, language: i18n.language, role: MembershipRole.ADMIN, usernameOrEmail: values.emails, sendEmailInvitation: true, isOrg: true, }); }}>
( <> { const targetValues = e.target.value.split(","); const emails = targetValues.length === 1 ? targetValues[0].trim().toLocaleLowerCase() : targetValues.map((email) => email.trim().toLocaleLowerCase()); return onChange(emails); }} /> {error && {error.message}} )} />
); };