Examples
importOK is a reusable custom web component that embeds an import wizard into your app. You can follow this installation guide to use it as a React component, in your Next.js project.
For the sake of simplicity, we are going to install and configure importOK to import a list of Contacts. Our app will be expecting four fields: first name
last name
email
and phone
First, import the importOK package for React:
1npm install @importok/javascript2npm install @importok/react
To embed the wizard, add the following into your page. The wizard will be added as a child element to the first argument provided, so make sure to adjust that accordingly.
1import dynamic from 'next/dynamic'; 2 3const ImportokWizard = dynamic(() => import('@importok/react'), { 4 ssr: false 5}); 6 7export default function Home() { 8 /** 9 * Import fields to be mapped10 * Check https://importok.io/docs/fields for more details11 */12 const fields = {13 first_name: {14 label: 'First Name',15 transformers: 'capitalize|trim'16 },17 last_name: {18 label: 'Last Name',19 validators: 'required',20 transformers: 'capitalize|trim'21 },22 email: {23 label: 'Email',24 validators: 'email|required',25 transformers: 'lowercase|trim'26 },27 phone: {28 label: 'Phone',29 transformers: 'trim'30 }31 };32 33 /**34 * Custom transformers35 * Check https://importok.io/docs/custom-transformers for more details36 */37 const transformers = {};38 39 /**40 * Custom validators41 * Check https://importok.io/docs/custom-validators for more details42 */43 const validators = {};44 45 /**46 * Custom providers47 * Check https://importok.io/docs/data-providers for more details48 */49 const providers = {};50 51 /**52 * Push the provided record to the API53 * Check https://importok.io/docs/webhooks for more details54 */55 const saveRecord = async function (record, meta) {56 return await fetch('https://httpstat.us/200');57 };58 59 return (60 <div className="App">61 <ImportokWizard62 title="ImportOK Example for Next.js"63 fields={fields}64 transformers={transformers}65 validators={validators}66 providers={providers}67 onRecordReady={saveRecord}68 />69 </div>70 );71}
That's all! You can now open your page and give it a try. Keep in mind that there is a limit of 20 records for each import during the trial. Once subscribed, you will receive access to the private packages and lift the trial limits.
title
Description | Primary text to be displayed at the top of the wizard, across all steps. |
---|---|
Type | string |
Default | Import |
subtitles
Description | Secondary text to be displayed at each wizard step. |
---|---|
Type | string[] |
Default | [ 'Upload your file to get started', 'Match source to target columns', 'Review validation errors and fix your data', 'Please do not close this window during the import process.', ] |
fields
Description | Fields to be mapped - refer to Fields for more details. |
---|---|
Type | { [key: string]: ImportField; } |
Default | {} |
transformers
Description | Custom transformers - refer to Build your own transformers for more details. |
---|---|
Type | { [key: string]: (record: ImportRecord, key: string, ...args: string[]); } |
Default | {} |
validators
Description | Custom validators - refer to Build your own validators for more details. |
---|---|
Type | { [key: string]: (record: ImportRecord, key: string, ...args: string[]); } |
Default | {} |
providers
Description | Custom providers - refer to Data providers for more details. |
---|---|
Type | { [key: string]: DataProvider; } |
Default | {} |
mapper
Description | Custom mapping strategy - refer to Mapping strategy for more details. |
---|---|
Type | MapperStrategy |
Default | LevenshteinMappingStrategy |
style
Description | Custom CSS rules. Please refer to Styling for more details. |
---|---|
Type | string |
Default | undefined |
locale
Description | The locale to use. Please refer to Internalization for more details. |
---|---|
Type | string |
Default | en |
translations
Description | Provide additional translations, or overwrite the existing ones. Please refer to Internalization for more details. |
---|---|
Type | { [key: string]: { [key: string]: string } } |
sampleFile
Description | Example file that can be download in the first step as an example. |
---|---|
Type | string |
Default | '' |
uploadedFile
Description | Raw file to be imported. Useful if your application already offers an upload area. |
---|---|
Type | File |
Default | undefined |
throttle
Description | Throttle the import process - applicable when used with onRecordReady |
---|---|
Type | number |
Default | 0 (no throttle) |
meta
Description | Meta data to be passed to onRecordReady and onImportReady . |
---|---|
Type | object |
Default | {} |
onRecordReady
Description | Callback to import a single record. |
---|---|
Type | function(record: ImportRecord, meta: object): Promise<any> |
Event props |
|
Default | undefined |
onImportReady
Description | Callback to import multiple records at once. |
---|---|
Type | function(records: ImportRecord[], meta: object): Promise<any> |
Event props |
|
Default | undefined |
onImportProgress
Description | Triggered when the progress changes. |
---|---|
Event props |
|
onStepEnter
Description | Triggered when the user enters a new step of the wizard. |
---|---|
Event props |
|
onStepExit
Description | Triggered when the user is about to exit the current step. |
---|---|
Event props |
|