"use client"; import React, { useState } from "react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { Button } from "@/components/ui/button"; import { Checkbox } from "@/components/ui/checkbox"; import { Label } from "@/components/ui/label"; import { Link } from "@/i18n/routing"; import { useTranslations } from "next-intl"; import { Dialog, DialogContent, DialogFooter, DialogTrigger, } from "@/components/ui/dialog"; import { FormField } from "@/components/auth/form-field"; import { loginSchema, LoginFormData, LoginFormProps } from "@/types/auth"; import { useAuth } from "@/hooks/use-auth"; import { listRole } from "@/service/landing/landing"; import { Role } from "@/types/auth"; export const LoginForm: React.FC = ({ onSuccess, onError, className, }) => { const t = useTranslations("LandingPage"); const { login } = useAuth(); const [showPassword, setShowPassword] = useState(false); const [rememberMe, setRememberMe] = useState(true); const [roles, setRoles] = useState([]); const [selectedCategory, setSelectedCategory] = useState("5"); const [isDialogOpen, setIsDialogOpen] = useState(false); const { register, handleSubmit, formState: { errors, isSubmitting }, getValues, } = useForm({ resolver: zodResolver(loginSchema), mode: "onChange", }); // Load roles on component mount React.useEffect(() => { const loadRoles = async () => { try { const response = await listRole(); setRoles(response?.data?.data || []); } catch (error) { console.error("Failed to load roles:", error); } }; loadRoles(); }, []); const handlePasswordToggle = () => { setShowPassword(!showPassword); }; const handleLogin = async (data: LoginFormData) => { try { await login(data); onSuccess?.(data); } catch (error: any) { onError?.(error.message || "Login failed"); } }; const onSubmit = async (data: LoginFormData) => { try { // Pass the form data to the parent component // The auth page will handle email validation and flow transitions onSuccess?.(data); } catch (error: any) { onError?.(error.message || "Login failed"); } }; return (
{/* Header */}

{t("logInPlease", { defaultValue: "Log In Please" })}

{t("acc", { defaultValue: "Acc" })} {t("register", { defaultValue: "Register" })}

{t("categoryReg", { defaultValue: "Category Reg" })}

{t("selectOne", { defaultValue: "Select One" })}

{roles.map((role) => (
setSelectedCategory(e.target.value)} className="text-red-500 focus:ring-red-500" />
))}
{t("next", { defaultValue: "Next" })}
{/* Username Field */} {/* Password Field */} {/* Remember Me and Forgot Password */}
setRememberMe(checked as boolean)} disabled={isSubmitting} />
{t("forgotPass", { defaultValue: "Forgot Pass" })}
{/* Submit Button */}
); };