Add country mapping support for imports and geographic map
- Add normalizeCountryToCode utility to convert country names to ISO-2 codes - Support English, French and common alternate spellings - Update Typeform import to support country field mapping - Update Notion import to support country field mapping - Allow project.update to set/update country with automatic normalization - Fix geographic distribution map showing empty when country data exists Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
getNotionDatabaseSchema,
|
||||
queryNotionDatabase,
|
||||
} from '@/lib/notion'
|
||||
import { normalizeCountryToCode } from '@/lib/countries'
|
||||
|
||||
export const notionImportRouter = router({
|
||||
/**
|
||||
@@ -91,6 +92,7 @@ export const notionImportRouter = router({
|
||||
teamName: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
tags: z.string().optional(), // Multi-select property
|
||||
country: z.string().optional(), // Country name or ISO code
|
||||
}),
|
||||
// Store unmapped columns in metadataJson
|
||||
includeUnmappedInMetadata: z.boolean().default(true),
|
||||
@@ -148,6 +150,15 @@ export const notionImportRouter = router({
|
||||
}
|
||||
}
|
||||
|
||||
// Get country and normalize to ISO code
|
||||
let country: string | null = null
|
||||
if (input.mappings.country) {
|
||||
const countryValue = getPropertyValue(record.properties, input.mappings.country)
|
||||
if (typeof countryValue === 'string') {
|
||||
country = normalizeCountryToCode(countryValue)
|
||||
}
|
||||
}
|
||||
|
||||
// Build metadata from unmapped columns
|
||||
let metadataJson: Record<string, unknown> | null = null
|
||||
if (input.includeUnmappedInMetadata) {
|
||||
@@ -156,6 +167,7 @@ export const notionImportRouter = router({
|
||||
input.mappings.teamName,
|
||||
input.mappings.description,
|
||||
input.mappings.tags,
|
||||
input.mappings.country,
|
||||
].filter(Boolean))
|
||||
|
||||
metadataJson = {}
|
||||
@@ -179,6 +191,7 @@ export const notionImportRouter = router({
|
||||
teamName: typeof teamName === 'string' ? teamName.trim() : null,
|
||||
description: typeof description === 'string' ? description : null,
|
||||
tags,
|
||||
country,
|
||||
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
|
||||
externalIdsJson: {
|
||||
notionPageId: record.id,
|
||||
|
||||
Reference in New Issue
Block a user