import { ArrowRight } from "lucide-react"; import { useRouter } from "next/router"; import { useState } from "react"; import { z } from "zod"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import { Button, showToast, TextField } from "@calcom/ui"; import { Plus, X } from "@calcom/ui/components/icon"; const querySchema = z.object({ id: z.string().transform((val) => parseInt(val)), }); export const AddNewTeamsForm = () => { const { t } = useLocale(); const router = useRouter(); const { id: orgId } = querySchema.parse(router.query); const [counter, setCounter] = useState(1); const [inputValues, setInputValues] = useState([""]); const handleCounterIncrease = () => { setCounter((prevCounter) => prevCounter + 1); setInputValues((prevInputValues) => [...prevInputValues, ""]); }; const handleInputChange = (index: number, value: string) => { const newInputValues = [...inputValues]; newInputValues[index] = value; setInputValues(newInputValues); }; const handleRemoveInput = (index: number) => { const newInputValues = [...inputValues]; newInputValues.splice(index, 1); setInputValues(newInputValues); setCounter((prevCounter) => prevCounter - 1); }; const createTeamsMutation = trpc.viewer.organizations.createTeams.useMutation({ async onSuccess(data) { if (data.duplicatedSlugs.length) { showToast(t("duplicated_slugs_warning", { slugs: data.duplicatedSlugs.join(", ") }), "warning"); setTimeout(() => { router.push(`/event-types`); }, 3000); } else { router.push(`/event-types`); } }, onError: (error) => { showToast(t(error.message), "error"); }, }); return ( <> {Array.from({ length: counter }, (_, index) => (
handleInputChange(index, e.target.value)} addOnClassname="bg-transparent p-0 border-l-0" addOnSuffix={ index > 0 && ( ) } />
))} ); };