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.
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 ImportokWizard from '@importok/react'; 2 3function App() { 4 /** 5 * Import fields to be mapped 6 * Check https://importok.io/docs/fields for more details 7 */ 8 const fields = { 9 first_name: {10 label: 'First Name',11 transformers: 'capitalize|trim'12 },13 last_name: {14 label: 'Last Name',15 validators: 'required',16 transformers: 'capitalize|trim'17 },18 email: {19 label: 'Email',20 validators: 'email|required',21 transformers: 'lowercase|trim'22 },23 phone: {24 label: 'Phone',25 transformers: 'trim'26 }27 };28 29 /**30 * Custom transformers31 * Check https://importok.io/docs/custom-transformers for more details32 */33 const transformers = {};34 35 /**36 * Custom validators37 * Check https://importok.io/docs/custom-validators for more details38 */39 const validators = {};40 41 /**42 * Custom providers43 * Check https://importok.io/docs/data-providers for more details44 */45 const providers = {};46 47 /**48 * Push the provided record to the API49 * Check https://importok.io/docs/webhooks for more details50 */51 const saveRecord = async function (record, meta) {52 return await fetch('https://httpstat.us/200');53 };54 55 return (56 <div className="App">57 <ImportokWizard58 title="ImportOK Example for React"59 fields={fields}60 transformers={transformers}61 validators={validators}62 providers={providers}63 onRecordReady={saveRecord}64 />65 </div>66 );67}
That's all! You can now open your page and give a try. Keep in mind that 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 |
|