Import company and person from csv file (#1236)
* feat: wip implement back-end call csv import * fix: rebase IconBrandTwitter missing * feat: person and company csv import * fix: test & clean * fix: clean & test
This commit is contained in:
@ -3,7 +3,7 @@ import { v4 } from 'uuid';
|
||||
import type {
|
||||
Errors,
|
||||
Meta,
|
||||
} from '@/spreadsheet-import/components/steps/ValidationStep/types';
|
||||
} from '@/spreadsheet-import/steps/components/ValidationStep/types';
|
||||
import type {
|
||||
Data,
|
||||
Fields,
|
||||
@ -93,8 +93,9 @@ export const addErrorsAndRunHooks = <T extends string>(
|
||||
case 'regex': {
|
||||
const regex = new RegExp(validation.value, validation.flags);
|
||||
data.forEach((entry, index) => {
|
||||
const value = entry[field.key]?.toString() ?? '';
|
||||
if (!value.match(regex)) {
|
||||
const value = entry[field.key]?.toString();
|
||||
|
||||
if (value && !value.match(regex)) {
|
||||
errors[index] = {
|
||||
...errors[index],
|
||||
[field.key]: {
|
||||
@ -108,6 +109,22 @@ export const addErrorsAndRunHooks = <T extends string>(
|
||||
});
|
||||
break;
|
||||
}
|
||||
case 'function': {
|
||||
data.forEach((entry, index) => {
|
||||
const value = entry[field.key]?.toString();
|
||||
|
||||
if (value && !validation.isValid(value)) {
|
||||
errors[index] = {
|
||||
...errors[index],
|
||||
[field.key]: {
|
||||
level: validation.level || 'error',
|
||||
message: validation.errorMessage || 'Field is invalid',
|
||||
},
|
||||
};
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import type { Columns } from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
||||
import type { Columns } from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
|
||||
import type { Fields } from '@/spreadsheet-import/types';
|
||||
|
||||
export const findUnmatchedRequiredFields = <T extends string>(
|
||||
|
||||
@ -4,7 +4,7 @@ import type {
|
||||
Column,
|
||||
Columns,
|
||||
MatchColumnsProps,
|
||||
} from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
||||
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
|
||||
import type { Field, Fields } from '@/spreadsheet-import/types';
|
||||
|
||||
import { findMatch } from './findMatch';
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import {
|
||||
Columns,
|
||||
ColumnType,
|
||||
} from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
||||
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
|
||||
import type { Data, Fields, RawData } from '@/spreadsheet-import/types';
|
||||
|
||||
import { normalizeCheckboxValue } from './normalizeCheckboxValue';
|
||||
|
||||
@ -2,7 +2,7 @@ import {
|
||||
Column,
|
||||
ColumnType,
|
||||
MatchColumnsProps,
|
||||
} from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
||||
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
|
||||
import type { Field } from '@/spreadsheet-import/types';
|
||||
|
||||
import { uniqueEntries } from './uniqueEntries';
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import {
|
||||
Column,
|
||||
ColumnType,
|
||||
} from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
||||
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
|
||||
|
||||
export const setIgnoreColumn = <T extends string>({
|
||||
header,
|
||||
|
||||
@ -3,7 +3,7 @@ import {
|
||||
MatchedOptions,
|
||||
MatchedSelectColumn,
|
||||
MatchedSelectOptionsColumn,
|
||||
} from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
||||
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
|
||||
|
||||
export const setSubColumn = <T>(
|
||||
oldColumn: MatchedSelectColumn<T> | MatchedSelectOptionsColumn<T>,
|
||||
|
||||
@ -3,7 +3,7 @@ import uniqBy from 'lodash/uniqBy';
|
||||
import type {
|
||||
MatchColumnsProps,
|
||||
MatchedOptions,
|
||||
} from '@/spreadsheet-import/components/steps/MatchColumnsStep/MatchColumnsStep';
|
||||
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
|
||||
|
||||
export const uniqueEntries = <T extends string>(
|
||||
data: MatchColumnsProps<T>['data'],
|
||||
|
||||
Reference in New Issue
Block a user