From 10ee6b37dc7fb655dbcf74e3c810912920f21e77 Mon Sep 17 00:00:00 2001 From: Tommaso Morganti Date: Sat, 14 Nov 2026 02:27:07 +0100 Subject: [PATCH 1/4] =?UTF-8?q?feat(soci):=20add=20Soci=20=E2=80=BA=20Fees?= =?UTF-8?q?=20and=20the=20Socio=20card=20in=20My=20area?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Soci › Fees (`/dashboard/people/fees`, `soci:read`) lists one fee year's fees as a queue: a Year menu, segments To review / Due / Paid / Exempt with totals, and the To review count next to Fees in the panel. Review (lg dialog, bottom sheet on phones) shows the uploaded receipt in eSign's PDF viewer or as an image, the declared transfer and the last rejection, then Confirm, or Reject with a required reason, warning after 31 December that the socio lapses. Mark as paid records a payment made outside the dashboard (`soci:write`). The register gains a Fee filter, and the socio page a Fees card with every fee year, its receipt, Review and Mark as paid, which can also open a year with no fee yet. My area shows the Socio card for an account that is a socio (`soci.me.*`, `people:self`): number, admission and status; this year's fee with the bank details, a copy button per value and Upload transfer receipt while Due, the review state once uploaded, the last rejection; past fees; and My details, with Complete your details while fields are missing. A socio without a People record sees only the Socio card instead of the "ask HR" empty state. The Receipts page and My area's fee-card mockups, and their mockup data, are removed. `soci.contract.ts` follows the backend's fee and `me` shapes, and the agent-mode fake covers every fee state, a rejection, an exempt year and a fee not open yet; `AGENT_SOCIO` picks the socio My area shows. Closes #156 --- AGENTS.md | 11 +- README.md | 50 ++- docs/design.md | 33 +- docs/people/README.md | 4 + docs/people/fees.md | 7 +- docs/people/permissions.md | 7 +- src/components/shell/nav.ts | 28 +- src/env.ts | 6 + src/features/people/mockup-data.ts | 108 +----- src/features/people/my-area-page.tsx | 57 ++- src/features/people/my-fee-card.tsx | 79 ---- src/features/people/receipts-page.tsx | 255 ------------- src/features/soci/fee-dialogs.tsx | 394 ++++++++++++++++++++ src/features/soci/fee-ui.tsx | 134 +++++++ src/features/soci/fees-page.tsx | 267 ++++++++++++++ src/features/soci/my-socio-card.tsx | 245 +++++++++++++ src/features/soci/my-socio-dialogs.tsx | 263 +++++++++++++ src/features/soci/register-page.tsx | 45 ++- src/features/soci/soci-fees.ts | 50 +++ src/features/soci/soci-format.ts | 8 +- src/features/soci/soci-self.functions.ts | 45 +++ src/features/soci/soci-write.functions.ts | 31 +- src/features/soci/soci.api.server.ts | 83 ++++- src/features/soci/soci.contract.ts | 138 ++++++- src/features/soci/soci.fake.server.ts | 428 ++++++++++++++++++++-- src/features/soci/soci.functions.ts | 30 +- src/features/soci/soci.samples.server.ts | 69 ++++ src/features/soci/socio-page.tsx | 109 +++++- src/routeTree.gen.ts | 42 +-- src/routes/dashboard.tsx | 14 +- src/routes/dashboard/account/me.tsx | 16 +- src/routes/dashboard/people/fees.tsx | 30 ++ src/routes/dashboard/people/receipts.tsx | 8 - tests/people-navigation.test.mjs | 20 +- tests/server-security.test.mjs | 7 +- tests/soci-fees.test.mjs | 59 +++ 36 files changed, 2563 insertions(+), 617 deletions(-) delete mode 100644 src/features/people/my-fee-card.tsx delete mode 100644 src/features/people/receipts-page.tsx create mode 100644 src/features/soci/fee-dialogs.tsx create mode 100644 src/features/soci/fee-ui.tsx create mode 100644 src/features/soci/fees-page.tsx create mode 100644 src/features/soci/my-socio-card.tsx create mode 100644 src/features/soci/my-socio-dialogs.tsx create mode 100644 src/features/soci/soci-fees.ts create mode 100644 src/features/soci/soci-self.functions.ts create mode 100644 src/features/soci/soci.samples.server.ts create mode 100644 src/routes/dashboard/people/fees.tsx delete mode 100644 src/routes/dashboard/people/receipts.tsx create mode 100644 tests/soci-fees.test.mjs diff --git a/AGENTS.md b/AGENTS.md index 79959e6a..e615e7c4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -28,14 +28,17 @@ What the app is and how to run it: [`README.md`](README.md). UI rules: [`docs/de permissions yet can accept one (`peopleInviteMiddleware`: signed in, the token is the proof); the old `/dashboard/account/me?peopleInvite=` links redirect there. `/dashboard` admits `people:self` without `admin:access`; Capo Admin and Team Lead come from the person's own record (`peopleRoles` in the route context) and - only open their sections. Receipts, Census and My area's fee card are unconnected mockups (#138): static sample data - from `mockup-data.ts`, no server functions, disabled actions and a `MockupBanner`, gated by `people:read`, to be rebuilt - in Phase 2 (#144) and Phase 3 (#145). Handoff notes, decisions and the plan: `docs/people/`. + only open their sections. Census is an unconnected mockup (#138): static sample data from `mockup-data.ts`, no server + functions, disabled actions and a `MockupBanner`, gated by `people:read`, to be rebuilt in Phase 3 (#145). Handoff + notes, decisions and the plan: `docs/people/`. - **Soci** (`src/features/soci/`, People's Soci group): the Libro Soci, through `sociApi(context)`, which parses the backend's `soci.*` responses with `soci.contract.ts` (a copy of the backend's) and serves `soci.fake.server.ts` in agent mode. `soci:read` opens Register and the socio pages, `soci:write` admits (a new Microsoft 365 account in Soci, then the record), registers an account already in Soci, edits and changes member numbers, which moved here from Microsoft 365 › - Members. Design: `docs/people/soci.md`. + Members. Soci › Fees reviews uploaded transfer receipts (Confirm, Reject) and marks fees as paid, also from the socio + page. My area's Socio card (`soci.me.*`, `people:self`, `soci-self.functions.ts`) shows the signed-in socio's fee, bank + details, Upload transfer receipt and Complete your details; a socio without a People record sees only that card. + `AGENT_SOCIO` picks the socio My area shows in agent mode. Design: `docs/people/soci.md`. - **Shared UI**: `src/components/shell`, `src/components/primitives`, `src/components/ui`. ## Conventions diff --git a/README.md b/README.md index 8f731634..a57e2704 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ Microsoft 365 has a read-only member directory (`azure:members:read`) and a read adds only that new user to Soci, which gives them the Socio role. **People** keeps one record per volunteer (Overview, Admins, Teams, Linking), plus Telegram › Capo Admin and Account › -My area for volunteers themselves, and the Libro Soci (Soci › Register). The dashboard talks to typed `people.*` and +My area for volunteers themselves, and the Libro Soci (Soci › Register and Fees, and the Socio card in My area). The dashboard talks to typed `people.*` and `soci.*` contracts (`src/features/people/people.contract.ts`, documented in `docs/people/contract.md`, and `src/features/soci/soci.contract.ts`); agent mode serves sample data from `people.fake.server.ts` and -`soci.fake.server.ts`. Receipts and Census are unconnected UI mockups with static sample data, to be rebuilt in Phase 2 -(#144) and Phase 3 (#145). Permissions: `people:read` (which also opens the mockups), `people:write`, `people:appoint`, -`people:self`, which alone admits non-admins to My area and, by the role on their record, Capo Admin or their team, and -`soci:read` and `soci:write` for the register. See `docs/people/README.md` and `docs/people/soci.md`. +`soci.fake.server.ts`. Census is an unconnected UI mockup with static sample data, to be rebuilt in Phase 3 (#145). +Permissions: `people:read` (which also opens the mockup), `people:write`, `people:appoint`, `people:self`, which alone +admits non-admins (soci included) to My area and, by the role on their record, Capo Admin or their team, and +`soci:read` and `soci:write` for the register and fees. See `docs/people/README.md` and `docs/people/soci.md`. Built with TanStack Start (React 19), Vite+, Nitro, Tailwind CSS v4 and shadcn/Base UI. The server is an OIDC BFF: only it holds the IdP access/refresh/ID tokens. Browsers hold an opaque, HttpOnly session cookie; sessions live in a @@ -31,23 +31,24 @@ Signing in as a real user needs a development client registered in the IdP. Set the following runtime variables (the build does not need secrets): -| Variable | Meaning | -| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `APP_URL` | Dashboard's public origin. Required outside development; HTTPS in production. Development defaults to `http://localhost:$PORT` (3001). Used for exact Origin CSRF validation and callback/logout URLs. | -| `BACKEND_URL` | tRPC backend origin; use the in-cluster service address in production. Defaults to `http://localhost:3000` in development. | -| `IDP_URL` | Public IdP origin; defaults to `https://auth.polinetwork.org`. Issuer is `$IDP_URL/api/auth`. Browser redirects retain this public origin. | -| `IDP_INTERNAL_URL` | Optional internal IdP origin, e.g. `http://auth-service.auth.svc.cluster.local:3000`. Rewrites discovery, token, JWKS and revocation transport only; issuer, JWT assertion audiences (public token/revoke endpoints) and browser URLs remain public. | -| `OIDC_CLIENT_ID` | Registered confidential dashboard client, with authorization code and refresh grants, scopes `openid profile email offline_access backend:admin`, and backend resource link. | -| `OIDC_CLIENT_PRIVATE_JWK` | Private signing JWK JSON with `kid` and `alg` (`EdDSA`/Ed25519 or `ES256`/P-256); inject from this service's Key Vault. Register only its public JWKS in the IdP. | -| `OIDC_CLIENT_SECRET` | Alternative `client_secret_basic` credential; set exactly one client credential mode. | -| `BACKEND_RESOURCE` | Backend OAuth resource/audience; defaults to `https://backend.internal.polinetwork.org`. Sent on every authorize, code exchange and refresh request. | -| `REDIS_URL` | Dedicated dashboard Redis connection. Required outside development; development defaults to `redis://localhost:6379`. Never point to shared backend Redis. | -| `SESSION_SECRET` | Independent random secret of at least 32 characters, encrypting the 10-minute state/nonce/PKCE cookie. Rotation invalidates pending login attempts. | -| `AGENT_PERMISSIONS` | Development only. Comma-separated permissions for the agent-mode user (default: all). `people:self` alone previews the restricted People view. | -| `AGENT_PERSON` | Development only. The agent-mode user's People record (default `P-0007`, Direttivo). `P-0098` is a Capo Admin, `P-0034` the IT Team Lead, `P-0115` an IT member; `none` previews a sign-in without a record. Sending an invite prints its link in the dev server's console. | -| `AGENT_MODE` | Fake all-permission user in development only. It has no access token, so the backend refuses its calls; People serves sample data. Production ignores this mode. | -| `PORT` | Local listening port (3001 by default); use a port ≥10000 for agent previews. | -| `TEST_REDIS_URL` | Opt-in disposable Redis for integration tests. Tests create/delete only UUID session keys. | +| Variable | Meaning | +| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `APP_URL` | Dashboard's public origin. Required outside development; HTTPS in production. Development defaults to `http://localhost:$PORT` (3001). Used for exact Origin CSRF validation and callback/logout URLs. | +| `BACKEND_URL` | tRPC backend origin; use the in-cluster service address in production. Defaults to `http://localhost:3000` in development. | +| `IDP_URL` | Public IdP origin; defaults to `https://auth.polinetwork.org`. Issuer is `$IDP_URL/api/auth`. Browser redirects retain this public origin. | +| `IDP_INTERNAL_URL` | Optional internal IdP origin, e.g. `http://auth-service.auth.svc.cluster.local:3000`. Rewrites discovery, token, JWKS and revocation transport only; issuer, JWT assertion audiences (public token/revoke endpoints) and browser URLs remain public. | +| `OIDC_CLIENT_ID` | Registered confidential dashboard client, with authorization code and refresh grants, scopes `openid profile email offline_access backend:admin`, and backend resource link. | +| `OIDC_CLIENT_PRIVATE_JWK` | Private signing JWK JSON with `kid` and `alg` (`EdDSA`/Ed25519 or `ES256`/P-256); inject from this service's Key Vault. Register only its public JWKS in the IdP. | +| `OIDC_CLIENT_SECRET` | Alternative `client_secret_basic` credential; set exactly one client credential mode. | +| `BACKEND_RESOURCE` | Backend OAuth resource/audience; defaults to `https://backend.internal.polinetwork.org`. Sent on every authorize, code exchange and refresh request. | +| `REDIS_URL` | Dedicated dashboard Redis connection. Required outside development; development defaults to `redis://localhost:6379`. Never point to shared backend Redis. | +| `SESSION_SECRET` | Independent random secret of at least 32 characters, encrypting the 10-minute state/nonce/PKCE cookie. Rotation invalidates pending login attempts. | +| `AGENT_PERMISSIONS` | Development only. Comma-separated permissions for the agent-mode user (default: all). `people:self` alone previews the restricted People view. | +| `AGENT_PERSON` | Development only. The agent-mode user's People record (default `P-0007`, Direttivo). `P-0098` is a Capo Admin, `P-0034` the IT Team Lead, `P-0115` an IT member; `none` previews a sign-in without a record. Sending an invite prints its link in the dev server's console. | +| `AGENT_SOCIO` | Development only. The member number of the socio My area shows (default `7`: Due after a rejected receipt); `4` has a receipt to review, `1` has paid, `23` is Due with details to complete, `34` is exempt, `41`'s fee isn't open yet; `none` is not a socio. With `AGENT_PERSON=none`, a socio without a People record. | +| `AGENT_MODE` | Fake all-permission user in development only. It has no access token, so the backend refuses its calls; People serves sample data. Production ignores this mode. | +| `PORT` | Local listening port (3001 by default); use a port ≥10000 for agent previews. | +| `TEST_REDIS_URL` | Opt-in disposable Redis for integration tests. Tests create/delete only UUID session keys. | Before review run `pnpm check`, `pnpm typecheck`, `pnpm test` and `pnpm build`. Run real Redis tests with `TEST_REDIS_URL=redis://127.0.0.1: pnpm test`. The OIDC integration test uses a local fake provider with @@ -102,8 +103,3 @@ Logout deletes the server session, attempts refresh revocation, and redirects to requests require an `Origin` exactly equal to `APP_URL`'s configured origin. Sessions and identity responses are not cacheable. Production cookies are host-only, `Secure`, `HttpOnly`, `SameSite=Lax`; tokens and client keys never appear in browser storage or route loader output. - -People receipt signing reuses PoliNetwork eSign's CIE popup and keeps ZIP download/signed-file upload as an option. -The People backend (including the durable receipt/eSign bridge) is still pending; see -[`docs/people/fees.md`](docs/people/fees.md#integration-with-esign). Agent mode previews the manual receipt flow and -reports the backend requirement for CIE signing. diff --git a/docs/design.md b/docs/design.md index 891d4301..47cb2e18 100644 --- a/docs/design.md +++ b/docs/design.md @@ -93,11 +93,11 @@ the Account page. **Panel** (240px, 200px below 1100px). Rendered only for services with two or more sections (Telegram, Microsoft 365, Web, Reports); WhatsApp, Overview and Account have none. A service may group its sections (`group` on `Section`): the panel draws each group's title, 11px uppercase and subtle, above its first visible section, and the mobile pills only -keep the order. People groups Volunteers (Overview, Admins, Teams, Census, Linking) and Soci (Register, and the Receipts -mockup until Fees replaces it; Deletion pending). A 64px header with the service icon and title, then 38px items: +keep the order. People groups Volunteers (Overview, Admins, Teams, Census, Linking) and Soci (Register, Fees; Deletion +pending). A 64px header with the service icon and title, then 38px items: the current one has a muted fill, an accent icon and a 3px accent bar; on deep pages the parent section keeps the fill -and accent icon without the bar (`data-ancestor`). The only counts are the open reports next to Reports › Open and the documents to sign next to Signatures › To sign, each as a -small accent pill. +and accent icon without the bar (`data-ancestor`). The only counts are the open reports next to Reports › Open, the documents to sign next to Signatures › To sign and +the receipts to review next to Soci › Fees, each as a small accent pill. From 1440px, the panel has a reserved 240px slot even on pages without a panel, so opening a service keeps the content in place. Between 760px and 1439px, the content follows the panel as it opens or closes. @@ -597,15 +597,20 @@ Rules that the templates above don't imply. use `FormDialog` with `tone="danger"`; plain confirmations stay `ConfirmDialog`. - **Soci › Register** (`docs/people/soci.md`): the Libro Soci, one record per admission. Status segments (Active / Ended / All) scope the table; Number leads on desktop, the name on mobile. Alerts above the table list the Soci - group's accounts without a record (with Register) and each kind of mismatch. Rows open the socio page - (`/dashboard/people/soci/$number`), a deep page with Edit and Change number. -- **Fees and receipts** (`docs/people/fees.md`): the register's first row action follows the fee (Review receipt, - Send reminder, or an empty slot); its header keeps one outline action (Send reminders), with Export register as a boxed - icon. People › Receipts is a queue with the pipeline as segments and the officer's to-sign count in the panel. - Sign with CIE uses the shared eSign flow; Download to sign and Upload signed stay in its signing-options menu. - Review receipt is an `lg` `FormDialog` whose Reject switches it to a required reason (`tone="danger"`, Back on - the left). The fee status shows once per page: the record and My area say it in their fee card, not in Member or My - roles. Amounts are `formatCents` ("€10.00") with tabular numbers. + group's accounts without a record (with Register) and each kind of mismatch, and a Fee filter menu narrows by this + year's fee. Rows open the socio page (`/dashboard/people/soci/$number`), a deep page with Edit, Change number and a + Fees card (one row per fee year, View receipt or Review, Mark as paid; the card's Mark as paid also opens a year + that has no fee yet). +- **Soci › Fees** (`docs/people/soci.md`): a queue for one fee year (the Year menu, `?year=`), receipts to review first: + segments To review / Due / Paid / Exempt with totals, and the To review count in the panel. The row's first action is + Review for a receipt to review, an empty slot otherwise, then Mark as paid. Review is an `lg` `FormDialog` with the + receipt (eSign's `PdfViewer` in its compact mode, or the image), the declared transfer and the last rejection; + Reject switches it to a required reason with three one-click starts (`tone="danger"`, Back on the left), and after + 31 December warns that the socio lapses. Amounts are `formatEuro` ("€5.00") with tabular numbers. +- **Socio card** (My area): the membership, this year's fee (bank details with a copy button per value and Upload + transfer receipt while Due, the review state and Replace receipt once uploaded, the last rejection in a danger + alert), past fees, and My details with Complete your details while fields are missing. A socio without a People + record sees only the Socio card. - **Admins**: Groups, Capo Admin of reference, Member and Census never hide; the rest follow the table width. The four quick filters scroll sideways on phones. - **Teams**: index cards then all members; a Team Lead without `people:read` sees only their team, as the section @@ -618,4 +623,4 @@ Rules that the templates above don't imply. - **Capo Admin** (Telegram) and **My area** (Account): self-service pages that open with `people:self` and a role on the person's own record; no personal emails of others, only phone, Telegram and PoliNetwork addresses. -Receipt previews use eSign’s `PdfViewer` in its compact mode. Receipt requests in Signatures show their receipt reference; their signature boxes are fixed. +Transfer receipt previews use eSign’s `PdfViewer` in its compact mode. diff --git a/docs/people/README.md b/docs/people/README.md index ff1c5aec..ff22821f 100644 --- a/docs/people/README.md +++ b/docs/people/README.md @@ -10,6 +10,10 @@ Everything an agent needs to build, or continue building, the People area of the > this you?", Ask to be added) and Telegram group tracking (group columns, join requests) are removed. The permissions > `people:members:read`, `people:members:write`, `people:fees:write` and `people:receipts:sign` are gone; the mockups > open with `people:read`. Sections below that describe these features describe the mockup or the removed design. +> +> **Phase 2 (#144)** rebuilt Soci on the `soci.*` procedures ([`soci.md`](soci.md)): Soci › Register and Admit socio +> (#155), then Soci › Fees and My area's Socio card (#156), which replaced the Receipts and fee-card mockups. Only the +> census remains a mockup. | File | What it is | | ------------------------------ | ---------------------------------------------------------------------------------------- | diff --git a/docs/people/fees.md b/docs/people/fees.md index 8acd9917..41948024 100644 --- a/docs/people/fees.md +++ b/docs/people/fees.md @@ -1,10 +1,9 @@ # People area: fees and receipts > [!IMPORTANT] -> **This describes an unconnected mockup.** Since #138, People › Receipts and My area's fee card render static -> sample data (the Member register mockup was replaced by Soci › Register in #155), make no backend call and disable every action. The procedures, permissions -> (`people:fees:write`, `people:receipts:sign`) and the eSign receipt bridge below are removed. Soci, fees and receipts -> will be rebuilt from scratch on Microsoft 365 members in Phase 2 (#144); this file stays as the design reference. +> **This describes a removed design.** Since #138 People › Receipts and My area's fee card were unconnected mockups; +> #156 replaced them with Soci › Fees and the Socio card. The procedures, permissions (`people:fees:write`, +> `people:receipts:sign`) and the eSign receipt bridge below are removed; this file stays only as a reference. > > **Superseded by [`soci.md`](soci.md)** (9 November 2026): Phase 2 issues no receipts, uses the Regolamento's rules > (€5, renewals until 31 December) and the `soci:*` permissions. diff --git a/docs/people/permissions.md b/docs/people/permissions.md index 9786c1e8..bb61c232 100644 --- a/docs/people/permissions.md +++ b/docs/people/permissions.md @@ -12,9 +12,10 @@ count only once PoliNetwork Auth holds them (the record is linked and the role a | Capo Admin: `people:self`, P-0003 | My area + Telegram › Capo Admin | Read-only list of the admins who have them as Capo Admin of reference | | `people:read` | People overview, person records, Admins, Teams, Linking | Read contacts and notes; no editing, linking or appointments | | `people:link` | Link account and Unlink on records and Overview | Search the IdP's accounts, link one by hand, unlink (Auth revokes the roles first) | -| `soci:read` | Soci › Register, socio pages | Read the Libro Soci, its activity and the Soci group's accounts without a record | -| `soci:write` | Same | Admit socio, Register existing socio, Edit, Change number | -| `people:read` (mockups) | Receipts, Census; the fee card in My area | None: unconnected mockups with sample data (#138), to be rebuilt in Phase 2 (#144) and Phase 3 (#145) | +| `soci:read` | Soci › Register, Fees, socio pages | Read the Libro Soci, its activity, fees and uploaded receipts, and the Soci group's accounts without a record | +| `soci:write` | Same | Admit socio, Register existing socio, Edit, Change number, Confirm or Reject a receipt, Mark as paid | +| Socio: `people:self`, a Soci account | My area's Socio card | Upload transfer receipt, Complete your details (empty fields only) | +| `people:read` (mockup) | Census | None: an unconnected mockup with sample data (#138), to be rebuilt in Phase 3 (#145) | | Master Admin: all explicit permissions, P-0007 | All permitted sections | All People mutations | `people:write` enables record, admin-role, team and invite mutations on readable pages; diff --git a/src/components/shell/nav.ts b/src/components/shell/nav.ts index beb7b16a..ef982564 100644 --- a/src/components/shell/nav.ts +++ b/src/components/shell/nav.ts @@ -109,7 +109,7 @@ export type PageMatch = | { kind: "people-person"; personId: string } | { kind: "people-soci" } | { kind: "people-socio"; number: number } - | { kind: "people-receipts" } + | { kind: "people-fees" } | { kind: "people-admins" } | { kind: "people-teams" } | { kind: "people-team"; teamId: string } @@ -234,15 +234,14 @@ const people: Service = { group: "Soci", searchPlaceholder: "Search by name, number, mailbox or CF…", }, - // Receipts is an unconnected mockup, to be replaced by Fees (Phase 2, #144). { - id: "receipts", - title: "Receipts", + id: "fees", + title: "Fees", icon: Receipt, - path: "/dashboard/people/receipts", - permission: "people:read", + path: "/dashboard/people/fees", + permission: "soci:read", group: "Soci", - searchPlaceholder: "Search by name or receipt number…", + searchPlaceholder: "Search by name, number or mailbox…", }, ], } @@ -502,7 +501,7 @@ export function matchPath(pathname: string): PageMatch { if (second === undefined) return { kind: "people-overview" } if (third === undefined) { if (second === "soci") return { kind: "people-soci" } - if (second === "receipts") return { kind: "people-receipts" } + if (second === "fees") return { kind: "people-fees" } if (second === "admins") return { kind: "people-admins" } if (second === "teams") return { kind: "people-teams" } if (second === "census") return { kind: "people-census" } @@ -579,7 +578,7 @@ export function serviceFor(match: PageMatch): Service { case "people-person": case "people-soci": case "people-socio": - case "people-receipts": + case "people-fees": case "people-admins": case "people-teams": case "people-team": @@ -637,8 +636,8 @@ export function sectionFor(match: PageMatch): Section | null { case "people-soci": case "people-socio": return section(people, "soci") - case "people-receipts": - return section(people, "receipts") + case "people-fees": + return section(people, "fees") case "people-admins": return section(people, "admins") case "people-teams": @@ -720,10 +719,14 @@ export function documentTitle(match: PageMatch): string { return current ? `${current.title} - ${service.title} - PoliNetwork Admin` : `${service.title} - PoliNetwork Admin` } -/** Counts that mark a service and one of its sections: open reports, documents waiting for the user's signature. */ +/** + * Counts that mark a service or one of its sections: open reports, documents waiting for the user's signature, and + * transfer receipts waiting for review in this fee year. + */ export type PendingCounts = { reports: Promise signatures: Promise + fees: Promise } const NO_COUNT: Promise = Promise.resolve(null) @@ -746,5 +749,6 @@ export function sectionPending( ): Promise { if (serviceId === "reports" && sectionId === "open") return pending.reports if (serviceId === "esign" && sectionId === "inbox") return pending.signatures + if (serviceId === "people" && sectionId === "fees") return pending.fees return NO_COUNT } diff --git a/src/env.ts b/src/env.ts index 1040ed07..c33a1e86 100644 --- a/src/env.ts +++ b/src/env.ts @@ -13,6 +13,12 @@ export const env = createEnv({ AGENT_PERMISSIONS: z.string().optional(), /** Development only: the agent-mode user's person record in the People sample data. */ AGENT_PERSON: z.string().default("P-0007"), + /** + * Development only: the member number of the socio the agent-mode user is in My area, or `none`. In the sample + * register 7 has a rejected receipt to upload again, 4 one waiting for review, 1 has paid, 34 is exempt and 41's + * fee isn't open yet. + */ + AGENT_SOCIO: z.string().default("7"), NODE_ENV: z.enum(["development", "test", "production"]), BACKEND_URL: z.url(), }, diff --git a/src/features/people/mockup-data.ts b/src/features/people/mockup-data.ts index f54fc12e..f67e4cfe 100644 --- a/src/features/people/mockup-data.ts +++ b/src/features/people/mockup-data.ts @@ -1,41 +1,14 @@ import type { StatusTone } from "@/components/primitives" /** - * Static sample data for the People pages kept as unconnected UI mockups: fees, receipts and the census. Nothing here - * comes from or goes to the backend, and none of it is part of the People contract (`people.contract.ts`). Phase 2 - * (#144) rebuilds fees on the Soci register; Phase 3 (#145) rebuilds the census. + * Static sample data for the People page kept as an unconnected UI mockup: the census. Nothing here comes from or goes + * to the backend, and none of it is part of the People contract (`people.contract.ts`). Phase 3 (#145) rebuilds it. */ type Tone = { label: string; tone: StatusTone } -export const MOCK_FEE_STATUSES = ["due", "receipt", "paid", "unpaid"] as const -export const MOCK_RECEIPT_STATUSES = ["toSign", "signed", "sent", "failed", "voided"] as const - -export type MockFeeStatus = (typeof MOCK_FEE_STATUSES)[number] -export type MockReceiptStatus = (typeof MOCK_RECEIPT_STATUSES)[number] -export type MockSigner = "president" | "vicePresident" export type MockCensusAnswer = "continues" | "leaving" -export const MOCK_FEE_STATUS = { - paid: { label: "Paid", tone: "success" }, - receipt: { label: "Receipt uploaded", tone: "brand" }, - due: { label: "Due", tone: "warning" }, - unpaid: { label: "Unpaid", tone: "danger" }, -} satisfies Record - -export const MOCK_RECEIPT_STATUS = { - toSign: { label: "To sign", tone: "warning" }, - signed: { label: "Signed", tone: "brand" }, - sent: { label: "Sent", tone: "success" }, - failed: { label: "Send failed", tone: "danger" }, - voided: { label: "Voided", tone: "neutral" }, -} satisfies Record - -export const MOCK_SIGNER_LABEL = { president: "President", vicePresident: "Vice-president" } satisfies Record< - MockSigner, - string -> - export const MOCK_CENSUS_ANSWER = { continues: { label: "Continues", tone: "success" }, leaving: { label: "Leaving", tone: "warning" }, @@ -45,83 +18,6 @@ export const MOCK_NO_ANSWER = { label: "No answer", tone: "neutral" } satisfies export const MOCK_CENSUS_SOURCE = { forms: "Imported from Forms", dashboard: "Dashboard" } as const -/** "€10.00": the mock amounts are integer cents. */ -export function formatCents(cents: number) { - return new Intl.NumberFormat("en-GB", { style: "currency", currency: "EUR" }).format(cents / 100) -} - -/** The fee year every mockup shows. */ -export const MOCK_FEE_YEAR = "2026/27" - -export type MockReceipt = { - id: string - /** The fee year's first calendar year and a sequence never reused. */ - number: string - name: string - memberNumber: string - amountCents: number - issuedOn: string - status: MockReceiptStatus - signer: MockSigner - signedBy: string | null -} - -export const MOCK_OFFICERS = { president: "Giulia Rossi", vicePresident: "Marco Bianchi" } satisfies Record< - MockSigner, - string -> - -export const MOCK_RECEIPTS: readonly MockReceipt[] = [ - receipt("2026/001", "Anna Bruno", "0034", "2026-09-15", "sent", "president"), - receipt("2026/002", "Davide Romano", "0021", "2026-09-22", "sent", "president"), - receipt("2026/003", "Giulia Rossi", "0001", "2026-09-30", "sent", "vicePresident"), - receipt("2026/004", "Elena Ricci", "0023", "2026-10-06", "voided", "president"), - receipt("2026/005", "Sara Colombo", "0007", "2026-10-12", "failed", "president"), - receipt("2026/006", "Matteo Gallo", "0041", "2026-10-20", "signed", "president"), - receipt("2026/007", "Marco Bianchi", "0004", "2026-10-27", "toSign", "president"), -] - -function receipt( - number: string, - name: string, - memberNumber: string, - issuedOn: string, - status: MockReceiptStatus, - signer: MockSigner -): MockReceipt { - const signed = status === "signed" || status === "sent" || status === "failed" - return { - id: `mock-${number}`, - number, - name, - memberNumber, - amountCents: 1000, - issuedOn, - status, - signer, - signedBy: signed ? MOCK_OFFICERS[signer] : null, - } -} - -export type MockMyFee = { - year: string - status: MockFeeStatus - amountCents: number - dueOn: string - instructions: { beneficiary: string; iban: string; reference: string } - receipts: { id: string; number: string; year: string; sentOn: string }[] -} - -/** My area's fee card: a current member who still owes this year's fee, and last year's receipt. */ -export const MOCK_MY_FEE = { - year: MOCK_FEE_YEAR, - status: "due", - amountCents: 1000, - dueOn: "2026-12-31", - instructions: { beneficiary: "PoliNetwork APS", iban: "IT00 X000 0000 0000 0000 0000 000", reference: "Quota 0007" }, - receipts: [{ id: "mock-2025/019", number: "2025/019", year: "2025/26", sentOn: "2025-10-21" }], -} satisfies MockMyFee - export type MockCampaign = { id: string year: string diff --git a/src/features/people/my-area-page.tsx b/src/features/people/my-area-page.tsx index a6eed237..9919d97a 100644 --- a/src/features/people/my-area-page.tsx +++ b/src/features/people/my-area-page.tsx @@ -7,6 +7,7 @@ import { type DataTableColumn, EmptyState, IconButton, + InlineAlert, type KeyValueItem, KeyValueList, PlatformGlyph, @@ -14,9 +15,11 @@ import { SectionHeading, Unset, } from "@/components/primitives" -import { PageBar, PageContent, useCan } from "@/components/shell" +import { PageBar, PageContent } from "@/components/shell" +import { MySocioCards } from "@/features/soci/my-socio-card" +import { formatMemberNumber } from "@/features/soci/soci-format" +import type { Me } from "@/features/soci/soci.contract" -import { MyFeeCard } from "./my-fee-card" import { assignmentLabel, formatDay, @@ -32,10 +35,46 @@ import type { MyArea } from "./people.contract" type Linked = Extract -/** Account › My area: what the signed-in person's record says. */ -export function MyAreaPage({ area }: { area: MyArea }) { - if (area.state === "none") return - return +/** The signed-in account's socio record; `null` when it isn't a socio's, `"error"` when it couldn't be read. */ +export type MySocio = Me | null | "error" + +/** + * Account › My area: what the signed-in person's People record says, and their Socio card when their Microsoft 365 + * account is a socio's. A socio without a People record sees only the Socio card. + */ +export function MyAreaPage({ area, socio }: { area: MyArea; socio: MySocio }) { + if (area.state === "none") return socio === null ? : + return +} + +function SocioSection({ socio }: { socio: Exclude }) { + if (socio === "error") + return ( + + Your socio record couldn't be loaded, so your fee and details aren't shown. Reload the page to try again. + + ) + return +} + +function SocioOnlyView({ socio }: { socio: Exclude }) { + return ( + <> + + {socio.details.firstName} {socio.details.lastName} ·{" "} + {formatMemberNumber(socio.number)} + + ) + } + /> + + + + + ) } function NoRecordView() { @@ -53,10 +92,8 @@ function NoRecordView() { ) } -function LinkedView({ area }: { area: Linked }) { +function LinkedView({ area, socio }: { area: Linked; socio: MySocio }) { const { person, contacts, roster } = area - // The fee card is an unconnected mockup (Phase 2, #144), shown only to People readers. - const canRead = useCan("people:read") const roles = openAssignments(person) const name = personName(person) @@ -131,7 +168,7 @@ function LinkedView({ area }: { area: Linked }) {
- {canRead ? : null} + {socio === null ? null : }
diff --git a/src/features/people/my-fee-card.tsx b/src/features/people/my-fee-card.tsx deleted file mode 100644 index f31ab090..00000000 --- a/src/features/people/my-fee-card.tsx +++ /dev/null @@ -1,79 +0,0 @@ -import { FileDown, FileText, Upload } from "lucide-react" - -import { buttonMotion, KeyValueList, SectionCard } from "@/components/primitives" -import { Button } from "@/components/ui/button" -import { cn } from "@/lib/utils" - -import { MockupBanner } from "./mockup-banner" -import { formatCents, MOCK_FEE_STATUS, MOCK_MY_FEE } from "./mockup-data" -import { formatDay } from "./people-format" -import { Row, RowIcon, Rows, StateBadge, SubHeading } from "./people-ui" - -/** - * My area's fee card, as an unconnected mockup with sample data (Phase 2, #144): how a member would pay and upload - * the bank's transfer receipt, and download their signed receipts. Nothing is read or sent; every action is disabled. - */ -export function MyFeeCard() { - const fee = MOCK_MY_FEE - return ( - } - padding="flush" - > -
- -

- Pay {formatCents(fee.amountCents)} by bank transfer by{" "} - {formatDay(fee.dueOn)}, then upload the bank’s transfer receipt. -

-
- {fee.instructions.iban} }, - { key: "Amount", value: {formatCents(fee.amountCents)} }, - { key: "Reference", value: {fee.instructions.reference} }, - ]} - /> -
-
- -
-
- - Your receipts - {fee.receipts.map((receipt) => ( - } - title={ - <> - {receipt.number} - - Fee {receipt.year} - - - } - meta={`Sent ${formatDay(receipt.sentOn)}`} - end={ - - } - /> - ))} - -
- ) -} diff --git a/src/features/people/receipts-page.tsx b/src/features/people/receipts-page.tsx deleted file mode 100644 index da785a66..00000000 --- a/src/features/people/receipts-page.tsx +++ /dev/null @@ -1,255 +0,0 @@ -import { Ban, FileArchive, FileDown, Receipt as ReceiptIcon, RotateCw, Search, Upload } from "lucide-react" -import { useDeferredValue, useState } from "react" - -import { - buttonMotion, - Chip, - DataTable, - type DataTableColumn, - EmptyState, - IconButton, - RowActions, - SegmentedControl, -} from "@/components/primitives" -import { Count, PageBar, PageContent, Toolbar } from "@/components/shell" -import { Button } from "@/components/ui/button" -import { cn } from "@/lib/utils" - -import { MockupBanner } from "./mockup-banner" -import { - formatCents, - MOCK_FEE_YEAR, - MOCK_RECEIPT_STATUS, - MOCK_RECEIPT_STATUSES, - MOCK_RECEIPTS, - MOCK_SIGNER_LABEL, - type MockReceipt, - type MockReceiptStatus, -} from "./mockup-data" -import { formatDay } from "./people-format" -import { MonoChip, PersonCell, StateBadge } from "./people-ui" - -type Scope = "all" | MockReceiptStatus - -function matchesQuery(receipt: MockReceipt, query: string) { - if (!query) return true - return [receipt.number, receipt.name, receipt.memberNumber].some((value) => value.toLocaleLowerCase().includes(query)) -} - -const columns: DataTableColumn[] = [ - { - id: "number", - label: "Receipt", - width: 116, - mobile: "hidden", - cell: (receipt) => ( - - {receipt.number} - - ), - }, - { - id: "member", - label: "Member", - fill: true, - minWidth: 200, - mobile: "main", - cell: (receipt) => ( - <> - - {/* Mobile cards: number, status and amount on one labelled line. */} - - {receipt.number} - - {formatCents(receipt.amountCents)} - - - ), - }, - { - id: "amount", - label: "Amount", - width: 96, - align: "end", - priority: 3, - mobile: "hidden", - cell: (receipt) => {formatCents(receipt.amountCents)}, - }, - { - id: "issued", - label: "Issued on", - width: 124, - priority: 2, - mobile: "hidden", - cell: (receipt) => {formatDay(receipt.issuedOn)}, - }, - { - id: "signer", - label: "Signer", - width: 248, - priority: 4, - mobile: "hidden", - cell: (receipt) => - receipt.status === "voided" ? null : ( - - {receipt.signedBy ?? MOCK_SIGNER_LABEL[receipt.signer]} - {receipt.signer === "vicePresident" ? {MOCK_SIGNER_LABEL.vicePresident} : null} - - ), - }, - { - id: "status", - label: "Status", - width: 136, - mobile: "hidden", - cell: (receipt) => , - }, -] - -const SCOPE_EMPTY = { - all: { title: "No receipts yet", text: "The mockup has no sample receipts." }, - toSign: { title: "No receipts to sign", text: "New receipts wait here for the President's signature." }, - signed: { title: "No receipts waiting to be emailed", text: "Signed receipts are emailed to the member right away." }, - sent: { title: "No receipts sent yet", text: "Receipts appear here once they're signed and emailed." }, - failed: { title: "No failed emails", text: "When a receipt can't be emailed, it waits here for a retry." }, - voided: { title: "No voided receipts", text: "Voided receipts keep their number and stay here." }, -} satisfies Record - -/** - * People › Receipts: an unconnected mockup of one fee year's receipts, To sign → Signed → Sent, kept to be reworked in - * Phase 2 (#144). It reads nothing from the backend and every action is disabled. - */ -export function ReceiptsPage() { - const receipts = MOCK_RECEIPTS - const [scope, setScope] = useState("all") - const [query, setQuery] = useState("") - const deferredQuery = useDeferredValue(query.trim().toLocaleLowerCase()) - const [pageNumber, setPage] = useState(1) - const [pageSize, setPageSize] = useState(20) - - const byStatus = (status: MockReceiptStatus) => receipts.filter((receipt) => receipt.status === status).length - const inScope = scope === "all" ? receipts : receipts.filter((receipt) => receipt.status === scope) - const filtered = inScope.filter((receipt) => matchesQuery(receipt, deferredQuery)) - const rows = filtered.slice((pageNumber - 1) * pageSize, pageNumber * pageSize) - const narrowed = deferredQuery !== "" - - return ( - <> - - Fee year {MOCK_FEE_YEAR} - - } - right={ - <> - - - - } - left={ - { - setQuery(value) - setPage(1) - }, - placeholder: "Search by name or receipt number…", - }} - filters={ - - label="Receipt status" - items={[ - { value: "all", label: "All", count: receipts.length }, - ...MOCK_RECEIPT_STATUSES.map((status) => ({ - value: status, - label: MOCK_RECEIPT_STATUS[status].label, - count: byStatus(status), - })), - ]} - value={scope} - onValueChange={(next) => { - setScope(next) - setPage(1) - }} - /> - } - count={ - narrowed ? ( - - ) : undefined - } - /> - } - /> - -
- - receipt.id} - rowLabel={(receipt) => `${receipt.number}, ${receipt.name}`} - rowProps={(receipt) => ({ - className: receipt.status === "voided" ? "text-(--pn-fg-muted)" : undefined, - })} - actions={(receipt) => ( - - {receipt.status === "failed" ? ( - - ) : ( - - )} - - - - )} - actionsWidth={132} - pagination={{ - page: pageNumber, - pageSize, - total: filtered.length, - onPage: setPage, - onPageSize: (size) => { - setPageSize(size) - setPage(1) - }, - }} - empty={ - narrowed ? ( - setQuery("")}> - Clear search - - } - /> - ) : ( - - ) - } - /> -
-
- - ) -} diff --git a/src/features/soci/fee-dialogs.tsx b/src/features/soci/fee-dialogs.tsx new file mode 100644 index 00000000..6b13c607 --- /dev/null +++ b/src/features/soci/fee-dialogs.tsx @@ -0,0 +1,394 @@ +import { useServerFn } from "@tanstack/react-start" +import { ArrowLeft, Ban } from "lucide-react" +import { useState } from "react" + +import { + buttonMotion, + DateField, + dialogFooter, + dialogFooterButton, + fieldControl, + fieldHintId, + FieldCounter, + FormDialog, + FormField, + InlineAlert, + KeyValueList, + SegmentedControl, + SelectField, +} from "@/components/primitives" +import { Button } from "@/components/ui/button" +import { Textarea } from "@/components/ui/textarea" +import { formatDay, todayIso } from "@/features/people/people-format" +import { errorMessage, useRefreshAfter } from "@/features/people/people-hooks" +import { formatDateTime } from "@/lib/format" +import { cn } from "@/lib/utils" + +import { amountMismatch, ReceiptPreview } from "./fee-ui" +import { feeYearLabel, feeYearOf, formatEuro, pastDeadline, renewalDeadline } from "./soci-fees" +import { formatMemberNumber, socioName } from "./soci-format" +import { confirmFee, markFeePaid, rejectFee } from "./soci-write.functions" +import type { Fee } from "./soci.contract" + +type DialogProps = { open: boolean; onOpenChange: (open: boolean) => void } + +/** Who a fee belongs to, as the Fees list and the socio page both have it. */ +export type FeeSocio = { number: number; firstName: string; lastName: string; mailbox: string } + +const REASON_MAX = 500 + +/** One-click starts for the rejection reason, which the socio reads in the email and in My area. */ +const REASON_STARTS = [ + "The amount doesn't match the fee.", + "The payment reference is missing.", + "The file isn't readable: upload the bank's PDF receipt.", +] as const + +/** + * Review: the uploaded receipt, the declared transfer and the last rejection, then Confirm, or Reject with a required + * reason. Reject switches the dialog to the reason (danger, Back on the left). After the renewal deadline, rejecting + * warns that the socio lapses at the next daily run unless they pay. + */ +export function ReviewFeeDialog({ open, onOpenChange, socio, fee }: DialogProps & { socio: FeeSocio; fee: Fee }) { + const confirm = useServerFn(confirmFee) + const reject = useServerFn(rejectFee) + const refresh = useRefreshAfter() + const [rejecting, setRejecting] = useState(false) + const [reason, setReason] = useState("") + const [submitted, setSubmitted] = useState(false) + const upload = fee.upload + const name = socioName(socio) + const late = pastDeadline(fee.year, todayIso()) + const reasonError = submitted && !reason.trim() ? "Say why, so the socio can fix it." : undefined + + async function submit() { + if (!upload) return + const ref = { number: socio.number, year: fee.year, fileId: upload.fileId } + if (!rejecting) { + try { + await confirm({ data: ref }) + } catch (caught) { + console.error(caught) + throw new Error(errorMessage(caught, "Couldn't confirm the receipt. Try again."), { cause: caught }) + } + onOpenChange(false) + await refresh(`${name}'s ${fee.label} fee is paid.`) + return + } + setSubmitted(true) + if (!reason.trim()) return + try { + await reject({ data: { ...ref, reason: reason.trim() } }) + } catch (caught) { + console.error(caught) + throw new Error(errorMessage(caught, "Couldn't reject the receipt. Try again."), { cause: caught }) + } + onOpenChange(false) + await refresh(`Receipt rejected. ${name} gets the reason by email.`) + } + + return ( + { + setRejecting(false) + setSubmitted(false) + }} + > + + Back + + ) : ( + + ) + } + notice={ + rejecting && late ? ( + + The renewal deadline, {formatDay(renewalDeadline(fee.year))}, has passed: once rejected, the fee is Due + again and {name} lapses at the next daily run unless it's paid. + + ) : undefined + } + > + {!upload ? ( + There's no receipt to review for this fee. + ) : rejecting ? ( +
+ +