import * as z from "zod"; import { useForm, zodResolver } from "@mantine/form"; import useAuth from "@/features/auth/hooks/use-auth"; import { ILogin } from "@/features/auth/types/auth.types"; import { Container, Title, TextInput, Button, PasswordInput, Box, Anchor, Group, } from "@mantine/core"; import classes from "./auth.module.css"; import { useRedirectIfAuthenticated } from "@/features/auth/hooks/use-redirect-if-authenticated.ts"; import { Link } from "react-router-dom"; import APP_ROUTE from "@/lib/app-route.ts"; import { useTranslation } from "react-i18next"; import SsoLogin from "@/ee/components/sso-login.tsx"; import { useWorkspacePublicDataQuery } from "@/features/workspace/queries/workspace-query.ts"; import { Error404 } from "@/components/ui/error-404.tsx"; import React from "react"; const formSchema = z.object({ email: z .string() .min(1, { message: "email is required" }) .email({ message: "Invalid email address" }), password: z.string().min(1, { message: "Password is required" }), }); export function LoginForm() { const { t } = useTranslation(); const { signIn, isLoading } = useAuth(); useRedirectIfAuthenticated(); const { data, isLoading: isDataLoading, isError, error, } = useWorkspacePublicDataQuery(); const form = useForm({ validate: zodResolver(formSchema), initialValues: { email: "", password: "", }, }); async function onSubmit(data: ILogin) { await signIn(data); } if (isDataLoading) { return null; } if (isError && error?.["response"]?.status === 404) { return ; } return ( {t("Login")} {!data?.enforceSso && ( <>
{t("Forgot your password?")} )}
); }