- helpers puros movidos utilities->lib: slug, phone, wordStartFilter, voteEstimate (9 inversoes lib->utilities zeradas) - chaves de consent em src/lib/campaignConsentKeys.ts (client-safe); campaignInvite/campaignConsent re-exportam; onda0ConsentTexts referencia as constantes - 'server-only' em 21 loaders Payload/cache (CLI segue com --conditions=react-server) - ciclo de tipos supporterListFilters <-> supporterUi quebrado (SupporterListFilterInput estrutural; sqlFilters idem) - votePledgeData dividido: votePledgeViews (puro, client-safe) + votePledgeData (loaders, server-only) - padrao contract-module - predicados de role client-safe em src/lib/campaignRoles.ts; access/shared deriva deles (fonte unica); nav.ts para de importar o barrel campaignAccess (casts 'as CampaignUser' eliminados)
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
import { positiveRelationshipId, trimmedNullableText } from '@/lib/schemas/primitives'
|
|
import {
|
|
getVoteEstimateOrderViolation,
|
|
VOTE_ESTIMATE_ORDER_ERROR_MESSAGE,
|
|
} from '@/lib/voteEstimate'
|
|
|
|
const optionalEstimate = z.number().int().min(0).max(1_000_000).nullable().optional()
|
|
|
|
export const voteEstimateScenarioFieldsSchema = z
|
|
.object({
|
|
pessimistic: optionalEstimate,
|
|
central: optionalEstimate,
|
|
optimistic: optionalEstimate,
|
|
})
|
|
.superRefine((value, ctx) => {
|
|
const violation = getVoteEstimateOrderViolation(value)
|
|
if (violation) {
|
|
ctx.addIssue({
|
|
code: 'custom',
|
|
message: VOTE_ESTIMATE_ORDER_ERROR_MESSAGE,
|
|
path: [violation],
|
|
})
|
|
}
|
|
})
|
|
|
|
/** Staff declare votes on behalf of a linked leadership in one municipality. */
|
|
export const declareVotesSchema = z.object({
|
|
municipality: positiveRelationshipId,
|
|
leadership: positiveRelationshipId,
|
|
declaredVotes: z.number().int().min(0).max(1_000_000),
|
|
})
|
|
|
|
/** Staff record their internal estimate for one pledge. */
|
|
export const estimateVotesSchema = z.object({
|
|
pledge: positiveRelationshipId,
|
|
estimatedVotes: voteEstimateScenarioFieldsSchema,
|
|
estimateNote: trimmedNullableText(1000),
|
|
})
|
|
|
|
export type DeclareVotesInput = z.input<typeof declareVotesSchema>
|
|
export type EstimateVotesInput = z.input<typeof estimateVotesSchema>
|