2.1.9 • Published 3 months ago

dromo-uploader-react v2.1.9

Weekly downloads
7
License
MIT
Repository
-
Last release
3 months ago

dromo

npm version

You can view a live demo here

Install

To get add Dromo to your own project:

npm install --save dromo-uploader-react

Usage

Check out our developer documentation here

import React, { useState } from "react";
import { isoCountries } from "./DemoData";
import "./styles.css";

import DromoUploader from "dromo-uploader-react";
import { IColumnHookInput, IColumnHookOutput, IDeveloperField, IDeveloperSettings, IRowHookInput, IRowHookOutput } from "../../dist/interfaces";

export default function App() {
  const [results, setResults] = useState("");

  const fields: IDeveloperField[] = [
    // required field
    {
      label: "Geography",
      key: "geography",
      alternateMatches: ["region"],
      description: "Region of the sale",
      validators: [{ validate: "required" }]
    },
    {
      label: "Country",
      key: "country"
    },
    // unique
    {
      label: "Order Number",
      key: "orderNumber",
      validators: [{ validate: "unique" }]
    },
    {
      label: "Priority",
      key: "priority"
    },
    // boolean
    {
      label: "Sold Offline?",
      key: "soldOffline",
      type: "checkbox",
      validators: [
        {
          validate: "regex_match",
          regex: "^$|^(1|0|yes|no|true|false|on|off)$",
          regexOptions: { ignoreCase: true }
        }
      ]
    },
    // options
    {
      label: "Type",
      key: "type",
      type: "select",
      selectOptions: [
        { label: "Food", value: "food" },
        { label: "Clothing", value: "clothing" },
        { label: "Household Items", value: "household_items" },
        { label: "Produce", value: "produce" }
      ],
      validators: [{ validate: "required" }]
    },
    // simple regex
    {
      label: "Amount Sold",
      key: "amountSold",
      validators: [{ validate: "regex_match", regex: "^[0-9]*$" }]
    },
    {
      label: "Profit",
      key: "profit"
    }
  ];

  const settings: IDeveloperSettings = {
    importIdentifier: "Sales",
    displayEncoding: true,
    allowInvalidSubmit: true,
    backendSync: false,
    manualInputDisabled: false,
    manualInputOnly: false,
    allowCustomFields: true,
    maxRecords: null,
    developmentMode: true
  };

  const user = {
    id: "1",
    name: "Jane Doe",
    email: "jane@dromo.io",
    companyId: "Dromo",
    companyName: "12345"
  };

  const rowHooks = [(record: IRowHookInput) => {
    const newRecord: IRowHookOutput = record;
    
    if (record.index < 10) {
      if (newRecord.row.geography) {
        newRecord.row.geography.info = [{
          message: "Prepend 0 to value",
          level: "error"
        }];
        newRecord.row.geography.value = "0" + newRecord.row.geography.value;
      }
    }

    return newRecord;
  }];

  const columnHooks = [{
    fieldName: "country",
    callback: (values: Array<IColumnHookInput>) => {
      const newValues = new Array<IColumnHookOutput>();
      values.forEach((row) => {
        // Update row if ISO country code exists for the
        // existing country name
        if (isoCountries[row.value]) {
          const newRow: IColumnHookOutput = {
            index: row.index,
            value: isoCountries[row.value],
            info: [{
              message: "Update to use ISO country code",
              level: "info"
            }]
          };

          newValues.push(newRow);
        }
      });

      return newValues;
    }
  }];

  return (
    <div>
      <div>
        <DromoUploader
          licenseKey="TEST_KEY"
          style={{ padding: 15, border: 0 }}
          settings={settings}
          fields={fields}
          user={user}
          rowHooks={rowHooks}
          columnHooks={columnHooks}
          onResults={(data: any, metadata: IResultMetadata) => setResults(JSON.stringify(data, null, 2))}
        >
          Launch Dromo
        </DromoUploader>
      </div>
      <textarea readOnly id="response" value={results} />
    </div>
  );
}
2.1.9

3 months ago

2.1.8

5 months ago

2.1.6

7 months ago

2.1.7

7 months ago

2.1.5

8 months ago

2.1.2

10 months ago

2.1.4

8 months ago

2.1.3

10 months ago

2.0.24

11 months ago

2.0.23

12 months ago

2.0.22

1 year ago

2.0.20

1 year ago

2.0.21

1 year ago

2.0.19

1 year ago

2.0.18

1 year ago

2.0.17

1 year ago

2.0.16

1 year ago

2.0.15

2 years ago

2.0.14

2 years ago

2.0.13

2 years ago

2.0.12

2 years ago

2.0.10

2 years ago

2.0.9

2 years ago

2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.0

2 years ago

1.4.0

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.32

3 years ago

1.2.28

3 years ago

1.2.29

3 years ago

1.2.30

3 years ago

1.2.31

3 years ago

1.2.27

3 years ago

1.2.26

3 years ago

1.2.18

3 years ago

1.2.19

3 years ago

1.2.20

3 years ago

1.2.23

3 years ago

1.2.24

3 years ago

1.2.21

3 years ago

1.2.22

3 years ago

1.2.25

3 years ago

1.2.16

3 years ago

1.2.17

3 years ago

1.2.12

3 years ago

1.2.13

3 years ago

1.2.14

3 years ago

1.2.15

3 years ago

1.2.6

4 years ago

1.2.9

3 years ago

1.2.10

3 years ago

1.2.4

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.9

4 years ago

1.1.10

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago