/* ===========================================================================
VESTIRÉ STUDIO — auth screens (customer login / register / admin) -> window
=========================================================================== */
const { useState } = React;
function AuthShell({ ctx, children }) {
return (
{ctx && (
ctx.nav("home")}>
Back to store
)}
{children}
);
}
function AuthError({ msg }) {
if (!msg) return null;
return {msg}
;
}
function PasswordField({ label = "Password", value, onChange, autoFocus }) {
const [show, setShow] = useState(false);
return (
);
}
/* ---- CUSTOMER LOGIN ------------------------------------------------------ */
function CLogin({ ctx }) {
const [id, setId] = useState("");
const [pw, setPw] = useState("");
const [err, setErr] = useState("");
const [busy, setBusy] = useState(false);
async function submit(e) {
if (e) e.preventDefault();
setBusy(true); setErr("");
try { await ctx.login(id, pw); } catch (ex) { setErr(ex.message); setBusy(false); }
}
return (
Welcome back
Sign in to rent, buy and track your requests.
New here? ctx.nav("register")}>Create an account
ctx.nav("adminLogin")}>Studio admin sign in
);
}
/* ---- REGISTER ------------------------------------------------------------ */
function CRegister({ ctx }) {
const [f, setF] = useState({ fullname: "", username: "", email: "", password: "", phone: "", address: "", gender: "Female" });
const set = (k) => (e) => setF((p) => ({ ...p, [k]: e.target.value }));
const [err, setErr] = useState("");
const [busy, setBusy] = useState(false);
async function submit(e) {
if (e) e.preventDefault();
setBusy(true); setErr("");
try { await ctx.register(f); } catch (ex) { setErr(ex.message); setBusy(false); }
}
return (
Create your account
Join Vestiré Studio to reserve gowns.
Already have an account? ctx.nav("login")}>Sign in
);
}
/* ---- ADMIN LOGIN --------------------------------------------------------- */
function CAdminLogin({ ctx }) {
const [email, setEmail] = useState("");
const [pw, setPw] = useState("");
const [err, setErr] = useState("");
const [busy, setBusy] = useState(false);
async function submit(e) {
if (e) e.preventDefault();
setBusy(true); setErr("");
try { await ctx.adminLogin(email, pw); } catch (ex) { setErr(ex.message); setBusy(false); }
}
return (
Studio admin
Manage gowns, requests and customers.
ctx.nav("login")}>Back to customer sign in
);
}
Object.assign(window, { AuthShell, CLogin, CRegister, CAdminLogin });