"use client"; import { useAuth } from "@/lib/auth-context"; import { SHOP_INFO } from "@/lib/constants"; import Image from "next/image"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { FormEvent, useState } from "react"; import Button from "@/components/atoms/buttons/Button"; // Static OTP for demo (in production, this would be sent via SMS) const DEMO_OTP = "123456"; export default function RegisterPage() { const router = useRouter(); const { completeRegistration } = useAuth(); const [step, setStep] = useState<"phone" | "otp">("phone"); const [phone, setPhone] = useState(""); const [otp, setOtp] = useState(""); const [errors, setErrors] = useState({ phone: "", otp: "" }); // Validate Vietnamese phone number const validatePhone = (phoneNumber: string): boolean => { // Vietnamese phone format: 10 digits starting with 0 // Valid prefixes: 03, 05, 07, 08, 09 const phoneRegex = /^(0[3|5|7|8|9])[0-9]{8}$/; return phoneRegex.test(phoneNumber); }; const handlePhoneSubmit = (e: FormEvent) => { e.preventDefault(); if (!phone.trim()) { setErrors({ ...errors, phone: "Vui lòng nhập số điện thoại" }); return; } if (!validatePhone(phone)) { setErrors({ ...errors, phone: "Số điện thoại không hợp lệ (VD: 0987654321)", }); return; } // Move to OTP step setStep("otp"); setErrors({ phone: "", otp: "" }); }; const handleOtpSubmit = (e: FormEvent) => { e.preventDefault(); if (!otp.trim()) { setErrors({ ...errors, otp: "Vui lòng nhập mã OTP" }); return; } if (otp !== DEMO_OTP) { setErrors({ ...errors, otp: "Mã OTP không đúng" }); return; } // Complete registration completeRegistration(phone); router.push("/"); }; const handleBackToPhone = () => { setStep("phone"); setOtp(""); setErrors({ phone: "", otp: "" }); }; return (
{step === "phone" ? "Đăng ký tài khoản khách hàng" : "Xác thực số điện thoại"}