import { useForm, Controller } from "react-hook-form"; import { WEBAPP_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import slugify from "@calcom/lib/slugify"; import { trpc } from "@calcom/trpc/react"; import { Icon } from "@calcom/ui"; import { Button, Avatar } from "@calcom/ui/v2"; import ImageUploader from "@calcom/ui/v2/core/ImageUploader"; import { Form, TextField } from "@calcom/ui/v2/core/form/fields"; const CreateANewTeamForm = (props: { nextStep: () => void; setTeamId: (teamId: number) => void }) => { const { t } = useLocale(); const utils = trpc.useContext(); const createTeamMutation = trpc.useMutation("viewer.teams.create", { onSuccess(data) { utils.invalidateQueries(["viewer.teams.list"]); props.setTeamId(data.id); props.nextStep(); }, }); const formMethods = useForm(); return (
{ createTeamMutation.mutate({ name: values.name, slug: values.slug || null, logo: values.logo || null, }); }}>
( { formMethods.setValue("name", e?.target.value); if (formMethods.formState.touchedFields["slug"] === undefined) { formMethods.setValue("slug", slugify(e?.target.value)); } }} autoComplete="off" /> )} />
( { formMethods.setValue("slug", slugify(e?.target.value), { shouldTouch: true }); }} /> )} />
(
{ formMethods.setValue("avatar", newAvatar); }} imageSrc={value} />
)} />
{createTeamMutation.isError &&

{createTeamMutation.error.message}

}
); }; export default CreateANewTeamForm;