Fix/csv import (#1397)

* feat: add ability to enable or disable header selection

* feat: limit to max of 200 records for now

* fix: bigger modal

* feat: add missing standard fields for company

* fix: person fields

* feat: add hotkeys on dialog

* feat: mobile device

* fix: company import error

* fix: csv import crash

* fix: use scoped hotkey
This commit is contained in:
Jérémy M
2023-09-04 11:50:12 +02:00
committed by GitHub
parent f29d843db9
commit c0cb3a47f3
19 changed files with 213 additions and 86 deletions

View File

@ -3,12 +3,7 @@ import { v4 as uuidv4 } from 'uuid';
import { useSpreadsheetImport } from '@/spreadsheet-import/hooks/useSpreadsheetImport';
import { SpreadsheetOptions } from '@/spreadsheet-import/types';
import { useSnackBar } from '@/ui/snack-bar/hooks/useSnackBar';
import { useUpsertEntityTableItems } from '@/ui/table/hooks/useUpsertEntityTableItems';
import { useUpsertTableRowIds } from '@/ui/table/hooks/useUpsertTableRowIds';
import {
GetPeopleDocument,
useInsertManyPersonMutation,
} from '~/generated/graphql';
import { useInsertManyPersonMutation } from '~/generated/graphql';
import { fieldsForPerson } from '../utils/fieldsForPerson';
@ -16,8 +11,6 @@ export type FieldPersonMapping = (typeof fieldsForPerson)[number]['key'];
export function useSpreadsheetPersonImport() {
const { openSpreadsheetImport } = useSpreadsheetImport<FieldPersonMapping>();
const upsertEntityTableItems = useUpsertEntityTableItems();
const upsertTableRowIds = useUpsertTableRowIds();
const { enqueueSnackBar } = useSnackBar();
const [createManyPerson] = useInsertManyPersonMutation();
@ -49,15 +42,12 @@ export function useSpreadsheetPersonImport() {
variables: {
data: createInputs,
},
refetchQueries: [GetPeopleDocument],
refetchQueries: 'active',
});
if (result.errors) {
throw result.errors;
}
upsertTableRowIds(createInputs.map((person) => person.id));
upsertEntityTableItems(createInputs);
} catch (error: any) {
enqueueSnackBar(error?.message || 'Something went wrong', {
variant: 'error',

View File

@ -2,7 +2,7 @@ import { isValidPhoneNumber } from 'libphonenumber-js';
import {
IconBrandLinkedin,
IconBrandTwitter,
IconBrandX,
IconBriefcase,
IconMail,
IconMap,
@ -19,13 +19,6 @@ export const fieldsForPerson = [
type: 'input',
},
example: 'Tim',
validations: [
{
rule: 'required',
errorMessage: 'Firstname is required',
level: 'error',
},
],
},
{
icon: <IconUser />,
@ -36,13 +29,6 @@ export const fieldsForPerson = [
type: 'input',
},
example: 'Cook',
validations: [
{
rule: 'required',
errorMessage: 'Lastname is required',
level: 'error',
},
],
},
{
icon: <IconMail />,
@ -53,13 +39,6 @@ export const fieldsForPerson = [
type: 'input',
},
example: 'tim@apple.dev',
validations: [
{
rule: 'required',
errorMessage: 'email is required',
level: 'error',
},
],
},
{
icon: <IconBrandLinkedin />,
@ -72,7 +51,7 @@ export const fieldsForPerson = [
example: 'https://www.linkedin.com/in/timcook',
},
{
icon: <IconBrandTwitter />,
icon: <IconBrandX />,
label: 'X URL',
key: 'xUrl',
alternateMatches: ['x', 'x url'],