import { useState } from "react"; import { Form, required, useLogin, useNotify, useTranslate } from "ra-core"; import type { SubmitHandler, FieldValues } from "react-hook-form"; import { Link as RouterLink } from "react-router"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ds/ui/badge"; import { TextInput } from "@/components/admin/text-input"; import { Notification } from "@/components/admin/notification"; import { useConfigurationContext } from "@/components/atomic-crm/root/ConfigurationContext.tsx"; import { ThemeModeToggle } from "@/components/admin/theme-mode-toggle"; import { LocalesMenuButton } from "@/components/admin/locales-menu-button"; import { AnimatedCircuitSVG } from "@/components/atomic-crm/misc/AnimatedCircuitSVG"; /** * Login page displayed when authentication is enabled and the user is not authenticated. * * Automatically shown when an unauthenticated user tries to access a protected route. * Handles login via authProvider.login() and displays error notifications on failure. * * @see {@link https://marmelab.com/shadcn-admin-kit/docs/loginpage LoginPage documentation} * @see {@link https://marmelab.com/shadcn-admin-kit/docs/security Security documentation} */ export const LoginPage = (props: { redirectTo?: string }) => { const { darkModeLogo, lightModeLogo, title, isDemo } = useConfigurationContext(); const { redirectTo } = props; const [loading, setLoading] = useState(false); const login = useLogin(); const notify = useNotify(); const translate = useTranslate(); const handleSubmit: SubmitHandler = (values) => { setLoading(true); login(values, redirectTo) .then(() => { setLoading(false); }) .catch((error) => { setLoading(false); notify( typeof error === "string" ? error : typeof error === "undefined" || !error.message ? "ra.auth.sign_in_error" : error.message, { type: "error", messageArgs: { _: typeof error === "string" ? error : error && error.message ? error.message : undefined, }, }, ); }); }; const demoDefaultValues = { email: "janedoe@realtimex.ai", password: "crmdemo", }; return (
{title} {title} {title}

{translate("crm.auth.sign_in")}

{isDemo && ( Demo )}
{isDemo && (

Welcome to the Live Demo! Explore all features using the prefilled credentials.

)}
{translate("ra-supabase.reset_password.forgot_password")} {translate("crm.auth.login_otp_link")}
); };