Skip to content

Commit

Permalink
Merge pull request #619 from bcgov/SRS-249
Browse files Browse the repository at this point in the history
Handle Custom API Submission Failure and add message instead of loading symbol
  • Loading branch information
nikhila-aot authored Feb 9, 2024
2 parents c297aa0 + 7bac222 commit ca305ef
Show file tree
Hide file tree
Showing 5 changed files with 729 additions and 13 deletions.
9 changes: 9 additions & 0 deletions backend/applications/src/app/controllers/form.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ export class FormController {
submissionId,
formId,
);

if(!savedSubmission)
{
return Promise.reject({
statusCode: 404,
message: 'Form data not found'
})
}

const submissionResponse: SubmissionResponse =
this.transformResult(savedSubmission);
return submissionResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import { Link, useParams } from "react-router-dom";
import { useDispatch, useSelector } from "react-redux";
import startCase from "lodash/startCase";
Expand Down Expand Up @@ -28,6 +28,7 @@ import { setBundleSubmissionData } from "../../actions/bundleActions";
import BundleView from "../Bundle/item/submission/View";
import BundleHistory from "./BundleHistory";
import { TYPE_BUNDLE } from "../../constants/applicationConstants";
import Nodata from "../Nodata";

const ViewApplication = React.memo(() => {
const { t } = useTranslation();
Expand All @@ -49,6 +50,7 @@ const ViewApplication = React.memo(() => {
const tenantKey = useSelector((state) => state.tenants?.tenantId);
const dispatch = useDispatch();
const redirectUrl = MULTITENANCY_ENABLED ? `/tenant/${tenantKey}/` : "/";
const [customSubmissionAPIFailed,setCustomSubmissionAPIFailed] = useState(false);

useEffect(() => {
dispatch(setApplicationDetailLoader(true));
Expand All @@ -62,9 +64,17 @@ const ViewApplication = React.memo(() => {
getCustomSubmission(
res.submissionId,
res.formId,
(err, data) => {
if (res.formType === TYPE_BUNDLE) {
dispatch(setBundleSubmissionData({ data: data.data }));
(err, data) => {
if(err)
{
setCustomSubmissionAPIFailed(true);
dispatch(setBundleSubmissionData({ data: null }));
}
else
{
if (res.formType === TYPE_BUNDLE) {
dispatch(setBundleSubmissionData({ data: data.data }));
}
}
}
)
Expand Down Expand Up @@ -149,15 +159,19 @@ const ViewApplication = React.memo(() => {
</Translation>
}
>
{applicationDetail.formType === TYPE_BUNDLE &&
currentForm.isBundle ? (
<BundleView
bundleIdProp={applicationDetail.formId}
showPrintButton={false}
/>
) : (
<View page="application-detail" />
)}
{

customSubmissionAPIFailed ? (<Nodata/>) :
applicationDetail.formType === TYPE_BUNDLE &&
currentForm.isBundle ? (
<BundleView
bundleIdProp={applicationDetail.formId}
showPrintButton={false}
/>
) : (
<View page="application-detail" />
)
}
</Tab>
<Tab
eventKey="history"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { Redirect, Route, Switch, useParams } from "react-router-dom";
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { resetSubmission, selectRoot } from "react-formio";
import View from "./View";
import Edit from "./Edit";
import { getApplicationById } from "../../../../apiManager/services/applicationServices";
import { setApplicationDetailLoader } from "../../../../actions/applicationActions";
import NotFound from "../../../NotFound";
import { getUserRolePermission } from "../../../../helper/user";
import {
BASE_ROUTE,
CLIENT,
CUSTOM_SUBMISSION_URL,
CUSTOM_SUBMISSION_ENABLE,
STAFF_REVIEWER,
} from "../../../../constants/constants";
import { CLIENT_EDIT_STATUS } from "../../../../constants/applicationConstants";
import Loading from "../../../../containers/Loading";
import {
clearFormError,
clearSubmissionError,
} from "../../../../actions/formActions";
import {
formioGetSubmission,
getCustomSubmission,
} from "../../../../apiManager/services/FormServices";
import {
resetBundleData,
setBundleSubmissionData,
} from "../../../../actions/bundleActions";
//import {setApiCallError} from "../../../../actions/ErroHandling";
import NoData from '../../../../components/Nodata';

const Item = React.memo(() => {
const { bundleId, submissionId } = useParams();
const dispatch = useDispatch();
// const showViewSubmissions= useSelector((state) => state.user.showViewSubmissions);
//const path = props.location.pathname;
const applicationId = useSelector(
(state) => state.bundle?.bundleSubmission?.data?.applicationId || null
);
const userRoles = useSelector((state) => {
return selectRoot("user", state).roles;
});
const applicationStatus = useSelector(
(state) => state.applications.applicationDetail?.applicationStatus || ""
);
const [showSubmissionLoading, setShowSubmissionLoading] = useState(true);
const [editAllowed, setEditAllowed] = useState(false);
const [loading, setLoading] = useState(true);
const [customSubmissionAPIFailed,setCustomSubmissionAPIFailed] = useState(false);

useEffect(() => {
dispatch(clearSubmissionError("submission"));
dispatch(resetSubmission("submission"));
dispatch(clearFormError("form"));
dispatch(resetBundleData());
setLoading(true);

if (CUSTOM_SUBMISSION_URL && CUSTOM_SUBMISSION_ENABLE) {
console.log("invoking here 1 ");
dispatch(
getCustomSubmission(submissionId, bundleId, (err, res) => {
console.log('here i am ');
if(err)
{
if(window.location.href.indexOf("undefined") != -1)
{
console.log("error occurred",err,res);
}
else
{
setCustomSubmissionAPIFailed(true);
//dispatch(setApiCallError({message: 'Unable to fetch form data. Please contact support.'}));
console.log("error occurred dp ",err,res);
}
}
dispatch(setBundleSubmissionData({ data: res.data }));
setLoading(false);
})
);
} else {
formioGetSubmission(bundleId, submissionId)
.then((res) => {
dispatch(setBundleSubmissionData({ data: res.data.data }));
setLoading(false);
})
.catch(() => {
setLoading(false);
});
}
}, [submissionId, bundleId, dispatch]);

useEffect(() => {
if (applicationId) {
dispatch(setApplicationDetailLoader(true));
dispatch(getApplicationById(applicationId));
}
}, [applicationId, dispatch]);

useEffect(() => {
if (getUserRolePermission(userRoles, STAFF_REVIEWER)) {
setEditAllowed(true);
} else if (applicationStatus) {
if (getUserRolePermission(userRoles, CLIENT)) {
setEditAllowed(CLIENT_EDIT_STATUS.includes(applicationStatus));
setShowSubmissionLoading(false);
}
}
}, [applicationStatus, userRoles]);

useEffect(() => {
if (editAllowed && applicationStatus) setShowSubmissionLoading(false);
}, [applicationStatus, editAllowed]);

if (customSubmissionAPIFailed)
{
return (
<NoData/>
);
}
else
{
return (
<div>
<Switch>
<Route
exact
path={`${BASE_ROUTE}bundle/:bundleId/submission/:submissionId`}
component={loading ? Loading : View}
/>
<Redirect
exact
from={`${BASE_ROUTE}bundle/:bundleId/submission/:submissionId/edit/:notavailable`}
to="/404"
/>
{showSubmissionLoading ? (
<Route
path={`${BASE_ROUTE}bundle/:bundleId/submission/:submissionId/edit`}
component={Loading}
/>
) : null}
{editAllowed ? (
<Route
path={`${BASE_ROUTE}bundle/:bundleId/submission/:submissionId/edit`}
component={loading ? Loading : Edit}
/>
) : null}
<Route
path={`${BASE_ROUTE}bundle/:bundleId/submission/:submissionId/:notavailable`}
component={NotFound}
/>
</Switch>
</div>
);
}
});

export default Item;
Loading

0 comments on commit ca305ef

Please sign in to comment.