diff --git a/apps/backend/lambdas/auth/Dockerfile b/apps/backend/lambdas/auth/Dockerfile index 5a8a986f..16f6cef1 100644 --- a/apps/backend/lambdas/auth/Dockerfile +++ b/apps/backend/lambdas/auth/Dockerfile @@ -6,6 +6,12 @@ WORKDIR /shared/types COPY shared/types/package.json ./ COPY shared/types/ ./ +# Before lambda-auth: it resolves @branch/rbac as file:../rbac and needs its dist. +WORKDIR /shared/rbac +COPY shared/rbac/package.json shared/rbac/tsconfig.json ./ +COPY shared/rbac/src ./src/ +RUN npm install && npm run build + WORKDIR /shared/lambda-auth COPY shared/lambda-auth/package.json shared/lambda-auth/tsconfig.json ./ COPY shared/lambda-auth/src ./src/ @@ -17,6 +23,11 @@ COPY shared/lambda-http/package.json shared/lambda-http/tsconfig.json ./ COPY shared/lambda-http/src ./src/ RUN npm install && npm run build +WORKDIR /shared/store +COPY shared/store/package.json shared/store/tsconfig.json ./ +COPY shared/store/src ./src/ +RUN npm install && npm run build + WORKDIR /app # Copy package files diff --git a/apps/backend/lambdas/donors/Dockerfile b/apps/backend/lambdas/donors/Dockerfile index 6d566340..0373baef 100644 --- a/apps/backend/lambdas/donors/Dockerfile +++ b/apps/backend/lambdas/donors/Dockerfile @@ -4,6 +4,12 @@ WORKDIR /shared/types COPY shared/types/package.json ./ COPY shared/types/ ./ +# Before lambda-auth: it resolves @branch/rbac as file:../rbac and needs its dist. +WORKDIR /shared/rbac +COPY shared/rbac/package.json shared/rbac/tsconfig.json ./ +COPY shared/rbac/src ./src/ +RUN npm install && npm run build + WORKDIR /shared/lambda-auth COPY shared/lambda-auth/package.json shared/lambda-auth/tsconfig.json ./ COPY shared/lambda-auth/src ./src/ @@ -15,6 +21,11 @@ COPY shared/lambda-http/package.json shared/lambda-http/tsconfig.json ./ COPY shared/lambda-http/src ./src/ RUN npm install && npm run build +WORKDIR /shared/store +COPY shared/store/package.json shared/store/tsconfig.json ./ +COPY shared/store/src ./src/ +RUN npm install && npm run build + WORKDIR /app COPY apps/backend/lambdas/donors/package*.json ./ RUN npm install --no-package-lock diff --git a/apps/backend/lambdas/expenditures/Dockerfile b/apps/backend/lambdas/expenditures/Dockerfile index b34ac87d..73e3d1ba 100644 --- a/apps/backend/lambdas/expenditures/Dockerfile +++ b/apps/backend/lambdas/expenditures/Dockerfile @@ -4,6 +4,12 @@ WORKDIR /shared/types COPY shared/types/package.json ./ COPY shared/types/ ./ +# Before lambda-auth: it resolves @branch/rbac as file:../rbac and needs its dist. +WORKDIR /shared/rbac +COPY shared/rbac/package.json shared/rbac/tsconfig.json ./ +COPY shared/rbac/src ./src/ +RUN npm install && npm run build + WORKDIR /shared/lambda-auth COPY shared/lambda-auth/package.json shared/lambda-auth/tsconfig.json ./ COPY shared/lambda-auth/src ./src/ @@ -15,6 +21,11 @@ COPY shared/lambda-http/package.json shared/lambda-http/tsconfig.json ./ COPY shared/lambda-http/src ./src/ RUN npm install && npm run build +WORKDIR /shared/store +COPY shared/store/package.json shared/store/tsconfig.json ./ +COPY shared/store/src ./src/ +RUN npm install && npm run build + WORKDIR /app COPY apps/backend/lambdas/expenditures/package*.json ./ RUN npm install --no-package-lock diff --git a/apps/backend/lambdas/projects/Dockerfile b/apps/backend/lambdas/projects/Dockerfile index 99d32377..78d2e9e0 100644 --- a/apps/backend/lambdas/projects/Dockerfile +++ b/apps/backend/lambdas/projects/Dockerfile @@ -4,6 +4,12 @@ WORKDIR /shared/types COPY shared/types/package.json ./ COPY shared/types/ ./ +# Before lambda-auth: it resolves @branch/rbac as file:../rbac and needs its dist. +WORKDIR /shared/rbac +COPY shared/rbac/package.json shared/rbac/tsconfig.json ./ +COPY shared/rbac/src ./src/ +RUN npm install && npm run build + WORKDIR /shared/lambda-auth COPY shared/lambda-auth/package.json shared/lambda-auth/tsconfig.json ./ COPY shared/lambda-auth/src ./src/ @@ -15,6 +21,11 @@ COPY shared/lambda-http/package.json shared/lambda-http/tsconfig.json ./ COPY shared/lambda-http/src ./src/ RUN npm install && npm run build +WORKDIR /shared/store +COPY shared/store/package.json shared/store/tsconfig.json ./ +COPY shared/store/src ./src/ +RUN npm install && npm run build + WORKDIR /app COPY apps/backend/lambdas/projects/package*.json ./ RUN npm install --no-package-lock diff --git a/apps/backend/lambdas/reports/Dockerfile b/apps/backend/lambdas/reports/Dockerfile index 2e2bd306..acd1b5e9 100644 --- a/apps/backend/lambdas/reports/Dockerfile +++ b/apps/backend/lambdas/reports/Dockerfile @@ -4,6 +4,12 @@ WORKDIR /shared/types COPY shared/types/package.json ./ COPY shared/types/ ./ +# Before lambda-auth: it resolves @branch/rbac as file:../rbac and needs its dist. +WORKDIR /shared/rbac +COPY shared/rbac/package.json shared/rbac/tsconfig.json ./ +COPY shared/rbac/src ./src/ +RUN npm install && npm run build + WORKDIR /shared/lambda-auth COPY shared/lambda-auth/package.json shared/lambda-auth/tsconfig.json ./ COPY shared/lambda-auth/src ./src/ @@ -15,6 +21,11 @@ COPY shared/lambda-http/package.json shared/lambda-http/tsconfig.json ./ COPY shared/lambda-http/src ./src/ RUN npm install && npm run build +WORKDIR /shared/store +COPY shared/store/package.json shared/store/tsconfig.json ./ +COPY shared/store/src ./src/ +RUN npm install && npm run build + WORKDIR /app COPY apps/backend/lambdas/reports/package*.json ./ RUN npm install --no-package-lock diff --git a/apps/backend/lambdas/users/Dockerfile b/apps/backend/lambdas/users/Dockerfile index e4bc86f6..c48b6090 100644 --- a/apps/backend/lambdas/users/Dockerfile +++ b/apps/backend/lambdas/users/Dockerfile @@ -4,6 +4,12 @@ WORKDIR /shared/types COPY shared/types/package.json ./ COPY shared/types/ ./ +# Before lambda-auth: it resolves @branch/rbac as file:../rbac and needs its dist. +WORKDIR /shared/rbac +COPY shared/rbac/package.json shared/rbac/tsconfig.json ./ +COPY shared/rbac/src ./src/ +RUN npm install && npm run build + WORKDIR /shared/lambda-auth COPY shared/lambda-auth/package.json shared/lambda-auth/tsconfig.json ./ COPY shared/lambda-auth/src ./src/ @@ -15,6 +21,11 @@ COPY shared/lambda-http/package.json shared/lambda-http/tsconfig.json ./ COPY shared/lambda-http/src ./src/ RUN npm install && npm run build +WORKDIR /shared/store +COPY shared/store/package.json shared/store/tsconfig.json ./ +COPY shared/store/src ./src/ +RUN npm install && npm run build + WORKDIR /app COPY apps/backend/lambdas/users/package*.json ./ RUN npm install --no-package-lock diff --git a/apps/frontend/AGENTS.md b/apps/frontend/AGENTS.md index f6bf8e7f..801aa495 100644 --- a/apps/frontend/AGENTS.md +++ b/apps/frontend/AGENTS.md @@ -64,7 +64,9 @@ Import direction is one-way and must stay that way: `api.ts` ← `authClient.ts` **Refresh.** Access tokens last one hour. `AuthProvider` schedules a refresh ~2 minutes before expiry, and `authedFetch` refreshes reactively on a 401. Refresh is single-flight, so a burst of concurrent 401s produces one `POST /auth/refresh`. Cognito does not re-issue a refresh token, so `saveTokens` leaves the stored one alone when the response omits it. -**Guarding.** `src/app/components/AuthGate.tsx`, mounted once in `providers.tsx`, is the app's only route guard — static export means `middleware.ts` would never run. `src/lib/routes.ts` classifies routes and is **protected-by-default**: a new page under `src/app/` is guarded without opting in. Public routes are `/login`, `/forgot-password`, `/reset-password` (authenticated users get bounced off them). Which permission a page needs comes from `PAGE_PERMISSIONS` in `@branch/rbac`, so AuthGate, the Navbar and the lambdas all read one table. Always compare paths through `normalizePath` — `trailingSlash: true` means production sees `/login/` where dev and tests see `/login`. +**Guarding.** `src/app/components/AuthGate.tsx`, mounted once in `providers.tsx`, is the app's only route guard — static export means `middleware.ts` would never run. `src/lib/routes.ts` classifies routes and is **protected-by-default**: a new page under `src/app/` is guarded without opting in. Public routes are `/login`, `/forgot-password`, `/reset-password` (authenticated users get bounced off them). Open routes (`/help/**`) render for everyone, signed in or not, and skip the Chakra/Auth shell in `providers.tsx`: they are prerendered with real content, and Chakra's Emotion styles inline into SSR HTML and break hydration. + +**Help pages.** `/help` is the user guide, served at `branchaccounting.org/help`. Guides are data in `src/app/help/guides.ts` (numbered one-line steps; `[label](/path)` makes a link) and `[slug]/page.tsx` prerenders one page per guide via `generateStaticParams`. Screenshots live in `public/help//`; `test/app/HelpGuides.test.ts` fails on a missing image or a link to a page that does not exist. Retake screenshots against a local stack with seeded demo data, never production. Which permission a page needs comes from `PAGE_PERMISSIONS` in `@branch/rbac`, so AuthGate, the Navbar and the lambdas all read one table. Always compare paths through `normalizePath` — `trailingSlash: true` means production sees `/login/` where dev and tests see `/login`. ## Permissions diff --git a/apps/frontend/public/help/accounts/add-button.png b/apps/frontend/public/help/accounts/add-button.png new file mode 100644 index 00000000..f20d589d Binary files /dev/null and b/apps/frontend/public/help/accounts/add-button.png differ diff --git a/apps/frontend/public/help/accounts/form-add.png b/apps/frontend/public/help/accounts/form-add.png new file mode 100644 index 00000000..7b0254b0 Binary files /dev/null and b/apps/frontend/public/help/accounts/form-add.png differ diff --git a/apps/frontend/public/help/donations/form-add.png b/apps/frontend/public/help/donations/form-add.png new file mode 100644 index 00000000..3b4745bc Binary files /dev/null and b/apps/frontend/public/help/donations/form-add.png differ diff --git a/apps/frontend/public/help/donations/new-button.png b/apps/frontend/public/help/donations/new-button.png new file mode 100644 index 00000000..f7145488 Binary files /dev/null and b/apps/frontend/public/help/donations/new-button.png differ diff --git a/apps/frontend/public/help/donors/form-add.png b/apps/frontend/public/help/donors/form-add.png new file mode 100644 index 00000000..432805ae Binary files /dev/null and b/apps/frontend/public/help/donors/form-add.png differ diff --git a/apps/frontend/public/help/donors/new-button.png b/apps/frontend/public/help/donors/new-button.png new file mode 100644 index 00000000..e2b898cf Binary files /dev/null and b/apps/frontend/public/help/donors/new-button.png differ diff --git a/apps/frontend/public/help/expenses/form-receipt.png b/apps/frontend/public/help/expenses/form-receipt.png new file mode 100644 index 00000000..4d73b6f2 Binary files /dev/null and b/apps/frontend/public/help/expenses/form-receipt.png differ diff --git a/apps/frontend/public/help/expenses/form-submit.png b/apps/frontend/public/help/expenses/form-submit.png new file mode 100644 index 00000000..6e7cf152 Binary files /dev/null and b/apps/frontend/public/help/expenses/form-submit.png differ diff --git a/apps/frontend/public/help/expenses/new-button.png b/apps/frontend/public/help/expenses/new-button.png new file mode 100644 index 00000000..c7aca257 Binary files /dev/null and b/apps/frontend/public/help/expenses/new-button.png differ diff --git a/apps/frontend/public/help/profile/edit.png b/apps/frontend/public/help/profile/edit.png new file mode 100644 index 00000000..fcd6d6fd Binary files /dev/null and b/apps/frontend/public/help/profile/edit.png differ diff --git a/apps/frontend/public/help/profile/two-factor.png b/apps/frontend/public/help/profile/two-factor.png new file mode 100644 index 00000000..ce5faf9a Binary files /dev/null and b/apps/frontend/public/help/profile/two-factor.png differ diff --git a/apps/frontend/public/help/projects/add-button.png b/apps/frontend/public/help/projects/add-button.png new file mode 100644 index 00000000..0a3f74ec Binary files /dev/null and b/apps/frontend/public/help/projects/add-button.png differ diff --git a/apps/frontend/public/help/projects/form-save.png b/apps/frontend/public/help/projects/form-save.png new file mode 100644 index 00000000..31835026 Binary files /dev/null and b/apps/frontend/public/help/projects/form-save.png differ diff --git a/apps/frontend/public/help/projects/nav-projects.png b/apps/frontend/public/help/projects/nav-projects.png new file mode 100644 index 00000000..b61a5c33 Binary files /dev/null and b/apps/frontend/public/help/projects/nav-projects.png differ diff --git a/apps/frontend/public/help/reports/download.png b/apps/frontend/public/help/reports/download.png new file mode 100644 index 00000000..59a14547 Binary files /dev/null and b/apps/frontend/public/help/reports/download.png differ diff --git a/apps/frontend/public/help/reports/generate-button.png b/apps/frontend/public/help/reports/generate-button.png new file mode 100644 index 00000000..9793d22f Binary files /dev/null and b/apps/frontend/public/help/reports/generate-button.png differ diff --git a/apps/frontend/public/help/reports/generate-form.png b/apps/frontend/public/help/reports/generate-form.png new file mode 100644 index 00000000..f14843f6 Binary files /dev/null and b/apps/frontend/public/help/reports/generate-form.png differ diff --git a/apps/frontend/public/help/reset-password/forgot-link.png b/apps/frontend/public/help/reset-password/forgot-link.png new file mode 100644 index 00000000..3955d252 Binary files /dev/null and b/apps/frontend/public/help/reset-password/forgot-link.png differ diff --git a/apps/frontend/public/help/reset-password/request-code.png b/apps/frontend/public/help/reset-password/request-code.png new file mode 100644 index 00000000..685c6e76 Binary files /dev/null and b/apps/frontend/public/help/reset-password/request-code.png differ diff --git a/apps/frontend/public/help/review-expenses/decision.png b/apps/frontend/public/help/review-expenses/decision.png new file mode 100644 index 00000000..7b71b9ac Binary files /dev/null and b/apps/frontend/public/help/review-expenses/decision.png differ diff --git a/apps/frontend/public/help/review-expenses/pending-row.png b/apps/frontend/public/help/review-expenses/pending-row.png new file mode 100644 index 00000000..f8882bcf Binary files /dev/null and b/apps/frontend/public/help/review-expenses/pending-row.png differ diff --git a/apps/frontend/public/help/review-expenses/save.png b/apps/frontend/public/help/review-expenses/save.png new file mode 100644 index 00000000..4df4694e Binary files /dev/null and b/apps/frontend/public/help/review-expenses/save.png differ diff --git a/apps/frontend/public/help/sign-in/dashboard.png b/apps/frontend/public/help/sign-in/dashboard.png new file mode 100644 index 00000000..1e44be5d Binary files /dev/null and b/apps/frontend/public/help/sign-in/dashboard.png differ diff --git a/apps/frontend/public/help/sign-in/login.png b/apps/frontend/public/help/sign-in/login.png new file mode 100644 index 00000000..0ddbdfe5 Binary files /dev/null and b/apps/frontend/public/help/sign-in/login.png differ diff --git a/apps/frontend/src/app/components/AuthGate.tsx b/apps/frontend/src/app/components/AuthGate.tsx index c81c892e..ad54ddbd 100644 --- a/apps/frontend/src/app/components/AuthGate.tsx +++ b/apps/frontend/src/app/components/AuthGate.tsx @@ -51,6 +51,8 @@ export default function AuthGate({ children }: { children: React.ReactNode }) { } }, [isLoading, isAuthenticated, subject, access, pathname, router]); + if (access === 'open') return <>{children}; + if (isLoading) return ; // Render suppression — the redirect above is asynchronous, and without these diff --git a/apps/frontend/src/app/components/Navbar.tsx b/apps/frontend/src/app/components/Navbar.tsx index d2be8a95..ba69cfbf 100644 --- a/apps/frontend/src/app/components/Navbar.tsx +++ b/apps/frontend/src/app/components/Navbar.tsx @@ -37,6 +37,7 @@ const NAV_ITEMS: NavItem[] = [ { label: "Reports", href: "/reports" }, { label: "Accounts", href: "/accounts" }, { label: "Profile", href: "/profile" }, + { label: "Help", href: "/help" }, { label: "Log Out", action: "logout" }, ]; diff --git a/apps/frontend/src/app/help/AdminTag.tsx b/apps/frontend/src/app/help/AdminTag.tsx new file mode 100644 index 00000000..e2aa4130 --- /dev/null +++ b/apps/frontend/src/app/help/AdminTag.tsx @@ -0,0 +1,18 @@ +export default function AdminTag() { + return ( + + Admins + + ); +} diff --git a/apps/frontend/src/app/help/[slug]/page.tsx b/apps/frontend/src/app/help/[slug]/page.tsx new file mode 100644 index 00000000..141ea835 --- /dev/null +++ b/apps/frontend/src/app/help/[slug]/page.tsx @@ -0,0 +1,87 @@ +import Image from 'next/image'; +import Link from 'next/link'; +import { notFound } from 'next/navigation'; +import { assetPath } from '@/lib/asset'; +import { GUIDES, guideBySlug } from '../guides'; +import AdminTag from '../AdminTag'; + +export function generateStaticParams() { + return GUIDES.map((g) => ({ slug: g.slug })); +} + +export const dynamicParams = false; + +function withLinks(text: string) { + return text.split(/(\[[^\]]+\]\([^)]+\))/).map((part, i) => { + const m = /^\[([^\]]+)\]\(([^)]+)\)$/.exec(part); + if (!m) return part; + return ( + + {m[1]} + + ); + }); +} + +export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }) { + const guide = guideBySlug((await params).slug); + return { title: guide ? `${guide.title} | BRANCH Help` : 'BRANCH Help' }; +} + +export default async function GuidePage({ params }: { params: Promise<{ slug: string }> }) { + const guide = guideBySlug((await params).slug); + if (!guide) notFound(); + + return ( +
+ + ← All guides + +

+ {guide.title} + {guide.adminOnly && } +

+
    + {guide.steps.map((step) => ( +
  1. +

    {withLinks(step.text)}

    + {step.image && ( + {step.alt + )} +
  2. + ))} +
+ {guide.notes && ( + + )} +
+ ); +} diff --git a/apps/frontend/src/app/help/guides.ts b/apps/frontend/src/app/help/guides.ts new file mode 100644 index 00000000..38947015 --- /dev/null +++ b/apps/frontend/src/app/help/guides.ts @@ -0,0 +1,263 @@ +export type Section = 'Accounts' | 'Expenses' | 'Projects' | 'Donors & donations' | 'Reports'; + +export interface GuideStep { + text: string; + image?: string; + alt?: string; +} + +export interface Guide { + slug: string; + title: string; + section: Section; + adminOnly?: boolean; + steps: GuideStep[]; + notes?: string[]; +} + +export const SECTIONS: Section[] = ['Accounts', 'Expenses', 'Projects', 'Donors & donations', 'Reports']; + +export const GUIDES: Guide[] = [ + { + slug: 'sign-in', + title: 'Sign in', + notes: [ + 'First time? Use the temporary password from your welcome email. BRANCH then asks you to pick your own.', + 'The menu only shows pages your role can use.', + 'You only see projects you are staff on. Admins see everything.', + ], + section: 'Accounts', + steps: [ + { + text: 'On the [login page](/login), enter your email and password, then click Login.', + image: '/help/sign-in/login.png', + alt: 'Login page with the Login button highlighted', + }, + { + text: 'Use the menu on the left to move around.', + image: '/help/sign-in/dashboard.png', + alt: 'Dashboard with the menu on the left', + }, + ], + }, + { + slug: 'reset-password', + title: 'Reset your password', + notes: ['No email? Check spam, or click Resend code.'], + section: 'Accounts', + steps: [ + { + text: 'On the [login page](/login), click Forgot password?', + image: '/help/reset-password/forgot-link.png', + alt: 'Login page with Forgot password highlighted', + }, + { + text: 'Enter your email and click Request reset code.', + image: '/help/reset-password/request-code.png', + alt: 'Forgot password page with Request reset code highlighted', + }, + { text: 'Enter the code from your email and a new password.' }, + { text: 'Click Reset Password.' }, + ], + }, + { + slug: 'profile', + title: 'Edit your profile', + section: 'Accounts', + steps: [ + { + text: 'Go to [Profile](/profile) and click Edit Profile.', + image: '/help/profile/edit.png', + alt: 'Profile page with Edit Profile highlighted', + }, + { text: 'Change your details and click Save.' }, + ], + }, + { + slug: 'two-factor', + title: 'Turn on two-factor sign-in', + notes: ['Once it is on, you need a code from the app every time you sign in.'], + section: 'Accounts', + steps: [ + { + text: 'Go to [Profile](/profile) and click Set Up Two-Factor.', + image: '/help/profile/two-factor.png', + alt: 'Profile page with Set Up Two-Factor highlighted', + }, + { text: 'Scan the code with an authenticator app.' }, + { text: 'Enter the 6-digit code and click Verify.' }, + ], + }, + { + slug: 'expenses', + title: 'Submit an expense', + notes: [ + 'An expense only counts toward a project’s spending once an admin approves it.', + 'You can submit expenses only for projects you are staff on.', + 'You can edit or delete your expense while it is Pending or Needs Info. After that, only an admin can change it.', + ], + section: 'Expenses', + steps: [ + { + text: 'Go to [Expenses](/expenses) and click New Expense.', + image: '/help/expenses/new-button.png', + alt: 'Expenses page with New Expense highlighted', + }, + { text: 'Fill in the date, amount, type, project and description.' }, + { + text: 'Upload the receipt as a PDF.', + image: '/help/expenses/form-receipt.png', + alt: 'Expense form with the receipt upload highlighted', + }, + { + text: 'Click Submit For Review.', + image: '/help/expenses/form-submit.png', + alt: 'Expense form with Submit For Review highlighted', + }, + ], + }, + { + slug: 'review-expenses', + title: 'Review an expense', + notes: [ + 'Approving adds the expense to the project’s spending and the Dashboard.', + 'Needs Info sends it back so the submitter can fix it.', + 'Only admins can read admin notes, so tell the submitter directly what is missing.', + ], + section: 'Expenses', + adminOnly: true, + steps: [ + { + text: 'Go to [Expenses](/expenses) and click a Pending expense.', + image: '/help/review-expenses/pending-row.png', + alt: 'Expenses list with a pending expense highlighted', + }, + { + text: 'Choose Approved or Needs Info and add a note.', + image: '/help/review-expenses/decision.png', + alt: 'Review form with Approved highlighted', + }, + { + text: 'Click Save Changes.', + image: '/help/review-expenses/save.png', + alt: 'Review form with Save Changes highlighted', + }, + ], + }, + { + slug: 'projects', + title: 'Add a project', + notes: [ + 'Staff you add can see the project and submit expenses for it.', + 'A project moves to Archived after its end date. Tick “still in progress” if it has none.', + 'Deleting a project also deletes its expenses, donations, staff and reports.', + ], + section: 'Projects', + adminOnly: true, + steps: [ + { + text: 'Go to [Projects](/projects).', + image: '/help/projects/nav-projects.png', + alt: 'Menu with Projects highlighted', + }, + { + text: 'Click Add New Project.', + image: '/help/projects/add-button.png', + alt: 'Projects page with Add New Project highlighted', + }, + { + text: 'Fill in the form and click Save.', + image: '/help/projects/form-save.png', + alt: 'Project form with Save highlighted', + }, + ], + }, + { + slug: 'donors', + title: 'Add a donor', + notes: ['Add the donor before you record their donations.', 'Project directors can view donors but not add them.'], + section: 'Donors & donations', + adminOnly: true, + steps: [ + { + text: 'Go to [Donors](/donors) and click New Donor.', + image: '/help/donors/new-button.png', + alt: 'Donors page with New Donor highlighted', + }, + { + text: 'Fill in the form and click Add Donor.', + image: '/help/donors/form-add.png', + alt: 'Donor form with Add Donor highlighted', + }, + ], + }, + { + slug: 'donations', + title: 'Record a donation', + notes: ['Each donation goes to one project. Split a gift across projects by recording it once per project.'], + section: 'Donors & donations', + adminOnly: true, + steps: [ + { + text: 'Go to [Donations](/donations) and click New Donation.', + image: '/help/donations/new-button.png', + alt: 'Donations page with New Donation highlighted', + }, + { + text: 'Pick the date, donor and project, enter the amount, and click Add Donation.', + image: '/help/donations/form-add.png', + alt: 'Donation form with Add Donation highlighted', + }, + ], + }, + { + slug: 'reports', + title: 'Create a report', + notes: ['Each report covers one project.', 'Already have a report file? Click Upload Report to store it here.'], + section: 'Reports', + adminOnly: true, + steps: [ + { + text: 'Go to [Reports](/reports) and click Generate.', + image: '/help/reports/generate-button.png', + alt: 'Reports page with Generate highlighted', + }, + { + text: 'Name it, pick the type, project and format, and click Generate.', + image: '/help/reports/generate-form.png', + alt: 'Report form with Generate highlighted', + }, + { + text: 'To download a report, click the arrow on its row.', + image: '/help/reports/download.png', + alt: 'Reports list with a download button highlighted', + }, + ], + }, + { + slug: 'accounts', + title: 'Invite a user', + notes: [ + 'Tick Admin only for people who should manage everything.', + 'Everyone else sees only the projects you add them to as staff.', + ], + section: 'Accounts', + adminOnly: true, + steps: [ + { + text: 'Go to [Accounts](/accounts) and click Add User.', + image: '/help/accounts/add-button.png', + alt: 'Accounts page with Add User highlighted', + }, + { + text: 'Enter their email and name, and click Add User. They get an email to sign in.', + image: '/help/accounts/form-add.png', + alt: 'Add User form with Add User highlighted', + }, + ], + }, +]; + +export function guideBySlug(slug: string): Guide | undefined { + return GUIDES.find((g) => g.slug === slug); +} diff --git a/apps/frontend/src/app/help/layout.tsx b/apps/frontend/src/app/help/layout.tsx new file mode 100644 index 00000000..47655faa --- /dev/null +++ b/apps/frontend/src/app/help/layout.tsx @@ -0,0 +1,42 @@ +import Image from 'next/image'; +import Link from 'next/link'; +import { assetPath } from '@/lib/asset'; + +export const metadata = { + title: 'BRANCH Help', + description: 'Step-by-step guides for the BRANCH accounting platform', +}; + +const GREEN = '#2D6138'; + +export default function HelpLayout({ children }: { children: React.ReactNode }) { + return ( +
+
+
+ + + BRANCH Help + + + Open BRANCH + +
+
+
{children}
+
+ ); +} diff --git a/apps/frontend/src/app/help/page.tsx b/apps/frontend/src/app/help/page.tsx new file mode 100644 index 00000000..0662b671 --- /dev/null +++ b/apps/frontend/src/app/help/page.tsx @@ -0,0 +1,38 @@ +import Link from 'next/link'; +import { GUIDES, SECTIONS } from './guides'; +import AdminTag from './AdminTag'; + +export default function HelpIndexPage() { + return ( +
+

How do I…

+ {SECTIONS.map((section) => ( +
+

{section}

+
    + {GUIDES.filter((g) => g.section === section).map((g) => ( +
  • + + {g.title} + {g.adminOnly && } + +
  • + ))} +
+
+ ))} +
+ ); +} diff --git a/apps/frontend/src/app/login/page.tsx b/apps/frontend/src/app/login/page.tsx index 79839207..0136c7e2 100644 --- a/apps/frontend/src/app/login/page.tsx +++ b/apps/frontend/src/app/login/page.tsx @@ -263,6 +263,9 @@ function LoginPageContent() { Forgot password? + + Help + ); diff --git a/apps/frontend/src/app/providers.tsx b/apps/frontend/src/app/providers.tsx index 2dbc6d9e..5d725f80 100644 --- a/apps/frontend/src/app/providers.tsx +++ b/apps/frontend/src/app/providers.tsx @@ -1,6 +1,8 @@ 'use client'; import { useState } from 'react'; +import { usePathname } from 'next/navigation'; +import { classifyRoute } from '@/lib/routes'; import { ChakraProvider, defaultSystem } from '@chakra-ui/react'; import { QueryClientProvider } from '@tanstack/react-query'; import { AuthProvider } from '@/context/AuthContext'; @@ -20,6 +22,10 @@ export function Providers({ children }: { children: React.ReactNode }) { // Per-mount, not module-level: a client shared across renders would leak one // user's cache into the next in tests and in any future SSR pass. const [queryClient] = useState(makeQueryClient); + const pathname = usePathname() ?? '/'; + + // Chakra's Emotion styles break hydration on prerendered open pages. + if (classifyRoute(pathname) === 'open') return <>{children}; return ( diff --git a/apps/frontend/src/lib/api.ts b/apps/frontend/src/lib/api.ts index f68fec48..3134f0c2 100644 --- a/apps/frontend/src/lib/api.ts +++ b/apps/frontend/src/lib/api.ts @@ -10,7 +10,7 @@ const SERVICE_PORTS: Record = { function resolveBaseUrl(path: string): string { const override = process.env.NEXT_PUBLIC_API_BASE_URL; if (override) return override; - const service = path.split('/')[1] ?? ''; + const service = path.split(/[/?]/)[1] ?? ''; const port = SERVICE_PORTS[service] ?? '3006'; return `http://localhost:${port}`; } diff --git a/apps/frontend/src/lib/routes.ts b/apps/frontend/src/lib/routes.ts index 855dcf8e..139d9e40 100644 --- a/apps/frontend/src/lib/routes.ts +++ b/apps/frontend/src/lib/routes.ts @@ -12,7 +12,7 @@ import { type RbacSubject, } from '@branch/rbac'; -export type RouteAccess = 'public' | 'protected' | 'bootstrap'; +export type RouteAccess = 'public' | 'open' | 'protected' | 'bootstrap'; export const LOGIN_PATH = '/login'; @@ -52,6 +52,8 @@ const PUBLIC_PREFIXES = [ '/reset-password', ] as const; +const OPEN_PREFIXES = ['/help'] as const; + /** * Strips the trailing slash and lowercases. * @@ -76,6 +78,7 @@ export function classifyRoute(pathname: string): RouteAccess { if (path === '/') return 'bootstrap'; if (PUBLIC_PREFIXES.some((prefix) => matchesPrefix(path, prefix))) return 'public'; + if (OPEN_PREFIXES.some((prefix) => matchesPrefix(path, prefix))) return 'open'; return 'protected'; } diff --git a/apps/frontend/test/app/HelpGuides.test.ts b/apps/frontend/test/app/HelpGuides.test.ts new file mode 100644 index 00000000..c5832bbc --- /dev/null +++ b/apps/frontend/test/app/HelpGuides.test.ts @@ -0,0 +1,41 @@ +import fs from 'fs'; +import path from 'path'; +import { GUIDES, SECTIONS, guideBySlug } from '@/app/help/guides'; + +const PUBLIC_DIR = path.join(__dirname, '../../public'); + +describe('help guides', () => { + it('have unique slugs', () => { + const slugs = GUIDES.map((g) => g.slug); + expect(new Set(slugs).size).toBe(slugs.length); + }); + + it('each belong to a listed section', () => { + for (const g of GUIDES) expect(SECTIONS).toContain(g.section); + }); + + const images: [string, string, string | undefined][] = GUIDES.flatMap((g) => + g.steps.flatMap((s) => (s.image ? [[g.slug, s.image, s.alt] as [string, string, string | undefined]] : [])), + ); + + it.each(images)( + '%s: %s exists and has alt text', + (_slug, image, alt) => { + expect(fs.existsSync(path.join(PUBLIC_DIR, image))).toBe(true); + expect(alt).toBeTruthy(); + }, + ); + + const links = GUIDES.flatMap((g) => + g.steps.flatMap((s) => [...s.text.matchAll(/\]\(([^)]+)\)/g)].map((m) => [g.slug, m[1]])), + ); + + it.each(links)('%s links to %s, a real page', (_slug, href) => { + expect(fs.existsSync(path.join(__dirname, '../../src/app', href, 'page.tsx'))).toBe(true); + }); + + it('looks guides up by slug', () => { + expect(guideBySlug('sign-in')?.title).toBe('Sign in'); + expect(guideBySlug('nope')).toBeUndefined(); + }); +}); diff --git a/apps/frontend/test/components/AuthGate.test.tsx b/apps/frontend/test/components/AuthGate.test.tsx index da35c4f7..3dfebeaa 100644 --- a/apps/frontend/test/components/AuthGate.test.tsx +++ b/apps/frontend/test/components/AuthGate.test.tsx @@ -121,6 +121,21 @@ describe('AuthGate', () => { }); }); + describe('open routes', () => { + it.each([ + ['an anonymous visitor', () => session()], + ['a signed-in member', () => session({ subject: memberSubject() })], + ['a session still resolving', () => session({ isLoading: true })], + ])('shows /help to %s without redirecting', (_label, make) => { + currentPath = '/help/sign-in'; + authState = make(); + renderGate(); + + expect(screen.getByTestId('protected-content')).toBeInTheDocument(); + expect(mockReplace).not.toHaveBeenCalled(); + }); + }); + describe('admin routes', () => { it('shows a no-access panel to a non-admin instead of redirecting', () => { currentPath = '/reports'; diff --git a/apps/frontend/test/lib/routes.test.ts b/apps/frontend/test/lib/routes.test.ts index 7b4d3acf..ca5dd70a 100644 --- a/apps/frontend/test/lib/routes.test.ts +++ b/apps/frontend/test/lib/routes.test.ts @@ -52,6 +52,14 @@ describe('classifyRoute', () => { it('does not treat a lookalike prefix as public', () => { expect(classifyRoute('/login-help')).toBe('protected'); }); + + it.each(['/help', '/help/', '/help/sign-in', '/help/expenses/'])('treats %s as open', (path) => { + expect(classifyRoute(path)).toBe('open'); + }); + + it('does not treat a lookalike prefix as open', () => { + expect(classifyRoute('/helpdesk')).toBe('protected'); + }); }); /** Would this subject be let into this page by AuthGate? */