diff --git a/components/case/summary.js b/components/case/summary.js index 48677fe2..b252b94a 100644 --- a/components/case/summary.js +++ b/components/case/summary.js @@ -32,32 +32,17 @@ import { signIn, useSession } from "next-auth/react"; import { destroyCookie, parseCookies, setCookie } from "nookies"; import { getFormCollectionByID, getDetailsProxy } from "../utils"; -import Pinswg_advertsid from "./summaryTypes/pinswg_advertsid"; -import Pinswg_callinss77id from "./summaryTypes/pinswg_callinss77id"; -import Pinswg_commonlandid from "./summaryTypes/pinswg_commonlandid"; -import Pinswg_communityinfrastructurelevyid from "./summaryTypes/pinswg_communityinfrastructurelevyid"; -import Pinswg_compulsorypurchaseordersid from "./summaryTypes/pinswg_compulsorypurchaseordersid"; -import Pinswg_dnsid from "./summaryTypes/pinswg_dnsid"; -import Pinswg_sipscase from "./summaryTypes/pinswg_sipscase"; -import Pinswg_electricityactid from "./summaryTypes/pinswg_electricityactid"; -import Pinswg_enforcementlistedbuildingconseid from "./summaryTypes/pinswg_enforcementlistedbuildingconseid"; -import Pinswg_enforcementnoticeappeals174id from "./summaryTypes/pinswg_enforcementnoticeappeals174id"; -import Pinswg_environmentalpermittingid from "./summaryTypes/pinswg_environmentalpermittingid"; -import Pinswg_harbourrevisionorderid from "./summaryTypes/pinswg_harbourrevisionorderid"; -import Pinswg_hedgeshedgerowstreepreservatioid from "./summaryTypes/pinswg_hedgeshedgerowstreepreservatioid"; -import Pinswg_householderappealhasid from "./summaryTypes/pinswg_householderappealhasid"; -import Pinswg_lawfuldevelopmentcertificatappid from "./summaryTypes/pinswg_lawfuldevelopmentcertificatappid"; -import Pinswg_ldpid from "./summaryTypes/pinswg_ldpid"; -import Pinswg_listedbuildingandconservationrid from "./summaryTypes/pinswg_listedbuildingandconservationrid"; -import Pinswg_maintenanceoflands217id from "./summaryTypes/pinswg_maintenanceoflands217id"; -import Pinswg_miscellaneouscasewordid from "./summaryTypes/pinswg_miscellaneouscasewordid"; -import Pinswg_nonvalidationid from "./summaryTypes/pinswg_nonvalidationid"; -import Pinswg_planningappeals78id from "./summaryTypes/pinswg_planningappeals78id"; -import Pinswg_planningconditionss73s79id from "./summaryTypes/pinswg_planningconditionss73s79id"; -import Pinswg_planningobligationappeals106id from "./summaryTypes/pinswg_planningobligationappeals106id"; -import Pinswg_rowid from "./summaryTypes/pinswg_rowid"; -import Pinswg_transportandworkactid from "./summaryTypes/pinswg_transportandworkactid"; -import Pinswg_wayleaveid from "./summaryTypes/pinswg_wayleaveid"; +import * as CaseTypes from "./summaryTypes"; // ✅ must match filename exactly +import { + capitalizeFirstLetter, + formatDates, + showReps, + hasValidKey, + isObjectNotEmpty, + hasOwnPropertyAndNotNull, + linkedCasesList, +} from "./summary/utils/helpers"; + import CaseNoticeBanner from "./caseNoticeBanner"; import WatchModal from "./watchmodal"; import EIADetails from "./eia"; @@ -269,23 +254,6 @@ const CaseSummary = (props) => { const zoom = isNaN(parseFloat(siteCoords.latitude)) ? 7 : 12; - function hasValidKey(obj, key) { - return ( - obj.hasOwnProperty(key) && - obj[key] !== null && - obj[key] !== undefined && - obj[key] !== "" - ); - } - - function hasOwnPropertyAndNotNull(obj, property) { - return obj.hasOwnProperty(property) && obj[property] !== null; - } - - function isObjectNotEmpty(obj, key) { - return obj.hasOwnProperty(key) && Object.keys(obj[key]).length > 0; - } - let showDetailsBlock = showDetails == true ? ( <> @@ -729,6 +697,115 @@ const CaseSummary = (props) => {
+ {getFormCollectionByID( + appealTypeID + ).PrimaryIdAttribute == + "pinswg_sipscase" && + showReps( + detailsObj.pinswg_consultationopen, + detailsObj.pinswg_consultationclose + ) && ( + <> + {showRepButton( + props + .currentView + .caseReference + .appealType + ) ? ( + <> + + {props + .currentView + .caseReference + .appealType == + 846040002 + ? t( + "case:summary-make-consultation-label" + ) + : t( + "case:summary-make-representation-label" + )} + + + { + //spinnerState(); + router.back(); + }} + className="govuk-button govuk-button--secondary" + > + {t( + "case:summary-back-button-label" + )} + + + ) : !isLPA && + props.currentView + .caseReference + .appealType == + 846040004 ? ( + "" + ) : ( + <> +
+
+

+ {t( + "case:representation-date-passed-label", + { + startDate: + formatDates( + detailsObj.pinswg_consultationopen + ), + endDate: + formatDates( + detailsObj.pinswg_consultationclose + ), + } + )} +
{" "} + {t( + "case:representation-date-passed-additional-label" + )}{" "} + + {t( + "home:login-contact-email" + )} + +

+
+
+ + )} + + )} + {(_.has( detailsObj, "pinswg_startdate" @@ -776,9 +853,17 @@ const CaseSummary = (props) => { }} className="govuk-button" > - {t( - "case:summary-make-representation-label" - )} + {props + .currentView + .caseReference + .appealType == + 846040002 + ? t( + "case:summary-make-consultation-label" + ) + : t( + "case:summary-make-representation-label" + )} { detailsObj.pinswg_finalcommentsduedate ) && (
- {t( - "case:representation-period-ended-on-label" - )} + {props.currentView + .caseReference + .appealType == + 84604002 + ? t( + "case:consultation-period-ended-on-label" + ) + : t( + "case:representation-period-ended-on-label" + )} + {props.currentView .caseReference .appealType == @@ -1073,7 +1166,15 @@ const CaseSummary = (props) => { } id="case-summary" > - {showSummary(casesObj, detailsObj)} + {showSummary( + appealTypeID, + casesObj, + detailsObj, + formatDates, + linkedCasesList, + currentView, + showMap + )}
{((hasValidKey( @@ -1559,13 +1660,6 @@ const CaseSummary = (props) => { showFilteredDocs={props.showFilteredDocs} />
- {/* */}
@@ -1591,9 +1685,14 @@ const CaseSummary = (props) => { href="/representation" className="govuk-button" > - {t( - "case:summary-make-representation-label" - )} + {props.currentView.caseReference + .appealType == 846040002 + ? t( + "case:summary-make-consultation-label" + ) + : t( + "case:summary-make-representation-label" + )} )} @@ -1613,303 +1712,29 @@ const CaseSummary = (props) => { ); - function showSummary(casesObj, detailsObj) { - let appealIDObj = - getFormCollectionByID(appealTypeID).PrimaryIdAttribute; + function showSummary( + appealTypeID, + casesObj, + detailsObj, + formatDates, + linkedCasesList, + currentView, + showMap + ) { + const id = getFormCollectionByID(appealTypeID).PrimaryIdAttribute; - switch (appealIDObj) { - case "pinswg_advertsid": - return ( - - ); - break; - case "pinswg_callinss77id": - return ( - - ); - break; - case "pinswg_commonlandid": - return ( - - ); - break; - case "pinswg_communityinfrastructurelevyid": - return ( - - ); - break; + const Component = CaseTypes[capitalizeFirstLetter(id)]; - case "pinswg_compulsorypurchaseordersid": - return ( - - ); - break; - case "pinswg_dnsid": - return ( - - ); - break; - case "pinswg_sipscase": - return ( - - ); - break; - case "pinswg_electricityactid": - return ( - - ); - break; - case "pinswg_enforcementlistedbuildingconseid": - return ( - - ); - break; - case "pinswg_enforcementnoticeappeals174id": - return ( - - ); - break; - case "pinswg_enforcementpermittingid": - return ( - - ); - break; - case "pinswg_harbourrevisionorderid": - return ( - - ); - break; - case "pinswg_hedgeshedgerowstreepreservatioid": - return ( - - ); - break; - case "pinswg_householderappealhasid": - return ( - - ); - break; - case "pinswg_lawfuldevelopmentcertificatappid": - return ( - - ); - break; - case "pinswg_ldpid": - return ( - - ); - break; - case "pinswg_listedbuildingandconservationrid": - return ( - - ); - break; - case "pinswg_maintenanceoflands217id": - return ( - - ); - break; - case "pinswg_miscellaneouscasewordid": - return ( - - ); - break; - case "pinswg_nonvalidationid": - return ( - - ); - break; - case "pinswg_planningappeals78id": - return ( - - ); - break; - - case "pinswg_planningconditionss73s79id": - return ( - - ); - break; - - case "pinswg_planningobligationappeals106id": - return ( - - ); - break; - case "pinswg_rowid": - return ( - - ); - break; - case "pinswg_transportandworkactid": - return ( - - ); - break; - case "pinswg_wayleaveid": - return ( - - ); - break; - } + return Component ? ( + + ) : null; } useEffect(() => { @@ -1931,67 +1756,6 @@ const CaseSummary = (props) => { expDate.setDate(now.getDate() + 365); - function 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; - } - - function linkedCasesList(linkedCasesReference) { - //console.log(linkedCasesReference); - - linkedCasesReference = linkedCasesReference.value || []; - - return ( - <> -
    - {linkedCasesReference.map((item, key) => { - return ( -
  • - - {item.title} - -
  • - ); - //console.log(item.incidentid, item.title); - })} -
- - ); - } - - function showReps(startDate, endDate) { - let date = new Date(); - date = new Date(date.toDateString()); - const start = new Date(startDate); - const end = new Date(endDate); - - return date >= start && date <= end ? true : false; - } - function showRepButton(appealType) { switch (appealType) { case 846040012: @@ -2039,14 +1803,6 @@ const CaseSummary = (props) => { } } - function showRepsEnded(startDate, endDate) { - let date = new Date(); - date = new Date(date.toDateString()); - const start = new Date(startDate); - const end = new Date(endDate); - return date > start && date > end ? true : false; - } - if (status == "authenticated" && cookies.pedwWatchCase != null) { selectWatchedCase( props.accountDetails.accountDetails.contactid, diff --git a/components/case/summary/utils/helpers.js b/components/case/summary/utils/helpers.js new file mode 100644 index 00000000..d712ef7c --- /dev/null +++ b/components/case/summary/utils/helpers.js @@ -0,0 +1,76 @@ +export function capitalizeFirstLetter(val) { + return String(val).charAt(0).toUpperCase() + String(val).slice(1); +} + +export function formatDates(dateObj, showTime) { + const d = new Date(dateObj); + const dd = String(d.getDate()).padStart(2, "0"); + const mm = String(d.getMonth() + 1).padStart(2, "0"); + const yyyy = d.getFullYear(); + const hh = String(d.getHours()).padStart(2, "0"); + const mins = String(d.getMinutes()).padStart(2, "0"); + + return showTime && !(hh === "00" && mins === "00") + ? `${hh}:${mins}` + : `${dd}/${mm}/${yyyy}`; +} + +export function hasValidKey(obj, key) { + return obj?.hasOwnProperty(key) && obj[key] !== null && obj[key] !== ""; +} + +export function showReps(startDate, endDate) { + const now = new Date(); + const start = new Date(startDate); + const end = new Date(endDate); + return now >= start && now <= end; +} + +export function showRepsEnded(startDate, endDate) { + const now = new Date(); + const start = new Date(startDate); + const end = new Date(endDate); + return now > start && now > end; +} + +export function isObjectNotEmpty(obj, key) { + return obj.hasOwnProperty(key) && Object.keys(obj[key]).length > 0; +} + +export function hasOwnPropertyAndNotNull(obj, property) { + return obj.hasOwnProperty(property) && obj[property] !== null; +} + +export function linkedCasesList(linkedCasesReference) { + //console.log(linkedCasesReference); + + linkedCasesReference = linkedCasesReference.value || []; + + return ( + <> +
    + {linkedCasesReference.map((item, key) => { + return ( +
  • + + {item.title} + +
  • + ); + //console.log(item.incidentid, item.title); + })} +
+ + ); +} diff --git a/components/case/summaryTypes/index.js b/components/case/summaryTypes/index.js new file mode 100644 index 00000000..82e62fc8 --- /dev/null +++ b/components/case/summaryTypes/index.js @@ -0,0 +1,26 @@ +export { default as Pinswg_advertsid } from "./pinswg_advertsid"; +export { default as Pinswg_callinss77id } from "./pinswg_callinss77id"; +export { default as Pinswg_commonlandid } from "./pinswg_commonlandid"; +export { default as Pinswg_communityinfrastructurelevyid } from "./pinswg_communityinfrastructurelevyid"; +export { default as Pinswg_compulsorypurchaseordersid } from "./pinswg_compulsorypurchaseordersid"; +export { default as Pinswg_dnsid } from "./pinswg_dnsid"; +export { default as Pinswg_sipscase } from "./pinswg_sipscase"; +export { default as Pinswg_electricityactid } from "./pinswg_electricityactid"; +export { default as Pinswg_enforcementlistedbuildingconseid } from "./pinswg_enforcementlistedbuildingconseid"; +export { default as Pinswg_enforcementnoticeappeals174id } from "./pinswg_enforcementnoticeappeals174id"; +export { default as Pinswg_environmentalpermittingid } from "./pinswg_environmentalpermittingid"; +export { default as Pinswg_harbourrevisionorderid } from "./pinswg_harbourrevisionorderid"; +export { default as Pinswg_hedgeshedgerowstreepreservatioid } from "./pinswg_hedgeshedgerowstreepreservatioid"; +export { default as Pinswg_householderappealhasid } from "./pinswg_householderappealhasid"; +export { default as Pinswg_lawfuldevelopmentcertificatappid } from "./pinswg_lawfuldevelopmentcertificatappid"; +export { default as Pinswg_ldpid } from "./pinswg_ldpid"; +export { default as Pinswg_listedbuildingandconservationrid } from "./pinswg_listedbuildingandconservationrid"; +export { default as Pinswg_maintenanceoflands217id } from "./pinswg_maintenanceoflands217id"; +export { default as Pinswg_miscellaneouscasewordid } from "./pinswg_miscellaneouscasewordid"; +export { default as Pinswg_nonvalidationid } from "./pinswg_nonvalidationid"; +export { default as Pinswg_planningappeals78id } from "./pinswg_planningappeals78id"; +export { default as Pinswg_planningconditionss73s79id } from "./pinswg_planningconditionss73s79id"; +export { default as Pinswg_planningobligationappeals106id } from "./pinswg_planningobligationappeals106id"; +export { default as Pinswg_rowid } from "./pinswg_rowid"; +export { default as Pinswg_transportandworkactid } from "./pinswg_transportandworkactid"; +export { default as Pinswg_wayleaveid } from "./pinswg_wayleaveid"; diff --git a/components/search/repsonresults.js b/components/search/repsonresults.js index b7b9a48b..21d0af84 100644 --- a/components/search/repsonresults.js +++ b/components/search/repsonresults.js @@ -119,9 +119,14 @@ const RepsOnResults = (props) => { )} */}
- {t( - "case:summary-representation-open-label" - )}{" "} + {props.currentView.caseReference + .appealType == 846040002 + ? t( + "case:summary-consultation-open-label" + ) + : t( + "case:summary-representation-open-label" + )}{" "}
) : !isLPA && diff --git a/locales/cy/auth.json b/locales/cy/auth.json index e1fd69b0..f47bac26 100644 --- a/locales/cy/auth.json +++ b/locales/cy/auth.json @@ -10,7 +10,7 @@ "auth-error-Signin-label": "Ceisiwch fewngofnodi gyda chyfrif gwahanol.", "auth-error-OAuthSignin-label": "Ceisiwch fewngofnodi gyda chyfrif gwahanol.", "auth-error-OAuthCallback-label": "Ceisiwch fewngofnodi gyda chyfrif gwahanol.", - "auth-error- OAuthCreateAccount-label": "Ceisiwch fewngofnodi gyda chyfrif gwahanol.", + "auth-error-OAuthCreateAccount-label": "Ceisiwch fewngofnodi gyda chyfrif gwahanol.", "auth-error-EmailCreateAccount-label": "Ceisiwch fewngofnodi gyda chyfrif gwahanol.", "auth-error-Callback-label": "Ceisiwch fewngofnodi gyda chyfrif gwahanol.", "auth-error-OAuthAccountNotLinked-label": "I gadarnhau pwy ydych, mewngofnodwch gyda'r un cyfrif a ddefnyddioch yn wreiddiol.", diff --git a/locales/cy/case.json b/locales/cy/case.json index b9b4a013..8c5d3af5 100644 --- a/locales/cy/case.json +++ b/locales/cy/case.json @@ -17,7 +17,9 @@ "summary-environmental-statement-label": "Lleoliad Datganiad Amgylcheddol", "summary-last-modified-label": "Addaswyd ddiwethaf", "summary-make-representation-label": "Cyflwyno sylwadau", + "summary-make-consultation-label": "Cyflwyno Ymateb i'r Ymgynghoriad", "summary-representation-open-label": "Cynrychioliadau yn agor", + "summary-consultation-open-label": "Ymgynghoriad ar agor", "summary-back-button-label": "Ewch yn ôl", "summary-case-details-label": "Manylion yr Achos", "summary-project-details-label": "Manylion y Prosiect", @@ -98,6 +100,7 @@ "representation-comments": "Sylwadau", "representation-files": "Ffeiliau perthnasol", "representation-period-ended-on-label": "Daeth y Cyfnod Sylwadau i ben ar ", + "consultation-period-ended-on-label": "Daeth y Cyfnod Ymgynghori i ben ar", "stop-watching-case-link": "Stopiwch wylio'r achos hwn", "watch-this-case-link": "Gwyliwch yr achos hwn", "you-are-watching-label": "Ydych chi eisiau gwylio achos ", diff --git a/locales/en/auth.json b/locales/en/auth.json index 1d3ac756..96e69b78 100644 --- a/locales/en/auth.json +++ b/locales/en/auth.json @@ -10,7 +10,7 @@ "auth-error-Signin-label": "Try signing with a different account.", "auth-error-OAuthSignin-label": "Try signing with a different account.", "auth-error-OAuthCallback-label": "Try signing with a different account.", - "auth-error- OAuthCreateAccount-label": "Try signing with a different account.", + "auth-error-OAuthCreateAccount-label": "Try signing with a different account.", "auth-error-EmailCreateAccount-label": "Try signing with a different account.", "auth-error-Callback-label": "Try signing with a different account.", "auth-error-OAuthAccountNotLinked-label": "To confirm your identity, sign in with the same account you used originally.", diff --git a/locales/en/case.json b/locales/en/case.json index 0097725e..3827770a 100644 --- a/locales/en/case.json +++ b/locales/en/case.json @@ -17,7 +17,9 @@ "summary-environmental-statement-label": "Environmental Statement Location", "summary-last-modified-label": "Last modified", "summary-make-representation-label": "Make representation", + "summary-make-consultation-label": "Submit a Consultation Response", "summary-representation-open-label": "Representations open", + "summary-consultation-open-label": "Consultation open", "summary-back-button-label": "Go back", "summary-case-details-label": "Case Details", "summary-project-details-label": "Project Details", @@ -98,6 +100,7 @@ "representation-comments": "Representation", "representation-files": "Relevant files", "representation-period-ended-on-label": "Representation Period ended on ", + "consultation-period-ended-on-label": "Consultation Period ended on ", "stop-watching-case-link": "Stop watching this case", "watch-this-case-link": "Watch this case", "you-are-watching-label": "Do you want to watch case ",