feat(invitations): add the candidate invitation inbox with C4 acceptance and decline

This commit is contained in:
shira committed 2026-10-09 20:30:35 +03:00
1 parent 12a7213d4a
commit a856066316
54 files changed
+3897 -136

No files matched your search

+17 -3
View File
@@ -2,10 +2,10 @@
[Русский](README.md) | English
A React and TypeScript SPA built with Vite and organized using FSD. Registration, email confirmation, sign-in, consent settings, the candidate profile and questionnaire, candidate assessment, company profiles, employer needs, and support cases use the API. A manual assessment request creates a support case and displays its current state; the screen does not present it as an assessment result. The result history and result page use the API. Candidate search, the employer's read of an anonymous card, and sending an invitation from a search result use the API; the company's invitation list and the candidate's invitation screens remain placeholders.
A React and TypeScript SPA built with Vite and organized using FSD. Registration, email confirmation, sign-in, consent settings, the candidate profile and questionnaire, candidate assessment, company profiles, employer needs, and support cases use the API. A manual assessment request creates a support case and displays its current state; the screen does not present it as an assessment result. The result history and result page use the API. Candidate search, the employer's read of an anonymous card, and sending an invitation from a search result use the API. The candidate reads incoming invitations, accepts them with a choice of contacts, and declines them; the company's invitation list remains a placeholder.
- `src/app/` starts the application: the route tree (`router/`), the query client (`providers/`), global styles, and the route error page.
- `src/pages/` holds public pages, sign-in and registration, candidate profile and questionnaire, assessment results, company and employer needs pages, candidate search, the invitation to a candidate, support cases, technical status, and remaining placeholders.
- `src/pages/` holds public pages, sign-in and registration, candidate profile and questionnaire, assessment results, company and employer needs pages, candidate search, the invitation to a candidate, the candidate's incoming invitations, support cases, technical status, and remaining placeholders.
- `src/widgets/` holds shells: `public-shell`, `candidate-shell`, `employer-shell`, the result history widget `assessment-history`, the search result widget `match-list`, the invitation preview `invitation-preview`, and the technical `system-status` widget.
- `src/entities/` holds entity models, including `need` (see [Need entity](#need-entity)), `company`, and `invitation`; `src/features/` holds user actions and forms.
- `src/shared/ui/` holds design tokens, fonts, logos, and primitives; `src/shared/config/` holds route paths; `src/shared/api/` holds the API client with generated endpoints, Zod schemas, and MSW mocks.
@@ -20,7 +20,7 @@ From the repository root, `make -C frontend dev` starts development and `make -C
| Group | Paths | Shell |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| Public | `/`, `/login`, `/register`, `/verify-email`, `/support`, `/status` | `PublicShell` |
| Candidate | `/candidate` with `onboarding`, `profile`, `questionnaire`, `assessment`, `results`, `results/:attemptId`, `invitations`, `privacy`, `support/cases`, `support/cases/new`, `support/cases/manual-assessment`, and `support/cases/:caseId` | `CandidateShell` |
| Candidate | `/candidate` with `onboarding`, `profile`, `questionnaire`, `assessment`, `results`, `results/:attemptId`, `invitations`, `invitations/:invitationId`, `privacy`, `support/cases`, `support/cases/new`, `support/cases/manual-assessment`, and `support/cases/:caseId` | `CandidateShell` |
| Employer | `/employer` redirects to `/employer/company`; `/employer/company`, `/employer/needs`, `/employer/needs/new`, `/employer/needs/:needId`, `/employer/candidates`, `/employer/invitations/new`, `/employer/support/cases`, `/employer/support/cases/new`, `/employer/support/cases/:caseId` | `EmployerShell` |
Each group has its own not-found page. Paths are defined once in `shared/config/paths.ts`. The router uses React Router data APIs (`createBrowserRouter`): a route-level error boundary, loader redirects, and later `lazy` code splitting for cabinets. Loaders do not fetch data; server data belongs to TanStack Query. Cabinet boundaries read the current session and direct guests to sign-in. `/support` sends a signed-in user to the support area for their account or to sign-in. Need pages pass `organization_id` in the query string, but the client checks the current owner directory and the server authorizes every request.
@@ -150,6 +150,20 @@ Checks. Unit tests cover parsing and labels (`entities/match`), the request buil
Checks. Unit tests cover the range rules (`entities/invitation`), draft validation and pointer mapping, the send command over MSW (keys, a retry after a lost create and a lost send response, 400 with fields, a draft update, 412), and the preview and page markup (owner access, an empty address). The Playwright suite `e2e/invitation-compose.spec.ts` runs on the real backend in `make -C deploy test-e2e-registration`: five synthetic candidates publish the same card, the owner finds them with a search, opens the invitation from the result, fills [100000; 140000] net and a package, and checks the preview against every term; without the communication method a field error shows, no request is sent, and the candidates' inboxes stay empty. Then the send is slowed down and its first response lost, a second click during the request starts nothing, and the retry uses the same key; the result is one invitation in one inbox (`GET /me/invitations`) with the deadline the screen shows, also after a reload. A 403 for a recruiter is not checked in the browser, since the stand cannot grant that role; the screen for a non-owner role is covered by a unit test.
## Candidate incoming invitations
`/candidate/invitations` (`pages/candidate-invitations`) shows the incoming invitations: a cursor-paged list from `GET /me/invitations`, newest first, which records no view. `/candidate/invitations/:invitationId` opens one invitation. The contract is in the [API](../api/README.en.md#invitations-and-contact-grants).
- Reading and viewing. The screen reads the invitation with `GET /me/invitations/{id}` and records the view once per opening (`POST .../view` with the CSRF token, without an Idempotency-Key). Reading changes nothing; the view moves `delivered` to `viewed` and keeps the deadline. A view answer replaces the shown invitation only when its version is newer.
- Terms. The company, the role, the tasks, the team, the technologies, the format and place of work, the salary range with its basis (net or gross), the package, and the communication method are shown as in the company's preview (`widgets/invitation-preview`, the shared `InvitationTermsArticle`). The response deadline is shown with a UTC label (`formatServerMoment`). The candidate sees no company card: the contract returns only the name.
- Deadline. Whether an answer is open depends on the invitation state and the server clock (`useServerNow`, corrected by the `Date` header). After the deadline the answers are closed, even before the server applies the expiry on a later read.
- Acceptance with C4 (`features/accept-contact-consent`). The contact kinds come from `contact_consent.available_fields`: full name, email, phone, and Telegram, as far as the profile holds them. Nothing is preselected, and each kind is chosen separately. The button becomes available after at least one kind and a separate confirmation of the text are chosen. The consent text is shown as plain text, unchanged, with its paragraphs from the server response. Without a contact in the profile the invitation cannot be accepted, and the screen offers to open the profile.
- Decline (`features/respond-invitation`). A reason is chosen explicitly; none is preselected. The comment is optional for every reason, including "Другая причина", up to 500 characters. Only the candidate reads the comment.
- Outdated terms. A 412 `version_conflict` (and a 409 with the same code) reads the invitation again: the new version of the terms is shown, the choice of contacts and the confirmation are reset, and the screen asks for a new confirmation. A 409 `state_conflict` shows the final state instead of a retry. A repeated answer after a lost response or a 5xx uses the same Idempotency-Key (`entities/invitation/model/command-key.ts`); a changed choice gets a new key.
- Outcome. After acceptance the screen shows only the contact kinds that the grant covers (`contact_grant.fields`) and whether the company can read them now: with `readable` false and the reason `visibility`, it explains that the card must be published and open to the company. After a decline it shows the reason and the candidate's own comment. The company gets contacts only through its own endpoint, and only the kinds of the grant.
Checks. Unit tests cover the deadline and view rules, the classification of answer errors (`entities/invitation/model/response-failure.ts`), the idempotency keys, the form draft states, and the adapters and answer commands over MSW (CSRF and Idempotency-Key headers, schema checks of the response, a retry after a lost response), and the markup of the list, the screen, the forms, and the terms block. The Playwright suite `e2e/candidate-invitations.spec.ts` runs on the real backend in `make -C deploy test-e2e-registration`: five synthetic candidates publish a card, the owner finds them with a search, and three invitations are sent through the API. At 360 px a candidate accepts with the email only: the candidate's API shows one grant, and the company's contact endpoint returns the email and no phone. Outdated terms are checked with an intercepted response: the backend does not implement the raise of the upper salary bound after sending (`RaiseOrganizationInvitationSalary`), so the 412 and the new version of the terms come from a route, while the absence of a grant is checked on the real backend. A decline with "Другая причина" and no comment, followed by a reload, is checked on the real backend: the `declined` state stays after the reload, and the company's contact endpoint answers 404.
## Support and manual assessment
`/candidate/support/cases` and `/employer/support/cases` show each account's paginated support history. Their `.../new` routes create a case and `.../:caseId` routes show its status and history. The public `/support` route directs a signed-in user to their cabinet. The form draft stays in memory, and a retry of an unchanged request reuses its idempotency key. Support history is scoped to the current account and cleared when the session changes or the server denies access.