teqo-backup/src/utilities/campaignFormFields.ts
Francisco Ignácio Fontoura Solla 9fdbae05d7 Add C6 scale/DRY for supporters: bulk import, KPI aggregate, shared shells.
Phase 1 UX: StrictCombobox municipality in SupporterForm, AlertDialog in
RemoveSupporterDataButton. Phase 2 DRY: campaignListUrl + CampaignListPagination
+ campaignFormFields + mapCampaignFormActionError shared across nuclei,
supporters and action plans. Phase 3: single SQL aggregate for supporter list
KPIs via drizzle in the Payload txn. Phase 4: bulk drizzle insert for CSV import
inside the existing Payload txn with ON CONFLICT DO NOTHING, plus a fail-closed
skipContactPhoneInvariant context flag. Phase 5: HMAC-signed single-use import
token backed by a new supporterImportBatch staging collection so the full ok-row
set never crosses the Server Action boundary twice.
2026-07-18 22:17:31 -03:00

21 lines
532 B
TypeScript

export const fieldError = (
fieldErrors: Record<string, string[]> | undefined,
field: string,
): string | undefined => fieldErrors?.[field]?.[0]
export const errorProps = (
fieldErrors: Record<string, string[]> | undefined,
field: string,
idPrefix: string,
): {
error: string | undefined
invalid: boolean
describedBy: string | undefined
} => {
const error = fieldError(fieldErrors, field)
return {
error,
invalid: Boolean(error),
describedBy: error ? `${idPrefix}-${field}-error` : undefined,
}
}