Untitled
'use client'; import { useState } from 'react'; import { motion } from 'framer-motion'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import { Loader2, Lock } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; const formSchema = z.object({ email: z.string().email('Please enter a valid email address'), password: z.string().min(8, 'Password must be at least 8 characters'), }); type FormData = z.infer<typeof formSchema>; export default function LoginPage() { const [isLoading, setIsLoading] = useState(false); const { register, handleSubmit, formState: { errors }, } = useForm<FormData>({ resolver: zodResolver(formSchema), }); const onSubmit = async (data: FormData) => { setIsLoading(true); // Simulate API call await new Promise((resolve) => setTimeout(resolve, 1500)); console.log('Form submitted successfully:', data); setIsLoading(false); }; return ( <div className="min-h-screen bg-gradient-to-br from-gray-900 via-gray-800 to-gray-900 flex items-center justify-center p-4"> <motion.div initial={{ opacity: 0, y: 20 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.5 }} className="w-full max-w-md" > <Card className="backdrop-blur-lg bg-white/10 border-gray-700"> <CardHeader className="space-y-1"> <div className="flex items-center justify-center mb-4"> <Lock className="h-8 w-8 text-primary" /> </div> <CardTitle className="text-2xl text-center text-white"> Project Management Dashboard </CardTitle> <CardDescription className="text-gray-400 text-center"> Enter your credentials to access your account </CardDescription> </CardHeader> <form onSubmit={handleSubmit(onSubmit)}> <CardContent className="space-y-4"> <div className="space-y-2"> <Label htmlFor="email" className="text-white"> Email </Label> <Input id="email" type="email" placeholder="name@example.com" {...register('email')} className="bg-gray-800 border-gray-700 text-white placeholder:text-gray-400" /> {errors.email && ( <p className="text-sm text-red-500">{errors.email.message}</p> )} </div> <div className="space-y-2"> <Label htmlFor="password" className="text-white"> Password </Label> <Input id="password" type="password" {...register('password')} className="bg-gray-800 border-gray-700 text-white" /> {errors.password && ( <p className="text-sm text-red-500"> {errors.password.message} </p> )} </div> </CardContent> <CardFooter className="flex flex-col space-y-4"> <Button type="submit" className="w-full bg-primary hover:bg-primary/90" disabled={isLoading} > {isLoading && ( <Loader2 className="mr-2 h-4 w-4 animate-spin" /> )} Sign In </Button> <Button variant="link" className="text-gray-400 hover:text-white" type="button" > Forgot your password? </Button> </CardFooter> </form> </Card> </motion.div> </div> ); }
Leave a Comment