chekc box to download questionnaire
This commit is contained in:
@@ -4,6 +4,7 @@ import { useRouter } from "next/router";
|
||||
import { useState } from "react";
|
||||
import { useDropzone } from "react-dropzone";
|
||||
import { connect } from "react-redux";
|
||||
import { generateRepPDF } from "../../../actions";
|
||||
import RepComplete from "./representationComplete";
|
||||
import RepLPAQuestionnaireCheck_enforcement from "./representationQuestionnairesCheck/representationLPAQuestionnaireCheck_enforcement";
|
||||
import RepLPAQuestionnaireCheck_s78 from "./representationQuestionnairesCheck/representationLPAQuestionnaireCheck_s78";
|
||||
@@ -13,17 +14,19 @@ import {
|
||||
getThumbnailIconByExtension,
|
||||
formatDates,
|
||||
updateLinks,
|
||||
getDocLink,
|
||||
getDocLink
|
||||
} from "../../utils";
|
||||
|
||||
import {
|
||||
setCurrentReference,
|
||||
setCurrentView,
|
||||
setCurrentView
|
||||
} from "../../../store/currentView/action";
|
||||
|
||||
const RepCompleteSubmit = (props) => {
|
||||
let { t } = useTranslation();
|
||||
const [confirmSections, setConfirmSections] = useState(false);
|
||||
const [downloadQuestionnaire, setDownloadQuestionnaire] = useState(false);
|
||||
const [downloadInProgress, setDownloadInProgress] = useState(false);
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
@@ -42,7 +45,7 @@ const RepCompleteSubmit = (props) => {
|
||||
questionnaireCount,
|
||||
finaliseAppealProcess,
|
||||
setCurrentReference,
|
||||
docsOffline,
|
||||
docsOffline
|
||||
} = props;
|
||||
|
||||
let ShowDocLinks = getDocLink(docsOffline);
|
||||
@@ -169,7 +172,7 @@ const RepCompleteSubmit = (props) => {
|
||||
typeof filesUploadObj[key].name != "undefined" &&
|
||||
buildAppealFilesArray.push({
|
||||
"name": filesUploadObj[key].name,
|
||||
"size": filesUploadObj[key].contentLength,
|
||||
"size": filesUploadObj[key].contentLength
|
||||
});
|
||||
}
|
||||
|
||||
@@ -185,7 +188,7 @@ const RepCompleteSubmit = (props) => {
|
||||
// : [];
|
||||
|
||||
let arrUniq = [
|
||||
...new Map(buildAppealFilesArray.map((v) => [v.name, v])).values(),
|
||||
...new Map(buildAppealFilesArray.map((v) => [v.name, v])).values()
|
||||
];
|
||||
|
||||
buildAppealFilesArray = buildAppealFilesArray.filter(function (el) {
|
||||
@@ -217,7 +220,7 @@ const RepCompleteSubmit = (props) => {
|
||||
arrUniq = removeEmptyObjects(arrUniq);
|
||||
|
||||
Object.assign(formObj.representationForm.values, {
|
||||
"filesList": arrUniq,
|
||||
"filesList": arrUniq
|
||||
});
|
||||
|
||||
let filterFiles = [];
|
||||
@@ -235,7 +238,6 @@ const RepCompleteSubmit = (props) => {
|
||||
}
|
||||
|
||||
const checkRepDatePassed = () => {
|
||||
return false;
|
||||
if (repFormData.representationType == "Questionnaire") {
|
||||
return false;
|
||||
} else {
|
||||
@@ -255,6 +257,62 @@ const RepCompleteSubmit = (props) => {
|
||||
}
|
||||
};
|
||||
|
||||
const triggerQuestionnaireDownload = async () => {
|
||||
if (
|
||||
repFormData.representationType !== "Questionnaire" ||
|
||||
!downloadQuestionnaire
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (downloadInProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setDownloadInProgress(true);
|
||||
|
||||
const containerID =
|
||||
props.accountDetails?.containerID ||
|
||||
props.props?.accountDetails?.containerID ||
|
||||
props.props?.props?.accountDetails?.containerID;
|
||||
const caseRef =
|
||||
currentView?.caseReference?.ticketnumber ||
|
||||
repFormData?.caseRef ||
|
||||
repFormData?.ticketnumber;
|
||||
|
||||
if (!containerID || !caseRef) {
|
||||
console.error(
|
||||
"Questionnaire download skipped: missing containerID or case reference",
|
||||
{ containerID, caseRef }
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const pdfBlob = await generateRepPDF(
|
||||
repFormData,
|
||||
containerID,
|
||||
caseRef,
|
||||
{ download: true }
|
||||
);
|
||||
|
||||
if (pdfBlob) {
|
||||
const blobUrl = window.URL.createObjectURL(pdfBlob);
|
||||
const anchor = document.createElement("a");
|
||||
anchor.href = blobUrl;
|
||||
anchor.download = `${repFormData.repfile_name || "questionnaire"}.pdf`;
|
||||
document.body.appendChild(anchor);
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Questionnaire download failed", error);
|
||||
} finally {
|
||||
setDownloadInProgress(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{currentView.representationSubmitConfirmation == true ? (
|
||||
@@ -305,12 +363,12 @@ const RepCompleteSubmit = (props) => {
|
||||
"Questionnaire"
|
||||
? "Holiadur"
|
||||
: repFormData.representationType ==
|
||||
"Statement"
|
||||
? "Datganiad"
|
||||
: repFormData.representationType ==
|
||||
"Final comments"
|
||||
? "Sylwadau terfynol"
|
||||
: repFormData.representationType
|
||||
"Statement"
|
||||
? "Datganiad"
|
||||
: repFormData.representationType ==
|
||||
"Final comments"
|
||||
? "Sylwadau terfynol"
|
||||
: repFormData.representationType
|
||||
: repFormData.representationType}
|
||||
</dd>
|
||||
|
||||
@@ -368,7 +426,7 @@ const RepCompleteSubmit = (props) => {
|
||||
"appealType":
|
||||
repFormData.appealType,
|
||||
"repDetails":
|
||||
repFormData,
|
||||
repFormData
|
||||
});
|
||||
setRepresentationSubmit(
|
||||
false
|
||||
@@ -421,7 +479,7 @@ const RepCompleteSubmit = (props) => {
|
||||
"appealType":
|
||||
repFormData.appealType,
|
||||
"repDetails":
|
||||
repFormData,
|
||||
repFormData
|
||||
}
|
||||
);
|
||||
setRepresentationSubmit(
|
||||
@@ -458,7 +516,7 @@ const RepCompleteSubmit = (props) => {
|
||||
<span
|
||||
className="multiline-elipsis"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: repFormData.representationComments,
|
||||
__html: repFormData.representationComments
|
||||
}}
|
||||
/>
|
||||
</dd>
|
||||
@@ -482,7 +540,7 @@ const RepCompleteSubmit = (props) => {
|
||||
"appealType":
|
||||
repFormData.appealType,
|
||||
"repDetails":
|
||||
repFormData,
|
||||
repFormData
|
||||
});
|
||||
setRepresentationSubmit(
|
||||
false
|
||||
@@ -562,7 +620,7 @@ const RepCompleteSubmit = (props) => {
|
||||
"appealType":
|
||||
repFormData.appealType,
|
||||
"repDetails":
|
||||
repFormData,
|
||||
repFormData
|
||||
}),
|
||||
setRepresentationSubmit(
|
||||
false
|
||||
@@ -609,6 +667,7 @@ const RepCompleteSubmit = (props) => {
|
||||
"myrepresentations:rep-check-tandc-para-three"
|
||||
)}
|
||||
</p>
|
||||
<p></p>
|
||||
|
||||
{checkRepDatePassed() ? (
|
||||
<div className="govuk-warning-text noticebanner">
|
||||
@@ -676,6 +735,35 @@ const RepCompleteSubmit = (props) => {
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{repFormData.representationType ==
|
||||
"Questionnaire" && (
|
||||
<div className="govuk-checkboxes govuk-checkboxes--small">
|
||||
<div className="govuk-checkboxes__item">
|
||||
<input
|
||||
name="pinswg_downloadQuestionnaire"
|
||||
id="pinswg_downloadQuestionnaire"
|
||||
type="checkbox"
|
||||
className="govuk-checkboxes__input"
|
||||
checked={
|
||||
downloadQuestionnaire
|
||||
}
|
||||
onChange={(e) => {
|
||||
setDownloadQuestionnaire(
|
||||
e.target.checked
|
||||
);
|
||||
}}
|
||||
/>
|
||||
<label
|
||||
className="govuk-label govuk-checkboxes__label"
|
||||
htmlFor="pinswg_downloadQuestionnaire"
|
||||
>
|
||||
{t(
|
||||
"myrepresentations:rep-check-tandc-para-five"
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="govuk-form-group">
|
||||
<div className="govuk-checkboxes govuk-checkboxes--small">
|
||||
<div className="govuk-checkboxes__item">
|
||||
@@ -714,10 +802,11 @@ const RepCompleteSubmit = (props) => {
|
||||
type="submit"
|
||||
className="govuk-button"
|
||||
data-module="govuk-button"
|
||||
onClick={() => {
|
||||
onClick={async () => {
|
||||
// setRepresentationSubmitConfirmation(
|
||||
// true
|
||||
// );
|
||||
await triggerQuestionnaireDownload();
|
||||
setRepresentationSubmit(
|
||||
true
|
||||
);
|
||||
@@ -754,7 +843,7 @@ const mapStateToProps = (state) => {
|
||||
currentView: state.currentView,
|
||||
myRepresentations: state.myRepresentations,
|
||||
initialValues: state.currentView.caseReference.repDetails,
|
||||
accountDetails: state.accountDetails,
|
||||
accountDetails: state.accountDetails
|
||||
//form: state.form,
|
||||
};
|
||||
};
|
||||
@@ -763,7 +852,7 @@ const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
setCurrentReference: (currentReference) => {
|
||||
dispatch(setCurrentReference(currentReference));
|
||||
},
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user