# Import Mapper

> Map the columns of an uploaded CSV to CRM fields: sample values per column, a field picker, the required fields still missing, and the rows that will fail.

Component · CRM · Halo kit · [Live page](https://ui.twentyfirst.media/halo/components/ImportMapper/)

Map the columns of an uploaded CSV to CRM fields: sample values per column, a field picker, the
required fields still missing, and the rows that will fail.

- Columns can be skipped; `problems` lists rows with their message so they can be fixed before the
  import.

## Example

```tsx
import * as React from "react";
import { ImportMapper, Panel } from "@twentyfirstmedia/halo";

export default function Preview() {
  const [mapping, setMapping] = React.useState<Record<string, string>>({
    Vorname: "first",
    Nachname: "last",
    "E-Mail": "email",
    Firma: "company",
    Telefon: "",
    Notizen: "",
  });
  return (
    <Panel title="Import contacts" subtitle="contacts-export.csv" style={{ maxWidth: 820 }}>
      <ImportMapper
        rows={1204}
        mapping={mapping}
        onChange={setMapping}
        columns={[
          { name: "Vorname", samples: ["Lena", "Jonas", "Ayşe"] },
          { name: "Nachname", samples: ["Hartmann", "Pick", "Demir"] },
          { name: "E-Mail", samples: ["lena@nordhafen.de", "jonas@pick.studio"] },
          { name: "Firma", samples: ["Nordhafen Outdoor", "Pick Studio"] },
          { name: "Telefon", samples: ["+49 40 2287 1190", "0172 5550 123"] },
          { name: "Notizen", samples: ["Met at OMR", ""] },
        ]}
        fields={[
          { id: "first", label: "First name", required: true },
          { id: "last", label: "Last name", required: true },
          { id: "email", label: "Email", required: true },
          { id: "phone", label: "Phone" },
          { id: "company", label: "Company" },
          { id: "note", label: "Note" },
        ]}
        problems={[
          { row: 17, message: "Email is not valid" },
          { row: 245, message: "Email already exists (merge or skip)" },
        ]}
      />
    </Panel>
  );
}
```

## Props

### ImportMapper

| Prop | Type | Notes |
| --- | --- | --- |
| `columns` | `{ name: string; samples: string[] }[]` | The file's columns with a few sample values. |
| `fields` | `{ id: string; label: string; required?: boolean }[]` | The fields records can take. |
| `mapping` | `Record<string, string>` | Column → field id ("" to skip). |
| `onChange?` | `(mapping: Record<string, string>) => void` |  |
| `rows?` | `number` | Rows in the file. |
| `problems?` | `{ row: number; message: string }[]` | Problems found in the rows. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### Panel

| Prop | Type | Notes |
| --- | --- | --- |
| `side?` | `boolean` |  |
| `title?` | `string` |  |
| `subtitle?` | `string` |  |
| `action?` | `ReactNode` |  |
| `children?` | `ReactNode` |  |
| `surface?` | `Surface` | `"glass"`: translucent glass over what is behind (maps, 3D, video, photos); `"solid"` opts out inside a glass `UIProvider`. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
