Send platform operators to the platform console after sign-in #9

Merged
denis_ireri merged 1 commits from fix/operator-landing into main 2026-10-13 15:06:37 +00:00
4 changed files with 26 additions and 5 deletions
Showing only changes of commit d15273e2a6 - Show all commits
+6 -2
View File
@@ -113,7 +113,8 @@ export default function AdminDashboardPage() {
}
const scope: "global" | "branch" = selectedBranchId === "ALL" ? "global" : "branch";
const showNoBranchesNudge = me.role === "SUPER_ADMIN" && branchesLoaded && branches.length === 0;
// The operator's own business is a placeholder; don't nudge it to set up branches.
const showNoBranchesNudge = me.role === "SUPER_ADMIN" && !me.isPlatformAdmin && branchesLoaded && branches.length === 0;
return (
<main className="min-h-screen bg-sand-50 pb-12">
@@ -130,7 +131,10 @@ export default function AdminDashboardPage() {
? `${me.branchName} Dashboard`
: "Branch Dashboard"}
</h1>
<p className="mt-1 text-xs text-sand-200/60">{me.name}</p>
<p className="mt-1 text-xs text-sand-200/60">
{me.name}
{me.isPlatformAdmin && " · Platform operator"}
</p>
<div className="mt-2">
<AccountLinks />
</div>
+3 -1
View File
@@ -167,7 +167,9 @@ export async function POST(req: NextRequest) {
phoneNumber: user.phoneNumber,
email: user.email,
},
redirectTo: user.role === "DELIVERY" ? "/terminal" : "/admin/dashboard",
// Platform operators start on the console for every business, not on
// their own (placeholder) business's dashboard.
redirectTo: isPlatformAdmin(user) ? "/platform" : user.role === "DELIVERY" ? "/terminal" : "/admin/dashboard",
isPlatformAdmin: isPlatformAdmin(user),
});
+3 -1
View File
@@ -12,7 +12,9 @@ export default function RootPage() {
(async () => {
try {
const result = await apiFetch<{ user: AuthUser }>("/api/auth/me");
if (result.user.role === "DELIVERY") {
if (result.user.isPlatformAdmin) {
router.replace("/platform");
} else if (result.user.role === "DELIVERY") {
router.replace("/terminal");
} else {
router.replace("/admin/dashboard");
+13
View File
@@ -132,3 +132,16 @@ describe("moving staff between branches", () => {
expect((await move(t.owner, t.branchB)).status).toBe(404);
});
});
describe("where sign-in lands", () => {
it("sends the platform operator to the platform console, owners to the dashboard, cashiers to the till", async () => {
const t = await makeTenant();
await Promise.all([setPassword(t.owner, "owner-pass"), setPassword(t.cashierA, "cashier-pass")]);
expect((await json(await signIn(t.owner, "owner-pass"))).body.redirectTo).toBe("/admin/dashboard");
expect((await json(await signIn(t.cashierA, "cashier-pass"))).body.redirectTo).toBe("/terminal");
await db(() => User.updateOne({ _id: t.owner.id }, { email: "operator@aquaflow.test", platformAdmin: true }));
const operator = { ...t.owner, email: "operator@aquaflow.test" };
expect((await json(await signIn(operator, "owner-pass"))).body.redirectTo).toBe("/platform");
});
});