Skip to content

Commit

Permalink
updated error handling flow for incorrect IRT upload
Browse files Browse the repository at this point in the history
  • Loading branch information
matbusby committed Apr 26, 2024
1 parent 1fae97a commit 831f8f5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
8 changes: 4 additions & 4 deletions services/common/src/components/forms/RenderFileUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useEffect, useState } from "react";
import { useSelector, connect } from "react-redux";
import { connect, useSelector } from "react-redux";
import "filepond-polyfill";
import { FilePond, registerPlugin } from "react-filepond";
import { Form, Popover, Switch, notification } from "antd";
import { Form, notification, Popover, Switch } from "antd";
import { invert, uniq } from "lodash";
import { FunnelPlotOutlined } from "@ant-design/icons";
import "filepond/dist/filepond.min.css";
import FilePondPluginFileValidateSize from "filepond-plugin-file-validate-size";
import FilePondPluginFileValidateType from "filepond-plugin-file-validate-type";
import * as tus from "tus-js-client";
import { HttpRequest, HttpResponse } from "tus-js-client";
import { APPLICATION_OCTET_STREAM, ENVIRONMENT, SystemFlagEnum } from "@mds/common/index";
import { bindActionCreators } from "redux";
import { pollDocumentUploadStatus } from "@mds/common/redux/actionCreators/documentActionCreator";
Expand All @@ -21,7 +22,6 @@ import {
MultipartDocumentUpload,
UploadResult,
} from "@mds/common/utils/fileUploadHelper.interface";
import { HttpRequest, HttpResponse } from "tus-js-client";
import { BaseInputProps } from "./BaseInput";

registerPlugin(FilePondPluginFileValidateSize, FilePondPluginFileValidateType);
Expand Down Expand Up @@ -211,7 +211,7 @@ export const FileUpload = (props: FileUploadProps) => {
}
props.importIsSuccessful(true);
} catch (err) {
props.importIsSuccessful(false, err);
props.importIsSuccessful(false, err.response.data);
}

if (showWhirlpool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ export const IRTFileImport: FC<IRTFileImportProps> = ({
renderTextColumn("create_user", "Imported By"),
];

const handleCreateInformationRequirementsTable = (
const handleCreateInformationRequirementsTable = async (
projectGuid: string,
file: IFileInfo,
documentGuid: string
) => {
dispatch(createInformationRequirementsTable(projectGuid, file, documentGuid));
return dispatch(createInformationRequirementsTable(projectGuid, file, documentGuid));
};

const handleUpdateInformationRequirementsTableByFile = (
const handleUpdateInformationRequirementsTableByFile = async (
projectGuid: string,
informationRequirementsTableGuid: string,
file: IFileInfo,
documentGuid: string
) => {
dispatch(
return dispatch(
updateInformationRequirementsTableByFile(
projectGuid,
informationRequirementsTableGuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ export const ImportIRTErrorModal = (props) => {
</h3>
<b>{description}</b>
<br />
{errorSection.map((es) => (
<p>
{errorSection.map((es, index) => (
<p key={index}>
Section {es.section} Row {es.row_number}
</p>
))}
Expand Down Expand Up @@ -109,7 +109,6 @@ export const ImportIRTErrorModal = (props) => {
}
return (
<div>
<p>{props.errors}</p>
<div className="ant-modal-footer">
<Button type="primary" onClick={props.closeModal}>
Close
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const InformationRequirementsTablePage = () => {
if (importFailed && importErrors) {
openIRTImportErrorModal(importErrors);
}
}, [importFailed]);
}, [importFailed, importErrors]);

useEffect(() => {
if (uploadedSuccessfully) {
Expand All @@ -144,7 +144,7 @@ export const InformationRequirementsTablePage = () => {

const getRequirementsVersion = () => {
return (
project.information_requirements_table.requirements?.[0].version ??
project.information_requirements_table.requirements?.[0]?.version ??
requirements[requirements.length - 1].version
);
};
Expand Down Expand Up @@ -204,13 +204,13 @@ export const InformationRequirementsTablePage = () => {

const importIsSuccessful = async (success, err) => {
if (!success) {
const hasBadRequestError = err?.response?.data?.message.includes("400 Bad Request: [");
const formattedError = marshalImportIRTError(err?.response?.data?.message);
const hasBadRequestError = err?.message.includes("400 Bad Request: [");
const formattedError = marshalImportIRTError(err?.message);
await handleFetchData();

setHasBadRequestError(hasBadRequestError);
setImportFailed(true);
setImportErrors(formattedError);
setHasBadRequestError(hasBadRequestError);
return;
}

Expand Down

0 comments on commit 831f8f5

Please sign in to comment.