import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { toast } from "sonner"; import { authRequest, authVerify } from "@/api/driver"; import { digitsOnly, formatPhone } from "@/lib/format"; import { useAuth } from "@/store/auth"; import { Spinner } from "@/components/Spinner"; export function LoginPage() { const nav = useNavigate(); const setSession = useAuth((s) => s.setSession); const [phone, setPhone] = useState(""); // national 10 digits const [code, setCode] = useState(""); const [step, setStep] = useState<"phone" | "code">("phone"); const [channel, setChannel] = useState(""); const [busy, setBusy] = useState(false); const e164 = "7" + phone; async function requestCode() { if (phone.length < 10) return; setBusy(true); try { const r = await authRequest(e164); if (r.status === "onboarding") { sessionStorage.setItem("pp-onboarding", JSON.stringify({ ...r.deep_links, phone })); nav("/onboarding"); return; } setChannel(r.channel); setStep("code"); } catch (err: any) { toast.error(err?.response?.status === 404 ? "Номер не найден. Обратитесь в парк." : "Не удалось отправить код"); } finally { setBusy(false); } } async function verify() { if (code.length < 4) return; setBusy(true); try { const r = await authVerify(e164, code); setSession(r.token, r.driver_id); nav("/"); } catch { toast.error("Неверный или просроченный код"); } finally { setBusy(false); } } return (

Премиум Водитель

Вход в приложение

{step === "phone" ? ( <> setPhone(digitsOnly(e.target.value).replace(/^7/, "").slice(0, 10))} className="card w-full px-4 py-3 mb-3 text-base bg-white" />

Код придёт в Telegram или MAX.

) : ( <>

Код отправлен в {channel === "max" ? "MAX" : "Telegram"}.

setCode(digitsOnly(e.target.value).slice(0, 6))} className="card w-full px-4 py-3 mb-3 text-base tracking-widest bg-white" /> )}
); }