function BranchLogin({ salesUrl }) { const [email, setEmail] = React.useState(''); const [password, setPassword] = React.useState(''); const [loading, setLoading] = React.useState(false); const [message, setMessage] = React.useState(''); const submit = async (e) => { e && e.preventDefault(); setLoading(true); setMessage(''); try { const res = await fetch(salesUrl + '/auth/branch-login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password }) }); const data = await res.json(); if (!res.ok || !data.success) throw new Error(data.message || 'Login failed'); // show welcome message setMessage(`Welcome, ${data.payload?.name || 'Branch user'}!`); // optionally store branch token // Remove any sales token to avoid both tokens co-existing in the same browser try { localStorage.removeItem('sales_token'); } catch (__) {} localStorage.setItem('branch_token', data.token); // Notify the app in the same tab that a branch login happened try { window.dispatchEvent(new Event('branch-login')); } catch (__) {} // Navigate to branch dashboard try { location.hash = '#branch'; } catch (__) {} } catch (err) { setMessage(err.message || 'Login failed'); } finally { setLoading(false); } }; return (
🏪

Branch Login

Sign in to your branch account

setEmail(e.target.value)} required />
setPassword(e.target.value)} required />
{message && (
{message.includes('Welcome') ? '✅' : '❌'}
{message}
)}

Need help? Contact your administrator

); } // Register as global for in-browser JSX loader window.BranchLogin = BranchLogin;