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:
@ -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,
|
||||
useInsertManyCompanyMutation,
|
||||
} from '~/generated/graphql';
|
||||
import { useInsertManyCompanyMutation } from '~/generated/graphql';
|
||||
|
||||
import { fieldsForCompany } from '../utils/fieldsForCompany';
|
||||
|
||||
@ -16,8 +11,6 @@ export type FieldCompanyMapping = (typeof fieldsForCompany)[number]['key'];
|
||||
|
||||
export function useSpreadsheetCompanyImport() {
|
||||
const { openSpreadsheetImport } = useSpreadsheetImport<FieldCompanyMapping>();
|
||||
const upsertEntityTableItems = useUpsertEntityTableItems();
|
||||
const upsertTableRowIds = useUpsertTableRowIds();
|
||||
const { enqueueSnackBar } = useSnackBar();
|
||||
|
||||
const [createManyCompany] = useInsertManyCompanyMutation();
|
||||
@ -34,11 +27,11 @@ export function useSpreadsheetCompanyImport() {
|
||||
// TODO: Add better type checking in spreadsheet import later
|
||||
const createInputs = data.validData.map((company) => ({
|
||||
id: uuidv4(),
|
||||
name: company.name as string,
|
||||
domainName: company.domainName as string,
|
||||
address: company.address as string,
|
||||
employees: parseInt(company.employees as string, 10),
|
||||
linkedinUrl: company.linkedinUrl as string | undefined,
|
||||
name: (company.name ?? '') as string,
|
||||
domainName: (company.domainName ?? '') as string,
|
||||
address: (company.address ?? '') as string,
|
||||
employees: parseInt((company.employees ?? '') as string, 10),
|
||||
linkedinUrl: (company.linkedinUrl ?? '') as string | undefined,
|
||||
}));
|
||||
|
||||
try {
|
||||
@ -46,15 +39,12 @@ export function useSpreadsheetCompanyImport() {
|
||||
variables: {
|
||||
data: createInputs,
|
||||
},
|
||||
refetchQueries: [GetPeopleDocument],
|
||||
refetchQueries: 'active',
|
||||
});
|
||||
|
||||
if (result.errors) {
|
||||
throw result.errors;
|
||||
}
|
||||
|
||||
upsertTableRowIds(createInputs.map((company) => company.id));
|
||||
upsertEntityTableItems(createInputs);
|
||||
} catch (error: any) {
|
||||
enqueueSnackBar(error?.message || 'Something went wrong', {
|
||||
variant: 'error',
|
||||
|
||||
Reference in New Issue
Block a user