diff --git a/.env.local b/.env.local index b9c63e5f..5beabc0f 100644 --- a/.env.local +++ b/.env.local @@ -255,7 +255,7 @@ APPLICATIONINSIGHTS_CONNECTIONSTRING = InstrumentationKey=7a06e24a-793c-47bc-898 // Test Connection string -# NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=cc60e8e7-5b30-4c2b-a176-8b96b21b12df;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=2a4094be-6fd1-46ab-a67d-5f241692b129 +NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=cc60e8e7-5b30-4c2b-a176-8b96b21b12df;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=2a4094be-6fd1-46ab-a67d-5f241692b129 // Preprod Connection string # NEXT_PUBLIC_APP_INSIGHT = InstrumentationKey=7370f0f9-834d-4c7a-b3c4-9951fcad5ad2;IngestionEndpoint=https://ukwest-0.in.applicationinsights.azure.com/;LiveEndpoint=https://ukwest.livediagnostics.monitor.azure.com/;ApplicationId=04362cb7-6dfc-469e-8274-12243e8be851 diff --git a/components/account/personaldetailsComplete.js b/components/account/personaldetailsComplete.js index ff2199c0..cc2ec545 100644 --- a/components/account/personaldetailsComplete.js +++ b/components/account/personaldetailsComplete.js @@ -50,7 +50,7 @@ const PersonalDetailsComplete = (props) => { } doUpdate(); - }, [loggedinUserId, formValues, prefLang]); + }, [loggedinUserId, formValues, prefLang, userLang]); return ( <> diff --git a/components/admin/tabs/appeals.js b/components/admin/tabs/appeals.js index 18266189..2fb81863 100644 --- a/components/admin/tabs/appeals.js +++ b/components/admin/tabs/appeals.js @@ -28,9 +28,15 @@ function AppealsTab(props) { const [fieldSortState, setfieldSortState] = useState("desc"); const [loginToWatch, setLoginToWatch] = useState("true"); - const searchDetailsObj = props.searchResultsObj.searchDetailsObj || {}; - const resultsArr = props.searchResultsObj.searchResultsObj.value || []; - const searchResultsObj = props.searchResultsObj.searchResultsObj; + const { + searchResultsObj: searchResultsState, + setSearchResults, + setSearchDetails + } = props; + + const searchDetailsObj = searchResultsState.searchDetailsObj || {}; + const resultsArr = searchResultsState.searchResultsObj.value || []; + const searchResultsObj = searchResultsState.searchResultsObj; const { t } = useTranslation(); const router = useRouter(); @@ -75,20 +81,14 @@ function AppealsTab(props) { fieldSort, selectedOption ).then((data) => { - props.setSearchResults(data); // ✅ use props, not import + setSearchResults(data); return getSearchDetailsPaged(data).then((details) => { - props.setSearchDetails(details); // ✅ use props, not import + setSearchDetails(details); setShowSpinnerState(false); }); }); }, - [ - advancedSearch, - searchString, - selectedOption, - props.setSearchDetails, - props.setSearchResults - ] + [selectedOption, setSearchDetails, setSearchResults] ); useEffect(() => { diff --git a/components/admin/tabs/documents.js b/components/admin/tabs/documents.js index ce9cce63..aa573d4c 100644 --- a/components/admin/tabs/documents.js +++ b/components/admin/tabs/documents.js @@ -936,17 +936,16 @@ const DocumentsTab = (props) => { ) .then((data) => data) .then((data) => { - props.setDocumentDetails(data); + setDocumentDetails(data); setShowSpinnerState(false); }); }, [ - props.incidentid, selectedOption, selectedDocumentType, selectedWeeks, selectedDocumentOrigin, - props.setDocumentDetails + setDocumentDetails ] ); @@ -957,7 +956,7 @@ const DocumentsTab = (props) => { orderBy, fieldSort ).then((data) => { - props.setDocumentDetails(data); + setDocumentDetails(data); return data; }); @@ -1060,7 +1059,7 @@ const DocumentsTab = (props) => { selectedDocumentType, selectedWeeks ).then((data) => { - props.setDocumentDetails(data); + setDocumentDetails(data); setDocumentSearchState(true); return data; @@ -1072,13 +1071,11 @@ const DocumentsTab = (props) => { //const searchDocumentResultsObj = docDetailsObj(); }, [ incidentid, - props.setDocumentDetails, + setDocumentDetails, selectedOption, selectedDocumentType, fieldSortState, orderByState, - getDocumentTypes, - getOrigin, getDocumentResults, lang, selectedWeeks @@ -1134,7 +1131,7 @@ const DocumentsTab = (props) => { )} - ); }; diff --git a/components/case/representation/index.js b/components/case/representation/index.js index 0b12e97b..bacfa553 100644 --- a/components/case/representation/index.js +++ b/components/case/representation/index.js @@ -874,15 +874,29 @@ let MakeRepresentation = (props) => { // Prepare data object for upload const dataObj = cleanedValues; + const caseFolderReference = + props.caseReference || + dataObj.ticketnumber || + currentView?.caseReference?.ticketnumber || + currentView?.caseReference?.currentReference || + dataObj.caseRef || + ""; + // Update links on values const updatedValues = updateLinks(cleanedValues); + const resolvedContainerID = + updatedValues.containerID || + dataObj.containerID || + props?.props?.accountDetails?.containerID || + props?.props?.accountDetails?.accountDetails?.containerID; + // Perform file upload and return the promise return uploadRepFiles( dataObj, [{}], - updatedValues.containerID, - `${props.caseReference}/${dataObj.repfile_name}` + resolvedContainerID, + `${caseFolderReference}/${dataObj.repfile_name}` ); }; diff --git a/components/case/summary.js b/components/case/summary.js index f4f096b3..ec58e6d6 100644 --- a/components/case/summary.js +++ b/components/case/summary.js @@ -2076,10 +2076,12 @@ const CaseSummary = (props) => { ) : null; } + const fallbackIncidentId = setCaseQueryObj?.value?.[0]?.incidentid; + useEffect(() => { const linkCaseObj = async () => { let docObj = await getLinkedCases( - incidentid || setCaseQueryObj.value[0].incidentid + incidentid || fallbackIncidentId ).then((data) => { //console.log(data); setCurrentLinkedCases(data); @@ -2090,7 +2092,7 @@ const CaseSummary = (props) => { }; const linkedCases = linkCaseObj(); - }, [incidentid, setCurrentLinkedCases]); + }, [incidentid, fallbackIncidentId, setCurrentLinkedCases]); let now = new Date(); let expDate = new Date(now); diff --git a/components/myportal/awaitingsubmissionfromblob.js b/components/myportal/awaitingsubmissionfromblob.js index 4fbadb85..c6a05dda 100644 --- a/components/myportal/awaitingsubmissionfromblob.js +++ b/components/myportal/awaitingsubmissionfromblob.js @@ -353,8 +353,8 @@ const AwaitingSubmissionFromBlob = (props) => {

{t("myportal:awatitingsubmission-card-title")}

- + {props.awaitingSubmissionFromBlob["@odata.count"] > 1 && (
{ onClick={() => { setCurrentView({ "viewName": "My Representations", - "viewKey": "myRepresentations", + "viewKey": "myRepresentations" }); }} > @@ -65,7 +65,7 @@ const mapDispatchToProps = (dispatch) => { return { setCurrentView: (currentView) => { dispatch(setCurrentView(currentView)); - }, + } }; }; diff --git a/components/myportal/myrepresentationsfromblob.js b/components/myportal/myrepresentationsfromblob.js index 129cfd1e..0240f2fd 100644 --- a/components/myportal/myrepresentationsfromblob.js +++ b/components/myportal/myrepresentationsfromblob.js @@ -43,7 +43,7 @@ const MyRepresentations = (props) => { onClick={() => { setCurrentView({ "viewName": "My Representations", - "viewKey": "myRepresentations", + "viewKey": "myRepresentations" }); }} > @@ -64,7 +64,7 @@ const mapDispatchToProps = (dispatch) => { return { setCurrentView: (currentView) => { dispatch(setCurrentView(currentView)); - }, + } }; }; diff --git a/components/myportal/topthree_reps.js b/components/myportal/topthree_reps.js index a425266f..40c3ab99 100644 --- a/components/myportal/topthree_reps.js +++ b/components/myportal/topthree_reps.js @@ -238,8 +238,12 @@ const TopThree = (props) => { ? "/fymhorth/representation" : "/myportal/representation", query: { - case: showTopThreeArr[key] - .ticketnumber, + case: + showTopThreeArr[key] + .ticketnumber || + showTopThreeArr[key].caseRef || + showTopThreeArr[key] + .pinswg_name, state: "edit", created: showTopThreeArr[key] diff --git a/components/myportal/viewall.js b/components/myportal/viewall.js index 6d360189..4e0e8ddb 100644 --- a/components/myportal/viewall.js +++ b/components/myportal/viewall.js @@ -4,7 +4,7 @@ import useTranslation from "next-translate/useTranslation"; import Link from "next/link"; import { useRouter } from "next/router"; import { parseCookies } from "nookies"; -import { useCallback, useState } from "react"; +import { useState } from "react"; import { connect } from "react-redux"; import { deleteAwaitingSubmissionsFromBlob, @@ -98,7 +98,7 @@ const ViewAllResults = (props) => { const isWatchedCases = currentViewKey === "watchedCases"; const isMyCases = currentViewKey === "myCases"; - var resultsArr = isAwaitingSubmissionDetails + const resultsArr = isAwaitingSubmissionDetails ? props["awaitingSubmission"].awaitingSubmissionDetails.case : isMySubmittedReps ? props[currentViewKey][currentViewKey] @@ -286,7 +286,7 @@ const ViewAllResults = (props) => { } setCurrentReference({ - "statuscode": item.statuscode, + "statuscode": item.statuscode ?? null, ticketnumber: item.ticketnumber, currentReference: getCurrentReference(item), currentType: currentViewKey, @@ -452,10 +452,10 @@ const ViewAllResults = (props) => { const renderLineBreak = valueToDisplay && idx < 4; // Only insert
if it's not the last element return ( - <> + {valueToDisplay} {renderLineBreak &&
} - +
); })} @@ -845,15 +845,12 @@ const ViewAllResults = (props) => { //setShowSpinnerState(true); }; - const getSearchPageResults = useCallback( - (pageNumber, orderBy, fieldSort) => { - //console.log(advancedSearch, searchString, pageNumber); - //console.log(pageNumber, orderBy, fieldSort); - resultsArr.sort(dynamicSort(orderBy, fieldSort)); - //console.log(resultsArr); - }, - [selectedOption] - ); + const getSearchPageResults = (pageNumber, orderBy, fieldSort) => { + //console.log(advancedSearch, searchString, pageNumber); + //console.log(pageNumber, orderBy, fieldSort); + resultsArr.sort(dynamicSort(orderBy, fieldSort)); + //console.log(resultsArr); + }; function dynamicSort(property, order) { var sort_order = 1; diff --git a/components/newappeal/aboutyou.js b/components/newappeal/aboutyou.js index c9857a89..1167350b 100644 --- a/components/newappeal/aboutyou.js +++ b/components/newappeal/aboutyou.js @@ -619,7 +619,6 @@ let AboutYou = (props) => { component={RenderTextfield} type="text" className="govuk-input govuk-input--width-20" - validate={[required, emojicheck]} label={t( "newappeal:about-you-agent-contact-details-companyname-label" )} diff --git a/components/newappeal/complete.js b/components/newappeal/complete.js index a9f3d150..96d48804 100644 --- a/components/newappeal/complete.js +++ b/components/newappeal/complete.js @@ -13,6 +13,8 @@ let CompleteAppeal = (props) => { const legacyProps = props.props; const legacyFormState = legacyProps.form; const legacyAccountDetails = legacyProps.accountDetails; + const router = useRouter(); + const { locale } = router; useEffect(() => { let incidentId = props.appealType.caseReference.incidentid; @@ -77,14 +79,12 @@ let CompleteAppeal = (props) => { legacyAccountDetails.loggedinUserId, props.appealType.appealTypeID, legacyAccountDetails.loggedinUserEmail, - legacyAccountDetails.containerID + legacyAccountDetails.containerID, + router.locale ]); let { t } = useTranslation(); - const router = useRouter(); - const { locale } = router; - const { formXML, sectionCount, diff --git a/components/search/addresssearchresults.js b/components/search/addresssearchresults.js index f980c090..93212458 100644 --- a/components/search/addresssearchresults.js +++ b/components/search/addresssearchresults.js @@ -897,20 +897,23 @@ const SearchResults = (props) => { setCurrentPage(pageNumber); - resultsArr = _.sortBy(resultsArr, [ - function (o) { - return o[orderBy]; - } - ]); + let sortedResults = []; + setResultsArr((previousResults) => { + sortedResults = _.sortBy(previousResults, [ + function (o) { + return o[orderBy]; + } + ]); - fieldSort == "desc" && resultsArr.reverse(); + fieldSort == "desc" && sortedResults.reverse(); + return sortedResults; + }); setShowSpinnerState(false); - setResultsArr(resultsArr); console.log( "================================\n", - resultsArr, + sortedResults, "sort done", "\n=================================\n" ); diff --git a/lib/representation/pageLoaders.js b/lib/representation/pageLoaders.js index 7b3fd710..b0bcd7e8 100644 --- a/lib/representation/pageLoaders.js +++ b/lib/representation/pageLoaders.js @@ -150,6 +150,11 @@ export const loadExistingRepresentation = async ({ store, ctx, bootstrap }) => { console.log("is lpa?:", isLPA); + const searchResultsObj = await getBasicSearch(query.case); + const searchDetailsObj = await getSearchDetails(searchResultsObj); + + store.dispatch(setSearchResults(searchResultsObj)); + store.dispatch(setSearchDetails(searchDetailsObj)); store.dispatch(setContainerID(thisSession.user.id)); store.dispatch(setMyRepresentations(myRepresentations)); store.dispatch(setMyRepresentationsDetails(myRepresentationsDetails)); @@ -166,7 +171,6 @@ export const loadExistingRepresentation = async ({ store, ctx, bootstrap }) => { store.dispatch( setCurrentReference({ - "statuscode": result.statuscode, "ticketnumber": result.ticketnumber || result.caseRef || result.pinswg_name, "currentReference": result.caseRef, @@ -181,7 +185,7 @@ export const loadExistingRepresentation = async ({ store, ctx, bootstrap }) => { store.dispatch(setRepresentationCapacity(result.representationCapacity)); const repsFileListObj = await getRepsFilesBlobs( - result.containerID, + result.containerID || thisSession.user.id, result.ticketnumber || result.caseRef, result.repfile_name ); @@ -224,8 +228,6 @@ export const loadNewRepresentation = async ({ store, ctx, bootstrap }) => { store.dispatch( setCurrentReference({ - "statuscode": searchResultsObj.value[0].statuscode, - "isNRW": accountDetails.emailaddress1.includes(process.env.NRWDOMAIN) || false, diff --git a/pages/api/file/upload.js b/pages/api/file/upload.js index 70072889..c4423a08 100644 --- a/pages/api/file/upload.js +++ b/pages/api/file/upload.js @@ -9,6 +9,8 @@ const ApiProxy = nextConnect(); ApiProxy.use(middleware); ApiProxy.post(async (req, res) => { + const getFieldValue = (field) => (Array.isArray(field) ? field[0] : field); + const checkHash = req.query.hash; if (typeof checkHash === "undefined" || checkHash.length === 0) { @@ -32,10 +34,14 @@ ApiProxy.post(async (req, res) => { }); } - const appealData = req.body.appealData; - const containerID = req.body?.containerID?.[0]; - const casefolderID = req.body?.casefolderID?.[0]; - const repOrAppeal = req.body.repOrAppeal || false; + const appealData = getFieldValue(req.body?.appealData); + const containerID = getFieldValue(req.body?.containerID); + const casefolderID = getFieldValue(req.body?.casefolderID); + const repOrAppealRaw = getFieldValue(req.body?.repOrAppeal); + const repOrAppeal = + repOrAppealRaw === true || + repOrAppealRaw === "true" || + repOrAppealRaw === "1"; if ( typeof containerID === "undefined" || diff --git a/pages/auth/signin2.js b/pages/auth/signin2.js index b4e703e3..b82e4138 100644 --- a/pages/auth/signin2.js +++ b/pages/auth/signin2.js @@ -7,7 +7,7 @@ import Footer from "../../components/footer"; import Header from "../../components/header"; import ServiceBanner from "../../components/servicebanner"; import { useRouter } from "next/router"; -import { useState, useEffect } from "react"; +import { useState, useEffect, useCallback } from "react"; const SignIn = (props) => { let { t, lang } = useTranslation(); @@ -20,7 +20,7 @@ const SignIn = (props) => { const [formData, setFormData] = useState({ email: query.email || "", callbackUrl: "", - csrfToken: "", + csrfToken: "" }); const [submitForm, setSubmitForm] = useState(false); @@ -54,23 +54,26 @@ const SignIn = (props) => { // }, 500); // Short delay to ensure form is populated before submission // }; - const handleSubmit = async (event) => { - event.preventDefault(); - setButtonDisabled(true); // Disable the submit button to avoid multiple submissions + const handleSubmit = useCallback( + async (event) => { + event.preventDefault(); + setButtonDisabled(true); // Disable the submit button to avoid multiple submissions - try { - const res = await fetch("/api/auth/signin/emailAPI", { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify(formData), - }); + try { + const res = await fetch("/api/auth/signin/emailAPI", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(formData) + }); - const data = await res.json(); - setResponse(data); // Update response state - } catch (error) { - console.error("Error submitting the form:", error); - } - }; + const data = await res.json(); + setResponse(data); // Update response state + } catch (error) { + console.error("Error submitting the form:", error); + } + }, + [formData] + ); // Trigger form submission automatically when data is ready useEffect(() => { @@ -79,7 +82,7 @@ const SignIn = (props) => { setFormData((prevState) => ({ ...prevState, csrfToken: csrfToken, - callbackUrl: callbackUrl || prevState.callbackUrl, // Ensure callback URL is set + callbackUrl: callbackUrl || prevState.callbackUrl // Ensure callback URL is set })); } }, [query.email, csrfToken, callbackUrl, response]); @@ -89,7 +92,7 @@ const SignIn = (props) => { if (formData.email && formData.csrfToken && !response) { handleSubmit(new Event("submit")); } - }, [formData, response]); + }, [formData, response, handleSubmit]); // Handle redirection after form submission based on response useEffect(() => { @@ -231,8 +234,8 @@ export async function getServerSideProps(context) { return { redirect: { destination: "/403", // custom "Access Denied" page - permanent: false, - }, + permanent: false + } }; } @@ -240,8 +243,8 @@ export async function getServerSideProps(context) { return { redirect: { destination: "/status", - permanent: false, - }, + permanent: false + } }; } @@ -250,7 +253,7 @@ export async function getServerSideProps(context) { "\n//////////////////////\n", "Sign in callbackurl: " + context.req.headers.host, context.locale, - csrfToken + "\n//////////////////////\n", + csrfToken + "\n//////////////////////\n" ); let formURL = context.req.headers.host; console.log("formUrl:", formURL); @@ -279,7 +282,7 @@ export async function getServerSideProps(context) { url.search = params.toString(); return { - props: { csrfToken: csrfToken, callbackUrl: url.toString() }, + props: { csrfToken: csrfToken, callbackUrl: url.toString() } }; }