//===========================================
// 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 { runAsynchronouslyWithAlert } from "@hexclave/shared/dist/utils/promises";
import { Button, Input } from "@hexclave/ui";
import { useState } from "react";
import { useForm } from "react-hook-form";
import * as yup from "yup";
import { FormWarningText } from "../../../components/elements/form-warning";
import { MessageCard } from "../../../components/message-cards/message-card";
import { useStackApp, useUser } from "../../../lib/hooks";
import { useTranslation } from "../../../lib/translations";
import { PageLayout } from "../page-layout";
import { Section } from "../section";
export function TeamCreationPage(props?: {
mockMode?: boolean,
}) {
const { t } = useTranslation();
const teamCreationSchema = yupObject({
displayName: yupString().defined().nonEmpty(t("Please enter a team name")),
});
const { register, handleSubmit, formState: { errors } } = useForm({
resolver: yupResolver(teamCreationSchema)
});
const app = useStackApp();
const project = app.useProject();
const user = useUser({ or: props?.mockMode ? 'return-null' : 'redirect' });
const navigate = app.useNavigate();
const [loading, setLoading] = useState(false);
// In mock mode, show that team creation is disabled
if (props?.mockMode) {
return (
);
}
if (!project.config.clientTeamCreationEnabled) {
return ;
}
const onSubmit = async (data: yup.InferType) => {
if (props?.mockMode) {
// Mock mode - just show an alert
alert("Mock mode: Team creation clicked");
return;
}
setLoading(true);
let team;
try {
team = await user?.createTeam({ displayName: data.displayName });
} finally {
setLoading(false);
}
if (team) {
navigate(`#team-${team.id}`);
}
};
return (
);
}