import React, { useState } from "react"; import { useGoogleLogin } from "@react-oauth/google"; import { api } from "../../lib/api"; const PhoneInputScreen = ({ onRequestOtp, onCancel, onGoogleSuccess, onRegisterSuccess }) => { const [activeTab, setActiveTab] = useState("login"); // Register Form State const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [phone, setPhone] = useState(""); const [password, setPassword] = useState(""); const [isRegistering, setIsRegistering] = useState(false); const [errorMsg, setErrorMsg] = useState(""); const login = useGoogleLogin({ onSuccess: onGoogleSuccess, onError: () => alert("Login Failed") }); const handleRegister = async () => { if (!name || !email || !phone || !password) { setErrorMsg("Please fill all fields."); return; } setIsRegistering(true); setErrorMsg(""); try { // Connects cleanly with the api configuration defined by VITE_API_URL or defaulted to local proxy. const response = await api.post("/api/auth/register", { name, email, phone, password, }); // Pass the successful name/email down the line dynamically onRegisterSuccess({ name: response.user?.name || name, email: response.user?.email || email, phone: response.user?.phone || phone }); } catch (err) { if (err.message.includes("409") || err.message.toLowerCase().includes("conflict") || err.message.toLowerCase().includes("already registered")) { setErrorMsg("Email already registered. Did you mean to log in?"); } else { setErrorMsg(err.message || "Registration failed. Please try again."); } } finally { setIsRegistering(false); } }; return (
Use the coupon below to get flat 10% OFF on your first booking with road.rentals.
Sign in to book your rides, manage trips, and enjoy a seamless travel experience
{/* Phone Input Box */}Register now to start your reliable travel journey with road.rentals
{/* Register Fields */}