Compare commits
2 Commits
5b7a2b847f
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 34ea64c4d4 | |||
| d15273e2a6 |
@@ -113,7 +113,8 @@ export default function AdminDashboardPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const scope: "global" | "branch" = selectedBranchId === "ALL" ? "global" : "branch";
|
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 (
|
return (
|
||||||
<main className="min-h-screen bg-sand-50 pb-12">
|
<main className="min-h-screen bg-sand-50 pb-12">
|
||||||
@@ -130,7 +131,10 @@ export default function AdminDashboardPage() {
|
|||||||
? `${me.branchName} Dashboard`
|
? `${me.branchName} Dashboard`
|
||||||
: "Branch Dashboard"}
|
: "Branch Dashboard"}
|
||||||
</h1>
|
</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">
|
<div className="mt-2">
|
||||||
<AccountLinks />
|
<AccountLinks />
|
||||||
</div>
|
</div>
|
||||||
@@ -142,7 +146,7 @@ export default function AdminDashboardPage() {
|
|||||||
onChange={setSelectedBranchId}
|
onChange={setSelectedBranchId}
|
||||||
isSuperAdmin={me.role === "SUPER_ADMIN"}
|
isSuperAdmin={me.role === "SUPER_ADMIN"}
|
||||||
/>
|
/>
|
||||||
{me.isPlatformAdmin && (
|
{me.isPlatformAdmin && (
|
||||||
<Link href="/platform" className="tap-target flex items-center rounded-xl2 bg-gradient-to-r from-flow-500 to-flow-700 px-4 text-sm font-semibold text-depth-950 hover:opacity-90">
|
<Link href="/platform" className="tap-target flex items-center rounded-xl2 bg-gradient-to-r from-flow-500 to-flow-700 px-4 text-sm font-semibold text-depth-950 hover:opacity-90">
|
||||||
Platform
|
Platform
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -167,7 +167,9 @@ export async function POST(req: NextRequest) {
|
|||||||
phoneNumber: user.phoneNumber,
|
phoneNumber: user.phoneNumber,
|
||||||
email: user.email,
|
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),
|
isPlatformAdmin: isPlatformAdmin(user),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -12,7 +12,9 @@ export default function RootPage() {
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const result = await apiFetch<{ user: AuthUser }>("/api/auth/me");
|
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");
|
router.replace("/terminal");
|
||||||
} else {
|
} else {
|
||||||
router.replace("/admin/dashboard");
|
router.replace("/admin/dashboard");
|
||||||
|
|||||||
@@ -132,3 +132,16 @@ describe("moving staff between branches", () => {
|
|||||||
expect((await move(t.owner, t.branchB)).status).toBe(404);
|
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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user