diff --git a/components/case/representation/index.js b/components/case/representation/index.js index b86d4750..0eb50ad5 100644 --- a/components/case/representation/index.js +++ b/components/case/representation/index.js @@ -389,6 +389,8 @@ let MakeRepresentation = (props) => { caseReference={caseReference} setRepFileName={setRepFileName} updateRepresentation={updateRepresentation} + setSavingStatus={setSavingStatus} + savingStatus={savingStatus} /> ); } else { @@ -408,6 +410,8 @@ let MakeRepresentation = (props) => { caseReference={caseReference} setRepFileName={setRepFileName} updateRepresentation={updateRepresentation} + setSavingStatus={setSavingStatus} + savingStatus={savingStatus} />; break; case "appellant": @@ -431,6 +435,8 @@ let MakeRepresentation = (props) => { props={props} setRepFileName={setRepFileName} updateRepresentation={updateRepresentation} + setSavingStatus={setSavingStatus} + savingStatus={savingStatus} /> ); break; @@ -464,6 +470,8 @@ let MakeRepresentation = (props) => { questionnaireCount={questionnaireCount} setRepFileName={setRepFileName} updateRepresentation={updateRepresentation} + setSavingStatus={setSavingStatus} + savingStatus={savingStatus} /> ); break; @@ -488,6 +496,8 @@ let MakeRepresentation = (props) => { props={props} setRepFileName={setRepFileName} updateRepresentation={updateRepresentation} + setSavingStatus={setSavingStatus} + savingStatus={savingStatus} /> ); break; @@ -512,6 +522,8 @@ let MakeRepresentation = (props) => { props={props} setRepFileName={setRepFileName} updateRepresentation={updateRepresentation} + setSavingStatus={setSavingStatus} + savingStatus={savingStatus} /> ); break; @@ -615,6 +627,10 @@ let MakeRepresentation = (props) => { const sortFileObj = (filelistObj) => { let blobList = filelistObj; + function removeNullObjects(arr) { + return arr.filter((obj) => obj !== null); + } + function removeObjectsWithUndefinedKey(arr, key) { return arr.filter((obj) => obj[key] !== undefined); } @@ -623,6 +639,7 @@ let MakeRepresentation = (props) => { return arr.filter((obj) => Object.keys(obj).length > 0); } + blobList = removeNullObjects(blobList); blobList = removeEmptyObjects(blobList); blobList = removeObjectsWithUndefinedKey(blobList, "name"); @@ -819,6 +836,7 @@ let MakeRepresentation = (props) => { // Object.assign(values, { // "filesList": buildFileArray, // })), + uploadRepresentationFiles(values), generateRepPDF( values, @@ -931,54 +949,165 @@ let MakeRepresentation = (props) => { : values.representationCapacity, "locale": router.locale, })); - currentView.representationSubmit != true - ? _.isEmpty(currentView.representationCapacity) - ? isLPA - ? setRepresentationCapacity("lpa") - : setRepresentationCapacity( - values.representationCapacity - .replace(/(\band|[\s\-\+\(\)\,\&])/g, "") - .toLowerCase() - ) - : questionnaireCount != 0 && - showQuestionnaireSection < questionnaireCount - ? (setShowQuestionnaireSection(showQuestionnaireSection + 1), - updateRepresentation(values, false, false)) - : (updateRepresentation(values, false, false), - setRepresentationSubmit(true)) - : currentView.representationSubmit == true - ? (console.log("capacity", currentView.representationCapacity), - console.log("has errors:", props.invalid), - Object.assign(values, { "locale": router.locale }), - props.invalid == false && - updateRepresentation(values, false, false), - // values.hasOwnProperty("representationDocuments") && - // (values.representationDocuments.map((Blob) => - // buildFileArray.push({ - // "name": Blob.name, - // "size": Blob.size, - // }) - // ), - // Object.assign(values, { - // "filesList": buildFileArray, - // })), - console.log( - "====================== rep lpa payload:\n", - JSON.stringify(values) - ), - generateRepPDF( - values, - props.props.accountDetails.containerID, - currentView.caseReference.currentReference - ), - uploadRepresentationFiles(values), - setRepresentationSubmitConfirmation(true)) - : console.log("nit updated"); + + if (currentView.representationSubmit != true) { + if (_.isEmpty(currentView.representationCapacity)) { + if (isLPA) { + setRepresentationCapacity( + values.representationCapacity + .replace(/(\band|[\s\-\+\(\)\,\&])/g, "") + .toLowerCase() + ); + } else { + setRepresentationCapacity( + values.representationCapacity + .replace(/(\band|[\s\-\+\(\)\,\&])/g, "") + .toLowerCase() + ); + } + } else { + if (values.representationType == "Questionnaire") { + if ( + questionnaireCount != 0 && + showQuestionnaireSection < questionnaireCount + ) { + setShowQuestionnaireSection( + showQuestionnaireSection + 1 + ); + updateRepresentation(values, false, false); + } else { + updateRepresentation(values, false, false); + setRepresentationSubmit(true); + } + } else { + updateRepresentation(values, false, false); + setRepresentationSubmit(true); + } + } + } else { + if (currentView.representationSubmit == true) { + console.log("capacity", currentView.representationCapacity); + console.log("has errors:", props.invalid); + Object.assign(values, { "locale": router.locale }); + props.invalid == false && + updateRepresentation(values, false, false); + // values.hasOwnProperty("representationDocuments") && + // (values.representationDocuments.map((Blob) => + // buildFileArray.push({ + // "name": Blob.name, + // "size": Blob.size, + // }) + // ), + // Object.assign(values, { + // "filesList": buildFileArray, + // })), + console.log( + "====================== rep lpa payload:\n", + JSON.stringify(values) + ); + generateRepPDF( + values, + props.props.accountDetails.containerID, + currentView.caseReference.currentReference + ); + uploadRepresentationFiles(values); + setRepresentationSubmitConfirmation(true); + } else { + console.log("nit updated"); + } + } + + // currentView.representationSubmit != true + // ? _.isEmpty(currentView.representationCapacity) + // ? isLPA + // ? setRepresentationCapacity("lpa") + // : setRepresentationCapacity( + // values.representationCapacity + // .replace(/(\band|[\s\-\+\(\)\,\&])/g, "") + // .toLowerCase() + // ) + // : questionnaireCount != 0 && + // showQuestionnaireSection < questionnaireCount + // ? (setShowQuestionnaireSection(showQuestionnaireSection + 1), + // updateRepresentation(values, false, false)) + // : (updateRepresentation(values, false, false), + // setRepresentationSubmit(true)) + // : currentView.representationSubmit == true + // ? (console.log("capacity", currentView.representationCapacity), + // console.log("has errors:", props.invalid), + // Object.assign(values, { "locale": router.locale }), + // props.invalid == false && + // updateRepresentation(values, false, false), + // // values.hasOwnProperty("representationDocuments") && + // // (values.representationDocuments.map((Blob) => + // // buildFileArray.push({ + // // "name": Blob.name, + // // "size": Blob.size, + // // }) + // // ), + // // Object.assign(values, { + // // "filesList": buildFileArray, + // // })), + // console.log( + // "====================== rep lpa payload:\n", + // JSON.stringify(values) + // ), + // generateRepPDF( + // values, + // props.props.accountDetails.containerID, + // currentView.caseReference.currentReference + // ), + // uploadRepresentationFiles(values), + // setRepresentationSubmitConfirmation(true)) + // : console.log("nit updated"); //window.alert(`You submitted:\n\n${JSON.stringify(values, null, 2)}`); }; + const cleanFilesList = (blobList) => { + let newblobList = blobList.filesList; + function removeNullObjects(arr) { + if (arr.length === 0) { + return arr; + } + return arr.filter((obj) => obj !== null); + } + + function removeObjectsWithUndefinedKey(arr, key) { + if (arr.length === 0) { + return arr; + } + return arr.filter((obj) => obj[key] !== undefined); + } + + function removeEmptyObjects(arr) { + if (arr.length === 0) { + return arr; + } + return arr.filter( + (obj) => + obj && + typeof obj === "object" && + Object.keys(obj).length > 0 + ); + } + + newblobList = removeNullObjects(newblobList); + newblobList = removeEmptyObjects(newblobList); + newblobList = removeObjectsWithUndefinedKey(newblobList, "name"); + + Object.assign(blobList, { + "filesList": newblobList, + }); + + return blobList; + }; + const uploadRepresentationFiles = (values) => { + values = values.hasOwnProperty("filesList") + ? cleanFilesList(values) + : values; + // get filelists from values object let fileListObj = _.filter(values, function (v, key) { return _.includes(key, "representationDocuments"); @@ -1011,19 +1140,8 @@ let MakeRepresentation = (props) => { const repForm = props.props.form; - // try { - // let value = props.initialValues; - // setRepresentationCapacity( - // props.initialValues.representationCapacity.toLowerCase() - // ); - // //setRepresentationSubmit(false); - // } catch { - // console.log("not has props"); - // } - return (
-
hello {currentView.representationSubmit ? "yep" : "no"}
{currentView.representationSubmit == true ? ( { /> ) : ( <> - {!session ? ( + {/* {!session ? ( <>

@@ -1077,172 +1195,103 @@ let MakeRepresentation = (props) => { )} - ) : ( - <> -

- {t( - "myrepresentations:make-a-representation-on-label" - )}{" "} - {currentView.caseReference.currentReference}{" "} -

- {currentView.caseReference.caseReference} -
-
- {whichControl()} -
+ ) : ( */} + <> +

+ {t( + "myrepresentations:make-a-representation-on-label" + )}{" "} + {currentView.caseReference.currentReference}{" "} +

+
+
+ {whichControl()} +
-
- {" "} -
-
-

- {t( - "myrepresentations:timetable-title" - )}{" "} +
+ {" "} +
+
+

+ {t( + "myrepresentations:timetable-title" + )}{" "} + {currentView.caseReference + .appealType == 846040011} +

+
+
{currentView.caseReference - .appealType == - 846040011} -

-
-
- {currentView - .caseReference - .appealType == - 846040011 - ? t( - "myrepresentations:local-impact-report" - ) - : t( - "myrepresentations:questionnaire-due-label" - )} - : - - {" "} - {formatDates( - detailsObj.pinswg_questionnaireduedate || - detailsObj.pinswg_endofrepresentationperiod - )} - -
+ .appealType == 846040011 + ? t( + "myrepresentations:local-impact-report" + ) + : t( + "myrepresentations:questionnaire-due-label" + )} + : + + {" "} + {formatDates( + detailsObj.pinswg_questionnaireduedate || + detailsObj.pinswg_endofrepresentationperiod + )} + +
+
+ {t( + "myrepresentations:statements-due-label" + )} + : + + {" "} + {formatDates( + detailsObj.pinswg_statementduedate || + detailsObj.pinswg_statementsduedate || + detailsObj.pinswg_endofrepresentationperiod + )} + +
+ {currentView.caseReference + .appealType != + 846040011 && (
{t( - "myrepresentations:statements-due-label" + "myrepresentations:final-comments-due-label" )} : {" "} {formatDates( - detailsObj.pinswg_statementduedate || - detailsObj.pinswg_statementsduedate || - detailsObj.pinswg_endofrepresentationperiod + detailsObj.pinswg_finalcommentsduedate )}
- {currentView.caseReference - .appealType != - 846040011 && ( -
- {t( - "myrepresentations:final-comments-due-label" - )} - : - - {" "} - {formatDates( - detailsObj.pinswg_finalcommentsduedate - )} - -
- )} -
+ )}
-
{" "} - {/* {typeof props.props.currentView - .representationCapacity != - "undefined" && - props.props.currentView - .representationCapacity.length > - 0 && ( -
- {savingStatus ? ( - - {router.locale == - "cy" - ? "Nôl data" - : "Saving data"} - { - - ) : ( - - )} - ee -
- )} */} -
- {formObj.hasOwnProperty( - "representationForm" - ) && - formObj[ - "representationForm" - ].hasOwnProperty("values") && - formObj[ - "representationForm" - ].values.hasOwnProperty( - "representationType" - ) && - formObj["representationForm"] - .values - .representationType == - "Questionnaire" && - whichProgress()}
+
+ {formObj.hasOwnProperty( + "representationForm" + ) && + formObj[ + "representationForm" + ].hasOwnProperty("values") && + formObj[ + "representationForm" + ].values.hasOwnProperty( + "representationType" + ) && + formObj["representationForm"].values + .representationType == + "Questionnaire" && + whichProgress()} +
- - )} +
+ + {/* )} */} )} @@ -1266,7 +1315,6 @@ const mapStateToProps = (state) => { const mapDispatchToProps = (dispatch) => { return { setRepresentationCapacity: (representationCapacity) => { - //dispatch(reset("representationForm")); dispatch(setRepresentationCapacity(representationCapacity)); }, setRepresentationSubmit: (representationSubmit) => { diff --git a/components/case/representation/representationAgent.js b/components/case/representation/representationAgent.js index d8957c52..7c7fd20b 100644 --- a/components/case/representation/representationAgent.js +++ b/components/case/representation/representationAgent.js @@ -27,9 +27,10 @@ const RepAgent = (props) => { currentView, setRepFileName, updateRepresentation, + setSavingStatus, + savingStatus, } = props; const { acceptedFiles, getRootProps, getInputProps } = useDropzone(); - const [savingStatus, setSavingStatus] = useState(false); setRepFileName(formObj.representationForm.values); @@ -179,7 +180,7 @@ const RepAgent = (props) => { props.props.props.accountDetails .containerID } - filenamePrefix={props} + filenamePrefix={props.formObj} />
{props.currentView.caseReference.hasOwnProperty( diff --git a/components/case/representation/representationAppellant.js b/components/case/representation/representationAppellant.js index b2d8a5fd..4a91796e 100644 --- a/components/case/representation/representationAppellant.js +++ b/components/case/representation/representationAppellant.js @@ -30,9 +30,10 @@ const RepAppellant = (props) => { currentView, setRepFileName, updateRepresentation, + setSavingStatus, + savingStatus, } = props; const { acceptedFiles, getRootProps, getInputProps } = useDropzone(); - const [savingStatus, setSavingStatus] = useState(false); setRepFileName(formObj.representationForm.values); @@ -157,7 +158,7 @@ const RepAppellant = (props) => { props.props.props.accountDetails .containerID } - filenamePrefix={props} + filenamePrefix={props.formObj} /> {props.currentView.caseReference.hasOwnProperty( diff --git a/components/case/representation/representationElements.js b/components/case/representation/representationElements.js index 70927e13..65463fc3 100644 --- a/components/case/representation/representationElements.js +++ b/components/case/representation/representationElements.js @@ -966,16 +966,33 @@ export const RenderFileUpload = (field) => { let blobList = filelistObj; + function removeNullObjects(arr) { + if (arr.length === 0) { + return arr; + } + return arr.filter((obj) => obj !== null); + } + function removeObjectsWithUndefinedKey(arr, key) { + if (arr.length === 0) { + return arr; + } return arr.filter((obj) => obj[key] !== undefined); } function removeEmptyObjects(arr) { - return arr.filter((obj) => Object.keys(obj).length > 0); + if (arr.length === 0) { + return arr; + } + return arr.filter( + (obj) => + obj && typeof obj === "object" && Object.keys(obj).length > 0 + ); } blobList = removeEmptyObjects(blobList); blobList = removeObjectsWithUndefinedKey(blobList, "name"); + blobList = removeNullObjects(blobList); let buildAppealFilesArray = []; @@ -1079,7 +1096,7 @@ export const RenderFileUpload = (field) => { {field.meta.touched && field.meta.error && ( {field.meta.error} )} - {blobList && Array.isArray(files) && ( + {/* {files && Array.isArray(files) && ( - )} + )} */} {blobList.map((blob, i) => (
diff --git a/components/case/representation/representationInterestedPartyPerson.js b/components/case/representation/representationInterestedPartyPerson.js index 2904bbf5..fe3688e2 100644 --- a/components/case/representation/representationInterestedPartyPerson.js +++ b/components/case/representation/representationInterestedPartyPerson.js @@ -26,11 +26,12 @@ const RepInterestedPartyPerson = (props) => { setRepresentationSubmit, setRepFileName, updateRepresentation, + setSavingStatus, + savingStatus, } = props; const required = (value) => (value ? undefined : "Required"); const { acceptedFiles, getRootProps, getInputProps } = useDropzone(); - const [savingStatus, setSavingStatus] = useState(false); setRepFileName(formObj.representationForm.values); @@ -175,7 +176,7 @@ const RepInterestedPartyPerson = (props) => { props.props.props.accountDetails .containerID } - filenamePrefix={props} + filenamePrefix={props.formObj} />
{props.currentView.caseReference.hasOwnProperty( diff --git a/components/case/representation/representationLPA.js b/components/case/representation/representationLPA.js index 9efe74c5..8061ab8b 100644 --- a/components/case/representation/representationLPA.js +++ b/components/case/representation/representationLPA.js @@ -19,7 +19,6 @@ import S78_Questionnaire from "./representationQuestionnaires/representationLPAQ let RepLPA = (props) => { let { t } = useTranslation(); - const router = useRouter(); const { locale } = router; const { @@ -38,9 +37,11 @@ let RepLPA = (props) => { setQuestionnaireCount, setRepFileName, updateRepresentation, + setSavingStatus, + savingStatus, } = props; const { acceptedFiles, getRootProps, getInputProps } = useDropzone(); - const [savingStatus, setSavingStatus] = useState(false); + const files = acceptedFiles.map((file) => (
  • {file.path} - {file.size} bytes @@ -197,6 +198,13 @@ let RepLPA = (props) => { ) && setRepFileName(props.formObj["representationForm"].values); + let filesListObj = + props.formObj.hasOwnProperty("representationForm") && + props.formObj["representationForm"].hasOwnProperty("values") && + props.formObj["representationForm"].values.hasOwnProperty("filesList") + ? props.formObj["representationForm"].values.filesList + : {}; + return ( <>
    @@ -291,6 +299,35 @@ let RepLPA = (props) => { > {" "}
    + {console.log( + "--------", + props.formObj.hasOwnProperty( + "representationForm" + ) && + props.formObj[ + "representationForm" + ].hasOwnProperty("values") && + props.formObj[ + "representationForm" + ].values.hasOwnProperty( + "filesList" + ) + ? props.props.props.form[ + "representationForm" + ].values.filesList + : "" + )} + {/* {props.formObj.hasOwnProperty( + "representationForm" + ) && + props.formObj[ + "representationForm" + ].hasOwnProperty("values") && + props.formObj[ + "representationForm" + ].values.hasOwnProperty( + "filesList" + ) && ( */} { } hint={"sdsd"} fileList={ - props.props.props.form[ + (props.formObj.hasOwnProperty( "representationForm" - ].values.filesList || [] + ) && + props.formObj[ + "representationForm" + ].hasOwnProperty( + "values" + ) && + props.formObj[ + "representationForm" + ].values.hasOwnProperty( + "filesList" + ) && + props.props.props.form[ + "representationForm" + ].values.filesList) || + [] } setFilesForRepresentation={[]} containerID={ props.props.props.accountDetails .containerID } - filenamePrefix={props} + filenamePrefix={props.formObj} /> + {/* // )} */}
    @@ -434,7 +486,7 @@ let RepLPA = (props) => { className="govuk-button" data-module="govuk-button" > - {t("common:continue-button")} + wwwww {t("common:continue-button")} {/* {router.query.state != "edit" && ( { className="govuk-button progress-save " onClick={() => { let valuesObj = - props.props.form[props.form] - .values || {}; + props.props.props.form[ + props.form + ].values || {}; console.log( "valuesobj:", diff --git a/components/myportal/topthree_reps.js b/components/myportal/topthree_reps.js index 5bd02076..7bb660b9 100644 --- a/components/myportal/topthree_reps.js +++ b/components/myportal/topthree_reps.js @@ -197,6 +197,7 @@ const TopThree = (props) => { query: { case: showTopThreeArr[key].caseRef, state: "edit", + created: showTopThreeArr[key].repfile_name, }, }} className="govuk-link--no-underline" diff --git a/components/representation.js b/components/representation.js index 19f113a9..8cc7d005 100644 --- a/components/representation.js +++ b/components/representation.js @@ -24,6 +24,7 @@ const CaseRepresentation = (props) => { caseReference={props.caseReference} currentType={props.currentType} searchResultsObj={props.searchResultsObj} + searchDetailsObj={props.searchDetailsObj} searchString={props.searchString} props={props.props} /> diff --git a/next.config.js b/next.config.js index afcdece6..9cd7c190 100644 --- a/next.config.js +++ b/next.config.js @@ -58,6 +58,7 @@ const buildId = Date.now().toString(); module.exports = { //output: "standalone", + reactStrictMode: false, env: { BUILD_ID_ENV: buildId, }, diff --git a/package.json b/package.json index 5dbe6827..f02c5116 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "@redux-devtools/extension": "^3.3.0", "@xmldom/xmldom": "^0.8.10", "applicationinsights": "^2.9.1", - "axios": "^1.6.2", + "axios": "^1.7.7", "compression": "^1.7.4", "cookie-cutter": "^0.2.0", "crypto-js": "^4.2.0", @@ -97,4 +97,4 @@ "eslint-plugin-jsdoc": "^48.2.3", "prisma": "^5.0.0" } -} \ No newline at end of file +} diff --git a/pages/api/file/generatepdf.js b/pages/api/file/generatepdf.js index 7057ea58..3c19856b 100644 --- a/pages/api/file/generatepdf.js +++ b/pages/api/file/generatepdf.js @@ -109,6 +109,49 @@ export default async function handler(req, res) { var checkHash = req.query.hash; let reqBodyobj = req.body; //JSON.parse(req.body); + const cleanFilesList = (blobList) => { + let newblobList = blobList.filesList; + function removeNullObjects(arr) { + if (arr.length === 0) { + return arr; + } + return arr.filter((obj) => obj !== null); + } + + function removeObjectsWithUndefinedKey(arr, key) { + if (arr.length === 0) { + return arr; + } + return arr.filter((obj) => obj[key] !== undefined); + } + + function removeEmptyObjects(arr) { + if (arr.length === 0) { + return arr; + } + return arr.filter( + (obj) => + obj && + typeof obj === "object" && + Object.keys(obj).length > 0 + ); + } + + newblobList = removeEmptyObjects(newblobList); + newblobList = removeObjectsWithUndefinedKey(newblobList, "name"); + newblobList = removeNullObjects(newblobList); + + Object.assign(blobList, { + "filesList": newblobList, + }); + + return blobList; + }; + + reqBodyobj = reqBodyobj.hasOwnProperty("filesList") + ? cleanFilesList(reqBodyobj) + : reqBodyobj; + console.log( "//////////////////////\nreqBodyobj" + req + diff --git a/pages/myportal/representation.js b/pages/myportal/representation.js index 8fa95a87..9639403c 100644 --- a/pages/myportal/representation.js +++ b/pages/myportal/representation.js @@ -5,7 +5,16 @@ import { useEffect } from "react"; import { getSession, useSession } from "next-auth/react"; import { useRouter } from "next/router"; import { connect, useDispatch } from "react-redux"; -import { getPersonalAccount, getPortalLoginProxy } from "../../actions"; +import { + getPersonalAccount, + getPortalLoginProxy, + getPortalLogin, + getRepsFromBlob, + getCase, + getPortalModuleDetails, + getBasicSearch, +} from "../../actions"; +import { getFormCollectionByID } from "../../components/utils"; import Breadcrumbs from "../../components/breadcrumbs"; import CookieBanner from "../../components/cookieBanner"; import Footer from "../../components/footer"; @@ -16,13 +25,33 @@ import { setContainerID, setLoggedInUserId, } from "../../store/accountDetails/action"; +import { wrapper } from "../../store/store"; +import { getSearchDetails } from "../../components/utils"; + +import { + setCurrentReference, + setCurrentView, + setRepresentationCapacity, +} from "../../store/currentView/action"; +import { + setSearchDetails, + setSearchResults, +} from "../../store/searchOutput/action"; +import { setSearch } from "../../store/search/action"; import NoSessionWarning from "../../components/nosession"; import ServiceBanner from "../../components/myportal/servicebanner"; import TimeOut from "../../components/timeout"; +import { + setMyRepresentations, + setMyRepresentationsDetails, + setMySubmittedReps, + setMySubmittedRepsDetails, +} from "../../store/myRepresentations/action"; + const RepresentationF = (props) => { - const { footerLinks, pages, accountDetails } = props; + const { footerLinks, pages } = props; let { t, lang } = useTranslation(); const router = useRouter(); @@ -31,34 +60,34 @@ const RepresentationF = (props) => { const dispatch = useDispatch(); - useEffect(() => { - const updateAccountStore = async () => { - const thisSession = await getSession(); + // useEffect(() => { + // const updateAccountStore = async () => { + // const thisSession = await getSession(); - if (thisSession) { - let loggedInUser = await getPortalLoginProxy( - thisSession.user.email - ); - dispatch( - setAccountDetails( - await getPersonalAccount( - loggedInUser.value[0].contactid - ) - ) - ); - dispatch(setContainerID(thisSession.user.id)); - dispatch(setLoggedInUserId(loggedInUser.value[0].contactid)); - //dispatch(setRepresentationSubmit(true)); - } - }; - updateAccountStore(); - }, [dispatch]); + // if (thisSession) { + // let loggedInUser = await getPortalLoginProxy( + // thisSession.user.email + // ); + // dispatch( + // setAccountDetails( + // await getPersonalAccount( + // loggedInUser.value[0].contactid + // ) + // ) + // ); + // dispatch(setContainerID(thisSession.user.id)); + // dispatch(setLoggedInUserId(loggedInUser.value[0].contactid)); + // //dispatch(setRepresentationSubmit(true)); + // } + // }; + // updateAccountStore(); + // }, [dispatch]); const { data: session, status } = useSession(); - if (status === "loading") { - return ; - } + // if (status === "loading") { + // return ; + // } return (
    @@ -169,60 +198,241 @@ const RepresentationF = (props) => { ); }; -// export const getServerSideProps = wrapper.getServerSideProps( -// (store) => async (ctx) => { -// const { query, req, res } = ctx; -// console.log("The query", query); +export const getServerSideProps = wrapper.getServerSideProps( + (store) => async (ctx) => { + const { query, req, res } = ctx; + console.log("The query", query); -// const { cookies } = req; + const { cookies } = req; -// let loggedInUserCookie = cookies.pinsUser; + let loggedInUserCookie = cookies.pinsUser; -// let thisSession = await getSession(ctx); -// let loggedInUser = {}; + let thisSession = await getSession(ctx); + let loggedInUser = {}; -// if (!thisSession) { -// console.log("not has sesssion......."); -// return { -// redirect: { -// destination: "/auth/signin", -// permanent: false, -// }, -// }; -// } else { -// [loggedInUser] = await Promise.all([ -// await getPortalLogin(thisSession.user.email), -// ]); + if (!thisSession) { + console.log("not has sesssion......."); + return { + redirect: { + destination: "/auth/signin", + permanent: false, + }, + }; + } else { + [loggedInUser] = await Promise.all([ + await getPortalLogin(thisSession.user.email), + ]); -// console.log( -// "=====//////////=====", -// thisSession, -// thisSession.user.email, -// loggedInUser -// ); -// loggedInUser = loggedInUser.value[0].contactid; -// } + console.log( + "=====//////////=====", + thisSession, + thisSession.user.email, + loggedInUser + ); + loggedInUser = loggedInUser.value[0].contactid; + } -// const accountDetails = await getPersonalAccount(loggedInUser); + const [accountDetails, myRepresentations] = await Promise.all([ + await getPersonalAccount(loggedInUser), + await getRepsFromBlob(thisSession.user.id), + ]); -// console.log(accountDetails); -// store.dispatch(setAccountDetails(accountDetails)); -// return { -// props: { -// containerID: thisSession.user.id, -// }, -// }; -// } -// ); + const myRepresentationsDetails = await getDetails( + myRepresentations, + "myRepresentations" + ); -const mapDispatchToProps = (dispatch) => { - return { - setAccountDetails: (loggedInUser) => { - dispatch(setAccountDetails(loggedInUser)); - }, - }; + console.log(accountDetails); + + const isLPA = + accountDetails[ + "pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue" + ] == "LPA" + ? true + : false; + + isLPA && store.dispatch(setRepresentationCapacity("lpa")); + + if (query.hasOwnProperty("state")) { + console.log("is lpa?:", isLPA); + + store.dispatch(setContainerID(thisSession.user.id)); + store.dispatch(setMyRepresentations(myRepresentations)); + store.dispatch( + setMyRepresentationsDetails(myRepresentationsDetails) + ); + + function findObjectByKeyValue(arr, key, value) { + return arr.find((obj) => obj[key] === value); + } + + const result = findObjectByKeyValue( + myRepresentations.value, + "repfile_name", + query.created + ); + + store.dispatch( + setCurrentReference({ + "ticketnumber": result.ticketnumber, + "currentReference": result.caseRef, + "currentType": "myRepresentations", + "incidentid": result.incidentID, + "appealType": result.appealType, + "repDetails": result, + }) + ); + store.dispatch(setAccountDetails(accountDetails)); + + return { + props: { + containerID: thisSession.user.id, + }, + }; + } else { + const searchResultsObj = await getBasicSearch(query.case); + const searchDetailsObj = await getSearchDetails(searchResultsObj); + + store.dispatch(setContainerID(thisSession.user.id)); + store.dispatch(setSearchResults(searchResultsObj)); + store.dispatch(setSearchDetails(searchDetailsObj)); + store.dispatch(setSearch(query.case)); + store.dispatch( + setCurrentView({ + "viewName": "My Representations", + "viewKey": "myRepresentations", + }) + ); + store.dispatch( + setCurrentReference({ + "ticketnumber": searchResultsObj.value[0].ticketnumber, + "currentReference": searchResultsObj.value[0].title, + "currentType": "myRepresentations", + "incidentid": searchResultsObj.value[0].incidentid, + "appealType": + searchResultsObj.value[0].pinswg_appealcasetype, + + "specialistProcess": + searchDetailsObj[0].value[0] + .pinswg_speacialistcaseprocess != null || + searchDetailsObj[0].value[0] + .pinswg_specialistcaseprocess != null + ? searchDetailsObj[0].value[0] + .pinswg_speacialistcaseprocess || + searchDetailsObj[0].value[0] + .pinswg_specialistcaseprocess + : "", + }) + ); + store.dispatch(setAccountDetails(accountDetails)); + + // return { + // props: { + // searchResultsObj: { + // searchResultsObj: searchResultsObj, + // searchDetailsObj: searchDetailsObj, + // }, + // containerID: thisSession.user.id, + // }, + // }; + } + } +); + +const getDetails = (resultsObj, detailsType) => { + let detailsArr = []; + + resultsObj = + detailsType == "mySubmittedReps" ? resultsObj : resultsObj.value; + + if (detailsType == "myRepresentations") { + const repsObj = resultsObj.map((searchDetail, index) => { + detailsArr.push( + getCase(searchDetail["incidentID"]).then((data) => { + let caseID = ""; + + switch (detailsType) { + case "myCases": + caseID = data.pinswg_title; + break; + case "myWatchedCases": + case "mySubmittedReps": + caseID = + data[ + "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + ]; + break; + case "awaitingSubmission": + case "myRepresentations": + caseID = data.ticketnumber; + break; + default: + caseID = data.pinswg_title; + } + return getPortalModuleDetails( + getFormCollectionByID(data.pinswg_appealcasetype) + .LogicalCollectionName, + caseID + ); + }) + ); + }); + } + + // const detailsObj = resultsObj.map(async (searchDetail, index) => { + // let caseID = ""; + + // switch (detailsType) { + // case "myCases": + // caseID = searchDetail.pinswg_title; + // break; + // case "myWatchedCases": + // case "mySubmittedReps": + // caseID = + // searchDetail[ + // "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + // ]; + // break; + // case "awaitingSubmission": + // caseID = searchDetail.ticketnumber; + // break; + // case "myRepresentations": + // caseID = searchDetail.casereference; + // break; + // default: + // caseID = searchDetail.pinswg_title; + // } + + // console.log(detailsType, " case id : ", caseID); + + // searchDetail.pinswg_appealcasetype != null && + // detailsArr.push( + // getPortalModuleDetails( + // getFormCollectionByID(searchDetail.pinswg_appealcasetype) + // .LogicalCollectionName, + // caseID + // // detailsType != "myWatchedCases" + // // ? searchDetail.ticketnumber + // // : searchDetail[ + // // "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" + // // ] + // ) + // ); + // }); + + let detArr = Promise.all(detailsArr); + console.log(detArr); + return detArr; }; +// const mapDispatchToProps = (dispatch) => { +// return { +// setAccountDetails: (loggedInUser) => { +// dispatch(setAccountDetails(loggedInUser)); +// }, +// }; +// }; + const mapStateToProps = (state) => { return { accountDetails: state.accountDetails, @@ -239,4 +449,4 @@ const mapStateToProps = (state) => { }; }; -export default connect(mapStateToProps, mapDispatchToProps)(RepresentationF); +export default connect(mapStateToProps)(RepresentationF);