From 4a7245db203d648a4654f166d7daea8d64336ae6 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Thu, 30 Sep 2021 17:11:33 +0100 Subject: [PATCH] logic to let child cases be shown in case details --- actions/index.js | 34 +++++--- components/case.js | 1 + components/case/documents.js | 4 +- components/case/summary.js | 130 ++++++++++++++++++++++++---- components/crmError.js | 2 +- components/dnssearchresults.js | 2 +- components/search/advancedsearch.js | 2 +- components/searchresults.js | 2 +- locales/cy/case.json | 1 + locales/en/case.json | 1 + pages/myportal/index.js | 17 ++-- store/currentView/action.js | 8 ++ store/currentView/reducer.js | 7 ++ 13 files changed, 171 insertions(+), 40 deletions(-) diff --git a/actions/index.js b/actions/index.js index 2c3dec21..f6f4a99c 100644 --- a/actions/index.js +++ b/actions/index.js @@ -143,7 +143,7 @@ export const getBasicSearch = (token, searchString) => { return axios .get( WEBAPI_URL + - "incidents?$select=_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=contains(title, '" + + "incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=contains(title, '" + searchString + "') and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true&$top=201", azureHeaders(token) @@ -166,7 +166,7 @@ export const getBasicDNSSearch = (token, searchString) => { return axios .get( WEBAPI_URL + - "incidents?$select=_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true", + "incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true", azureHeaders(token) ) .then((res) => res.data) @@ -204,7 +204,7 @@ export const getAdvancedSearch = (token, searchString) => { return axios .get( WEBAPI_URL + - "incidents?$select=_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" + + "incidents?$select=numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=" + queryString + " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true&$top=201", @@ -269,13 +269,8 @@ export const getSearchDocumentHistory = (token, documentID) => { }; export const getSearchDocumentDetails1 = (incidentID) => { - console.log(incidentID); + //console.log(incidentID); var token = getSASToken(); - console.log( - "/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " + - incidentID + - "&$select=pinswg_isharedocumentlocations,_pinswg_documentids_value,pinswg_isharelabelcasetype,pinswg_isharelabellpaname,pinswg_publishtoweb,pinswg_uploadstatus,pinswg_isharedocumentclassification,pinswg_isharedocumentreference" - ); return axios .get( "/api/proxy/pinswg_documents?$count=true&$filter=pinswg_publishtoweb eq true and _pinswg_documentids_value eq " + @@ -289,7 +284,7 @@ export const getSearchDocumentDetails1 = (incidentID) => { }; export const getSearchDocumentHistory1 = (documentID) => { - console.log(documentID); + // console.log(documentID); var token = getSASToken(); return axios .get( @@ -318,6 +313,25 @@ export const getBasicDNSSearchDetails = (token, appealType, caseReference) => { }); }; +export const getLinkedCases = (parentIncidentid) => { + console.log(parentIncidentid); + var token = getSASToken(); + + return axios + .get( + "/api/proxy/incidents?$count=true&$filter=_parentcaseid_value eq " + + parentIncidentid + + " and pinswg_appealcasetype ne null and pinswg_publishtoweb eq true &$select=title, incidentid," + ) + .then((res) => { + console.log(" linked date", res.data); + return res.data; + }) + .catch((error) => { + console.log("thiserror", error); + }); +}; + export const getFormData = (token, whichForm) => { //console.log("got to axios", whichForm); //console.log("api_root: ", BASE_URL); diff --git a/components/case.js b/components/case.js index 1a9feb83..317dbd05 100644 --- a/components/case.js +++ b/components/case.js @@ -30,6 +30,7 @@ const CaseSummary = (props) => { searchResultsObj={props.searchResultsObj} searchDetailsObj={props.searchDetailsObj} searchString={props.searchString} + incidentid={props.incidentid} /> { var documentDetailsArr = documentDetailsObj || []; const DocumentView = (documentDetailsArr) => { - console.log(documentDetailsArr); + //console.log(documentDetailsArr); documentDetailsArr = documentDetailsArr.value; @@ -173,7 +173,7 @@ const DocumentDetails = (props) => { const docDetailsObj = async () => { let docObj = await getSearchDocumentDetails1(incidentid) .then((data) => { - console.log(data); + //console.log(data); setDocumentDetails(data); return data; }) diff --git a/components/case/summary.js b/components/case/summary.js index bd0bcd6a..76b629b0 100644 --- a/components/case/summary.js +++ b/components/case/summary.js @@ -1,18 +1,26 @@ import Link from "next/link"; import { useRouter } from "next/router"; -import { useState } from "react"; +import { useState, useEffect, useRef } from "react"; +import { useDispatch, useSelector, shallowEqual, connect } from "react-redux"; import useTranslation from "next-translate/useTranslation"; import jsonpath from "jsonpath"; import _ from "lodash"; import transLookup from "../../data/lookuptranslations.json"; import LoadingOverlay from "react-loading-overlay"; +import { getLinkedCases } from "../../actions"; +import { + setCurrentLinkedCases, + setCurrentReference, +} from "../../store/currentView/action"; + const CaseSummary = (props) => { let { t } = useTranslation(); const router = useRouter(); const { locale } = router; const { + incidentid, caseReference, myCases, myRepresentations, @@ -21,6 +29,9 @@ const CaseSummary = (props) => { searchResultsObj, searchDetailsObj, currentType, + setCurrentLinkedCases, + linkedCasesReference, + setCurrentReference, } = props; const noRepresentationLink = ["/case", "/dnsdetails"]; @@ -322,28 +333,39 @@ const CaseSummary = (props) => { )}
- {_.has(detailsObj, [ - "pinswg_linkedstatus@OData.Community.Display.V1.FormattedValue", + {_.has(casesObj, [ + "numberofchildincidents", ]) - ? detailsObj[ - "pinswg_linkedstatus@OData.Community.Display.V1.FormattedValue" - ] + ? casesObj.numberofchildincidents > + 0 + ? t( + "case:summary-case-link-status-linked" + ) + : t( + "case:summary-case-link-status-not-linked" + ) : t( "case:summary-case-link-status-not-linked" )}
-
-
- {t( - "case:summary-linked-cases-label" - )} -
-
- {/* {casesObj.caseDetails.linkedCases || - ""} */} -
-
+ {casesObj.numberofchildincidents > 0 ? ( +
+
+ {t( + "case:summary-linked-cases-label" + )} +
+
+ {linkedCasesList( + props.currentView + .linkedCaseReferences + )} +
+
+ ) : ( + "" + )} @@ -582,6 +604,20 @@ const CaseSummary = (props) => { ); + useEffect(() => { + const linkCaseObj = async () => { + let docObj = await getLinkedCases(incidentid).then((data) => { + console.log(data); + setCurrentLinkedCases(data); + return data; + }); + + return linkCaseObj; + }; + + const linkedCases = linkCaseObj(); + }, [incidentid, setCurrentLinkedCases]); + const [showSpinnerState, setShowSpinnerState] = useState(false); let spinnerState = () => { @@ -599,6 +635,47 @@ const CaseSummary = (props) => { return dd + "/" + mm + "/" + yyyy; } + function linkedCasesList(linkedCasesReference) { + console.log(linkedCasesReference); + + linkedCasesReference = linkedCasesReference.value || []; + + return ( + <> + + + ); + } + return ( <> {showDetailsBlock} @@ -611,4 +688,21 @@ const CaseSummary = (props) => { ); }; -export default CaseSummary; +const mapStateToProps = (state) => { + return { + ...state, + }; +}; + +const mapDispatchToProps = (dispatch) => { + return { + setCurrentLinkedCases: (parentIncidentid) => { + dispatch(setCurrentLinkedCases(parentIncidentid)); + }, + setCurrentReference: (currentReference) => { + dispatch(setCurrentReference(currentReference)); + }, + }; +}; + +export default connect(mapStateToProps, mapDispatchToProps)(CaseSummary); diff --git a/components/crmError.js b/components/crmError.js index e067da63..8a9e8d12 100644 --- a/components/crmError.js +++ b/components/crmError.js @@ -15,7 +15,7 @@ const CRMError = (props) => { ? "LPAData" : "searchResultsObj"; - console.log(errorSwitch); + //console.log(errorSwitch); return (
diff --git a/components/dnssearchresults.js b/components/dnssearchresults.js index 12a27db1..d75c3b3b 100644 --- a/components/dnssearchresults.js +++ b/components/dnssearchresults.js @@ -17,7 +17,7 @@ export default function Search(props) { ? true : false; - console.log("has an error", hasError); + //console.log("has an error", hasError); return (
{ event.preventDefault(); spinnerState(); - console.log(values); + //console.log(values); // var appTypeCollection = values.appealTypes.split(",")[1]; // appTypeCollection = getFormCollection( diff --git a/components/searchresults.js b/components/searchresults.js index 02964fd9..ebd5743e 100644 --- a/components/searchresults.js +++ b/components/searchresults.js @@ -17,7 +17,7 @@ export default function Search(props) { ? true : false; - console.log("has an error", hasError); + //console.log("has an error", hasError); return (
async ({ query, req, res }) => { //console.log("the query", query); + + const token = await getSASToken(); + const [ myCases, myRepresentations, watchedCases, awaitingSubmission, ] = await Promise.all([ - await getMyCases("f8b454ed-eded-eb11-aac7-00224800be9c"), - await getMyRepresentations(), - await getWatchedCases(), - await getAwaitingSubmission(), + await getMyCases(token, "f8b454ed-eded-eb11-aac7-00224800be9c"), + await getMyRepresentations(token), + await getWatchedCases(token), + await getAwaitingSubmission(token), ]); const cookies = new Cookies(req, res); @@ -109,7 +113,7 @@ export const getServerSideProps = wrapper.getServerSideProps( // watchedCasesDetails, // awaitingSubmissionDetails, ] = await Promise.all([ - await getDetails(myCases), + await getDetails(token, myCases), // await getDetails(myRepresentations), // await getDetails(watchedCases), // await getDetails(awaitingSubmission), @@ -142,7 +146,7 @@ const getFormCollection = (formtype) => { return collectionName[0]; }; -const getDetails = (resultsObj) => { +const getDetails = (token, resultsObj) => { //console.log(resultsObj); let detailsArr = []; resultsObj = resultsObj.value; @@ -152,6 +156,7 @@ const getDetails = (resultsObj) => { } else { detailsArr.push( getPortalModuelDetails( + token, getFormCollection( "pinswg_" + searchDetail[ diff --git a/store/currentView/action.js b/store/currentView/action.js index 292372d3..028ce0a1 100644 --- a/store/currentView/action.js +++ b/store/currentView/action.js @@ -5,6 +5,7 @@ export const currentViewActionTypes = { SETREPRESENTATIONCAPACITY: "SETREPRESENTATIONCAPACITY", SETREPRESENTATIONSUBMIT: "SETREPRESENTATIONSUBMIT", SETREPRESENTATIONSUBMITCONFIRMATION: "SETREPRESENTATIONSUBMITCONFIRMATION", + SETCURRENTLINKEDCASES: "SETCURRENTLINKEDCASES", }; export const getCurrentViewObj = () => (dispatch) => { @@ -56,3 +57,10 @@ export const setRepresentationSubmitConfirmation = representationSubmitConfirmation: representationSubmitConfirmation, }); }; + +export const setCurrentLinkedCases = (linkedCaseReferences) => (dispatch) => { + return dispatch({ + type: currentViewActionTypes.SETCURRENTLINKEDCASES, + linkedCaseReferences: linkedCaseReferences, + }); +}; diff --git a/store/currentView/reducer.js b/store/currentView/reducer.js index 683089b6..1e2c4b68 100644 --- a/store/currentView/reducer.js +++ b/store/currentView/reducer.js @@ -6,6 +6,7 @@ const currentViewInitialState = { representationCapacity: {}, representationSubmit: null, representationSubmitConfirmation: {}, + linkedCaseReferences: {}, }; export default function reducer(state = currentViewInitialState, action) { @@ -20,6 +21,12 @@ export default function reducer(state = currentViewInitialState, action) { ...state, caseReference: action.caseReference, }; + + case currentViewActionTypes.SETCURRENTLINKEDCASES: + return { + ...state, + linkedCaseReferences: action.linkedCaseReferences, + }; case currentViewActionTypes.SETREPRESENTATIONCAPACITY: return { ...state,