Examples

Web Component

importOK is a reusable custom web component that embeds an import wizard into your app. You can follow this installation guide to set it up by using custom web components.

First, import the Javascript package for importOK:

1npm install @importok/javascript

To embed the wizard, use the following component.

1<importok-wizard></importok-wizard>

Next you will need to define and configure the custom component.

1import ImportOK from './node_modules/@importok/javascript/importok.js';
2/**
3 * Define the custom web component
4 */
5ImportOK.defineCustomElements();
6 
7/**
8 * Import fields to be mapped
9 * Check https://importok.io/docs/fields for more details
10 */
11const importFields = {
12 first_name: {
13 label: 'First Name',
14 transformers: 'capitalize|trim'
15 },
16 last_name: {
17 label: 'Last Name',
18 validators: 'required',
19 transformers: 'capitalize|trim'
20 },
21 email: {
22 label: 'Email',
23 validators: 'email|required',
24 transformers: 'lowercase|trim'
25 },
26 phone: {
27 label: 'Phone',
28 transformers: 'trim'
29 }
30};
31 
32/**
33 * Push the provided record to the API
34 * Check https://importok.io/docs/webhooks for more details
35 */
36const saveRecord = async function (record, meta) {
37 return await fetch('https://httpstat.us/200');
38};
39 
40/**
41 * Pass the full configuration to the wizard
42 */
43const wizard = document.querySelector('importok-wizard');
44wizard.config = {
45 fields: importFields,
46 meta: {
47 user_id: 1,
48 },
49 onRecordReady: saveRecord
50};

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.

Props

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
  • record The record to be imported.
  • meta The meta object passed in the meta prop (if any), plus additional meta data from import include the file size and type.
Default undefined

onImportReady

Description Callback to import multiple records at once.
Type function(records: ImportRecord[], meta: object): Promise<any>
Event props
  • records The records to be imported.
  • meta The meta object passed in the meta prop (if any), plus additional meta data from import include the file size and type.
Default undefined

onImportProgress

Description Triggered when the progress changes.
Event props
  • processed How many records processed so far, including failed.
  • failed How many records failed so far.
  • total Total number of records.

onStepEnter

Description Triggered when the user enters a new step of the wizard.
Event props
  • step The index of the step the user is entering.
  • previousStep The index of the step the user is leaving.

onStepExit

Description Triggered when the user is about to exit the current step.
Event props
  • step The index of the step the user is exiting.
  • nextStep The index of the step the user previously exited.