'use client'; //=========================================== // THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template //=========================================== import { yupResolver } from "@hookform/resolvers/yup"; import { yupObject, yupString } from "@hexclave/shared/dist/schema-fields"; import { runAsynchronously } from "@hexclave/shared/dist/utils/promises"; import { Button, Input, Label, Typography } from "@hexclave/ui"; import { useState } from "react"; import { useForm } from "react-hook-form"; import * as yup from "yup"; import { MessageCard, useStackApp, useUser } from ".."; import { FormWarningText } from "../components/elements/form-warning"; import { MaybeFullPage } from "../components/elements/maybe-full-page"; import { useTranslation } from "../lib/translations"; export function TeamCreation(props: { fullPage?: boolean }) { const { t } = useTranslation(); const schema = yupObject({ displayName: yupString().defined().nonEmpty(t('Please enter a team name')), }); const { register, handleSubmit, formState: { errors } } = useForm({ resolver: yupResolver(schema) }); const app = useStackApp(); const project = app.useProject(); const user = useUser({ or: 'redirect' }); const [loading, setLoading] = useState(false); if (!project.config.clientTeamCreationEnabled) { return ; } const onSubmit = async (data: yup.InferType) => { setLoading(true); try { await user.createTeam({ displayName: data.displayName }); await app.redirectToAccountSettings(); } finally { setLoading(false); } }; return (
{t('Create a Team')}
runAsynchronously(handleSubmit(onSubmit)(e))} noValidate >
); }