Files
goodgo-platform/apps/web/app/(auth)/login/page.tsx
Ho Ngoc Hai 0b29fac35e feat(notifications): add multi-channel notification module with Email, FCM, templates, and event listeners
- Domain: NotificationLog/NotificationPreference entities, repositories, channel value object
- Infrastructure: EmailService (nodemailer/SMTP), FcmService (firebase-admin), TemplateService (Handlebars)
- Application: SendNotification CQRS command, UserRegistered + AgentVerified event listeners
- Presentation: NotificationsController with history, preferences, and templates endpoints
- Prisma: NotificationLog and NotificationPreference models with proper indexes
- Templates: Vietnamese notification templates for user.registered, agent.verified, listing.approved, inquiry.received, password.reset

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-08 01:42:17 +07:00

124 lines
4.2 KiB
TypeScript

'use client';
import { useState } from 'react';
import Link from 'next/link';
import { useRouter } from 'next/navigation';
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { Loader2 } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card';
import { OAuthButtons } from '@/components/auth/oauth-buttons';
import { loginSchema, type LoginFormData } from '@/lib/validations/auth';
import { useAuthStore } from '@/lib/auth-store';
export default function LoginPage() {
const router = useRouter();
const { login, isLoading, error, clearError } = useAuthStore();
const [showPassword, setShowPassword] = useState(false);
const {
register,
handleSubmit,
formState: { errors },
} = useForm<LoginFormData>({
resolver: zodResolver(loginSchema),
});
const onSubmit = async (data: LoginFormData) => {
try {
await login(data);
router.push('/');
} catch {
// Error is handled by the store
}
};
return (
<Card>
<CardHeader className="space-y-1 text-center">
<CardTitle className="text-2xl font-bold">Đăng nhập</CardTitle>
<CardDescription>Nhập số điện thoại mật khẩu đ đăng nhập</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-4">
{error && (
<div className="rounded-md bg-destructive/10 p-3 text-sm text-destructive" role="alert">
{error}
<button type="button" onClick={clearError} className="ml-2 font-medium underline">
Bỏ qua
</button>
</div>
)}
<div className="space-y-2">
<Label htmlFor="phone">Số điện thoại</Label>
<Input
id="phone"
type="tel"
placeholder="0912345678"
autoComplete="tel"
{...register('phone')}
aria-invalid={!!errors.phone}
/>
{errors.phone && (
<p className="text-sm text-destructive" role="alert">{errors.phone.message}</p>
)}
</div>
<div className="space-y-2">
<div className="flex items-center justify-between">
<Label htmlFor="password">Mật khẩu</Label>
<button
type="button"
className="text-xs text-muted-foreground hover:text-primary"
onClick={() => setShowPassword(!showPassword)}
>
{showPassword ? 'Ẩn' : 'Hiện'}
</button>
</div>
<Input
id="password"
type={showPassword ? 'text' : 'password'}
placeholder="Nhập mật khẩu"
autoComplete="current-password"
{...register('password')}
aria-invalid={!!errors.password}
/>
{errors.password && (
<p className="text-sm text-destructive" role="alert">{errors.password.message}</p>
)}
</div>
<Button type="submit" className="w-full" disabled={isLoading}>
{isLoading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
Đăng nhập
</Button>
</form>
<div className="relative my-4">
<div className="absolute inset-0 flex items-center">
<span className="w-full border-t" />
</div>
<div className="relative flex justify-center text-xs uppercase">
<span className="bg-card px-2 text-muted-foreground">Hoặc đăng nhập với</span>
</div>
</div>
<OAuthButtons />
</CardContent>
<CardFooter className="justify-center">
<p className="text-sm text-muted-foreground">
Chưa tài khoản?{' '}
<Link href="/register" className="font-medium text-primary hover:underline">
Đăng
</Link>
</p>
</CardFooter>
</Card>
);
}