Saving progress spinner and language updates
This commit is contained in:
@@ -25,6 +25,8 @@ let BuildSection = (props) => {
|
||||
const [currentSectionSelected, setCurrentSectionSelected] = useState(1);
|
||||
const [pickupWhereLeftOff, setPickupWhereLeftOff] = useState(true);
|
||||
|
||||
const [savingStatus, setSavingStatus] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
progObj = getProgressObj(
|
||||
formXML,
|
||||
@@ -69,6 +71,7 @@ let BuildSection = (props) => {
|
||||
|
||||
const documentListObj = props.appealType.documentList;
|
||||
const currentSection = props.appealType.currentSection;
|
||||
|
||||
const parser = new DOMParser();
|
||||
var doc = parser.parseFromString(props.formXML, "text/xml");
|
||||
var titles = xpath.select(
|
||||
@@ -97,6 +100,16 @@ let BuildSection = (props) => {
|
||||
props
|
||||
);
|
||||
|
||||
const isProgressComplete = (progObj) => {
|
||||
const progressCount = 0;
|
||||
|
||||
for (let key in progObj) {
|
||||
progObj[key].allFieldsComplete === true && progressCount++;
|
||||
}
|
||||
|
||||
return progObj.length == progressCount;
|
||||
};
|
||||
|
||||
const lastIndex = progObj
|
||||
.map((whichIsLast) => whichIsLast.allFieldsComplete == true)
|
||||
.lastIndexOf(true);
|
||||
@@ -134,10 +147,11 @@ let BuildSection = (props) => {
|
||||
});
|
||||
};
|
||||
|
||||
const updateCaseProgress = (values, sendSavedEmail) => {
|
||||
const updateCaseProgress = (values, sendSavedEmail, useSaveStatus) => {
|
||||
let incidentId = props.appealType.caseReference.incidentid;
|
||||
let updateBody = values || {};
|
||||
|
||||
setSavingStatus(useSaveStatus);
|
||||
uploadAppealFiles(values);
|
||||
props.setNewAppealProgress(
|
||||
getProgressObj(formXML, titleList, mandatoryFieldsData, props)
|
||||
@@ -206,6 +220,13 @@ let BuildSection = (props) => {
|
||||
props.appealType.caseReference.incidentid +
|
||||
"'> from here </a>"
|
||||
);
|
||||
|
||||
useSaveStatus &&
|
||||
router.replace(
|
||||
router.locale != "en"
|
||||
? router.locale + "/myportal"
|
||||
: "/myportal"
|
||||
);
|
||||
};
|
||||
|
||||
const onHandleSubmit = (values) => {
|
||||
@@ -214,7 +235,7 @@ let BuildSection = (props) => {
|
||||
|
||||
delete valuesObj["_pinswg_appellant_value"];
|
||||
console.log("has errors:", props.invalid);
|
||||
props.invalid == false && updateCaseProgress(valuesObj, false);
|
||||
props.invalid == false && updateCaseProgress(valuesObj, false, false);
|
||||
|
||||
setCurrentSection(currentSection + 1);
|
||||
};
|
||||
@@ -330,7 +351,7 @@ let BuildSection = (props) => {
|
||||
delete valuesObj["_pinswg_appellant_value"];
|
||||
|
||||
//console.log("on save:", valuesObj);
|
||||
updateCaseProgress(valuesObj, false);
|
||||
updateCaseProgress(valuesObj, false, false);
|
||||
}}
|
||||
>
|
||||
{t("common:continue-button")}
|
||||
@@ -340,6 +361,7 @@ let BuildSection = (props) => {
|
||||
)}
|
||||
{props.sectionCount == currentSection ? (
|
||||
<button
|
||||
disabled={!isProgressComplete(progObj)}
|
||||
type="submit"
|
||||
className="govuk-button"
|
||||
data-module="govuk-button"
|
||||
@@ -383,27 +405,38 @@ let BuildSection = (props) => {
|
||||
/>
|
||||
|
||||
<hr className="govuk-section-break govuk-section-break--m govuk-section-break--visible" />
|
||||
<button
|
||||
className="govuk-button govuk-button--secondary progress-save "
|
||||
onClick={() => {
|
||||
let valuesObj =
|
||||
props.props.form[props.form].values || {};
|
||||
|
||||
console.log("valuesobj:", valuesObj);
|
||||
{savingStatus ? (
|
||||
<span className=" progress-save-active">
|
||||
Saving data
|
||||
<img
|
||||
className="data-loading-icon"
|
||||
src="/assets/images/loading.gif"
|
||||
alt={
|
||||
router.locale == "cy"
|
||||
? "Nôl data"
|
||||
: "Saving data"
|
||||
}
|
||||
/>
|
||||
</span>
|
||||
) : (
|
||||
<button
|
||||
className="govuk-button govuk-button--secondary progress-save "
|
||||
onClick={() => {
|
||||
let valuesObj =
|
||||
props.props.form[props.form].values || {};
|
||||
|
||||
delete valuesObj["_pinswg_appellant_value"];
|
||||
console.log("valuesobj:", valuesObj);
|
||||
|
||||
console.log("on save:", valuesObj);
|
||||
updateCaseProgress(valuesObj, true);
|
||||
router.replace(
|
||||
router.locale != "en"
|
||||
? router.locale + "/myportal"
|
||||
: "/myportal"
|
||||
);
|
||||
}}
|
||||
>
|
||||
{t("common:save-exit-button")}
|
||||
</button>
|
||||
delete valuesObj["_pinswg_appellant_value"];
|
||||
|
||||
console.log("on save:", valuesObj);
|
||||
updateCaseProgress(valuesObj, true, true);
|
||||
}}
|
||||
>
|
||||
{t("common:save-exit-button")}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user