teqo/src/utilities/supporterImport.ts
Francisco Ignácio Fontoura Solla 9ccfb3b704 Simplify C6 supporter paths and register C8 scale/DRY follow-ups.
Apply the /simplify cleanup to the C6 commit (identity maps, dead branches,
relationshipId reuse, native base64url, rowCount fix, canManageCampaignUsers
reuse) and register the unimplemented debits as roadmap item C8 with its plan.
2026-07-18 22:34:55 -03:00

54 lines
1.5 KiB
TypeScript

import type { SupporterVoteIntention } from '@/lib/schemas/supporter'
export type SupporterImportRowStatus =
| 'ok'
| 'duplicado_pelo_telefone'
| 'telefone_invalido'
| 'municipio_nao_reconhecido'
| 'nome_invalido'
| 'intencao_invalida'
export type SupporterImportPreviewRowBase = {
line: number
nome: string
telefone: string
municipio: string
intencao: string
}
export type SupporterImportOkRow = SupporterImportPreviewRowBase & {
status: 'ok'
normalizedPhone: string
canonicalCity?: string
voteIntention?: SupporterVoteIntention
}
export type SupporterImportPreviewRow =
| SupporterImportOkRow
| (SupporterImportPreviewRowBase & {
status: Exclude<SupporterImportRowStatus, 'ok'>
normalizedPhone?: string
canonicalCity?: string
voteIntention?: SupporterVoteIntention
})
export type SupporterImportPreviewResult = {
counts: {
ok: number
duplicate: number
error: number
}
/** First N rows for the on-screen preview table (the full set stays server-side). */
sampleRows: SupporterImportPreviewRow[]
/** Precomputed CSV of every error row, for the "Baixar relatório de erros" button. */
errorReportCsv: string
/** HMAC-signed token that `confirmSupporterImport` exchanges for the staged batch. */
importToken: string
}
export const isSupporterImportOkRow = (
row: SupporterImportPreviewRow,
): row is SupporterImportOkRow => row.status === 'ok'
export const isPreviewErrorRow = (row: SupporterImportPreviewRow): boolean =>
row.status !== 'ok' && row.status !== 'duplicado_pelo_telefone'