diff --git a/components/case/documents.js b/components/case/documents.js index e0f229f6..99476370 100644 --- a/components/case/documents.js +++ b/components/case/documents.js @@ -6,7 +6,7 @@ import { useState, useEffect, useRef, useCallback } from "react"; import { useDispatch, useSelector, shallowEqual, connect } from "react-redux"; import transLookup from "../../data/lookuptranslations.json"; import PaginationControl from "./pagination"; - +import { formatDates } from "../utils"; import CryptoJS from "crypto-js"; import { setCurrentPage } from "../../store/currentView/action"; @@ -429,15 +429,6 @@ const DocumentDetails = (props) => { return docObj; }; - function formatDates(dateObj) { - var dateObj = new Date(dateObj); - var dd = String(dateObj.getDate()).padStart(2, "0"); - var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0! - var yyyy = dateObj.getFullYear(); - - return dd + "/" + mm + "/" + yyyy; - } - const pagesCount = Math.ceil(documentDetailsObj["@odata.count"] / 10); let currentPage = 0; diff --git a/components/case/representation/index.js b/components/case/representation/index.js index 96b1ef35..ed88c415 100644 --- a/components/case/representation/index.js +++ b/components/case/representation/index.js @@ -39,22 +39,7 @@ import { sendEmail, generateRepPDF, } from "../../../actions"; - -import { - RenderPickList, - RenderRadioList, - RenderTextfield, -} from "./representationElements"; - -import ReactPDF, { - Document, - Page, - Text, - View, - StyleSheet, - PDFViewer, -} from "@react-pdf/renderer"; -import { object } from "prop-types"; +import { formatDates } from "../../../components/utils"; let MakeRepresentation = (props) => { let { t } = useTranslation(); @@ -87,6 +72,13 @@ let MakeRepresentation = (props) => { let setCaseQueryObj = props[currentType] || {}; var casesObj = {}; + const isLPA = + props.props.accountDetails.accountDetails[ + "pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue" + ] == "LPA" + ? true + : false; + currentType == "searchResultsObj" ? (casesObj = jsonpath.query( setCaseQueryObj, @@ -103,32 +95,52 @@ let MakeRepresentation = (props) => { const capacityOptionsArr = ["Appellant", "Agent", "Interested Party"]; - const appellantApplicantRepresentationArr = [ - "Statement", - "Final comments", - "Written statement of evidence", - "Other", - ]; + let setCaseDetailsObj = router.query.hasOwnProperty("state") + ? router.query.state == "edit" + ? props.props.myRepresentations.myRepresentations + : props.props.searchResultsObj.searchDetailsObj + : props.props.searchResultsObj.searchDetailsObj; - const interestedPersonRepresentationArr = [ - "Statement", - "Final comments", - "Other", - ]; + var detailsObj = {}; - const lpaRepresentationArr = [ - "Questionnaire", - "Final comments", - "Written statement of evidence", - "Other", - ]; + detailsObj = jsonpath.query( + setCaseDetailsObj, + '$..[?(@.pinswg_name=="' + + currentView.caseReference.currentReference + + '")]' + ); - const landOwnerRepresentationArr = [ - "Statement", - "Final comments", - "Written statement of evidence", - "Other", - ]; + detailsObj = detailsObj[0]; + + const buildRepsArr = (detailsObj) => { + let buildArr = []; + + let todaysDate = new Date(); + + let startDate = new Date(detailsObj.pinswg_startdate); + let questionnaireDate = new Date( + detailsObj.pinswg_questionnaireduedate + ); + let finalCommentsDate = new Date( + detailsObj.pinswg_finalcommentsduedate + ); + let statementDueDate = new Date(detailsObj.pinswg_statementduedate); + + isLPA && + todaysDate >= startDate && + todaysDate <= questionnaireDate && + buildArr.push("Questionnaire"); + + todaysDate >= startDate && + todaysDate <= statementDueDate && + buildArr.push("Statement"); + + todaysDate >= statementDueDate && + todaysDate <= finalCommentsDate && + buildArr.push("Final comments"); + + return buildArr; + }; const repCapacityType = () => { return _.isEmpty(formObj["representationForm"]) @@ -144,19 +156,12 @@ let MakeRepresentation = (props) => { .toLowerCase(); }; - const isLPA = - props.props.accountDetails.accountDetails[ - "pinswg_typeofinvolvement@OData.Community.Display.V1.FormattedValue" - ] == "LPA" - ? true - : false; - const whichControl = () => { - console.log(isLPA); - console.log( - currentView.representationCapacity, - _.isEmpty(currentView.representationCapacity) - ); + // console.log(isLPA); + // console.log( + // currentView.representationCapacity, + // _.isEmpty(currentView.representationCapacity) + // ); if (isLPA && _.isEmpty(currentView.representationCapacity)) { return ( @@ -196,9 +201,9 @@ let MakeRepresentation = (props) => { return ( { return ( { return ( { return ( { return ( { const repForm = props.props.form; - console.log( - "what is representationSubmit state: " + - currentView.representationSubmit, - props.initialValues - ); - try { let value = props.initialValues; - console.log("has props"), value; + //console.log("has props"), value; setRepresentationCapacity( props.initialValues.representationCapacity.toLowerCase() ); @@ -615,7 +614,392 @@ let MakeRepresentation = (props) => { Make a representation on:{" "} {currentView.caseReference.currentReference} - {whichControl()} +
+
+ {whichControl()} +
+
+ {" "} +
+
+

+ Timetable +

+
+
+ Questionnaire due: + + {" "} + {formatDates( + detailsObj.pinswg_questionnaireduedate + )} + +
+
+ Statements due: + + {" "} + {formatDates( + detailsObj.pinswg_statementduedate + )} + +
+
+ Final comments due: + + {" "} + {formatDates( + detailsObj.pinswg_finalcommentsduedate + )} + +
+
+
+
+ {formObj.hasOwnProperty( + "representationForm" + ) && + formObj[ + "representationForm" + ].hasOwnProperty("values") && + formObj[ + "representationForm" + ].values.hasOwnProperty( + "representationType" + ) && + formObj["representationForm"].values + .representationType == + "Questionnaire" && ( +
+
    +
  1. + +
  2. +
  3. + +
  4. +
  5. + +
  6. +
  7. + +
  8. +
  9. + +
  10. +
  11. + +
  12. +
+
+ )} +
+
)} @@ -626,7 +1010,7 @@ let MakeRepresentation = (props) => { }; const mapStateToProps = (state) => { - console.log("\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \n in map state", state); + //console.log("\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \n in map state", state); return { search: state.search, diff --git a/components/case/representation/representationQuestionnairesCheck/representationLPAQuestionnaireCheck_enforcement.js b/components/case/representation/representationQuestionnairesCheck/representationLPAQuestionnaireCheck_enforcement.js index 126bbd6a..e3fc9fde 100644 --- a/components/case/representation/representationQuestionnairesCheck/representationLPAQuestionnaireCheck_enforcement.js +++ b/components/case/representation/representationQuestionnairesCheck/representationLPAQuestionnaireCheck_enforcement.js @@ -2,19 +2,12 @@ import _ from "lodash"; import Link from "next/link"; import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; +import { formatDates } from "../../../utils"; let RepLPAQuestionnaireCheck_enforcement = (props) => { let { t } = useTranslation(); const { formObj, currentView, setSubmitBack } = props; const repFormData = formObj.representationForm.values; - function formatDates(dateObj) { - var dateObj = new Date(dateObj); - var dd = String(dateObj.getDate()).padStart(2, "0"); - var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0! - var yyyy = dateObj.getFullYear(); - - return dd + "/" + mm + "/" + yyyy; - } return ( <> diff --git a/components/case/representation/representationQuestionnairesCheck/representationLPAQuestionnaireCheck_s78.js b/components/case/representation/representationQuestionnairesCheck/representationLPAQuestionnaireCheck_s78.js index 25899d0d..7c7feace 100644 --- a/components/case/representation/representationQuestionnairesCheck/representationLPAQuestionnaireCheck_s78.js +++ b/components/case/representation/representationQuestionnairesCheck/representationLPAQuestionnaireCheck_s78.js @@ -2,19 +2,12 @@ import _ from "lodash"; import Link from "next/link"; import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; +import { formatDates } from "../../../utils"; let RepLPAQuestionnaireCheck_s78 = (props) => { let { t } = useTranslation(); const { formObj, currentView, setSubmitBack } = props; const repFormData = formObj.representationForm.values; - function formatDates(dateObj) { - var dateObj = new Date(dateObj); - var dd = String(dateObj.getDate()).padStart(2, "0"); - var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0! - var yyyy = dateObj.getFullYear(); - - return dd + "/" + mm + "/" + yyyy; - } return ( <> diff --git a/components/case/representationList.js b/components/case/representationList.js index 24e6e19b..2059054e 100644 --- a/components/case/representationList.js +++ b/components/case/representationList.js @@ -10,6 +10,7 @@ import transLookup from "../../data/lookuptranslations.json"; import { getRepresentations } from "../../actions"; import { setRepresentations } from "../../store/searchOutput/action"; import PaginationControl from "./pagination"; +import { formatDates } from "../utils"; const RepresentationList = (props) => { const { incidentid, representationsObj, setRepresentations } = props; @@ -153,15 +154,6 @@ const RepresentationList = (props) => { const representationResultsObj = representationDetailsObj(); }, [incidentid, setRepresentations]); - function formatDates(dateObj) { - var dateObj = new Date(dateObj); - var dd = String(dateObj.getDate()).padStart(2, "0"); - var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0! - var yyyy = dateObj.getFullYear(); - - return dd + "/" + mm + "/" + yyyy; - } - const pagesCount = Math.ceil(representationsObj["@odata.count"] / 10); let currentPage = 0; diff --git a/components/utils/index.js b/components/utils/index.js index 4246c828..45290bb1 100644 --- a/components/utils/index.js +++ b/components/utils/index.js @@ -417,3 +417,21 @@ export const bytesToSize = (bytes) => { var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); return Math.round(bytes / Math.pow(1024, i), 2) + " " + sizes[i]; }; + +export const formatDates = (dateObj, showTime) => { + var dateObj = new Date(dateObj); + var dd = String(dateObj.getDate()).padStart(2, "0"); + var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0! + var yyyy = dateObj.getFullYear(); + var hh = dateObj.getHours(); + hh = ("0" + hh).slice(-2); + var mins = dateObj.getMinutes(); + mins = ("0" + mins).slice(-2); + + const dateStr = showTime + ? hh == 0 && mins == 0 + ? "" + : hh + ":" + mins + : dd + "/" + mm + "/" + yyyy + " "; + return dateStr; +};