Context Directory
Location: src/context/
Purpose: React Context providers for cross-component client-side state. Each provider is hydrated once near the top of its layout from server-fetched data and read across the subtree with a typed hook.
Structure
context/
├── CampaignVisibilityContext.tsx # Per-campaign visibility / show/hide state
├── contextTypes.ts # Shared context type definitions
├── petitionContext.tsx # Petition data, formats, and operations for the signature workflow
├── signatureResultsContext/ # Signature results state shared across signature steps
│ ├── processFilledEntries.ts # Pre-processes a row before validation
│ ├── processFunc.ts # Final processing on submit
│ └── signatureResultContext.tsx # The provider + `useSignatureResult` hook
├── SignatureStepContext.tsx # Active step in the signature collection flow
└── TeamsContext.tsx # Teams, campaigns, permissionKeys, superAdminTeamId
Key providers
TeamsContext
The most-read context in the app.
type TeamsContextValue = SessionContext & {
teams: UserTeamsRecordType["teams"];
campaigns: CampaignType[];
superAdminTeamId: string;
};
SessionContext (from src/middleware/types.ts) carries permissionKeys, userTeamRole, etc. The provider is hydrated in the [primaryTeam] server layout from:
getUserTeams()—teams.getCampaignsForUser()—campaigns.getRoutePermissions({ teamId })—permissionKeys+teamAccess.SUPER_ADMIN_TEAM_IDenv constant —superAdminTeamId.
Client components call useTeams() to:
- Render or hide sidebar buttons based on
permissionKeys.includes(...). - Detect the super-admin team via
params.primaryTeam === superAdminTeamId. - Switch between teams or campaigns.
petitionContext
Holds the active petition, available formats, and helpers used during signature entry. Hydrated by getPetitionContextData() (src/lib/getPetitionContextData.ts).
SignatureStepContext
Tracks the current step in the multi-step signature collection workflow (signature-rows → es-validation → review → submit). See Signature Search & Validation.
signatureResultsContext
Holds the parsed Elasticsearch results for the current batch of signature rows. The wrapper file owns the provider; sibling files (processFilledEntries, processFunc) are pure helpers.
CampaignVisibilityContext
Toggles per-campaign visibility for the campaign switcher in the sidebar — used so a user with many campaigns can pin/hide entries.
Conventions
- Each context exports a
Providercomponent and auseX()hook that throws if called outside the provider. - Contexts are hydrated from server-fetched data passed as props; they should not fetch data themselves.