import * as z from "zod"; import { useForm, zodResolver } from "@mantine/form"; import { Container, Title, TextInput, Button, Box, Text, Anchor, Divider, } from "@mantine/core"; import classes from "../../features/auth/components/auth.module.css"; import { getCheckHostname } from "@/features/workspace/services/workspace-service.ts"; import { useState } from "react"; import { getSubdomainHost } from "@/lib/config.ts"; import { Link } from "react-router-dom"; import APP_ROUTE from "@/lib/app-route.ts"; import { useTranslation } from "react-i18next"; import JoinedWorkspaces from "@/ee/components/joined-workspaces.tsx"; import { useJoinedWorkspacesQuery } from "@/ee/cloud/query/cloud-query.ts"; const formSchema = z.object({ hostname: z.string().min(1, { message: "subdomain is required" }), }); export function CloudLoginForm() { const { t } = useTranslation(); const [isLoading, setIsLoading] = useState(false); const { data: joinedWorkspaces } = useJoinedWorkspacesQuery(); const form = useForm({ validate: zodResolver(formSchema), initialValues: { hostname: "", }, }); async function onSubmit(data: { hostname: string }) { setIsLoading(true); try { const checkHostname = await getCheckHostname(data.hostname); window.location.href = checkHostname.hostname; } catch (err) { if (err?.status === 404) { form.setFieldError("hostname", "We could not find this workspace"); } else { form.setFieldError("hostname", "An error occurred"); } } setIsLoading(false); } return (
{t("Login")} {joinedWorkspaces?.length > 0 && ( )}
.{getSubdomainHost()}} rightSectionWidth={150} withErrorStyles={false} {...form.getInputProps("hostname")} />
{t("Don't have a workspace?")}{" "} {t("Create new workspace")}
); }