// Phone + OTP login screen for the driver prototype.
// Dev backend accepts code "123456" for any +972 phone.
function LoginScreen({ onAuthed }) {
const [step, setStep] = React.useState('phone'); // 'phone' | 'code'
// Pre-fill the seeded demo number only in dev; production starts blank.
const [phone, setPhone] = React.useState(window.RESDRI_DEV ? '+972500000001' : '');
const [code, setCode] = React.useState('');
const [devCode, setDevCode] = React.useState(null);
const [error, setError] = React.useState(null);
const [busy, setBusy] = React.useState(false);
const sendOtp = async () => {
setError(null); setBusy(true);
try {
const r = await window.api.requestOtp(phone);
setDevCode(r.devCode || null);
setStep('code');
} catch (e) {
setError(e.message || 'تعذّر الإرسال');
} finally {
setBusy(false);
}
};
const verify = async () => {
setError(null); setBusy(true);
try {
const r = await window.api.verifyOtp(phone, code);
onAuthed(r.driver);
} catch (e) {
setError(e.message || 'رمز غير صحيح');
} finally {
setBusy(false);
}
};
return (
{/* Logo / title */}
R
ResDri
{step === 'phone' ? 'أدخل رقم هاتفك للمتابعة' : 'أدخل رمز التحقق المرسل'}
{step === 'phone' && (
<>
رقم الهاتف
setPhone(e.target.value)}
placeholder="+972 5X XXX XXXX"
style={inputStyle}
/>
{error &&
{error} }
{busy ? '...' : 'إرسال رمز التحقق'}
{window.RESDRI_DEV && (
<>
للتجربة: الرقم +972500000001 · الرمز 123456
API → {window.api?.BASE || '?'}
>
)}
>
)}
{step === 'code' && (
<>
رمز التحقق
setCode(e.target.value.replace(/\D/g, ''))}
placeholder="••••••"
style={{ ...inputStyle, textAlign: 'center', letterSpacing: 14, fontSize: 28, fontWeight: 800 }}
/>
{/* Pilot test-code hint — only in dev mode (localhost or ?dev=1).
Production users see a normal OTP entry with no leakage. */}
{window.RESDRI_DEV && (
<>
للتجربة استخدم الرمز {devCode || '123456'}
setCode(devCode || '123456')} style={{
background: 'transparent', border: 'none',
color: 'var(--primary)', fontFamily: 'inherit', fontSize: 12, fontWeight: 700,
padding: 6, marginTop: 4, cursor: 'pointer',
}}>
تعبئة الرمز تلقائياً
>
)}
{error &&
{error} }
{busy ? '...' : 'دخول'}
{ setStep('phone'); setCode(''); setError(null); }} style={{
background: 'transparent', border: 'none',
color: 'var(--text-2)', fontFamily: 'inherit', fontSize: 13, fontWeight: 700,
padding: 12, marginTop: 6, cursor: 'pointer',
}}>
تغيير الرقم
>
)}
);
}
const labelStyle = {
display: 'block',
fontSize: 11, fontWeight: 800,
color: 'var(--text-2)',
letterSpacing: '0.08em', textTransform: 'uppercase',
marginBottom: 8,
};
const inputStyle = {
width: '100%',
height: 56,
borderRadius: 16,
border: '1.5px solid var(--line-strong)',
background: 'var(--surface)',
color: 'var(--text)',
fontFamily: 'inherit', fontSize: 18, fontWeight: 700,
padding: '0 16px',
outline: 'none',
boxSizing: 'border-box',
};
function ErrorBanner({ children }) {
return (