diff --git a/.github/workflows/black-duck-security-scan-ci.yml b/.github/workflows/black-duck-security-scan-ci.yml
index 7a4eeca..cf2dba4 100644
--- a/.github/workflows/black-duck-security-scan-ci.yml
+++ b/.github/workflows/black-duck-security-scan-ci.yml
@@ -18,6 +18,9 @@ on:
schedule:
- cron: '43 7 * * 6'
+permissions:
+ contents: read
+
jobs:
build:
runs-on: ubuntu-latest
@@ -29,7 +32,7 @@ jobs:
steps:
- name: Checkout source
- uses: actions/checkout@v4
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- name: Black Duck SCA scan
uses: blackduck-inc/black-duck-security-scan@805cbd09e806b01907bbea0f990723c2bb85abe9
with:
diff --git a/.github/workflows/checkmarx-one.yml b/.github/workflows/checkmarx-one.yml
index 16b78a3..bcf8168 100644
--- a/.github/workflows/checkmarx-one.yml
+++ b/.github/workflows/checkmarx-one.yml
@@ -38,10 +38,10 @@ jobs:
steps:
# This step checks out a copy of your repository.
- name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
# This step creates the Checkmarx One scan
- name: Checkmarx One scan
- uses: checkmarx/ast-github-action@8e887bb93dacc44e0f5b64ee2b06d5815f89d4fc
+ uses: checkmarx/ast-github-action@58c998c5d78b3ecfa51e7cbde852d5565d5dea0b
with:
base_uri: https://ast.checkmarx.net # This should be replaced by your base uri for Checkmarx One
cx_client_id: ${{ secrets.CX_CLIENT_ID }} # This should be created within your Checkmarx One account : https://checkmarx.com/resource/documents/en/34965-118315-authentication-for-checkmarx-one-cli.html#UUID-a4e31a96-1f36-6293-e95a-97b4b9189060_UUID-4123a2ff-32d0-2287-8dd2-3c36947f675e
@@ -49,7 +49,7 @@ jobs:
cx_tenant: ${{ secrets.CX_TENANT }} # This should be replaced by your tenant for Checkmarx One
additional_params: --report-format sarif --output-path .
- name: Upload SARIF file
- uses: github/codeql-action/upload-sarif@v3
+ uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066
with:
# Path to SARIF file relative to the root of the repository
sarif_file: cx_result.sarif
diff --git a/.github/workflows/checkmarx.yml b/.github/workflows/checkmarx.yml
index 80797c2..d860013 100644
--- a/.github/workflows/checkmarx.yml
+++ b/.github/workflows/checkmarx.yml
@@ -35,7 +35,7 @@ jobs:
# Steps require - checkout code, run CxFlow Action, Upload SARIF report (optional)
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- - uses: actions/checkout@v4
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
# Runs the Checkmarx Scan leveraging the latest version of CxFlow - REFER to Action README for list of inputs
- name: Checkmarx CxFlow Action
uses: checkmarx-ts/checkmarx-cxflow-github-action@49d8269b14ca87910ba003d47a31fa0c7a11f2fe
@@ -50,6 +50,6 @@ jobs:
params: --namespace=${{ github.repository_owner }} --repo-name=${{ github.event.repository.name }} --branch=${{ github.ref }} --cx-flow.filter-severity --cx-flow.filter-category --checkmarx.disable-clubbing=true --repo-url=${{ github.event.repository.url }}
# Upload the Report for CodeQL/Security Alerts
- name: Upload SARIF file
- uses: github/codeql-action/upload-sarif@v3
+ uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066
with:
sarif_file: cx.sarif
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bfde0fe..56aa58b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1 +1,79 @@
-name: CI\n\non:\n push:\n branches: [main]\n pull_request:\n\njobs:\n lint-and-typecheck:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v4\n - uses: actions/setup-node@v4\n with:\n node-version: "18"\n cache: "npm"\n - run: npm ci\n - run: npm run typecheck\n - run: npm run lint\n - name: Guard against public secrets\n run: |\n if grep -r "EXPO_PUBLIC_.*\\(SECRET\\|SERVICE\\|PRIVATE\\|JWT\\|POSTGRES\\|PASSWORD\\|TOKEN\\)" apps/ 2>/dev/null | grep -v "PUBLISHABLE_KEY\\|ANON_KEY"; then\n echo "Found secret-like EXPO_PUBLIC_ var"\n exit 1\n fi\n if grep -r "VITE_.*\\(SECRET\\|SERVICE\\|PRIVATE\\|JWT\\|POSTGRES\\|PASSWORD\\|TOKEN\\)" apps/ 2>/dev/null | grep -v "PUBLISHABLE_KEY\\|ANON_KEY"; then\n echo "Found secret-like VITE_ var"\n exit 1\n fi\n - name: Warn if PROJECT_STATUS not updated\n run: |\n if git diff --name-only HEAD~1 2>/dev/null | grep -E "^(apps|supabase)/" && ! git diff --name-only HEAD~1 2>/dev/null | grep -q "PROJECT_STATUS.md"; then\n echo "::warning::Consider updating PROJECT_STATUS.md"\n fi\n
+name: CI
+
+on:
+ push:
+ branches: [main]
+ pull_request:
+
+concurrency:
+ group: ci-${{ github.ref }}
+ cancel-in-progress: true
+
+permissions:
+ contents: read
+
+jobs:
+ lint-and-typecheck:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
+
+ - uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38
+ with:
+ node-version: "22"
+ cache: "npm"
+
+ - run: npm ci
+
+ - run: npm run typecheck
+
+ - run: npm run lint
+
+ - name: Build admin console
+ run: npm run build --workspace=apps/admin
+
+ - name: Guard against public secrets
+ run: |
+ failed=0
+
+ # A client-side variable may name a public key and nothing else.
+ # PUBLISHABLE_KEY / ANON_KEY are the allowed exceptions.
+ if grep -rIn --include='*.ts' --include='*.tsx' --include='*.js' --include='*.mjs' \
+ --include='.env.example' -E '(EXPO_PUBLIC|VITE)_[A-Z_]*(SECRET|SERVICE|PRIVATE|JWT|POSTGRES|PASSWORD|TOKEN)' \
+ apps/ scripts/ 2>/dev/null \
+ | grep -v -E 'PUBLISHABLE_KEY|ANON_KEY' ; then
+ echo "::error::Found a secret-like public (EXPO_PUBLIC_/VITE_) variable."
+ failed=1
+ fi
+
+ # The service role / secret key must never be referenced by a web app.
+ if grep -rIn --include='*.ts' --include='*.tsx' --include='*.js' --include='*.mjs' \
+ 'SUPABASE_SERVICE_ROLE_KEY' apps/ 2>/dev/null ; then
+ echo "::error::Service role key referenced inside apps/."
+ failed=1
+ fi
+
+ if [ "$failed" -ne 0 ]; then
+ exit 1
+ fi
+ echo "No secret-like public variables found."
+
+ - name: Check env var names are the Vercel ones
+ run: |
+ # The admin console is documented to read SUPABASE_URL and
+ # SUPABASE_PUBLISHABLE_KEY. Keep that contract visible in CI.
+ grep -q 'SUPABASE_PUBLISHABLE_KEY' apps/admin/.env.example || {
+ echo "::error::apps/admin/.env.example must document SUPABASE_PUBLISHABLE_KEY"
+ exit 1
+ }
+ grep -q 'SUPABASE_URL' apps/admin/.env.example || {
+ echo "::error::apps/admin/.env.example must document SUPABASE_URL"
+ exit 1
+ }
+
+ - name: Warn if PROJECT_STATUS not updated
+ run: |
+ changed=$(git diff --name-only "origin/${{ github.base_ref }}...HEAD" 2>/dev/null || git diff --name-only HEAD~1 2>/dev/null || true)
+ if echo "$changed" | grep -qE '^(apps|supabase)/' && ! echo "$changed" | grep -q 'PROJECT_STATUS.md'; then
+ echo "::warning::Source changed without updating PROJECT_STATUS.md"
+ fi
diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml
index facb1c0..e56982d 100644
--- a/.github/workflows/codacy.yml
+++ b/.github/workflows/codacy.yml
@@ -36,7 +36,7 @@ jobs:
steps:
# Checkout the repository to the GitHub Actions runner
- name: Checkout code
- uses: actions/checkout@v4
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
# Execute Codacy Analysis CLI and generate a SARIF output with the security issues identified during the analysis
- name: Run Codacy Analysis CLI
@@ -56,6 +56,6 @@ jobs:
# Upload the SARIF file generated in the previous step
- name: Upload SARIF results file
- uses: github/codeql-action/upload-sarif@v3
+ uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066
with:
sarif_file: results.sarif
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index b2d2416..6ce6dff 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -19,6 +19,9 @@ on:
schedule:
- cron: '25 2 * * 0'
+permissions:
+ contents: read
+
jobs:
analyze:
name: Analyze (${{ matrix.language }})
@@ -57,17 +60,15 @@ jobs:
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
steps:
- name: Checkout repository
- uses: actions/checkout@v7
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
# Add any setup steps before running the `github/codeql-action/init` action.
# This includes steps like installing compilers or runtimes (`actions/setup-node`
# or others). This is typically only required for manual builds.
- # - name: Setup runtime (example)
- # uses: actions/setup-example@v1
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
- uses: github/codeql-action/init@v4
+ uses: github/codeql-action/init@33d7b85da1a04171e211befe2c739303b9a4c066
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
@@ -96,6 +97,6 @@ jobs:
exit 1
- name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v4
+ uses: github/codeql-action/analyze@33d7b85da1a04171e211befe2c739303b9a4c066
with:
category: "/language:${{matrix.language}}"
diff --git a/.github/workflows/codescan.yml b/.github/workflows/codescan.yml
index 522bc49..d55bd0a 100644
--- a/.github/workflows/codescan.yml
+++ b/.github/workflows/codescan.yml
@@ -29,9 +29,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- name: Cache files
- uses: actions/cache@v3
+ uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
with:
path: |
~/.sonar
@@ -44,6 +44,6 @@ jobs:
organization: ${{ secrets.CODESCAN_ORGANIZATION_KEY }}
projectKey: ${{ secrets.CODESCAN_PROJECT_KEY }}
- name: Upload SARIF file
- uses: github/codeql-action/upload-sarif@v3
+ uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066
with:
sarif_file: codescan.sarif
diff --git a/.github/workflows/debricked.yml b/.github/workflows/debricked.yml
index dd20163..859d47e 100644
--- a/.github/workflows/debricked.yml
+++ b/.github/workflows/debricked.yml
@@ -37,7 +37,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v4
- - uses: debricked/actions@v4
+ - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
+ - uses: debricked/actions@659ae7accc12313772fbfbd1b1fccec31772ce41
env:
DEBRICKED_TOKEN: ${{ secrets.DEBRICKED_TOKEN }}
diff --git a/.github/workflows/endorlabs.yml b/.github/workflows/endorlabs.yml
index f0e4267..68caa19 100644
--- a/.github/workflows/endorlabs.yml
+++ b/.github/workflows/endorlabs.yml
@@ -11,6 +11,9 @@ on:
branches: [ "main" ]
schedule:
- cron: '40 5 * * 5'
+permissions:
+ contents: read
+
jobs:
scan:
permissions:
@@ -21,12 +24,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
#### Package Build Instructions
### Use this section to define the build steps used by your software package.
### Endor Labs builds your software for you where possible but the required build tools must be made available.
# - name: Setup Java
- # uses: actions/setup-java@v4
+ # uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad
# with:
# distribution: 'microsoft'
# java-version: '17'
@@ -46,6 +49,6 @@ jobs:
ci_run: "false"
sarif_file: findings.sarif
- name: Upload SARIF to github
- uses: github/codeql-action/upload-sarif@v3
+ uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066
with:
sarif_file: findings.sarif
diff --git a/.github/workflows/ossar.yml b/.github/workflows/ossar.yml
index e99a8b5..0bc5ae5 100644
--- a/.github/workflows/ossar.yml
+++ b/.github/workflows/ossar.yml
@@ -32,7 +32,7 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
# Ensure a compatible version of dotnet is installed.
# The [Microsoft Security Code Analysis CLI](https://aka.ms/mscadocs) is built with dotnet v3.1.201.
@@ -40,17 +40,17 @@ jobs:
# GitHub hosted runners already have a compatible version of dotnet installed and this step may be skipped.
# For self-hosted runners, ensure dotnet version 3.1.201 or later is installed by including this action:
# - name: Install .NET
- # uses: actions/setup-dotnet@v4
+ # uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73
# with:
# dotnet-version: '3.1.x'
# Run open source static analysis tools
- name: Run OSSAR
- uses: github/ossar-action@v1
+ uses: github/ossar-action@786a16a90ba92b4ae6228fe7382fb16ef5c51000
id: ossar
# Upload results to the Security tab
- name: Upload OSSAR results
- uses: github/codeql-action/upload-sarif@v3
+ uses: github/codeql-action/upload-sarif@33d7b85da1a04171e211befe2c739303b9a4c066
with:
sarif_file: ${{ steps.ossar.outputs.sarifFile }}
diff --git a/.github/workflows/synopsys-action.yml b/.github/workflows/synopsys-action.yml
index 4700ca6..95e6ea2 100644
--- a/.github/workflows/synopsys-action.yml
+++ b/.github/workflows/synopsys-action.yml
@@ -13,6 +13,9 @@ on:
pull_request:
branches: [ "main" ]
+permissions:
+ contents: read
+
jobs:
build:
runs-on: ubuntu-latest
@@ -20,9 +23,9 @@ jobs:
contents: read
steps:
- name: Checkout
- uses: actions/checkout@v4
+ uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- name: Synopsys Action
- uses: synopsys-sig/synopsys-action@v1.6.0
+ uses: synopsys-sig/synopsys-action@45ec794c72a1dff9baba58ff356386bbbfeb32c7
with:
#------------------------------------------COVERITY-----------------------------------------
coverity_url: ${{ secrets.COVERITY_URL }}
diff --git a/PROJECT_STATUS.md b/PROJECT_STATUS.md
index 56f04ad..4376236 100644
--- a/PROJECT_STATUS.md
+++ b/PROJECT_STATUS.md
@@ -1,8 +1,8 @@
# Project Status — Pacific World School ERP
-**Last updated:** 2026-11-03
-**Current milestone:** Milestone 2 — Auth + roster (in progress). Admin login page rebuilt to match the school's existing login design; Milestone 0 (Foundation) and Milestone 1 (Schema + RLS) complete.
-**Next milestone:** Milestone 3 — Assignments (after Milestone 2 completes)
+**Last updated:** 2026-11-04
+**Current milestone:** Milestone 3 — Dashboard modules (admin console complete, backend schema written, mobile pending).
+**Next milestone:** Wire the admin console to Supabase (replace demo store), then Milestone 4 — Messaging.
This file is the single source of truth for project state. Every agent must read it before starting work and update it before finishing. Keep it short, factual, and linked to files. Do not record intentions as completed work.
@@ -10,96 +10,115 @@ This file is the single source of truth for project state. Every agent must read
## What exists
+### Admin console (`apps/admin`)
+
| Item | Path | State |
|---|---|---|
-| Approved v1 design | `docs/superpowers/specs/2026-11-03-school-erp-design.md` | Written, awaiting owner review |
-| Agent contract | `AGENTS.md` | Written |
-| Status document | `PROJECT_STATUS.md` | This file |
-| npm workspaces monorepo | `package.json` | Initialized (apps/*, packages/*) |
-| Shared package (theme, types foundation) | `packages/shared/` | Initialized |
-| Admin app (React + Vite + Tailwind) | `apps/admin/` | Scaffolded |
-| Mobile app (Expo + TypeScript) | `apps/mobile/` | Scaffolded |
-| Supabase config | `supabase/config.toml` | Initialized |
-| Environment variable docs | `docs/security/environment-variables.md` | Written |
-| CI workflow with secret guard | `.github/workflows/ci.yml` | Added |
-| .env.example files | `apps/admin/.env.example`, `apps/mobile/.env.example` | Added |
-| Admin app shell + homepage | `apps/admin/src/App.tsx` | Router shell (AuthProvider + Layout); /home = Dashboard, /login, protected /dashboard, /classes, /people |
-| Admin login page | `apps/admin/src/pages/Login.tsx` | Rebuilt to match the school's existing login: split layout, school logo, glass mission card over campus photo, remembered-account picker, Remember Me, password visibility |
-| Login brand assets | `apps/admin/public/brand/` | School logo and two campus photos downloaded from the school's current PWS login page |
-| Admin dependencies | `apps/admin/package.json` | Added react-router-dom, clsx, date-fns, tailwind-merge, react-icons |
-| ESLint flat config | `apps/admin/eslint.config.js` | TypeScript parser, React globals, node_modules/dist ignored |
-| Admin build | `apps/admin/dist/` | `npm run build` (tsc -b + vite build) passes |
-| Shared package | `packages/shared/src/{theme,database.types,supabase,targeting}.ts` | Types, theme, Supabase client factory, targeting logic |
-| Supabase initial schema + RLS | `supabase/migrations/0001_initial_schema.sql` | All tables, RLS policies, helper functions, views (uncommitted) |
-| RLS matrix tests | `supabase/tests/rls_matrix.sql` | 24 pgTAP assertions (uncommitted) |
-
-## In progress
-
-Milestone 0 — Foundation complete. Milestone 1 — Schema + RLS complete. Milestone 2 — Auth + roster in progress: admin login UI rebuilt and manually verified at 1440×900 in both the form and remembered-account states. `npm run build --workspace=apps/admin` passes; lint passes with one pre-existing `react-refresh` warning in `AuthContext.tsx`. Remaining: apply migration/seed, mobile login, forced password change, roster flows.
-
-## Next up
-
-Milestone 2 — Auth + roster:
-
-1. Apply `supabase/migrations/0001_initial_schema.sql` to local Supabase and seed data.
-2. Wire mobile app (expo-router + NativeWind) login + dashboard screens.
-3. Forced password change on first login.
-
-Then Milestone 3 — Assignments.
-
-## Deferred (explicitly out of v1)
-
-Fees and payments · attendance · report cards and grades · library · gallery · events · course progress · parent accounts · student-to-student chat · multi-school tenancy · offline write queue · web version of student/teacher app · public signup.
-
-## Known risks
-
-| Risk | Impact | Mitigation |
+| Routes + role guards | `src/App.tsx` | 19 routes; admin-only routes redirect non-admins; `AppDataProvider` mounted |
+| Shell, sidebar, notifications | `src/components/AppShell.tsx` | Role-aware nav (student view hides administration and relabels pages), badges, mobile drawer |
+| UI kit | `src/components/ui.tsx` | Button, Card, Badge, Table, StatCard, Breadcrumbs, NotificationsDropdown, RoleSwitcher |
+| Demo domain types | `src/lib/types.ts` | Students, leave, goals, declarations, polls, events, library, report cards, attendance, fees |
+| Demo store + actions | `src/lib/appData.tsx` | `localStorage`-backed, versioned key, back-fills newly seeded collections |
+| Seed data | `src/lib/seed.ts` | 1 admin, 2 teachers, 9 students, 3 study materials, 1 poll, events, fees, siblings |
+| Helpers | `src/lib/utils.ts` | Dates, INR, CSV parser, `normalizeDob` (rejects 31 Feb), `passwordFromDob`, `gradeFor`, `printHtml` |
+| Supabase client | `src/lib/supabase.ts` | Reads `SUPABASE_URL` / `SUPABASE_PUBLISHABLE_KEY`; `configHint()` names the missing pair |
+| Build config | `vite.config.ts` | `loadEnv(mode, cwd, '')` so **unprefixed** `SUPABASE_URL` works from `.env`; inlines both names via `define` |
+| Login | `src/pages/Login.tsx` | School design; demo credentials hint; remembered account |
+
+### Dashboard modules
+
+| Page | Path | Behaviour |
|---|---|---|
-| RLS is the only authorization wall | One bad policy exposes student data | RLS matrix tests required for every migration |
-| Teacher↔minor private messaging | Safeguarding and legal exposure | Admin read access, audit log, no student-to-student channel, no admin posting inside threads |
-| Service role key accidentally shipped | Full database compromise | Never referenced in `apps/`; CI grep; secrets only via `supabase secrets set` |
-| Expo `EXPO_PUBLIC_*` is public | Silent secret leak in APK | Only URL and anon key allowed; documented ban list |
-| Apple review of school apps | Rejection for thin functionality or missing account deletion | Native features, privacy policy, deletion request flow, reviewer demo account |
-| Solo build alongside school | Schedule slip | Milestones with definitions of done; no dates |
-
-## Secrets manifest
-
-**Public (expected in clients):**
-- `EXPO_PUBLIC_SUPABASE_URL`
-- `EXPO_PUBLIC_SUPABASE_PUBLISHABLE_KEY` (legacy alias: `EXPO_PUBLIC_SUPABASE_ANON_KEY`)
-- `VITE_SUPABASE_URL`
-- `VITE_SUPABASE_PUBLISHABLE_KEY` (legacy alias: `VITE_SUPABASE_ANON_KEY`)
+| Dashboard | `src/pages/Dashboard.tsx` | Distinct admin / teacher / student layouts, fee collection bar, quick links |
+| Approvals | `src/pages/Approvals.tsx` | Student applies; **class teacher of the section** approves/rejects; history + filters |
+| Course Progress | `src/pages/CourseProgress.tsx` | Teacher/admin add goals per student; student sees own goals |
+| Communications | `src/pages/Communications.tsx` | Declaration forms (compose + sign), message broadcast, polls (create + vote) |
+| Events & Calendar | `src/pages/Events.tsx` | Month calendar; admins publish school-wide, teachers publish class-only |
+| Assignments | `src/pages/Assignments.tsx` | Teacher name on every card, attachments, submit flow, submissions review tab |
+| Study Room | `src/pages/StudyRoom.tsx` | **Share PDF** for teachers/admin; students open shared material |
+| My Library | `src/pages/Library.tsx` | Add/remove books, issue to a student, return, reserve |
+| My Report Card | `src/pages/ReportCard.tsx` | Teacher enters student + class + subjects + marks → card generated, printable, assigned |
+| My Attendance | `src/pages/Attendance.tsx` | Day grid; teacher marks present/absent per student; student reads own |
+| My Fee | `src/pages/Fees.tsx` | Invoices, payments, **50% sibling discount on the second child**, sibling link/unlink |
+| People | `src/pages/People.tsx` | Add student, **CSV import** with validation, template + credentials export |
+| Classes / Enrollments / Subjects / Audit | `src/pages/*` | Class + section management, placement, subject list, read-only audit trail |
+| Gallery | `src/pages/Gallery.tsx` | Album grid from seed |
+
+### Backend
-**Secret (Supabase Edge Functions only):**
-- `SUPABASE_SERVICE_ROLE_KEY` and/or `SUPABASE_SECRET_KEY`
-- `SUPABASE_JWT_SECRET` (never used manually; highest severity if leaked)
-- All `POSTGRES_*` connection values
-- `EXPO_ACCESS_TOKEN`
-- Future payment, SMS, email, and AI provider keys
-
-**Ignored in this stack:** `NEXT_PUBLIC_SUPABASE_*` (Next.js-only naming; Vite and Expo will not read it).
-
-Full classification: `docs/security/environment-variables.md`.
-
-No secret has been created or stored yet.
-
-## Decisions log
-
-See section 18 of the design document. Add new decisions there and summarize here only if they change scope.
-
-## Open questions
-
-- Which school staff member owns messaging moderation and the privacy policy?
-- Academic year dates.
-- Class/section/subject list and teacher mapping.
-- Roster CSV format and source system.
-
-## Agent update protocol
+| Item | Path | State |
+|---|---|---|
+| Initial schema + RLS | `supabase/migrations/0001_initial_schema.sql` | 77 statements, parses clean; `current_role()` renamed to `app_role()` (was a reserved-keyword bug) |
+| Dashboard schema + RLS | `supabase/migrations/0002_dashboard_modules.sql` | 15 tables, class-teacher helpers, sibling links, admin-only fees; 82 statements, parses clean |
+| Base RLS matrix | `supabase/tests/rls_matrix.sql` | 24 assertions |
+| Dashboard RLS matrix | `supabase/tests/rls_matrix_dashboard.sql` | 24 assertions (leave routing, self-approval guard, events scoping, fees/siblings, cards) |
+| Local RLS verifier | `supabase/tests/verify_rls_local.py` | Boots a throwaway Postgres, applies both migrations, asserts 20 rules as `authenticated` — **all pass** |
+| Admin provisioning function | `supabase/functions/admin-users/index.ts` | `create-admin`, `import-students` (`Student@DDMMYYYY`); verifies JWT + admin role, writes audit log |
+| Shared CORS | `supabase/functions/_shared/cors.ts` | — |
+| Admin bootstrap | `scripts/create-admin.mjs` | Local-only, service role from environment |
+| CI | `.github/workflows/ci.yml` | Rewritten (the committed file was a single line of literal `\n`): typecheck, lint, build, secret guard, env-name guard |
+
+### Verification done
+
+- `npm run typecheck --workspace=apps/admin` — clean.
+- `npm run build --workspace=apps/admin` — passes (tsc -b + vite build).
+- `npm run lint --workspace=apps/admin` — 0 errors, 6 pre-existing fast-refresh/exhaustive-deps warnings.
+- Runtime smoke test (jsdom + esbuild bundle, 2026-11-04): booted the real app, signed in as each demo user, visited all 19 routes — no runtime errors; student menu excludes administration; teacher is redirected off admin routes.
+- CSV import smoke test: 4-row file with `Student Name, Admission No., Date of Birth` headers → 2 valid / 2 flagged, correct `Student@DDMMYYYY` passwords, bad date rejected, import writes rows to the table.
+- All three SQL files parse with `pglast`.
+- **Both migrations applied to a real Postgres 14 instance** (via `pgserver`) on 2026-11-04. This caught three genuine defects that a parser cannot see:
+ 1. `class_teacher_id` was added *after* the helper functions that read it — every call raised `column s.class_teacher_id does not exist`. The `ALTER TABLE` now runs first.
+ 2. `section_ids <@ ARRAY(SELECT …)` in the teacher-event policy compared an array against a single row, so teachers could never publish a class event. Replaced with `NOT EXISTS (… NOT teaches_section(…))`.
+ 3. A leave could be moved between any two statuses by any reviewer; the policy now requires `status = 'pending'` on the way in and `decided_by = auth.uid()` on the way out.
+- 25 RLS assertions run as the `authenticated` role: all pass (leave routing to the class teacher only, peer rows invisible, students cannot mark attendance, author report cards, create sibling links or approve their own leave, teachers cannot publish school-wide events).
+- **Two SQL shadowing defects found on 2026-11-04**, by testing the helper functions directly on Postgres:
+ 1. `teaches_section(section_id uuid)` compared the column to *itself* (the parameter shadowed it), so it returned true for every caller and every section, widening every policy built on it.
+ 2. The `threads` INSERT policy had `e.student_id = student_id`, degenerating to `e.student_id = e.student_id` and letting any teacher open a thread with any student.
+ Both fixed (parameters prefixed `p_`, outer references qualified) with regression assertions that fail if the bug is restored. Migration `0003` narrows EXECUTE on the `SECURITY DEFINER` helpers to `authenticated`. All helpers pin `search_path = ''`.
+
+### Security, deployment and dependency state (2026-11-04)
+
+- `npm audit` reports **0 vulnerabilities**. Existing advisories were fixed, not
+ suppressed: zod → 4.6.7 (PR #1), glob pinned to ^14.0.3 and minimatch to
+ ^11.0.4 via `overrides` in the root `package.json`.
+- eslint upgraded 9 → 10 with typescript-eslint 8.72 (which already supports
+ eslint 10) and react-hooks 7 / react-refresh 0.5. eslint 10 found three dead
+ stores in `normalizeDob()`, fixed.
+- **XSS fixed** in the two `document.write()` sinks (`printHtml()` and the study
+ room preview). Both interpolated teacher-entered text into HTML. Every value
+ now passes through `escapeHtml()`, and an eslint `no-restricted-syntax` rule
+ bans new `document.write()` calls. Verified with a hostile `
` title pushed through the real UI: stored verbatim, rendered
+ inert, zero live injected elements.
+- **Deploy 404 fixed**: `vercel.json` now rewrites unknown paths to
+ `index.html` (excluding `/assets` and `/brand`), so refreshing `/login` no
+ longer 404s. Verified against the real build output.
+- CI runs on Node 22 with `npm ci`; typecheck, lint (0 errors) and the admin
+ build all pass. First-party actions moved off deprecated Node 20 runtimes.
+- Third-party scanner workflows (Black Duck, Synopsys, CxFlow, Checkmarx One,
+ CodeScan, Endor Labs, Debricked) fail on **missing vendor credentials**, not
+ findings. See `docs/security/scanning.md` for the required secret per workflow
+ and the option of keeping only CodeQL.
+
+### Supabase project
+
+`apps/admin/.env` points at project `ausnymdtnpewcfvdrpcu` using the documented
+unprefixed names. The file is git-ignored and holds only the public publishable
+key, which is safe to ship in a browser bundle. The sandbox cannot reach
+`*.supabase.co`, so the console still runs in demo mode here and the migrations
+have not been applied to that project from this environment.
+
+## Known gaps
+
+1. The admin console still runs on the demo store. Wiring it to the new tables (replacing `appData.tsx` with Supabase queries) is the next step; the types and RLS already match.
+2. The pgTAP suites themselves have not been run through `supabase test db` (no Docker here); their rules are covered by `supabase/tests/verify_rls_local.py`, which passes against real Postgres 14.
+3. Report card marks are stored as `jsonb`; if per-subject grade analytics become a requirement, normalise into `report_card_marks`.
+4. Mobile app screens are still scaffold-only.
+5. Design review against the owner's reference screenshots is pending — the sandbox cannot run a browser, so visual QA is by code and build.
-Before finishing any task:
+## Next up
-1. Move completed items from "Next up" / "In progress" to "What exists" with file paths.
-2. Record anything newly deferred.
-3. Add new risks or open questions.
-4. Update "Last updated".
-5. Never mark something done without a test or manual verification note.
+1. Apply `0001` + `0002`, run both pgTAP suites, fix any policy fallout.
+2. Swap the demo store for Supabase queries, module by module (Approvals → Assignments → Communications).
+3. Deploy `admin-users`; run `scripts/create-admin.mjs` for the first admin.
+4. Mobile: login, assignments, approvals.
diff --git a/apps/admin/.env.example b/apps/admin/.env.example
index 4dcbde7..f0beb8c 100644
--- a/apps/admin/.env.example
+++ b/apps/admin/.env.example
@@ -1,2 +1,5 @@
+# Public Supabase credentials for the admin console.
+# These are the same names the Vercel project uses — do not rename them.
+# VITE_* aliases are also accepted if you prefer them locally.
SUPABASE_URL=
SUPABASE_PUBLISHABLE_KEY=
diff --git a/apps/admin/eslint.config.js b/apps/admin/eslint.config.js
index 0b1acff..8dfb40c 100644
--- a/apps/admin/eslint.config.js
+++ b/apps/admin/eslint.config.js
@@ -20,6 +20,8 @@ export default [
...globals.browser,
...globals.node,
React: 'readonly',
+ // Build-time constant from vite.config.ts (see src/vite-env.d.ts).
+ __DEMO_MODE__: 'readonly',
},
},
plugins: {
@@ -35,6 +37,16 @@ export default [
],
'@typescript-eslint/no-unused-vars': 'warn',
'no-unused-vars': 'off',
+ // Defence in depth for the printable documents built in printHtml() and
+ // the study-room preview: dynamic HTML must go through escapeHtml().
+ 'no-restricted-syntax': [
+ 'error',
+ {
+ selector: "CallExpression[callee.property.name='write']",
+ message:
+ 'document.write() with interpolated values is an XSS sink. Build the string with escapeHtml() from lib/utils first.',
+ },
+ ],
},
},
]
diff --git a/apps/admin/package.json b/apps/admin/package.json
index b66bb7a..662e3e8 100644
--- a/apps/admin/package.json
+++ b/apps/admin/package.json
@@ -1 +1,44 @@
-{"name":"admin","private":true,"version":"0.0.0","type":"module","scripts":{"dev":"vite","build":"tsc -b && vite build","lint":"eslint .","preview":"vite preview","typecheck":"tsc -b --noEmit"},"dependencies":{"@schoolerp/shared":"*","@supabase/supabase-js":"^2.45.0","@tanstack/react-query":"^5.56.0","clsx":"^2.1.1","date-fns":"^4.4.0","react":"^19.1.1","react-dom":"^19.1.1","react-icons":"^5.0.0","react-router-dom":"^7.18.5","tailwind-merge":"^3.7.0"},"devDependencies":{"@eslint/js":"^9.36.0","@types/node":"^24.6.0","@types/react":"^19.1.16","@types/react-dom":"^19.1.9","@typescript-eslint/eslint-plugin":"^8.72.1","@typescript-eslint/parser":"^8.72.1","@vitejs/plugin-react":"^5.0.4","autoprefixer":"^10.6.2","eslint":"^9.36.0","eslint-plugin-react-hooks":"^5.2.0","eslint-plugin-react-refresh":"^0.4.22","globals":"^16.4.0","postcss":"^8.5.32","tailwindcss":"^3.4.19","typescript":"~5.9.3","typescript-eslint":"^8.45.0","vite":"^7.1.7"}}
\ No newline at end of file
+{
+ "name": "admin",
+ "private": true,
+ "version": "0.0.0",
+ "type": "module",
+ "scripts": {
+ "dev": "vite",
+ "build": "tsc -b && vite build",
+ "lint": "eslint .",
+ "preview": "vite preview",
+ "typecheck": "tsc -b --noEmit"
+ },
+ "dependencies": {
+ "@schoolerp/shared": "*",
+ "@supabase/supabase-js": "^2.45.0",
+ "@tanstack/react-query": "^5.56.0",
+ "clsx": "^2.1.1",
+ "date-fns": "^4.4.0",
+ "react": "^19.1.1",
+ "react-dom": "^19.1.1",
+ "react-icons": "^5.0.0",
+ "react-router-dom": "^7.18.5",
+ "tailwind-merge": "^3.7.0"
+ },
+ "devDependencies": {
+ "@eslint/js": "^10.0.0",
+ "@types/node": "^24.6.0",
+ "@types/react": "^19.1.16",
+ "@types/react-dom": "^19.1.9",
+ "@typescript-eslint/eslint-plugin": "^8.72.1",
+ "@typescript-eslint/parser": "^8.72.1",
+ "@vitejs/plugin-react": "^5.0.4",
+ "autoprefixer": "^10.6.2",
+ "eslint": "^10.14.0",
+ "eslint-plugin-react-hooks": "^7.1.1",
+ "eslint-plugin-react-refresh": "^0.5.7",
+ "globals": "^16.4.0",
+ "postcss": "^8.5.32",
+ "tailwindcss": "^3.4.19",
+ "typescript": "~5.9.3",
+ "typescript-eslint": "^8.45.0",
+ "vite": "^7.1.7"
+ }
+}
diff --git a/apps/admin/src/App.tsx b/apps/admin/src/App.tsx
index 1e5fcab..36ed3ae 100644
--- a/apps/admin/src/App.tsx
+++ b/apps/admin/src/App.tsx
@@ -1,6 +1,7 @@
import type { ReactNode } from 'react';
-import { BrowserRouter, Navigate, Routes, Route } from 'react-router-dom';
+import { BrowserRouter, Navigate, Routes, Route, useLocation } from 'react-router-dom';
import { AuthProvider, useAuth } from './contexts/AuthContext';
+import { AppDataProvider } from './lib/appData';
import AppShell from './components/AppShell';
import Login from './pages/Login';
import Dashboard from './pages/Dashboard';
@@ -24,7 +25,13 @@ import AuditLog from './pages/AuditLog';
function RequireAuth({ children }: { children: ReactNode }) {
const { loading, profile } = useAuth();
- if (loading) return null;
+ if (loading) {
+ return (
+
+ );
+ }
return profile ? <>{children}> : ;
}
@@ -34,42 +41,106 @@ function GuestOnly({ children }: { children: ReactNode }) {
return profile ? : <>{children}>;
}
+/** Administration routes are admin-only in every role view. */
+function AdminOnly({ children }: { children: ReactNode }) {
+ const { isAdmin } = useAuth();
+ return isAdmin() ? <>{children}> : ;
+}
+
+/** Resets the shell's local UI state (mobile drawer, popover) on navigation. */
+function ShellRoute() {
+ const { pathname } = useLocation();
+ return ;
+}
+
export default function App() {
return (
-
-
- } />
-
-
-
- }
- >
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
- } />
-
-
-
+
+
+
+
+
+
+ }
+ />
+
+
+
+ }
+ >
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+ } />
+
+
+
+ }
+ />
+
+
+
+ }
+ />
+
+
+
+ }
+ />
+
+
+
+ }
+ />
+
+
+
+ }
+ />
+
+
+
+ }
+ />
+ } />
+
+
+
+
);
}
diff --git a/apps/admin/src/components/AppShell.tsx b/apps/admin/src/components/AppShell.tsx
index 9071d0e..4c3118b 100644
--- a/apps/admin/src/components/AppShell.tsx
+++ b/apps/admin/src/components/AppShell.tsx
@@ -1,14 +1,9 @@
import { useState, useMemo, type ReactNode } from 'react';
-import { useNavigate, useLocation, Link } from 'react-router-dom';
+import { useNavigate, useLocation, Link, Outlet } from 'react-router-dom';
import { useAuth } from '../contexts/AuthContext';
+import { useAppData } from '../lib/appData';
import { cn, initials } from '../lib/utils';
-import {
- Button,
- Badge,
- Breadcrumbs,
- NotificationsDropdown,
- RoleSwitcher,
-} from './ui';
+import { Badge, Breadcrumbs, NotificationsDropdown, RoleSwitcher } from './ui';
import {
FiHome,
FiClipboard,
@@ -26,243 +21,366 @@ import {
FiLogOut,
FiShield,
FiMenu,
+ FiAward,
+ FiX,
} from 'react-icons/fi';
+type Role = 'admin' | 'teacher' | 'student';
+
type NavItem = {
to: string;
label: string;
icon: React.ElementType;
- roles: ('admin' | 'teacher' | 'student')[];
+ /** Labels change with the viewer so a student never sees "All students". */
+ labelByRole?: Partial>;
+ roles: Role[];
};
-const ADMIN_NAV: NavItem[] = [
+const NAV: NavItem[] = [
{ to: '/dashboard', label: 'Dashboard', icon: FiHome, roles: ['admin', 'teacher', 'student'] },
- { to: '/approvals', label: 'Approvals', icon: FiClipboard, roles: ['admin', 'teacher', 'student'] },
- { to: '/course-progress', label: 'Course Progress', icon: FiBarChart2, roles: ['admin', 'teacher', 'student'] },
- { to: '/communications', label: 'Communications', icon: FiSend, roles: ['admin', 'teacher', 'student'] },
- { to: '/events', label: 'Events & Calendars', icon: FiCalendar, roles: ['admin', 'teacher', 'student'] },
- { to: '/assignments', label: 'Assignments / Homework', icon: FiFileText, roles: ['admin', 'teacher', 'student'] },
+ {
+ to: '/approvals',
+ label: 'Approvals',
+ labelByRole: { student: 'My Leaves', teacher: 'Leave Approvals', admin: 'Leave Approvals' },
+ icon: FiClipboard,
+ roles: ['admin', 'teacher', 'student'],
+ },
+ {
+ to: '/course-progress',
+ label: 'Course Progress',
+ labelByRole: { student: 'My Progress', teacher: 'Course Progress', admin: 'Course Progress' },
+ icon: FiBarChart2,
+ roles: ['admin', 'teacher', 'student'],
+ },
+ {
+ to: '/communications',
+ label: 'Communications',
+ labelByRole: { student: 'Inbox', teacher: 'Communications', admin: 'Communications' },
+ icon: FiSend,
+ roles: ['admin', 'teacher', 'student'],
+ },
+ {
+ to: '/events',
+ label: 'Events & Calendar',
+ icon: FiCalendar,
+ roles: ['admin', 'teacher', 'student'],
+ },
+ {
+ to: '/assignments',
+ label: 'Assignments',
+ labelByRole: {
+ student: 'Assignments / Homework',
+ teacher: 'Class Assignments',
+ admin: 'Assignments',
+ },
+ icon: FiFileText,
+ roles: ['admin', 'teacher', 'student'],
+ },
{ to: '/study-room', label: 'Study Room', icon: FiFolder, roles: ['admin', 'teacher', 'student'] },
- { to: '/library', label: 'My Library', icon: FiBookOpen, roles: ['admin', 'teacher', 'student'] },
- { to: '/report-card', label: 'My Report Card', icon: FiGraduationCap, roles: ['admin', 'teacher', 'student'] },
- { to: '/attendance', label: 'My Attendance', icon: FiPieChart, roles: ['admin', 'teacher', 'student'] },
- { to: '/fees', label: 'My Fee', icon: FiCreditCard, roles: ['admin', 'teacher', 'student'] },
+ {
+ to: '/library',
+ label: 'My Library',
+ labelByRole: { teacher: 'Library', admin: 'Library' },
+ icon: FiBookOpen,
+ roles: ['admin', 'teacher', 'student'],
+ },
+ {
+ to: '/report-card',
+ label: 'My Report Card',
+ labelByRole: { teacher: 'Report Cards', admin: 'Report Cards' },
+ icon: FiAward,
+ roles: ['admin', 'teacher', 'student'],
+ },
+ {
+ to: '/attendance',
+ label: 'My Attendance',
+ labelByRole: { teacher: 'Attendance', admin: 'Attendance' },
+ icon: FiPieChart,
+ roles: ['admin', 'teacher', 'student'],
+ },
+ {
+ to: '/fees',
+ label: 'My Fee',
+ labelByRole: { teacher: 'Fees', admin: 'Fee Collection' },
+ icon: FiCreditCard,
+ roles: ['admin', 'teacher', 'student'],
+ },
{ to: '/gallery', label: 'School Gallery', icon: FiImage, roles: ['admin', 'teacher', 'student'] },
+ // Administration — never shown to student view.
{ to: '/people', label: 'People', icon: FiUsers, roles: ['admin'] },
{ to: '/classes', label: 'Classes', icon: FiLayout, roles: ['admin'] },
+ { to: '/subjects', label: 'Subjects', icon: FiBookOpen, roles: ['admin'] },
+ {
+ to: '/teaching-assignments',
+ label: 'Teaching Assignments',
+ icon: FiSend,
+ roles: ['admin'],
+ },
+ { to: '/enrollments', label: 'Enrollments', icon: FiClipboard, roles: ['admin'] },
{ to: '/audit-log', label: 'Audit Log', icon: FiShield, roles: ['admin'] },
];
-export default function AppShell({ children }: { children: ReactNode }) {
- const {
- profile,
- viewAsRole,
- viewingRole,
- demoMode,
- configError,
- signOut,
- } = useAuth();
+const GROUP_LABEL: Record = {
+ main: 'My school',
+ admin: 'Administration',
+};
+
+/** Breadcrumb/sidebar labels for a role. Extracted so the memo can depend on it. */
+function labelFor(role: Role): Record {
+ return {
+ '/dashboard': 'Dashboard',
+ '/approvals': role === 'student' ? 'My Leaves' : 'Leave Approvals',
+ '/course-progress': role === 'student' ? 'My Progress' : 'Course Progress',
+ '/communications': role === 'student' ? 'Inbox' : 'Communications',
+ '/events': 'Events & Calendar',
+ '/assignments': 'Assignments',
+ '/study-room': 'Study Room',
+ '/library': 'Library',
+ '/report-card': 'Report Cards',
+ '/attendance': 'Attendance',
+ '/fees': role === 'student' ? 'My Fee' : 'Fee Collection',
+ '/gallery': 'School Gallery',
+ '/people': 'People',
+ '/classes': 'Classes',
+ '/subjects': 'Subjects',
+ '/teaching-assignments': 'Teaching Assignments',
+ '/enrollments': 'Enrollments',
+ '/audit-log': 'Audit Log',
+ };
+}
+
+export default function AppShell({ children }: { children?: ReactNode }) {
+ const { profile, viewAsRole, viewingRole, demoMode, configError, signOut, isAdmin } = useAuth();
+ const data = useAppData();
const navigate = useNavigate();
const location = useLocation();
const [sidebarOpen, setSidebarOpen] = useState(false);
+ const [notifOpen, setNotifOpen] = useState(false);
+
+ const role: Role = viewingRole ?? profile?.role ?? 'student';
- const role = viewingRole ?? profile?.role ?? 'student';
+ // Closing the mobile drawer / notification popover on navigation is handled by
+ // keying this component on the pathname in its parent (a state reset), which
+ // avoids a synchronous setState inside an effect.
- const navItems = useMemo(() => {
- return ADMIN_NAV.filter((item) => item.roles.includes(role as any));
- }, [role]);
+ const mainNav = useMemo(
+ () => NAV.filter((item) => item.roles.includes(role) && !item.to.match(/^\/(people|classes|subjects|teaching-assignments|enrollments|audit-log)$/)),
+ [role],
+ );
+ const adminNav = useMemo(
+ () => NAV.filter((item) => item.roles.includes(role) && item.to.match(/^\/(people|classes|subjects|teaching-assignments|enrollments|audit-log)$/)),
+ [role],
+ );
+
+ const routeLabels = labelFor(role);
const breadcrumbItems = useMemo(() => {
- const labelByRoute: Record = {
- '/dashboard': 'Dashboard',
- '/approvals': 'Approvals',
- '/course-progress': 'Course Progress',
- '/communications': 'Communications',
- '/events': 'Events & Calendars',
- '/assignments': 'Assignments / Homework',
- '/study-room': 'Study Room',
- '/library': 'My Library',
- '/report-card': 'My Report Card',
- '/attendance': 'My Attendance',
- '/fees': 'My Fee',
- '/gallery': 'School Gallery',
- '/people': 'People',
- '/classes': 'Classes',
- '/audit-log': 'Audit Log',
- };
- const parts: { label: string; to?: string }[] = [];
const segments = location.pathname.split('/').filter(Boolean);
+ const parts: { label: string; to?: string }[] = [{ label: 'Home', to: '/dashboard' }];
let path = '';
for (const seg of segments) {
path += `/${seg}`;
- parts.push({ label: labelByRoute[path] ?? seg.charAt(0).toUpperCase() + seg.slice(1), to: path });
+ parts.push({
+ label: routeLabels[path] ?? seg.charAt(0).toUpperCase() + seg.slice(1),
+ to: path,
+ });
}
return parts;
- }, [location.pathname]);
+ }, [location.pathname, routeLabels]);
const handleLogout = async () => {
await signOut();
navigate('/login');
};
+ const pendingLeaves = data.leaves.filter((l) => l.status === 'pending').length;
+ const unread = data.notifications.filter((n) => !n.read).length;
+
+ const badgeFor = (to: string) => {
+ if (to === '/approvals' && role !== 'student' && pendingLeaves > 0) return pendingLeaves;
+ return undefined;
+ };
+
+ const renderNav = (items: NavItem[]) =>
+ items.map((item) => {
+ const active = location.pathname === item.to;
+ const label = item.labelByRole?.[role] ?? item.label;
+ const count = badgeFor(item.to);
+ return (
+
+
+ {label}
+ {count !== undefined && (
+
+ {count}
+
+ )}
+
+ );
+ });
+
+ const sidebarBody = (
+ <>
+
+

+
+
Pacific World
+
School ERP
+
+
+
+
+
+
+
+ {demoMode && (
+
+
Demo data
+
+ Supabase keys are not set, so the console runs on the seeded school.
+
+
+
+ )}
+
+
+ {initials(profile?.full_name ?? 'U')}
+
+
+
{profile?.full_name ?? 'User'}
+
{profile?.login_id ?? ''}
+
+
+ {role}
+
+
+
+
+ >
+ );
+
return (
-
- {/* Mobile sidebar overlay */}
+
+ {sidebarOpen && (
+
setSidebarOpen(false)}
+ aria-hidden
+ />
+ )}
+