diff --git a/src/components/Tool/Import/Csv/CsvHeaders.test.tsx b/src/components/Tool/Import/Csv/CsvHeaders.test.tsx index 272e2998d..74524f8ed 100644 --- a/src/components/Tool/Import/Csv/CsvHeaders.test.tsx +++ b/src/components/Tool/Import/Csv/CsvHeaders.test.tsx @@ -99,8 +99,9 @@ describe('CsvHeaders', () => { >, ); - expect(queryByText('first_name is required')).toBeInTheDocument(); - expect(queryByText('last_name is required')).toBeInTheDocument(); + expect(queryByText('First Name is required')).toBeInTheDocument(); + expect(queryByText('Last Name is required')).toBeInTheDocument(); + expect(queryByText('Full Name is required')).toBeInTheDocument(); }); it('should not show errors if required headers are mapped', async () => { @@ -112,13 +113,16 @@ describe('CsvHeaders', () => { >, ); - expect(queryByText('first_name is required')).not.toBeInTheDocument(); - expect(queryByText('last_name is required')).not.toBeInTheDocument(); - expect(queryByText('full_name is required')).not.toBeInTheDocument(); + expect(queryByText('First Name is required')).not.toBeInTheDocument(); + expect(queryByText('Last Name is required')).not.toBeInTheDocument(); + expect(queryByText('Full Name is required')).not.toBeInTheDocument(); }); it('should allow the user to map every header', async () => { - uploadData.fileHeaders = { first_name: 'Test1', custom_header: 'Wee' }; + uploadData.fileHeaders = { + first_name: 'First Name', + custom_header: 'Wee', + }; const { findByRole } = render( { ); expect( - await findByRole('cell', { name: 'first_name' }), - ).toBeInTheDocument(); - expect( - await findByRole('cell', { name: 'custom_header' }), + await findByRole('cell', { name: 'First Name' }), ).toBeInTheDocument(); + expect(await findByRole('cell', { name: 'Wee' })).toBeInTheDocument(); }); }); diff --git a/src/components/Tool/Import/Csv/CsvHeaders.tsx b/src/components/Tool/Import/Csv/CsvHeaders.tsx index 992f500bf..e5f9962e0 100644 --- a/src/components/Tool/Import/Csv/CsvHeaders.tsx +++ b/src/components/Tool/Import/Csv/CsvHeaders.tsx @@ -3,6 +3,10 @@ import { Alert, Box, Button, + Card, + CardHeader, + List, + ListItem, MenuItem, Select, Table, @@ -10,20 +14,19 @@ import { TableCell, TableHead, TableRow, - Typography, } from '@mui/material'; import { cloneDeep } from 'lodash/fp'; import { useTranslation } from 'react-i18next'; import { useApiConstants } from 'src/components/Constants/UseApiConstants'; import { Confirmation } from 'src/components/common/Modal/Confirmation/Confirmation'; import useGetAppSettings from 'src/hooks/useGetAppSettings'; +import theme from 'src/theme'; import { CsvImportContext, CsvImportType, CsvImportValue, CsvImportViewStepEnum, } from './CsvImportContext'; -import { HeaderBox } from './HeaderBox'; import { get, save } from './csvImportService'; import { useRequiredHeaders, useSupportedHeaders } from './uploadCsvFile'; @@ -56,8 +59,21 @@ const updateUnmappedHeaders = ( fileHeadersMappings: object, setUnmappedHeaders: React.Dispatch>, ) => { - const unmapped = requiredHeaders.filter((header) => { - return !Object.values(fileHeadersMappings).includes(header); + const fileHeaderMappingsValues = Object.values(fileHeadersMappings); + + const containsName = + (fileHeaderMappingsValues.includes('first_name') && + fileHeaderMappingsValues.includes('last_name')) || + fileHeaderMappingsValues.includes('full_name'); + + // If the file's headers contain a name, then remove names from required headers. + const newRequiredHeaders = containsName + ? requiredHeaders.filter( + (header) => !['first_name', 'last_name', 'full_name'].includes(header), + ) + : requiredHeaders; + const unmapped = newRequiredHeaders.filter((header) => { + return !fileHeaderMappingsValues.includes(header); }); setUnmappedHeaders(unmapped); }; @@ -200,23 +216,34 @@ const CsvHeaders: React.FC = ({ {unmappedHeaders.map((header) => { return (

- {header} + {supportedHeaders[header]} {t(' is required')}

); })} + {unmappedHeaders.includes('full_name') && ( +

+ {t('* You need to include both First & Last Name OR Full Name')} +

+ )} )} - -
    -
  • + + + {t( 'Columns with duplicate or empty headers are ignored. Please ensure your CSV does not have any such headers!', )} -
  • -
  • {t('Street is required to import any address information.')}
  • -
+ + + {t('Street is required to import any address information.')} + +
{showBackWarningModal && ( @@ -233,10 +260,13 @@ const CsvHeaders: React.FC = ({ > )} - - - {t('Map your headers')} - + + @@ -248,15 +278,16 @@ const CsvHeaders: React.FC = ({ - {Object.keys(importHeaders).map((header) => { + {Object.entries(importHeaders).map(([header, headerName]) => { return ( - {header} - + {headerName} +
@@ -152,6 +156,7 @@ const CsvValues: React.FC = ({