diff --git a/src/features/import/components/ImportDialog/elements/ImportMessageList/ImportMessage.tsx b/src/features/import/components/ImportDialog/elements/ImportMessageList/ImportMessage.tsx index f3f8bab030..51d6e0a9a3 100644 --- a/src/features/import/components/ImportDialog/elements/ImportMessageList/ImportMessage.tsx +++ b/src/features/import/components/ImportDialog/elements/ImportMessageList/ImportMessage.tsx @@ -17,7 +17,7 @@ type Props = { description?: string; onCheck?: (checked: boolean) => void; onClickBack?: () => void; - rowIndices?: number[]; + rowNumbers?: number[]; status: 'error' | 'info' | 'success' | 'warning'; title: string; }; @@ -26,14 +26,12 @@ const ImportMessage: FC = ({ description, onCheck, onClickBack, - rowIndices, + rowNumbers, status, title, }) => { const messages = useMessages(messageIds); - const rowNumbers = rowIndices?.map((rowIndex) => rowIndex + 1); - return ( = ({ onCheck, onClickBack, problem }) => { = ({ onCheck, onClickBack, problem }) => { description={messages.preflight.messages.missingIdAndName.description()} onCheck={onCheck} onClickBack={onClickBack} - rowIndices={problem.indices} + rowNumbers={problem.rows} status="error" title={messages.preflight.messages.missingIdAndName.title()} /> @@ -103,7 +103,7 @@ const ImportMessageItem: FC = ({ onCheck, onClickBack, problem }) => { description={messages.preflight.messages.unknownPerson.description()} onCheck={onCheck} onClickBack={onClickBack} - rowIndices={problem.indices} + rowNumbers={problem.rows} status="error" title={messages.preflight.messages.unknownPerson.title()} /> @@ -114,7 +114,7 @@ const ImportMessageItem: FC = ({ onCheck, onClickBack, problem }) => { description={messages.preflight.messages.unknownError.description()} onCheck={onCheck} onClickBack={onClickBack} - rowIndices={problem.indices} + rowNumbers={problem.rows} status="error" title={messages.preflight.messages.unknownError.title()} /> diff --git a/src/features/import/hooks/usePreflight.ts b/src/features/import/hooks/usePreflight.ts index 9f6b4935e6..5be4491e07 100644 --- a/src/features/import/hooks/usePreflight.ts +++ b/src/features/import/hooks/usePreflight.ts @@ -59,6 +59,14 @@ export default function usePreflight(orgId: number) { ); } + const rowModifier = sheet.firstRowIsHeaders ? 2 : 1; + problems.forEach((problem) => { + if ('indices' in problem) { + problem.rows = problem.indices.map((index) => index + rowModifier); + } + return problem; + }); + const hasError = problems.some( (problem) => levelForProblem(problem) == 'error' ); diff --git a/src/features/import/utils/problems/types.ts b/src/features/import/utils/problems/types.ts index 375bd7c9e3..9e6f1fddea 100644 --- a/src/features/import/utils/problems/types.ts +++ b/src/features/import/utils/problems/types.ts @@ -14,6 +14,7 @@ export type ImportFieldProblem = { field: string; indices: number[]; kind: ImportProblemKind.INVALID_FORMAT; + rows?: number[]; }; export type ImportFieldMetaProblem = { @@ -29,6 +30,7 @@ export type ImportRowProblem = { | ImportProblemKind.UNEXPECTED_ERROR | ImportProblemKind.UNKNOWN_PERSON | ImportProblemKind.UNKNOWN_ERROR; + rows?: number[]; }; export type ImportSheetProblem = {