Data Import Wizard
Multi-step modal wizard that turns an Excel/CSV upload into Docyrus data source records — drag-drop, auto-mapped column→field assignment, per-type config, value-renderer preview, and a result summary.
Installation
pnpm dlx @docyrus/cli add @docyrus/ui-data-import-wizardpnpm add @docyrus/api-client @tanstack/react-queryWhen to Use
Reach for <DataImportWizard> (and the matching useDocyrusDataImportWizard hook) whenever you want to give end-users a fully-guided "upload XLSX → see results" flow against any Docyrus data source. The component is presentational — every prop is a state slice plus a callback — so the smart hook does the heavy lifting (file upload, analyse, auto-mapping, preview, import).
If you only need to import data programmatically, use the hook's imperative helpers (uploadAsync, analyseAsync, importAsync) and ignore the rendered wizard element.
Usage
'use client';
import { useDocyrusAuth } from '@docyrus/signin';
import { Button } from '@docyrus/ui/primitives/ui/button';
import { useDocyrusDataImportWizard } from '@docyrus/ui/hooks/use-docyrus-data-import-wizard';
export function ContactsImportButton() {
const { client } = useDocyrusAuth();
if (!client) return null;
const { openWizard, wizard } = useDocyrusDataImportWizard({
client,
appSlug: 'crm',
dataSourceSlug: 'contact',
requiredFieldSlugs: ['email']
});
return (
<>
<Button onClick={openWizard}>Import contacts…</Button>
{wizard}
</>
);
}Wizard Steps
| Step | Purpose |
|---|---|
| Upload | Drag-drop / file picker. Validates extension + size client-side, then chains upload → analyse mutations. |
| Map fields | One card per source column. Per type: relation reference_key, phone country code, date format, money/phone companion column. Auto-maps obvious matches. |
| Options | Toggle "Update existing records on unique-key match" (upsertUniqueFields). Summary tiles for row, column, and unique-field counts. |
| Preview | Renders the first N rows using useDocyrusFieldComponent(field.type, 'value-renderer') so every cell looks like it does in <DataGrid>. |
| Result | Tiles for successful records, warnings, duplicates, and errors. Per-row error list. "Import another file" / "Done" actions. |
API Reference
<DataImportWizard>
The dumb component. Drive every prop from your own state — typically through useDocyrusDataImportWizard, which already wires every prop. Only reach for the component directly when you need a custom state machine (e.g. a server-component wrapper).
| Prop | Type | Description |
|---|---|---|
open / onOpenChange | boolean / (open: boolean) => void | Modal open state. |
step / onStepChange | ImportWizardStep / (step) => void | Current step + setter. Steps: upload, mapping, options, preview, progress, result. |
targetFields | ReadonlyArray<DocyrusFieldLike> | Fields the user can map to. Supplied by the hook from useDocyrusDataViewSelect. |
requiredFieldSlugs | ReadonlyArray<string> | Slugs that must be mapped before leaving the mapping step. |
uniqueFieldSlugs | ReadonlyArray<string> | Slugs covered by unique indexes (drives the upsert toggle). |
file / uploadedFile / analysedFile / importResult | various | Snapshots of each phase's payload. |
mapping / onMappingChange | WizardMappingMap / (next) => void | Per-source-column mapping state. |
upsertUniqueFields / onUpsertChange | boolean / (next) => void | Upsert toggle. |
isUploading / isAnalysing / isImporting | boolean | Mutation pending flags. |
uploadError / analyseError / importError | Error | null | Per-phase errors surfaced in the relevant step's banner. |
onPickFile / onAnalyse / onConfirmMapping / onConfirmOptions / onStartImport / onReset / onClose | callbacks | Hook into each step's primary action. |
title / description / icon | ReactNode / ReactNode / string | Header customization (defaults are translated). |
previewRowCount | number | Default 10. |
maxFileSizeBytes | number | Default 20 * 1024 * 1024 (20 MB). |
acceptedExtensions | ReadonlyArray<string> | Default ['xlsx', 'xls', 'csv']. |
className | string | Extra class for the dialog body. |
Components
| Component | Description |
|---|---|
DataImportWizard | Top-level shell — composes AwesomeDialog + Stepper + step bodies + footer. |
UploadStep | Step 1 — drag-drop + file picker + spinners. |
MappingStep | Step 2 — per-column target select + per-type sub-config. |
OptionsStep | Step 3 — upsert toggle + summary tiles. |
PreviewStep | Step 4 — value-renderer-driven preview table. |
ProgressStep | Steps 5/6 — progress UI + result summary tiles. |
Each step component is exported individually so consumers can rearrange or replace them in custom flows.
Helpers
| Helper | Description |
|---|---|
buildAutoMapping(columns, fields) | Greedy slug + name + token-Jaccard matcher. Returns a WizardMappingMap. |
inferFieldOptions(field) | Default fieldOptions for field-relation, field-phone, and field-date* (matches the import API contract). |
validateMapping(mapping, requiredSlugs) | Returns { valid, missing, duplicateTargets }. |
buildImportOptions(mapping, fields, upsert, uniqueData?) | Converts UI state to the { fieldMapping, fieldOptions, uniqueData, upsertUniqueFields } POST body. |
collectUniqueDataLookups(mapping, fields, analysedFile) | Identifies columns that benefit from uniqueData pre-resolution. |
buildUniqueDataPayload(specs, resolved) | Merges pre-resolved matchedId maps with the lookup specs into the final payload entry. |
getSecondarySlug(fieldType) | Returns '__amount_currency' / '__phone_country' for composite field types. |
slugify(value) / normalizeKey(value) | Lowercase / kebab-case helpers used by the auto-mapper. |
Type Exports
| Type | Description |
|---|---|
DataImportWizardProps | Props for the top-level component. |
ImportWizardStep | 'upload' | 'mapping' | 'options' | 'preview' | 'progress' | 'result'. |
WizardMappingMap | Record<sourceColumn, ColumnMappingState>. |
ColumnMappingState | Per-source-column UI mapping: target slug, optional companion column, type-specific fieldOptions. |
UploadedFileInfo | Shape returned by the upload endpoint. |
AnalysedFile | Shape returned by the analyse endpoint (rows, columns, unique-field hints). |
ImportPayloadOptions | Body posted to the import endpoint. |
ImportResultPayload | Result returned by the import endpoint (success count, errors, duplicates). |
MappingValidationResult | { valid, missing, duplicateTargets }. |
ReservedTargetSlug | 'name' | 'description' | 'created_on' | 'autonumber_id'. |
UniqueDataLookupSpec | Helper type produced by collectUniqueDataLookups. |
Field-Type Awareness
Like useDocyrusDataGrid, every field type is handled automatically:
| Field type | Mapping-step extras | Preview |
|---|---|---|
field-relation, field-relatedField, field-userSelect, field-userMultiSelect | reference_key text input (defaults to 'name'). | Relation chip via RelationValue. |
field-phone | Default country code input (+90 default) + companion column for __phone_country. | Phone display. |
field-money | Companion column select for __amount_currency. | Currency formatter. |
field-date, field-dateTime, field-dateRange | DAY/MONTH/YEAR ordering select. | Tenant-aware date formatter. |
field-enum, field-status, field-select, field-radioGroup, field-multiSelect, field-tagSelect | Auto-mapped to the matching slug. | Color-coded enum chip. |
Reserved (name, description, created_on, autonumber_id) | Surfaced in the System group. | Plain text. |
See Also
useDocyrusDataImportWizard— smart hook that wires the wizard to a Docyrus data source in one call.useDocyrusFieldComponent— the registry that powers the preview-step value renderers.useDocyrusDataGrid— companion hook for displaying the imported records in a grid.
Data Grid View Select
A view selector with integrated view editor for DataGrid. Supports dropdown, horizontal-tabs, and vertical-tabs variants with full CRUD operations on saved views.
Data Table
A lightweight, read-only TanStack table for Docyrus data sources with value renderers, row selection, grouping, and optional pagination.