Compare commits
2 Commits
2d8c162834
...
10f795ebed
| Author | SHA1 | Date |
|---|---|---|
|
|
10f795ebed | |
|
|
bee6281dde |
|
|
@ -29,7 +29,7 @@ After the one-time [server setup](docs/STATIC-DEPLOYMENT.md), main-branch Drone
|
|||
|
||||
Storefront list returns only id/name/slug; details return prices/attributes/groups. The API has no product-media fields, so catalog cards use a generic branded placeholder rather than assigning local photos to unknown records. Existing marketing imagery remains intact.
|
||||
|
||||
Addresses, cart/checkout, orders, catalog, access, stock, coupons and pricing tools are available after sign-in. Public registration and procurement/production/B2B tools remain subsequent phases. There is no contact-message endpoint; simulated success was replaced with an availability notice. Newsletter signup awaits consent/messaging flows.
|
||||
Addresses, cart/checkout, orders, catalog, access, stock, coupons and pricing tools are available after sign-in. Customers can create their own account at `/workspace` (requires the backend `/auth/register` endpoint). There is no contact-message endpoint; simulated success was replaced with an availability notice. Newsletter signup awaits consent/messaging flows.
|
||||
|
||||
See [delivery phases](docs/PHASES.md) and [UAT evidence](docs/UAT-RESULTS.md).
|
||||
|
||||
|
|
|
|||
|
|
@ -38,4 +38,4 @@ Record the active and previous build/commit release IDs before rollout. The SSH
|
|||
|
||||
## Operational limits
|
||||
|
||||
Pending intents exist only within the active browser session; reloading signs out and discards them. After interruption, inspect orders or the stock ledger before beginning a new intent. The backend currently has no live gateway/carrier, public registration or contact delivery. Staff catalog/role writes follow the backend's existing concurrency policy; coordinate overlapping administration edits. Never reinterpret finalized merchandise as proof of payment or fulfillment.
|
||||
Pending intents exist only within the active browser session; reloading signs out and discards them. After interruption, inspect orders or the stock ledger before beginning a new intent. The backend currently has no live gateway/carrier or contact delivery; customer self-registration is available. Staff catalog/role writes follow the backend's existing concurrency policy; coordinate overlapping administration edits. Never reinterpret finalized merchandise as proof of payment or fulfillment.
|
||||
|
|
|
|||
|
|
@ -235,6 +235,21 @@ export async function login(
|
|||
}),
|
||||
);
|
||||
}
|
||||
export async function register(
|
||||
organizationId: string,
|
||||
name: string,
|
||||
email: string,
|
||||
password: string,
|
||||
) {
|
||||
const organization = organizationSchema.parse(organizationId);
|
||||
return parse(
|
||||
sessionSchema,
|
||||
await apiRequest("/auth/register", {
|
||||
method: "POST",
|
||||
body: { organizationId: organization, name, email, password },
|
||||
}),
|
||||
);
|
||||
}
|
||||
export async function getPrincipal(token: string) {
|
||||
return parse(principalSchema, await apiRequest("/auth/me", { token }));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import {
|
|||
login,
|
||||
organizationSchema,
|
||||
parse,
|
||||
register,
|
||||
type Principal,
|
||||
type Session,
|
||||
} from "./api";
|
||||
|
|
@ -29,6 +30,7 @@ const PlatformContext = createContext<{
|
|||
principal: Principal | null;
|
||||
scope: string;
|
||||
signIn: (email: string, password: string) => Promise<void>;
|
||||
signUp: (name: string, email: string, password: string) => Promise<void>;
|
||||
signOut: () => Promise<void>;
|
||||
notice: string;
|
||||
clearSession: (notice?: string) => void;
|
||||
|
|
@ -110,9 +112,15 @@ export function PlatformProvider({ children }: { children: ReactNode }) {
|
|||
/* The in-memory setting still works. */
|
||||
}
|
||||
}
|
||||
async function signIn(email: string, password: string) {
|
||||
function signIn(email: string, password: string) {
|
||||
return adopt(() => login(organization, email, password));
|
||||
}
|
||||
function signUp(name: string, email: string, password: string) {
|
||||
return adopt(() => register(organization, name, email, password));
|
||||
}
|
||||
async function adopt(start: () => ReturnType<typeof login>) {
|
||||
const version = ++generation.current;
|
||||
const next = await login(organization, email, password);
|
||||
const next = await start();
|
||||
try {
|
||||
const me = await getPrincipal(next.accessToken);
|
||||
if (
|
||||
|
|
@ -247,6 +255,7 @@ export function PlatformProvider({ children }: { children: ReactNode }) {
|
|||
principal,
|
||||
scope: principal ? `${principal.sessionId}:${accessRevision}` : "",
|
||||
signIn,
|
||||
signUp,
|
||||
signOut,
|
||||
notice,
|
||||
clearSession,
|
||||
|
|
|
|||
|
|
@ -11,20 +11,25 @@ import "./workspace.css";
|
|||
import { WorkspaceNavigation } from "@/components/WorkspaceShell";
|
||||
|
||||
export default function WorkspacePage() {
|
||||
const { organization, principal, signIn, signOut, notice } = usePlatform();
|
||||
const { organization, principal, signIn, signUp, signOut, notice } =
|
||||
usePlatform();
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<unknown>(null);
|
||||
const [creating, setCreating] = useState(false);
|
||||
async function submit(event: FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
const form = event.currentTarget;
|
||||
const fields = new FormData(form);
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
const name = String(fields.get("name") ?? "");
|
||||
const email = String(fields.get("email"));
|
||||
const password = String(fields.get("password"));
|
||||
form.reset();
|
||||
try {
|
||||
await signIn(email, password);
|
||||
await (creating
|
||||
? signUp(name, email, password)
|
||||
: signIn(email, password));
|
||||
} catch (error) {
|
||||
setError(error);
|
||||
} finally {
|
||||
|
|
@ -47,7 +52,7 @@ export default function WorkspacePage() {
|
|||
<Container maxWidth="md">
|
||||
<h1>Account Workspace</h1>
|
||||
<p className="workspace-intro">
|
||||
Sign in with your approved Mani Candles account.
|
||||
Sign in, or create a customer account to shop.
|
||||
</p>
|
||||
<Paper variant="outlined" className="workspace-panel">
|
||||
<ApiNotice error={error} />
|
||||
|
|
@ -68,7 +73,7 @@ export default function WorkspacePage() {
|
|||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p>No permissions assigned. Contact your administrator.</p>
|
||||
<p>Customer account. Use your cart, addresses and orders below.</p>
|
||||
)}
|
||||
<p className="workspace-intro">
|
||||
Open a customer or administration tool below.
|
||||
|
|
@ -89,11 +94,20 @@ export default function WorkspacePage() {
|
|||
backend.
|
||||
</Alert>
|
||||
)}
|
||||
{creating && (
|
||||
<TextField
|
||||
label="Full name"
|
||||
name="name"
|
||||
autoComplete="name"
|
||||
required
|
||||
inputProps={{ maxLength: 160 }}
|
||||
/>
|
||||
)}
|
||||
<TextField
|
||||
label="Email address"
|
||||
name="email"
|
||||
type="email"
|
||||
autoComplete="username"
|
||||
autoComplete={creating ? "email" : "username"}
|
||||
required
|
||||
inputProps={{ maxLength: 254 }}
|
||||
/>
|
||||
|
|
@ -101,16 +115,36 @@ export default function WorkspacePage() {
|
|||
label="Password"
|
||||
name="password"
|
||||
type="password"
|
||||
autoComplete="current-password"
|
||||
autoComplete={creating ? "new-password" : "current-password"}
|
||||
required
|
||||
inputProps={{ maxLength: 128 }}
|
||||
helperText={creating ? "At least 15 characters." : undefined}
|
||||
inputProps={{ minLength: creating ? 15 : 1, maxLength: 128 }}
|
||||
/>
|
||||
<Button
|
||||
variant="contained"
|
||||
type="submit"
|
||||
disabled={busy || !organization}
|
||||
>
|
||||
{busy ? "Signing in…" : "Sign in"}
|
||||
{creating
|
||||
? busy
|
||||
? "Creating account…"
|
||||
: "Create account"
|
||||
: busy
|
||||
? "Signing in…"
|
||||
: "Sign in"}
|
||||
</Button>
|
||||
<Button
|
||||
variant="text"
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => {
|
||||
setCreating(!creating);
|
||||
setError(null);
|
||||
}}
|
||||
>
|
||||
{creating
|
||||
? "Already have an account? Sign in"
|
||||
: "New customer? Create an account"}
|
||||
</Button>
|
||||
<small>
|
||||
Sessions stay in memory. Reloading or closing this page requires
|
||||
|
|
|
|||
|
|
@ -332,3 +332,19 @@ test("organization change cancels private scope and removes cached data", async
|
|||
await waitFor(() => expect(h.result.current.scope).toBe(""));
|
||||
expect(h.client.getQueriesData({ queryKey: ["private"] })).toEqual([]);
|
||||
});
|
||||
|
||||
test("sign-up registers in the configured organization and adopts the new session", async () => {
|
||||
const bodies: unknown[] = [];
|
||||
vi.stubGlobal("fetch", vi.fn(async (url: string, options?: RequestInit) => {
|
||||
if (url.endsWith("/auth/register")) {
|
||||
bodies.push(JSON.parse(String(options?.body)));
|
||||
return json(session, 201);
|
||||
}
|
||||
if (url.endsWith("/auth/me")) return json({ ...me, permissions: [] });
|
||||
throw new Error(`Unexpected request ${url}`);
|
||||
}));
|
||||
const h = harness();
|
||||
await act(() => h.result.current.signUp("Asha Buyer", "buyer@example.com", "a long enough password"));
|
||||
expect(bodies).toEqual([{ organizationId: id, name: "Asha Buyer", email: "buyer@example.com", password: "a long enough password" }]);
|
||||
expect(h.result.current.principal).toMatchObject({ userId: id, permissions: [] });
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue