mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-18 05:53:05 +00:00
Pass 2 W2: correcoes de fronteira lib/utilities e client boundary
- 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)
This commit is contained in:
parent
23e1f1e83d
commit
cf6ae6c47c
111 changed files with 397 additions and 321 deletions
|
|
@ -10,7 +10,7 @@ import {
|
||||||
} from '@/lib/formData'
|
} from '@/lib/formData'
|
||||||
import { supporterCreateSchema } from '@/lib/schemas/supporter'
|
import { supporterCreateSchema } from '@/lib/schemas/supporter'
|
||||||
import { mapCampaignFormActionError } from '@/utilities/campaignFormActionError'
|
import { mapCampaignFormActionError } from '@/utilities/campaignFormActionError'
|
||||||
import { sanitizeBrazilianPhoneInput } from '@/utilities/phone'
|
import { sanitizeBrazilianPhoneInput } from '@/lib/phone'
|
||||||
|
|
||||||
export type SupporterFormState = {
|
export type SupporterFormState = {
|
||||||
status?: 'success'
|
status?: 'success'
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import { isPlanilhaPlaceholderEmail } from '@/lib/schemas/advisor'
|
||||||
import { loadAdvisorDetail } from '@/utilities/advisorData'
|
import { loadAdvisorDetail } from '@/utilities/advisorData'
|
||||||
import { isCampaignUnrestricted } from '@/utilities/campaignAccess'
|
import { isCampaignUnrestricted } from '@/utilities/campaignAccess'
|
||||||
import { getCampaignUser } from '@/utilities/campaignAuth'
|
import { getCampaignUser } from '@/utilities/campaignAuth'
|
||||||
import { formatBrazilianPhoneInput } from '@/utilities/phone'
|
import { formatBrazilianPhoneInput } from '@/lib/phone'
|
||||||
import {
|
import {
|
||||||
sendAdvisorPasswordResetFormAction,
|
sendAdvisorPasswordResetFormAction,
|
||||||
updateAdvisorProfileFormAction,
|
updateAdvisorProfileFormAction,
|
||||||
|
|
|
||||||
|
|
@ -50,14 +50,9 @@ import {
|
||||||
parseMunicipalityUpdateFeedParams,
|
parseMunicipalityUpdateFeedParams,
|
||||||
} from '@/utilities/municipalityUpdatePageData'
|
} from '@/utilities/municipalityUpdatePageData'
|
||||||
import { loadAdvisorSummaries } from '@/utilities/municipalityViewModels'
|
import { loadAdvisorSummaries } from '@/utilities/municipalityViewModels'
|
||||||
import type { VoteEstimateScenarioViewModel } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
|
||||||
import {
|
import { loadMunicipalityPledges } from '@/utilities/votePledgeData'
|
||||||
aggregateMunicipalityPledgesFromRows,
|
import { aggregateMunicipalityPledgesFromRows, toMunicipalityPledgeCoverageView, type MunicipalityPledgeAggregate, type MunicipalityPledgeCoverageView } from '@/utilities/votePledgeViews'
|
||||||
loadMunicipalityPledges,
|
|
||||||
toMunicipalityPledgeCoverageView,
|
|
||||||
type MunicipalityPledgeAggregate,
|
|
||||||
type MunicipalityPledgeCoverageView,
|
|
||||||
} from '@/utilities/votePledgeData'
|
|
||||||
import { declareVotesFormAction, estimateVotesFormAction } from './pledgeFormActions'
|
import { declareVotesFormAction, estimateVotesFormAction } from './pledgeFormActions'
|
||||||
import { createMunicipalityUpdateFormAction } from './updateFormActions'
|
import { createMunicipalityUpdateFormAction } from './updateFormActions'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
CAMPAIGN_SESSION_EXPIRED_MESSAGE,
|
CAMPAIGN_SESSION_EXPIRED_MESSAGE,
|
||||||
mapCampaignFormActionError,
|
mapCampaignFormActionError,
|
||||||
} from '@/utilities/campaignFormActionError'
|
} from '@/utilities/campaignFormActionError'
|
||||||
import { toVoteEstimateScenarioViewModel } from '@/utilities/voteEstimate'
|
import { toVoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
import type { MunicipalityListExpectedVotesResponse } from './types'
|
import type { MunicipalityListExpectedVotesResponse } from './types'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import type { VoteEstimateScenarioViewModel } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
export type MunicipalityListExpectedVotesResponse =
|
export type MunicipalityListExpectedVotesResponse =
|
||||||
| {
|
| {
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ import {
|
||||||
parseActionPlanCreateFormData,
|
parseActionPlanCreateFormData,
|
||||||
parseActionPlanUpdateFormData,
|
parseActionPlanUpdateFormData,
|
||||||
} from '@/utilities/actionPlanFormData'
|
} from '@/utilities/actionPlanFormData'
|
||||||
import { slugify } from '@/utilities/slug'
|
import { slugify } from '@/lib/slug'
|
||||||
|
|
||||||
const getActionError = (error: unknown): ActionPlanFormState => {
|
const getActionError = (error: unknown): ActionPlanFormState => {
|
||||||
if (
|
if (
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import { mapCampaignFormActionError } from '@/utilities/campaignFormActionError'
|
||||||
import { acquireContactPhoneLocks } from '@/utilities/contactPhoneInvariant'
|
import { acquireContactPhoneLocks } from '@/utilities/contactPhoneInvariant'
|
||||||
import type { PayloadTransactionRequest } from '@/utilities/payloadTransaction'
|
import type { PayloadTransactionRequest } from '@/utilities/payloadTransaction'
|
||||||
import { withPayloadTransaction } from '@/utilities/payloadTransaction'
|
import { withPayloadTransaction } from '@/utilities/payloadTransaction'
|
||||||
import { sanitizeBrazilianPhoneInput } from '@/utilities/phone'
|
import { sanitizeBrazilianPhoneInput } from '@/lib/phone'
|
||||||
import { isUniqueSupporterConflict } from '@/utilities/supporterErrors'
|
import { isUniqueSupporterConflict } from '@/utilities/supporterErrors'
|
||||||
|
|
||||||
export type LeaderSupporterFormState = {
|
export type LeaderSupporterFormState = {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import { acquireTextAdvisoryLocks } from '@/utilities/postgresTransactionLocks'
|
||||||
import {
|
import {
|
||||||
normalizeVoteEstimateOnSave,
|
normalizeVoteEstimateOnSave,
|
||||||
toVoteEstimateScenarioViewModel,
|
toVoteEstimateScenarioViewModel,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
const getFreshStaffActor = (
|
const getFreshStaffActor = (
|
||||||
payload: Payload,
|
payload: Payload,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import {
|
||||||
mapCampaignFormActionError,
|
mapCampaignFormActionError,
|
||||||
type CampaignFormActionState,
|
type CampaignFormActionState,
|
||||||
} from '@/utilities/campaignFormActionError'
|
} from '@/utilities/campaignFormActionError'
|
||||||
import { normalizeBrazilianPhone } from '@/utilities/phone'
|
import { normalizeBrazilianPhone } from '@/lib/phone'
|
||||||
|
|
||||||
export const requestCampaignPasswordReset = async (
|
export const requestCampaignPasswordReset = async (
|
||||||
input: { email: string },
|
input: { email: string },
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import {
|
||||||
import { acquireContactPhoneLocks } from '@/utilities/contactPhoneInvariant'
|
import { acquireContactPhoneLocks } from '@/utilities/contactPhoneInvariant'
|
||||||
import type { PayloadTransactionRequest } from '@/utilities/payloadTransaction'
|
import type { PayloadTransactionRequest } from '@/utilities/payloadTransaction'
|
||||||
import { withPayloadTransaction } from '@/utilities/payloadTransaction'
|
import { withPayloadTransaction } from '@/utilities/payloadTransaction'
|
||||||
import { normalizeBrazilianPhone } from '@/utilities/phone'
|
import { normalizeBrazilianPhone } from '@/lib/phone'
|
||||||
import { relationshipId } from '@/utilities/relationship'
|
import { relationshipId } from '@/utilities/relationship'
|
||||||
import {
|
import {
|
||||||
isPreviewErrorRow,
|
isPreviewErrorRow,
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import { relationshipId, requireRelationshipId } from '@/utilities/relationship'
|
||||||
import {
|
import {
|
||||||
normalizeVoteEstimateOnSave,
|
normalizeVoteEstimateOnSave,
|
||||||
toVoteEstimateScenarioViewModel,
|
toVoteEstimateScenarioViewModel,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
const STAFF_DECLARE_REQUIRED = 'Somente a coordenação e a assessoria registram votos declarados.'
|
const STAFF_DECLARE_REQUIRED = 'Somente a coordenação e a assessoria registram votos declarados.'
|
||||||
const MUNICIPALITY_NOT_LINKED =
|
const MUNICIPALITY_NOT_LINKED =
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import {
|
||||||
eligibleCampaignStaffWhere,
|
eligibleCampaignStaffWhere,
|
||||||
} from '@/utilities/campaignAccess'
|
} from '@/utilities/campaignAccess'
|
||||||
import { relationshipId } from '@/utilities/relationship'
|
import { relationshipId } from '@/utilities/relationship'
|
||||||
import { slugify } from '@/utilities/slug'
|
import { slugify } from '@/lib/slug'
|
||||||
|
|
||||||
const trimmedText = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
const trimmedText = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import {
|
||||||
isCampaignUnrestricted,
|
isCampaignUnrestricted,
|
||||||
} from '@/utilities/campaignAccess'
|
} from '@/utilities/campaignAccess'
|
||||||
import { relationshipId } from '@/utilities/relationship'
|
import { relationshipId } from '@/utilities/relationship'
|
||||||
import { slugify } from '@/utilities/slug'
|
import { slugify } from '@/lib/slug'
|
||||||
|
|
||||||
const trimmedText = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
const trimmedText = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
canUpdateCampaignUserPhone,
|
canUpdateCampaignUserPhone,
|
||||||
} from '@/utilities/campaignAccess'
|
} from '@/utilities/campaignAccess'
|
||||||
import { buildCampaignPasswordResetUrl } from '@/utilities/campaignPasswordReset'
|
import { buildCampaignPasswordResetUrl } from '@/utilities/campaignPasswordReset'
|
||||||
import { normalizeBrazilianPhone } from '@/utilities/phone'
|
import { normalizeBrazilianPhone } from '@/lib/phone'
|
||||||
import {
|
import {
|
||||||
APIError,
|
APIError,
|
||||||
type CollectionAfterReadHook,
|
type CollectionAfterReadHook,
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import {
|
||||||
canManageContacts,
|
canManageContacts,
|
||||||
canReadContacts,
|
canReadContacts,
|
||||||
} from '@/utilities/campaignAccess'
|
} from '@/utilities/campaignAccess'
|
||||||
import { normalizeBrazilianPhone } from '@/utilities/phone'
|
import { normalizeBrazilianPhone } from '@/lib/phone'
|
||||||
import type { CollectionBeforeChangeHook, CollectionConfig } from 'payload'
|
import type { CollectionBeforeChangeHook, CollectionConfig } from 'payload'
|
||||||
import { APIError } from 'payload'
|
import { APIError } from 'payload'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import {
|
||||||
getVoteEstimateOrderViolation,
|
getVoteEstimateOrderViolation,
|
||||||
VOTE_ESTIMATE_ORDER_ERROR_MESSAGE,
|
VOTE_ESTIMATE_ORDER_ERROR_MESSAGE,
|
||||||
type VoteEstimateScenarioFields,
|
type VoteEstimateScenarioFields,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import {
|
import {
|
||||||
voteEstimateScenarioGroupAccess,
|
voteEstimateScenarioGroupAccess,
|
||||||
voteEstimateScenarioGroupFields,
|
voteEstimateScenarioGroupFields,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
canReadOrganization,
|
canReadOrganization,
|
||||||
canSetCampaignSystemField,
|
canSetCampaignSystemField,
|
||||||
} from '@/utilities/campaignAccess'
|
} from '@/utilities/campaignAccess'
|
||||||
import { slugify } from '@/utilities/slug'
|
import { slugify } from '@/lib/slug'
|
||||||
|
|
||||||
const trimmedText = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
const trimmedText = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { payloadAdminOnly } from '@/utilities/campaignAccess'
|
import { payloadAdminOnly } from '@/utilities/campaignAccess'
|
||||||
import { revalidateDocumentById, revalidatePostsListing } from '@/utilities/documents'
|
import { revalidateDocumentById, revalidatePostsListing } from '@/utilities/documents'
|
||||||
import { slugify } from '@/utilities/slug'
|
import { slugify } from '@/lib/slug'
|
||||||
import type { CollectionConfig } from 'payload'
|
import type { CollectionConfig } from 'payload'
|
||||||
|
|
||||||
const slug = 'post'
|
const slug = 'post'
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
canReadStateDeputy,
|
canReadStateDeputy,
|
||||||
canSetCampaignSystemField,
|
canSetCampaignSystemField,
|
||||||
} from '@/utilities/campaignAccess'
|
} from '@/utilities/campaignAccess'
|
||||||
import { slugify } from '@/utilities/slug'
|
import { slugify } from '@/lib/slug'
|
||||||
|
|
||||||
const trimmedText = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
const trimmedText = (value: unknown): string => (typeof value === 'string' ? value.trim() : '')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { payloadAdminOnly } from '@/utilities/campaignAccess'
|
import { payloadAdminOnly } from '@/utilities/campaignAccess'
|
||||||
import { revalidateDocumentById, revalidatePostsListing } from '@/utilities/documents'
|
import { revalidateDocumentById, revalidatePostsListing } from '@/utilities/documents'
|
||||||
import { slugify } from '@/utilities/slug'
|
import { slugify } from '@/lib/slug'
|
||||||
import type { CollectionConfig } from 'payload'
|
import type { CollectionConfig } from 'payload'
|
||||||
|
|
||||||
const slug = 'tag'
|
const slug = 'tag'
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import {
|
||||||
type VoteEstimateScenarioFields,
|
type VoteEstimateScenarioFields,
|
||||||
getVoteEstimateOrderViolation,
|
getVoteEstimateOrderViolation,
|
||||||
VOTE_ESTIMATE_ORDER_ERROR_MESSAGE,
|
VOTE_ESTIMATE_ORDER_ERROR_MESSAGE,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import {
|
import {
|
||||||
voteEstimateScenarioGroupAccess,
|
voteEstimateScenarioGroupAccess,
|
||||||
voteEstimateScenarioGroupFields,
|
voteEstimateScenarioGroupFields,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import type { ComponentProps } from 'react'
|
import type { ComponentProps } from 'react'
|
||||||
|
|
||||||
import { formatBrazilianPhoneInput, sanitizeBrazilianPhoneInput } from '@/utilities/phone'
|
import { formatBrazilianPhoneInput, sanitizeBrazilianPhoneInput } from '@/lib/phone'
|
||||||
|
|
||||||
import { FormInput } from './FormInput'
|
import { FormInput } from './FormInput'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
planilhaPlaceholderEmailForAdvisor,
|
planilhaPlaceholderEmailForAdvisor,
|
||||||
} from '@/lib/schemas/advisor'
|
} from '@/lib/schemas/advisor'
|
||||||
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
||||||
import { formatBrazilianPhoneInput, sanitizeBrazilianPhoneInput } from '@/utilities/phone'
|
import { formatBrazilianPhoneInput, sanitizeBrazilianPhoneInput } from '@/lib/phone'
|
||||||
|
|
||||||
const SAVE_DEBOUNCE_MS = 500
|
const SAVE_DEBOUNCE_MS = 500
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ import {
|
||||||
normalizeBrazilianPhone,
|
normalizeBrazilianPhone,
|
||||||
sanitizeBrazilianPhoneInput,
|
sanitizeBrazilianPhoneInput,
|
||||||
buildWhatsAppUrl,
|
buildWhatsAppUrl,
|
||||||
} from '@/utilities/phone'
|
} from '@/lib/phone'
|
||||||
|
|
||||||
type MunicipalityRef = { id: number; name: string; slug: string }
|
type MunicipalityRef = { id: number; name: string; slug: string }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import {
|
||||||
import {
|
import {
|
||||||
formatVoteEstimateEndpointsLabel,
|
formatVoteEstimateEndpointsLabel,
|
||||||
voteEstimateScenarioLabels,
|
voteEstimateScenarioLabels,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
const dateTimeFormatter = new Intl.DateTimeFormat('pt-BR', {
|
const dateTimeFormatter = new Intl.DateTimeFormat('pt-BR', {
|
||||||
dateStyle: 'short',
|
dateStyle: 'short',
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import { Spinner } from '@/components/ui/Spinner'
|
||||||
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
||||||
import { fieldError } from '@/utilities/campaignFormFields'
|
import { fieldError } from '@/utilities/campaignFormFields'
|
||||||
import { campaignRoleLabels, type CampaignUserShellView } from '@/utilities/campaignUserProfile'
|
import { campaignRoleLabels, type CampaignUserShellView } from '@/utilities/campaignUserProfile'
|
||||||
import { formatBrazilianPhoneDisplay } from '@/utilities/phone'
|
import { formatBrazilianPhoneDisplay } from '@/lib/phone'
|
||||||
|
|
||||||
type CampaignProfileSettingsProps = {
|
type CampaignProfileSettingsProps = {
|
||||||
user: CampaignUserShellView & {
|
user: CampaignUserShellView & {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import { Input } from '@/components/ui/input'
|
||||||
import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select'
|
import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select'
|
||||||
import { Spinner } from '@/components/ui/Spinner'
|
import { Spinner } from '@/components/ui/Spinner'
|
||||||
import { errorProps as buildErrorProps, fieldError } from '@/utilities/campaignFormFields'
|
import { errorProps as buildErrorProps, fieldError } from '@/utilities/campaignFormFields'
|
||||||
import { formatBrazilianPhoneInput, sanitizeBrazilianPhoneInput } from '@/utilities/phone'
|
import { formatBrazilianPhoneInput, sanitizeBrazilianPhoneInput } from '@/lib/phone'
|
||||||
import { municipalityComboboxOptions } from '@/utilities/territoryComboboxOptions'
|
import { municipalityComboboxOptions } from '@/utilities/territoryComboboxOptions'
|
||||||
|
|
||||||
const errorProps = (fieldErrors: Record<string, string[]> | undefined, field: string) =>
|
const errorProps = (fieldErrors: Record<string, string[]> | undefined, field: string) =>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
TableRow,
|
TableRow,
|
||||||
} from '@/components/ui/Table'
|
} from '@/components/ui/Table'
|
||||||
import type { LeaderContactListItem } from '@/utilities/leaderContactsPageData'
|
import type { LeaderContactListItem } from '@/utilities/leaderContactsPageData'
|
||||||
import { formatBrazilianPhoneInput } from '@/utilities/phone'
|
import { formatBrazilianPhoneInput } from '@/lib/phone'
|
||||||
|
|
||||||
const dateFormatter = new Intl.DateTimeFormat('pt-BR', {
|
const dateFormatter = new Intl.DateTimeFormat('pt-BR', {
|
||||||
dateStyle: 'short',
|
dateStyle: 'short',
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
import { createContext, useContext, useMemo, useState, type ReactNode } from 'react'
|
import { createContext, useContext, useMemo, useState, type ReactNode } from 'react'
|
||||||
|
|
||||||
import { DEFAULT_VOTE_ESTIMATE_SCENARIO, type VoteEstimateScenario } from '@/utilities/voteEstimate'
|
import { DEFAULT_VOTE_ESTIMATE_SCENARIO, type VoteEstimateScenario } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
type MunicipalityEstimateScenarioContextValue = {
|
type MunicipalityEstimateScenarioContextValue = {
|
||||||
scenario: VoteEstimateScenario
|
scenario: VoteEstimateScenario
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ import {
|
||||||
type MunicipalityGoalCoverage,
|
type MunicipalityGoalCoverage,
|
||||||
} from '@/utilities/goalCoverage'
|
} from '@/utilities/goalCoverage'
|
||||||
import type { MunicipalityPotential, RollOff } from '@/utilities/municipalityPotential'
|
import type { MunicipalityPotential, RollOff } from '@/utilities/municipalityPotential'
|
||||||
import type { VoteEstimateScenarioViewModel } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
|
||||||
import type { MunicipalityPledgeCoverageView } from '@/utilities/votePledgeData'
|
import type { MunicipalityPledgeCoverageView } from '@/utilities/votePledgeViews'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One `dt`/`dd` pair in the diagnostic grid, with a hover/focus/tap tooltip
|
* One `dt`/`dd` pair in the diagnostic grid, with a hover/focus/tap tooltip
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import {
|
||||||
type MunicipalityMultiFilterParam,
|
type MunicipalityMultiFilterParam,
|
||||||
} from '@/utilities/municipalityListFilters'
|
} from '@/utilities/municipalityListFilters'
|
||||||
import { type MunicipalityListState } from '@/utilities/municipalityListUrl'
|
import { type MunicipalityListState } from '@/utilities/municipalityListUrl'
|
||||||
import { normalizeSearchPhrase } from '@/utilities/wordStartFilter'
|
import { normalizeSearchPhrase } from '@/lib/wordStartFilter'
|
||||||
|
|
||||||
type MunicipalityHeaderFilterProps = {
|
type MunicipalityHeaderFilterProps = {
|
||||||
state: MunicipalityListState
|
state: MunicipalityListState
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { Badge } from '@/components/ui/Badge'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
||||||
import type { LeadershipRowViewModel } from '@/utilities/leadershipData'
|
import type { LeadershipRowViewModel } from '@/utilities/leadershipData'
|
||||||
import type { StaffPledgeRow } from '@/utilities/votePledgeData'
|
import type { StaffPledgeRow } from '@/utilities/votePledgeViews'
|
||||||
|
|
||||||
type MunicipalityLeadershipsPanelProps = {
|
type MunicipalityLeadershipsPanelProps = {
|
||||||
municipalityID: number
|
municipalityID: number
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,8 @@ import type {
|
||||||
import {
|
import {
|
||||||
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
||||||
voteEstimateScenarioLabels,
|
voteEstimateScenarioLabels,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import { toMunicipalityPledgeCoverageView } from '@/utilities/votePledgeData'
|
import { toMunicipalityPledgeCoverageView } from '@/utilities/votePledgeViews'
|
||||||
|
|
||||||
const dateFormatter = new Intl.DateTimeFormat('pt-BR')
|
const dateFormatter = new Intl.DateTimeFormat('pt-BR')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ import {
|
||||||
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
||||||
voteEstimatesEqual,
|
voteEstimatesEqual,
|
||||||
type VoteEstimateScenarioViewModel,
|
type VoteEstimateScenarioViewModel,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import type { MunicipalityPledgeCoverageView } from '@/utilities/votePledgeData'
|
import type { MunicipalityPledgeCoverageView } from '@/utilities/votePledgeViews'
|
||||||
|
|
||||||
const AUTOSAVE_MS = 600
|
const AUTOSAVE_MS = 600
|
||||||
const EXPECTED_VOTES_ENDPOINT = '/campanha/municipios/expected-votes'
|
const EXPECTED_VOTES_ENDPOINT = '/campanha/municipios/expected-votes'
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
||||||
voteEstimateScenarioLabels,
|
voteEstimateScenarioLabels,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* E8 "conta da cadeira" list cell: reads the shared scenario picker (same
|
* E8 "conta da cadeira" list cell: reads the shared scenario picker (same
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import {
|
||||||
formatVoteEstimateEndpointsLabel,
|
formatVoteEstimateEndpointsLabel,
|
||||||
hasAnyVoteEstimate,
|
hasAnyVoteEstimate,
|
||||||
voteEstimateScenarioLabels,
|
voteEstimateScenarioLabels,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
const SCENARIO_FLASH_MS = 420
|
const SCENARIO_FLASH_MS = 420
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import {
|
||||||
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
||||||
voteEstimateScenarioLabels,
|
voteEstimateScenarioLabels,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
type MunicipalityMapPanelProps = {
|
type MunicipalityMapPanelProps = {
|
||||||
bundle: MunicipalityMapBundle
|
bundle: MunicipalityMapBundle
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ import {
|
||||||
effectivePledgeVotesForScenario,
|
effectivePledgeVotesForScenario,
|
||||||
formatVoteEstimateRange,
|
formatVoteEstimateRange,
|
||||||
getVoteEstimateForScenario,
|
getVoteEstimateForScenario,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import { type StaffPledgeRow } from '@/utilities/votePledgeData'
|
import { type StaffPledgeRow } from '@/utilities/votePledgeViews'
|
||||||
import { hasAnyEstimate } from '@/utilities/voteEstimate'
|
import { hasAnyEstimate } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
const voteFormatter = new Intl.NumberFormat('pt-BR')
|
const voteFormatter = new Intl.NumberFormat('pt-BR')
|
||||||
const dateFormatter = new Intl.DateTimeFormat('pt-BR')
|
const dateFormatter = new Intl.DateTimeFormat('pt-BR')
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import { Input } from '@/components/ui/input'
|
||||||
import { Spinner } from '@/components/ui/Spinner'
|
import { Spinner } from '@/components/ui/Spinner'
|
||||||
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
import type { CampaignFormActionState } from '@/utilities/campaignFormActionError'
|
||||||
import { fieldError } from '@/utilities/campaignFormFields'
|
import { fieldError } from '@/utilities/campaignFormFields'
|
||||||
import type { VoteEstimateScenarioViewModel } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenarioViewModel } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
type PledgeEstimateFormProps = {
|
type PledgeEstimateFormProps = {
|
||||||
pledgeID: number
|
pledgeID: number
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import {
|
||||||
hasAnyVoteEstimate,
|
hasAnyVoteEstimate,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
type VoteEstimateScenarioViewModel,
|
type VoteEstimateScenarioViewModel,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import type { MunicipalityPledgeCoverageView } from '@/utilities/votePledgeData'
|
import type { MunicipalityPledgeCoverageView } from '@/utilities/votePledgeViews'
|
||||||
|
|
||||||
const voteFormatter = new Intl.NumberFormat('pt-BR')
|
const voteFormatter = new Intl.NumberFormat('pt-BR')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
ComboboxList,
|
ComboboxList,
|
||||||
} from '@/components/ui/combobox'
|
} from '@/components/ui/combobox'
|
||||||
import type { StrictComboboxOption } from '@/utilities/territoryComboboxOptions'
|
import type { StrictComboboxOption } from '@/utilities/territoryComboboxOptions'
|
||||||
import { matchesAtWordStart, normalizeSearchPhrase } from '@/utilities/wordStartFilter'
|
import { matchesAtWordStart, normalizeSearchPhrase } from '@/lib/wordStartFilter'
|
||||||
|
|
||||||
type StrictComboboxProps = {
|
type StrictComboboxProps = {
|
||||||
id: string
|
id: string
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import { Spinner } from '@/components/ui/Spinner'
|
||||||
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/ToggleGroup'
|
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/ToggleGroup'
|
||||||
import type { SupporterVoteIntention } from '@/lib/schemas/supporter'
|
import type { SupporterVoteIntention } from '@/lib/schemas/supporter'
|
||||||
import { fieldError, errorProps as buildErrorProps } from '@/utilities/campaignFormFields'
|
import { fieldError, errorProps as buildErrorProps } from '@/utilities/campaignFormFields'
|
||||||
import { formatBrazilianPhoneInput, sanitizeBrazilianPhoneInput } from '@/utilities/phone'
|
import { formatBrazilianPhoneInput, sanitizeBrazilianPhoneInput } from '@/lib/phone'
|
||||||
import { supporterVoteIntentionLabels } from '@/utilities/supporterUi'
|
import { supporterVoteIntentionLabels } from '@/utilities/supporterUi'
|
||||||
import { municipalityComboboxOptions } from '@/utilities/territoryComboboxOptions'
|
import { municipalityComboboxOptions } from '@/utilities/territoryComboboxOptions'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import {
|
||||||
import { Badge } from '@/components/ui/Badge'
|
import { Badge } from '@/components/ui/Badge'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
import { formatBrazilianPhoneInput } from '@/utilities/phone'
|
import { formatBrazilianPhoneInput } from '@/lib/phone'
|
||||||
import { supporterVoteIntentionLabels } from '@/utilities/supporterUi'
|
import { supporterVoteIntentionLabels } from '@/utilities/supporterUi'
|
||||||
import type { SupporterListItemViewModel } from '@/utilities/supporterViewModels'
|
import type { SupporterListItemViewModel } from '@/utilities/supporterViewModels'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import { toast } from 'sonner'
|
||||||
import { Alert, AlertDescription } from '@/components/ui/Alert'
|
import { Alert, AlertDescription } from '@/components/ui/Alert'
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Textarea } from '@/components/ui/textarea'
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
import { buildWhatsAppUrl } from '@/utilities/phone'
|
import { buildWhatsAppUrl } from '@/lib/phone'
|
||||||
|
|
||||||
export const SupporterShareKit = ({
|
export const SupporterShareKit = ({
|
||||||
supporterName,
|
supporterName,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
VOTE_ESTIMATE_SCENARIOS,
|
VOTE_ESTIMATE_SCENARIOS,
|
||||||
voteEstimateScenarioLabels,
|
voteEstimateScenarioLabels,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
export const VOTE_ESTIMATE_SCENARIO_OVERVIEW_HINT =
|
export const VOTE_ESTIMATE_SCENARIO_OVERVIEW_HINT =
|
||||||
'Troca o total desta visão geral e os votos na lista. No mapa, a cor só muda com Ano 2026.'
|
'Troca o total desta visão geral e os votos na lista. No mapa, a cor só muda com Ano 2026.'
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import {
|
||||||
voteEstimatesEqual,
|
voteEstimatesEqual,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
type VoteEstimateScenarioViewModel,
|
type VoteEstimateScenarioViewModel,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
const scenarioFieldName = (
|
const scenarioFieldName = (
|
||||||
fieldPrefix: 'estimatedVotes' | 'expectedVotes',
|
fieldPrefix: 'estimatedVotes' | 'expectedVotes',
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import {
|
||||||
voteEstimateScenarioLabels,
|
voteEstimateScenarioLabels,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
type VoteEstimateScenarioViewModel,
|
type VoteEstimateScenarioViewModel,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
const voteFormatter = new Intl.NumberFormat('pt-BR')
|
const voteFormatter = new Intl.NumberFormat('pt-BR')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ import {
|
||||||
type LucideIcon,
|
type LucideIcon,
|
||||||
} from 'lucide-react'
|
} from 'lucide-react'
|
||||||
|
|
||||||
|
import { isStaffCampaignRole, isUnrestrictedCampaignRole } from '@/lib/campaignRoles'
|
||||||
import type { CampaignUser } from '@/payload-types'
|
import type { CampaignUser } from '@/payload-types'
|
||||||
import { isCampaignStaff, isCampaignUnrestricted } from '@/utilities/campaignAccess'
|
|
||||||
import { canAccessSupporterArea } from '@/utilities/supporterUi'
|
import { canAccessSupporterArea } from '@/utilities/supporterUi'
|
||||||
|
|
||||||
export type CampaignNavItem = {
|
export type CampaignNavItem = {
|
||||||
|
|
@ -57,13 +57,13 @@ export const getCampaignNav = (role: CampaignUser['role']): CampaignNavItem[] =>
|
||||||
|
|
||||||
return staffNav.filter((item) => {
|
return staffNav.filter((item) => {
|
||||||
if (item.href === '/campanha/apoiadores') return canAccessSupporterArea(role)
|
if (item.href === '/campanha/apoiadores') return canAccessSupporterArea(role)
|
||||||
if (item.href === '/campanha/assessores') return isCampaignUnrestrictedRole(role)
|
if (item.href === '/campanha/assessores') return isUnrestrictedCampaignRole(role)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getCampaignSecondaryNav = (role: CampaignUser['role']): CampaignNavItem[] =>
|
export const getCampaignSecondaryNav = (role: CampaignUser['role']): CampaignNavItem[] =>
|
||||||
isCampaignStaffRole(role) ? staffSecondaryNav : []
|
isStaffCampaignRole(role) ? staffSecondaryNav : []
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compact set for the mobile bottom bar (max 5 items with a home slot).
|
* Compact set for the mobile bottom bar (max 5 items with a home slot).
|
||||||
|
|
@ -88,9 +88,3 @@ export const isCampaignNavActive = (pathname: string, href: string): boolean =>
|
||||||
}
|
}
|
||||||
return pathname === href || pathname.startsWith(`${href}/`)
|
return pathname === href || pathname.startsWith(`${href}/`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isCampaignStaffRole = (role: CampaignUser['role']): boolean =>
|
|
||||||
isCampaignStaff({ collection: 'campaignUser', role } as CampaignUser)
|
|
||||||
|
|
||||||
const isCampaignUnrestrictedRole = (role: CampaignUser['role']): boolean =>
|
|
||||||
isCampaignUnrestricted({ collection: 'campaignUser', role } as CampaignUser)
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import {
|
||||||
type MunicipalityCatalogEntry,
|
type MunicipalityCatalogEntry,
|
||||||
} from '@/lib/municipalityCatalog'
|
} from '@/lib/municipalityCatalog'
|
||||||
import { citiesForTseZone } from '@/lib/bahiaTseZones'
|
import { citiesForTseZone } from '@/lib/bahiaTseZones'
|
||||||
import { matchesAtWordStart, normalizeSearchPhrase } from '@/utilities/wordStartFilter'
|
import { matchesAtWordStart, normalizeSearchPhrase } from '@/lib/wordStartFilter'
|
||||||
|
|
||||||
export type AdvisorMunicipalityIndexEntry = {
|
export type AdvisorMunicipalityIndexEntry = {
|
||||||
id: number
|
id: number
|
||||||
|
|
|
||||||
10
src/lib/campaignConsentKeys.ts
Normal file
10
src/lib/campaignConsentKeys.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Stable LGPD consent keys the app resolves at runtime (fail-closed: the flows
|
||||||
|
* refuse to run while the admin has not created the Consent row with the exact
|
||||||
|
* key). Client-safe constants — the resolution logic lives in
|
||||||
|
* `src/utilities/campaignConsent.ts` (server-only).
|
||||||
|
*/
|
||||||
|
export const CAMPAIGN_INVITE_CONSENT_KEY = 'lideranca-autopreenchimento'
|
||||||
|
|
||||||
|
export const SUPPORTER_REGISTRATION_CONSENT_KEY = 'apoiador-cadastro'
|
||||||
|
export const SUPPORTER_VOTE_INTENTION_CONSENT_KEY = 'apoiador-intencao-voto'
|
||||||
18
src/lib/campaignRoles.ts
Normal file
18
src/lib/campaignRoles.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import type { CampaignUser } from '@/payload-types'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client-safe campaign ROLE predicates — the single source for what each role
|
||||||
|
* label means. Server-side actor checks (`isCampaignStaff(user)` etc.) derive
|
||||||
|
* from these in `src/utilities/access/shared.ts`; client components (sidebar,
|
||||||
|
* nav) use the role-level predicates directly instead of importing the access
|
||||||
|
* barrel.
|
||||||
|
*/
|
||||||
|
export type CampaignRole = CampaignUser['role']
|
||||||
|
|
||||||
|
/** Staff = coordinator, advisor, or candidate. Leaders are not staff. */
|
||||||
|
export const isStaffCampaignRole = (role: CampaignRole): boolean =>
|
||||||
|
role === 'coordinator' || role === 'advisor' || role === 'candidate'
|
||||||
|
|
||||||
|
/** Coordinator or candidate — unrestricted scope (all municipalities, decisions). */
|
||||||
|
export const isUnrestrictedCampaignRole = (role: CampaignRole): boolean =>
|
||||||
|
role === 'coordinator' || role === 'candidate'
|
||||||
|
|
@ -2,7 +2,7 @@ import 'server-only'
|
||||||
|
|
||||||
import { z, type ZodError } from 'zod'
|
import { z, type ZodError } from 'zod'
|
||||||
|
|
||||||
import type { VoteEstimateScenarioFields } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenarioFields } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
export class FormDataBoundaryError extends Error {
|
export class FormDataBoundaryError extends Error {
|
||||||
field: string
|
field: string
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import {
|
||||||
} from '@/lib/bahiaTerritories'
|
} from '@/lib/bahiaTerritories'
|
||||||
import { bahiaTseCityCodes } from '@/lib/bahiaTseCityCodes'
|
import { bahiaTseCityCodes } from '@/lib/bahiaTseCityCodes'
|
||||||
import { tseZonesForCity } from '@/lib/bahiaTseZones'
|
import { tseZonesForCity } from '@/lib/bahiaTseZones'
|
||||||
import { slugify } from '@/utilities/slug'
|
import { slugify } from '@/lib/slug'
|
||||||
|
|
||||||
export type MunicipalityKind = 'municipio' | 'zona'
|
export type MunicipalityKind = 'municipio' | 'zona'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,17 @@
|
||||||
|
import {
|
||||||
|
CAMPAIGN_INVITE_CONSENT_KEY,
|
||||||
|
SUPPORTER_REGISTRATION_CONSENT_KEY,
|
||||||
|
SUPPORTER_VOTE_INTENTION_CONSENT_KEY,
|
||||||
|
} from '@/lib/campaignConsentKeys'
|
||||||
import type { Consent } from '@/payload-types'
|
import type { Consent } from '@/payload-types'
|
||||||
import { CAMPAIGN_INVITE_CONSENT_KEY } from '@/utilities/campaignInvite'
|
|
||||||
|
|
||||||
export const ONDA0_PROVISIONAL_BANNER =
|
export const ONDA0_PROVISIONAL_BANNER =
|
||||||
'Texto provisório para MVP e testes internos da plataforma Teqo (campanha Jorge Solla). Não constitui parecer jurídico. Deve ser substituído por texto aprovado pela assessoria jurídica eleitoral antes de coleta de dados de titulares reais em produção.'
|
'Texto provisório para MVP e testes internos da plataforma Teqo (campanha Jorge Solla). Não constitui parecer jurídico. Deve ser substituído por texto aprovado pela assessoria jurídica eleitoral antes de coleta de dados de titulares reais em produção.'
|
||||||
|
|
||||||
export const ONDA0_CONSENT_KEYS = {
|
export const ONDA0_CONSENT_KEYS = {
|
||||||
leadershipAutofill: CAMPAIGN_INVITE_CONSENT_KEY,
|
leadershipAutofill: CAMPAIGN_INVITE_CONSENT_KEY,
|
||||||
supporterRegistration: 'apoiador-cadastro',
|
supporterRegistration: SUPPORTER_REGISTRATION_CONSENT_KEY,
|
||||||
supporterVoteIntention: 'apoiador-intencao-voto',
|
supporterVoteIntention: SUPPORTER_VOTE_INTENTION_CONSENT_KEY,
|
||||||
campaignPush: 'campanha-notificacoes-push',
|
campaignPush: 'campanha-notificacoes-push',
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
* Bom → optimistic, Regular → central (média), Mínimo → pessimistic.
|
* Bom → optimistic, Regular → central (média), Mínimo → pessimistic.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { VoteEstimateScenarioFields } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenarioFields } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
/** Parsed sheet triple — all three scenarios present (same keys as expectedVotes). */
|
/** Parsed sheet triple — all three scenarios present (same keys as expectedVotes). */
|
||||||
export type ProjectionVoteEstimates = Required<
|
export type ProjectionVoteEstimates = Required<
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { normalizeBrazilianPhone } from '@/utilities/phone'
|
import { normalizeBrazilianPhone } from '@/lib/phone'
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
const campaignIdentifierSchema = z
|
const campaignIdentifierSchema = z
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
import { normalizeBrazilianPhone } from '@/utilities/phone'
|
import { normalizeBrazilianPhone } from '@/lib/phone'
|
||||||
|
|
||||||
export const positiveRelationshipId = z.number().int().positive()
|
export const positiveRelationshipId = z.number().int().positive()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import {
|
||||||
positiveRelationshipId,
|
positiveRelationshipId,
|
||||||
trimmedNullableText,
|
trimmedNullableText,
|
||||||
} from '@/lib/schemas/primitives'
|
} from '@/lib/schemas/primitives'
|
||||||
import { normalizeSearchPhrase } from '@/utilities/wordStartFilter'
|
import { normalizeSearchPhrase } from '@/lib/wordStartFilter'
|
||||||
|
|
||||||
export const supporterVoteIntentions = ['certo', 'tende_a_certo', 'indeciso', 'outro'] as const
|
export const supporterVoteIntentions = ['certo', 'tende_a_certo', 'indeciso', 'outro'] as const
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { positiveRelationshipId, trimmedNullableText } from '@/lib/schemas/primi
|
||||||
import {
|
import {
|
||||||
getVoteEstimateOrderViolation,
|
getVoteEstimateOrderViolation,
|
||||||
VOTE_ESTIMATE_ORDER_ERROR_MESSAGE,
|
VOTE_ESTIMATE_ORDER_ERROR_MESSAGE,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
const optionalEstimate = z.number().int().min(0).max(1_000_000).nullable().optional()
|
const optionalEstimate = z.number().int().min(0).max(1_000_000).nullable().optional()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
// Domain modules may import from here; this module must not import from them.
|
// Domain modules may import from here; this module must not import from them.
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import { isStaffCampaignRole, isUnrestrictedCampaignRole } from '@/lib/campaignRoles'
|
||||||
import type { CampaignUser, User } from '@/payload-types'
|
import type { CampaignUser, User } from '@/payload-types'
|
||||||
import type { Access, PayloadRequest, Where } from 'payload'
|
import type { Access, PayloadRequest, Where } from 'payload'
|
||||||
|
|
||||||
|
|
@ -47,15 +48,14 @@ export const isCampaignCandidate = (user: CampaignActor): boolean =>
|
||||||
|
|
||||||
/** Coordinator or candidate — unrestricted scope (all municipalities, decisions). */
|
/** Coordinator or candidate — unrestricted scope (all municipalities, decisions). */
|
||||||
export const isCampaignUnrestricted = (user: CampaignActor): boolean =>
|
export const isCampaignUnrestricted = (user: CampaignActor): boolean =>
|
||||||
isCampaignCoordinator(user) || isCampaignCandidate(user)
|
isCampaignUser(user) && isUnrestrictedCampaignRole(user.role)
|
||||||
|
|
||||||
export const isCampaignLeader = (user: CampaignActor): boolean =>
|
export const isCampaignLeader = (user: CampaignActor): boolean =>
|
||||||
isCampaignUser(user) && user.role === 'leader'
|
isCampaignUser(user) && user.role === 'leader'
|
||||||
|
|
||||||
/** Staff = coordinator, advisor, or candidate. Leaders are not staff. */
|
/** Staff = coordinator, advisor, or candidate. Leaders are not staff. */
|
||||||
export const isCampaignStaff = (user: CampaignActor): boolean =>
|
export const isCampaignStaff = (user: CampaignActor): boolean =>
|
||||||
isCampaignUser(user) &&
|
isCampaignUser(user) && isStaffCampaignRole(user.role)
|
||||||
(user.role === 'coordinator' || user.role === 'advisor' || user.role === 'candidate')
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Eligible relationship targets for advisor assignments (municipality / action plan).
|
* Eligible relationship targets for advisor assignments (municipality / action plan).
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { ActionPlan, CampaignDemand, CampaignUser } from '@/payload-types'
|
import type { ActionPlan, CampaignDemand, CampaignUser } from '@/payload-types'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { ActionPlan, CampaignUser } from '@/payload-types'
|
import type { ActionPlan, CampaignUser } from '@/payload-types'
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,18 @@ import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
|
import {
|
||||||
|
CAMPAIGN_INVITE_CONSENT_KEY,
|
||||||
|
SUPPORTER_REGISTRATION_CONSENT_KEY,
|
||||||
|
SUPPORTER_VOTE_INTENTION_CONSENT_KEY,
|
||||||
|
} from '@/lib/campaignConsentKeys'
|
||||||
import type { Consent } from '@/payload-types'
|
import type { Consent } from '@/payload-types'
|
||||||
import { CAMPAIGN_INVITE_CONSENT_KEY } from '@/utilities/campaignInvite'
|
|
||||||
import { hashConsentContent } from '@/utilities/consentContentHash'
|
import { hashConsentContent } from '@/utilities/consentContentHash'
|
||||||
|
|
||||||
export const SUPPORTER_REGISTRATION_CONSENT_KEY = 'apoiador-cadastro'
|
export {
|
||||||
export const SUPPORTER_VOTE_INTENTION_CONSENT_KEY = 'apoiador-intencao-voto'
|
SUPPORTER_REGISTRATION_CONSENT_KEY,
|
||||||
|
SUPPORTER_VOTE_INTENTION_CONSENT_KEY,
|
||||||
|
} from '@/lib/campaignConsentKeys'
|
||||||
|
|
||||||
export type ConsentDescriptor = {
|
export type ConsentDescriptor = {
|
||||||
id: number
|
id: number
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { CampaignUser, VotePledge } from '@/payload-types'
|
import type { CampaignUser, VotePledge } from '@/payload-types'
|
||||||
|
|
@ -5,8 +7,8 @@ import { loadMunicipalityScope } from '@/utilities/campaignMunicipalityScope'
|
||||||
import type { MunicipalityGoalCoverage } from '@/utilities/goalCoverage'
|
import type { MunicipalityGoalCoverage } from '@/utilities/goalCoverage'
|
||||||
import { loadMunicipalityGoalCoverageBundle } from '@/utilities/municipalityGoalAccount'
|
import { loadMunicipalityGoalCoverageBundle } from '@/utilities/municipalityGoalAccount'
|
||||||
import { relationshipId, requireRelationshipId } from '@/utilities/relationship'
|
import { relationshipId, requireRelationshipId } from '@/utilities/relationship'
|
||||||
import type { VoteEstimateScenario } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenario } from '@/lib/voteEstimate'
|
||||||
import { rollupMunicipalityStaffVotes } from '@/utilities/votePledgeData'
|
import { rollupMunicipalityStaffVotes } from '@/utilities/votePledgeViews'
|
||||||
|
|
||||||
export type StaffDashboardView = {
|
export type StaffDashboardView = {
|
||||||
kind: 'staff'
|
kind: 'staff'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { CampaignDemandKind, CampaignDemandStatus } from '@/lib/schemas/campaignDemand'
|
import type { CampaignDemandKind, CampaignDemandStatus } from '@/lib/schemas/campaignDemand'
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
import { createHash, randomBytes } from 'node:crypto'
|
import { createHash, randomBytes } from 'node:crypto'
|
||||||
|
|
||||||
import { buildWhatsAppUrl } from '@/utilities/phone'
|
import { buildWhatsAppUrl } from '@/lib/phone'
|
||||||
|
|
||||||
|
export { CAMPAIGN_INVITE_CONSENT_KEY } from '@/lib/campaignConsentKeys'
|
||||||
|
|
||||||
export const CAMPAIGN_INVITE_CONSENT_KEY = 'lideranca-autopreenchimento'
|
|
||||||
export const CAMPAIGN_INVITE_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000
|
export const CAMPAIGN_INVITE_EXPIRATION_MS = 7 * 24 * 60 * 60 * 1000
|
||||||
|
|
||||||
export type CampaignInviteKind = 'login' | 'autopreenchimento'
|
export type CampaignInviteKind = 'login' | 'autopreenchimento'
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,8 @@ import { cache } from 'react'
|
||||||
import type { Payload, Where } from 'payload'
|
import type { Payload, Where } from 'payload'
|
||||||
|
|
||||||
import type { CampaignUser, Municipality } from '@/payload-types'
|
import type { CampaignUser, Municipality } from '@/payload-types'
|
||||||
import {
|
import { aggregatePledgesByMunicipality } from '@/utilities/votePledgeData'
|
||||||
aggregatePledgesByMunicipality,
|
import { type MunicipalityPledgeAggregate } from '@/utilities/votePledgeViews'
|
||||||
type MunicipalityPledgeAggregate,
|
|
||||||
} from '@/utilities/votePledgeData'
|
|
||||||
|
|
||||||
/** Superset of the fields the dashboard, map, and list overview consume. */
|
/** Superset of the fields the dashboard, map, and list overview consume. */
|
||||||
export type ScopedMunicipalityDoc = Pick<
|
export type ScopedMunicipalityDoc = Pick<
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { RelationOption } from '@/components/campaign/RelationMultiSelect'
|
import type { RelationOption } from '@/components/campaign/RelationMultiSelect'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Config } from '@/payload-types'
|
import type { Config } from '@/payload-types'
|
||||||
|
|
||||||
import configPromise from '@payload-config'
|
import configPromise from '@payload-config'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache tag for every `unstable_cache` entry derived from the immutable TSE
|
* Cache tag for every `unstable_cache` entry derived from the immutable TSE
|
||||||
* election collections (2014/2018/2022). The data only changes when the seed
|
* election collections (2014/2018/2022). The data only changes when the seed
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import configPromise from '@payload-config'
|
import configPromise from '@payload-config'
|
||||||
import { unstable_cache } from 'next/cache'
|
import { unstable_cache } from 'next/cache'
|
||||||
import { getPayload } from 'payload'
|
import { getPayload } from 'payload'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import { and, eq, type AnyColumn } from '@payloadcms/db-postgres/drizzle'
|
import { and, eq, type AnyColumn } from '@payloadcms/db-postgres/drizzle'
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Config } from '@/payload-types'
|
import type { Config } from '@/payload-types'
|
||||||
|
|
||||||
import configPromise from '@payload-config'
|
import configPromise from '@payload-config'
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import { formatElectionNumber } from '@/lib/electionInsights'
|
import { formatElectionNumber } from '@/lib/electionInsights'
|
||||||
import type { SuggestedGoalByScenario } from '@/utilities/municipalityPotential'
|
import type { SuggestedGoalByScenario } from '@/utilities/municipalityPotential'
|
||||||
import type { MunicipalityPledgeAggregate } from '@/utilities/votePledgeData'
|
import type { MunicipalityPledgeAggregate } from '@/utilities/votePledgeViews'
|
||||||
import {
|
import {
|
||||||
getVoteEstimateForScenario,
|
getVoteEstimateForScenario,
|
||||||
VOTE_ESTIMATE_SCENARIOS,
|
VOTE_ESTIMATE_SCENARIOS,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
type VoteEstimateScenarioFields,
|
type VoteEstimateScenarioFields,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* E8 "conta da cadeira" — coverage of the goal by auditable pledges.
|
* E8 "conta da cadeira" — coverage of the goal by auditable pledges.
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { RelationOption } from '@/components/campaign/RelationMultiSelect'
|
import type { RelationOption } from '@/components/campaign/RelationMultiSelect'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { SupportStatus } from '@/lib/schemas/leadership'
|
import type { SupportStatus } from '@/lib/schemas/leadership'
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,8 @@ import { cache } from 'react'
|
||||||
|
|
||||||
import { getMunicipalityFederalBaseline } from '@/lib/bahiaElectionAggregates'
|
import { getMunicipalityFederalBaseline } from '@/lib/bahiaElectionAggregates'
|
||||||
import type { Municipality } from '@/payload-types'
|
import type { Municipality } from '@/payload-types'
|
||||||
import {
|
import { aggregatePledgesByMunicipality } from '@/utilities/votePledgeData'
|
||||||
aggregatePledgesByMunicipality,
|
import { emptyMunicipalityPledgeAggregate, resolveMunicipalityStaffVoteTotal } from '@/utilities/votePledgeViews'
|
||||||
emptyMunicipalityPledgeAggregate,
|
|
||||||
resolveMunicipalityStaffVoteTotal,
|
|
||||||
} from '@/utilities/votePledgeData'
|
|
||||||
import {
|
import {
|
||||||
computeTerritoryRollup,
|
computeTerritoryRollup,
|
||||||
type TerritoryMunicipalityInput,
|
type TerritoryMunicipalityInput,
|
||||||
|
|
@ -18,7 +15,7 @@ import {
|
||||||
import {
|
import {
|
||||||
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
|
|
||||||
type MunicipalityDoc = Pick<
|
type MunicipalityDoc = Pick<
|
||||||
Municipality,
|
Municipality,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import configPromise from '@payload-config'
|
import configPromise from '@payload-config'
|
||||||
import { unstable_cache } from 'next/cache'
|
import { unstable_cache } from 'next/cache'
|
||||||
import { getPayload, type Payload } from 'payload'
|
import { getPayload, type Payload } from 'payload'
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,8 @@ import {
|
||||||
type MunicipalityUpdateViewModel,
|
type MunicipalityUpdateViewModel,
|
||||||
} from '@/utilities/municipalityUpdatePageData'
|
} from '@/utilities/municipalityUpdatePageData'
|
||||||
import type { MunicipalityDetailViewModel } from '@/utilities/municipalityViewModels'
|
import type { MunicipalityDetailViewModel } from '@/utilities/municipalityViewModels'
|
||||||
import {
|
import { loadMunicipalityPledges } from '@/utilities/votePledgeData'
|
||||||
aggregateMunicipalityPledgesFromRows,
|
import { aggregateMunicipalityPledgesFromRows, type MunicipalityPledgeAggregate } from '@/utilities/votePledgeViews'
|
||||||
loadMunicipalityPledges,
|
|
||||||
type MunicipalityPledgeAggregate,
|
|
||||||
} from '@/utilities/votePledgeData'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* E16 dossiê — section caps. The dossier is a 1–2 page pre-visit read, not a
|
* E16 dossiê — section caps. The dossier is a 1–2 page pre-visit read, not a
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import configPromise from '@payload-config'
|
import configPromise from '@payload-config'
|
||||||
import { unstable_cache } from 'next/cache'
|
import { unstable_cache } from 'next/cache'
|
||||||
import { getPayload, type Payload } from 'payload'
|
import { getPayload, type Payload } from 'payload'
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,8 @@ import {
|
||||||
zeroByVoteEstimateScenario,
|
zeroByVoteEstimateScenario,
|
||||||
type VoteEstimateScenarioFields,
|
type VoteEstimateScenarioFields,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import {
|
import { emptyMunicipalityPledgeAggregate, type MunicipalityPledgeAggregate } from '@/utilities/votePledgeViews'
|
||||||
emptyMunicipalityPledgeAggregate,
|
|
||||||
type MunicipalityPledgeAggregate,
|
|
||||||
} from '@/utilities/votePledgeData'
|
|
||||||
|
|
||||||
type GoalAccountReader = CampaignUser | User
|
type GoalAccountReader = CampaignUser | User
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import {
|
||||||
type RawSearchParams as CampaignListRawSearchParams,
|
type RawSearchParams as CampaignListRawSearchParams,
|
||||||
} from '@/utilities/campaignListUrl'
|
} from '@/utilities/campaignListUrl'
|
||||||
import { politicalTrendLabels, type PoliticalTrendStatus } from '@/utilities/municipalityLabels'
|
import { politicalTrendLabels, type PoliticalTrendStatus } from '@/utilities/municipalityLabels'
|
||||||
import { normalizeSearchPhrase } from '@/utilities/wordStartFilter'
|
import { normalizeSearchPhrase } from '@/lib/wordStartFilter'
|
||||||
|
|
||||||
import type { Municipality } from '@/payload-types'
|
import type { Municipality } from '@/payload-types'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { HISTORICAL_SERIES_YEARS } from '@/lib/electionResults'
|
import { HISTORICAL_SERIES_YEARS } from '@/lib/electionResults'
|
||||||
import type { MunicipalitiesByIbgeCode } from '@/utilities/municipalityMapNavigation'
|
import type { MunicipalitiesByIbgeCode } from '@/utilities/municipalityMapNavigation'
|
||||||
import type { VoteEstimateScenario } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenario } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Client-safe contract of the municipality map: the bundle shape the server
|
* Client-safe contract of the municipality map: the bundle shape the server
|
||||||
|
|
|
||||||
|
|
@ -30,12 +30,8 @@ import {
|
||||||
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
DEFAULT_VOTE_ESTIMATE_SCENARIO,
|
||||||
VOTE_ESTIMATE_SCENARIOS,
|
VOTE_ESTIMATE_SCENARIOS,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import {
|
import { emptyMunicipalityPledgeAggregate, resolveMunicipalityStaffVoteTotal, type MunicipalityPledgeAggregate } from '@/utilities/votePledgeViews'
|
||||||
emptyMunicipalityPledgeAggregate,
|
|
||||||
resolveMunicipalityStaffVoteTotal,
|
|
||||||
type MunicipalityPledgeAggregate,
|
|
||||||
} from '@/utilities/votePledgeData'
|
|
||||||
|
|
||||||
export type { MunicipalityMapSlugEntry, MunicipalitiesByIbgeCode } from '@/utilities/municipalityMapNavigation'
|
export type { MunicipalityMapSlugEntry, MunicipalitiesByIbgeCode } from '@/utilities/municipalityMapNavigation'
|
||||||
// Client components import the map vocabulary from the contract module; the
|
// Client components import the map vocabulary from the contract module; the
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload, Where } from 'payload'
|
import type { Payload, Where } from 'payload'
|
||||||
|
|
||||||
import { bahiaIdentityTerritories } from '@/lib/bahiaTerritories'
|
import { bahiaIdentityTerritories } from '@/lib/bahiaTerritories'
|
||||||
|
|
@ -33,11 +35,8 @@ import {
|
||||||
} from '@/utilities/municipalityViewModels'
|
} from '@/utilities/municipalityViewModels'
|
||||||
import { relationshipId } from '@/utilities/relationship'
|
import { relationshipId } from '@/utilities/relationship'
|
||||||
import { loadStateDeputySummaries } from '@/utilities/stateDeputyData'
|
import { loadStateDeputySummaries } from '@/utilities/stateDeputyData'
|
||||||
import { type VoteEstimateScenario } from '@/utilities/voteEstimate'
|
import { type VoteEstimateScenario } from '@/lib/voteEstimate'
|
||||||
import {
|
import { rollupMunicipalityStaffVotes, type MunicipalityPledgeAggregate } from '@/utilities/votePledgeViews'
|
||||||
rollupMunicipalityStaffVotes,
|
|
||||||
type MunicipalityPledgeAggregate,
|
|
||||||
} from '@/utilities/votePledgeData'
|
|
||||||
|
|
||||||
export class MunicipalityNotFoundError extends Error {
|
export class MunicipalityNotFoundError extends Error {
|
||||||
override name = 'MunicipalityNotFoundError'
|
override name = 'MunicipalityNotFoundError'
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import {
|
||||||
import { municipalityCatalog } from '@/lib/municipalityCatalog'
|
import { municipalityCatalog } from '@/lib/municipalityCatalog'
|
||||||
import type { BahiaIdentityTerritory } from '@/lib/bahiaTerritories'
|
import type { BahiaIdentityTerritory } from '@/lib/bahiaTerritories'
|
||||||
import type { CampaignGoal } from '@/payload-types'
|
import type { CampaignGoal } from '@/payload-types'
|
||||||
import type { VoteEstimateScenario } from '@/utilities/voteEstimate'
|
import type { VoteEstimateScenario } from '@/lib/voteEstimate'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* E8 "conta da cadeira" — derived electoral potential per municipality, built
|
* E8 "conta da cadeira" — derived electoral potential per municipality, built
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { MunicipalityVoteRankEntry } from '@/lib/municipalityVoteRank'
|
import type { MunicipalityVoteRankEntry } from '@/lib/municipalityVoteRank'
|
||||||
|
|
@ -12,9 +14,9 @@ import {
|
||||||
toVoteEstimateScenarioViewModel,
|
toVoteEstimateScenarioViewModel,
|
||||||
type VoteEstimateScenario,
|
type VoteEstimateScenario,
|
||||||
type VoteEstimateScenarioViewModel,
|
type VoteEstimateScenarioViewModel,
|
||||||
} from '@/utilities/voteEstimate'
|
} from '@/lib/voteEstimate'
|
||||||
import type { MunicipalityPledgeAggregate } from '@/utilities/votePledgeData'
|
import type { MunicipalityPledgeAggregate } from '@/utilities/votePledgeViews'
|
||||||
import { createEmptyMunicipalityPledgeAggregate } from '@/utilities/votePledgeData'
|
import { createEmptyMunicipalityPledgeAggregate } from '@/utilities/votePledgeViews'
|
||||||
|
|
||||||
export const municipalityListSelect = {
|
export const municipalityListSelect = {
|
||||||
name: true,
|
name: true,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { OrganizationKind } from '@/lib/schemas/organization'
|
import type { OrganizationKind } from '@/lib/schemas/organization'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Post, Tag } from '@/payload-types'
|
import type { Post, Tag } from '@/payload-types'
|
||||||
|
|
||||||
import configPromise from '@payload-config'
|
import configPromise from '@payload-config'
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { CampaignUser, Leadership, StateDeputy } from '@/payload-types'
|
import type { CampaignUser, Leadership, StateDeputy } from '@/payload-types'
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,20 @@
|
||||||
import type { Where } from 'payload'
|
import type { Where } from 'payload'
|
||||||
|
|
||||||
import { isContactSearchQueryReady, normalizeContactSearchQuery } from '@/lib/contactSearchQuery'
|
import { isContactSearchQueryReady, normalizeContactSearchQuery } from '@/lib/contactSearchQuery'
|
||||||
import { normalizeBrazilianPhone } from '@/utilities/phone'
|
import { normalizeBrazilianPhone } from '@/lib/phone'
|
||||||
import type { SupporterListState } from '@/utilities/supporterUi'
|
import type { SupporterVoteIntention } from '@/lib/schemas/supporter'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The filters the where-builder actually reads — a structural subset of
|
||||||
|
* `SupporterListState` (`supporterUi.ts`), declared here so the type flows
|
||||||
|
* url-module → where-builder without a module cycle.
|
||||||
|
*/
|
||||||
|
export type SupporterListFilterInput = {
|
||||||
|
q?: string
|
||||||
|
voteIntention?: SupporterVoteIntention
|
||||||
|
city?: string
|
||||||
|
municipality?: number
|
||||||
|
}
|
||||||
|
|
||||||
export type SupporterSearchTerms = {
|
export type SupporterSearchTerms = {
|
||||||
q: string
|
q: string
|
||||||
|
|
@ -35,7 +47,7 @@ const buildPayloadSearchWhere = (terms: SupporterSearchTerms): Where => {
|
||||||
return { or: searchFilters }
|
return { or: searchFilters }
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toPayloadWhere = (state: SupporterListState): Where => {
|
export const toPayloadWhere = (state: SupporterListFilterInput): Where => {
|
||||||
const filters: Where[] = []
|
const filters: Where[] = []
|
||||||
|
|
||||||
if (state.q) {
|
if (state.q) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import {
|
||||||
buildSupporterSearchTerms,
|
buildSupporterSearchTerms,
|
||||||
type SupporterSearchTerms,
|
type SupporterSearchTerms,
|
||||||
} from '@/utilities/supporterListFilters'
|
} from '@/utilities/supporterListFilters'
|
||||||
import type { SupporterListState } from '@/utilities/supporterUi'
|
import type { SupporterListFilterInput } from '@/utilities/supporterListFilters'
|
||||||
|
|
||||||
export type AggregateSqlConditions = {
|
export type AggregateSqlConditions = {
|
||||||
conditions: ReturnType<typeof sql>[]
|
conditions: ReturnType<typeof sql>[]
|
||||||
|
|
@ -28,7 +28,7 @@ const buildSqlSearchCondition = (terms: SupporterSearchTerms): ReturnType<typeof
|
||||||
return sql`(${sql.join(searchTerms, sql` OR `)})`
|
return sql`(${sql.join(searchTerms, sql` OR `)})`
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toAggregateSqlConditions = (state: SupporterListState): AggregateSqlConditions => {
|
export const toAggregateSqlConditions = (state: SupporterListFilterInput): AggregateSqlConditions => {
|
||||||
const conditions: ReturnType<typeof sql>[] = []
|
const conditions: ReturnType<typeof sql>[] = []
|
||||||
let needsContactJoin = false
|
let needsContactJoin = false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'server-only'
|
||||||
|
|
||||||
import type { Payload } from 'payload'
|
import type { Payload } from 'payload'
|
||||||
|
|
||||||
import type { RelationOption } from '@/components/campaign/RelationMultiSelect'
|
import type { RelationOption } from '@/components/campaign/RelationMultiSelect'
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import {
|
||||||
resolveBahiaMunicipality,
|
resolveBahiaMunicipality,
|
||||||
type SupporterVoteIntention,
|
type SupporterVoteIntention,
|
||||||
} from '@/lib/schemas/supporter'
|
} from '@/lib/schemas/supporter'
|
||||||
|
import { isStaffCampaignRole } from '@/lib/campaignRoles'
|
||||||
import type { CampaignUser, Supporter } from '@/payload-types'
|
import type { CampaignUser, Supporter } from '@/payload-types'
|
||||||
import {
|
import {
|
||||||
buildListHref,
|
buildListHref,
|
||||||
|
|
@ -122,4 +123,4 @@ export const getSupporterScopeLabel = (total: number): string =>
|
||||||
|
|
||||||
/** Staff roles with supporter-area access — matches collection-level supporter access. */
|
/** Staff roles with supporter-area access — matches collection-level supporter access. */
|
||||||
export const canAccessSupporterArea = (role: CampaignUser['role']): boolean =>
|
export const canAccessSupporterArea = (role: CampaignUser['role']): boolean =>
|
||||||
role === 'coordinator' || role === 'advisor' || role === 'candidate'
|
isStaffCampaignRole(role)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { territoryForCity } from '@/lib/bahiaTerritories'
|
import { territoryForCity } from '@/lib/bahiaTerritories'
|
||||||
import type { SupporterVoteIntention } from '@/lib/schemas/supporter'
|
import type { SupporterVoteIntention } from '@/lib/schemas/supporter'
|
||||||
import type { CampaignUser, Contact, Municipality, Supporter } from '@/payload-types'
|
import type { CampaignUser, Contact, Municipality, Supporter } from '@/payload-types'
|
||||||
import { formatBrazilianPhoneInput } from '@/utilities/phone'
|
import { formatBrazilianPhoneInput } from '@/lib/phone'
|
||||||
import { isPopulatedRelationship } from '@/utilities/relationship'
|
import { isPopulatedRelationship } from '@/utilities/relationship'
|
||||||
import { supporterSourceLabels } from '@/utilities/supporterUi'
|
import { supporterSourceLabels } from '@/utilities/supporterUi'
|
||||||
|
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue