Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set complete status before moving to step 4 #315

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 75 additions & 68 deletions src/webapp/components/upload/ReviewDataSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback, useEffect, useState } from "react";
import { Button, CircularProgress, Typography } from "@material-ui/core";
import { Backdrop, Button, CircularProgress, Typography } from "@material-ui/core";
import styled from "styled-components";
import { glassColors } from "../../pages/app/themes/dhis2.theme";
import i18n from "@eyeseetea/d2-ui-components/locales";
Expand All @@ -18,6 +18,7 @@ import { useGetLastSuccessfulAnalyticsRunTime } from "../../hooks/useGetLastSucc
import { Validations } from "../current-data-submission/Validations";
import { useQuestionnaires } from "../current-data-submission/Questionnaires";
import { QuestionnaireBase } from "../../../domain/entities/Questionnaire";
import { StyledLoaderContainer } from "./ConsistencyChecks";

interface ReviewDataSummaryProps {
changeStep: (step: number) => void;
Expand Down Expand Up @@ -52,7 +53,6 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
);
const { captureAccessGroup } = useCurrentUserGroupsAccess();
const [isReportReady, setIsReportReady] = useState<boolean>(false);
const [currentDataSubmissionId, setCurrentDataSubmissionId] = useState<string>("");
const [currentQuestionnaires, setCurrentQuestionnaires] = useState<QuestionnaireBase[]>();

const [questionnaires] = useQuestionnaires();
Expand All @@ -64,10 +64,6 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
const { lastSuccessfulAnalyticsRunTime, setRefetch } = useGetLastSuccessfulAnalyticsRunTime();

useEffect(() => {
if (dataSubmissionId !== "" && currentDataSubmissionId === "") {
setCurrentDataSubmissionId(dataSubmissionId);
}

if (questionnaires && !currentQuestionnaires) {
setCurrentQuestionnaires(questionnaires);
}
Expand All @@ -88,7 +84,6 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
lastSuccessfulAnalyticsRunTime,
primaryFileImportSummary?.importTime,
dataSubmissionId,
currentDataSubmissionId,
currentQuestionnaires,
questionnaires,
]);
Expand Down Expand Up @@ -118,8 +113,6 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
.run(
() => {
if (!secondaryUploadId) {
changeStep(4);
setIsLoading(false);
//If Questionnaires are not applicable to a module, then set status as COMPLETE on
//completion of dataset.
if (
Expand All @@ -130,9 +123,11 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
currentQuestionnaires?.every(q => q.isMandatory && q.isCompleted))
) {
compositionRoot.glassDataSubmission
.setStatus(currentDataSubmissionId, "COMPLETE")
.setStatus(dataSubmissionId, "COMPLETE")
.run(
() => {
changeStep(4);
setIsLoading(false);
if (captureAccessGroup.kind === "loaded") {
const userGroupsIds = captureAccessGroup.data.map(cag => {
return cag.id;
Expand All @@ -153,12 +148,17 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
}
},
error => {
console.debug(
"Error occurred when setting data submission status, error: " +
error
snackbar.error(
i18n.t(
"Error occurred when setting data submission status, error: " +
error
)
);
}
);
} else {
changeStep(4);
setIsLoading(false);
}
} else {
return compositionRoot.glassUploads
Expand Down Expand Up @@ -209,39 +209,42 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
"QUESTIONNAIRE_AND_DATASET" &&
currentQuestionnaires?.every(q => q.isMandatory && q.isCompleted))
) {
compositionRoot.glassDataSubmission
.setStatus(currentDataSubmissionId, "COMPLETE")
.run(
() => {
if (captureAccessGroup.kind === "loaded") {
const userGroupsIds = captureAccessGroup.data.map(cag => {
return cag.id;
});
const notificationText = `The data submission for ${currentModuleAccess.moduleName} module for year ${currentPeriod} and country ${currentOrgUnitAccess.orgUnitName} has changed to DATA TO BE APPROVED BY COUNTRY`;
compositionRoot.glassDataSubmission.setStatus(dataSubmissionId, "COMPLETE").run(
() => {
changeStep(4);
setIsLoading(false);
if (captureAccessGroup.kind === "loaded") {
const userGroupsIds = captureAccessGroup.data.map(cag => {
return cag.id;
});
const notificationText = `The data submission for ${currentModuleAccess.moduleName} module for year ${currentPeriod} and country ${currentOrgUnitAccess.orgUnitName} has changed to DATA TO BE APPROVED BY COUNTRY`;

compositionRoot.notifications
.send(
notificationText,
notificationText,
userGroupsIds,
currentOrgUnitAccess.orgUnitPath
)
.run(
() => {},
() => {}
);
}
},
error => {
console.debug(
"Error occurred when setting data submission status, error: " +
error
);
compositionRoot.notifications
.send(
notificationText,
notificationText,
userGroupsIds,
currentOrgUnitAccess.orgUnitPath
)
.run(
() => {},
() => {}
);
}
);
},
error => {
changeStep(4);
setIsLoading(false);
console.debug(
"Error occurred when setting data submission status, error: " +
error
);
}
);
} else {
changeStep(4);
setIsLoading(false);
}
changeStep(4);
setIsLoading(false);
},
errorMessage => {
snackbar.error(i18n.t(errorMessage));
Expand All @@ -259,25 +262,33 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
);
}
}, [
changeStep,
primaryFile,
secondaryFile,
compositionRoot.glassUploads,
snackbar,
captureAccessGroup,
compositionRoot.glassDataSubmission,
compositionRoot.notifications,
currentModuleAccess.moduleName,
currentOrgUnitAccess,
currentPeriod,
currentDataSubmissionId,
currentQuestionnaires,
primaryFile,
secondaryFile,
dataSubmissionId,
changeStep,
captureAccessGroup,
currentPeriod,
currentOrgUnitAccess.orgUnitName,
currentOrgUnitAccess.orgUnitPath,
snackbar,
]);

const goToFinalStepEffect = useCallbackEffect(goToFinalStep);

return (
<ContentWrapper>
<Backdrop open={isLoading || !dataSubmissionId} style={{ color: "#fff", zIndex: 1 }}>
<StyledLoaderContainer>
<CircularProgress color="inherit" size={50} />
<Typography variant="h6">{i18n.t("Loading")}</Typography>
</StyledLoaderContainer>
</Backdrop>

{moduleProperties.get(currentModuleAccess.moduleName)?.isSecondaryFileApplicable &&
!moduleProperties.get(currentModuleAccess.moduleName)?.isSingleFileTypePerSubmission && (
<div className="toggles">
Expand Down Expand Up @@ -349,23 +360,19 @@ export const ReviewDataSummary: React.FC<ReviewDataSummaryProps> = ({
</SectionCard>
</Section>
<div className="bottom">
{isLoading ? (
<CircularProgress size={25} />
) : (
<FlexWrapper>
<Button
variant="contained"
color={"primary"}
endIcon={<ChevronRightIcon />}
onClick={goToFinalStepEffect}
disableElevation
disabled={isRunningCalculation}
>
{i18n.t("Continue")}
</Button>
{isRunningCalculation && <CircularProgress size={25} />}
</FlexWrapper>
)}
<FlexWrapper>
<Button
variant="contained"
color={"primary"}
endIcon={<ChevronRightIcon />}
onClick={goToFinalStepEffect}
disableElevation
disabled={isRunningCalculation}
>
{i18n.t("Continue")}
</Button>
{isRunningCalculation && <CircularProgress size={25} />}
</FlexWrapper>
</div>
</ContentWrapper>
);
Expand Down
22 changes: 14 additions & 8 deletions src/webapp/hooks/useCurrentDataSubmissionId.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import { useEffect, useState } from "react";
import { useAppContext } from "../contexts/app-context";
import { useSnackbar } from "@eyeseetea/d2-ui-components";

export function useCurrentDataSubmissionId(moduleId: string, moduleName: string, orgUnit: string, period: string) {
const { currentUser, compositionRoot } = useAppContext();
const [currentDataSubmissionId, setCurrentDataSubmissionId] = useState<string>("");
const snackbar = useSnackbar();

useEffect(() => {
async function getDataSubmission() {
const isQuarterlyModule = currentUser.quarterlyPeriodModules.find(m => m.id === moduleId) ? true : false;
const currentDataSubmission = await compositionRoot.glassDataSubmission
.getSpecificDataSubmission(moduleId, moduleName, orgUnit, period, isQuarterlyModule)
.toPromise();
setCurrentDataSubmissionId(currentDataSubmission.id);
}
getDataSubmission();
const isQuarterlyModule = currentUser.quarterlyPeriodModules.find(m => m.id === moduleId) ? true : false;
compositionRoot.glassDataSubmission
.getSpecificDataSubmission(moduleId, moduleName, orgUnit, period, isQuarterlyModule)
.run(
currentDataSubmission => {
setCurrentDataSubmissionId(currentDataSubmission.id);
},
error => {
snackbar.error("Error fetching data submission : " + error);
}
);
}, [
compositionRoot.glassDataSubmission,
moduleId,
moduleName,
orgUnit,
period,
currentUser.quarterlyPeriodModules,
snackbar,
]);

return currentDataSubmissionId;
Expand Down