Merge pull request 'Send platform operators to the platform console after sign-in' (#9) from fix/operator-landing into main
Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
@@ -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>
|
||||
@@ -142,7 +146,7 @@ export default function AdminDashboardPage() {
|
||||
onChange={setSelectedBranchId}
|
||||
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">
|
||||
Platform
|
||||
</Link>
|
||||
|
||||
@@ -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
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user