// components/admin/tabs/AppealsTab.js import useTranslation from "next-translate/useTranslation"; import { useCallback, useState, useEffect } from "react"; import { JSONPath as jsonpath } from "jsonpath-plus"; import Link from "next/link"; import { useRouter } from "next/router"; import PaginationControl from "../../../components/search/pagination"; import { connect } from "react-redux"; import transLookup from "../../../data/lookuptranslations.json"; import { setSearchResults, setSearchDetails } from "../../../store/searchOutput/action"; import { getDetailsProxy, getSearchDetailsPaged, hasOwn } from "../../utils"; import { getAdvancedSearchPaged } from "../../../actions/services/searchService"; import { getNewAppealsPage } from "../../../actions/services/adminService"; import resolveCrmDisplayValue from "../../../lib/i18n/crmDisplay/resolveCrmDisplayValue"; import { setCurrentPage, setCurrentReference } from "../../../store/currentView/action"; function AppealsTab(props) { const [searchLoaded, setSearchLoaded] = useState(false); const [showSpinnerState, setShowSpinnerState] = useState(false); const [selectedOption, setSelectedOption] = useState(10); const [orderByState, setOrderbyState] = useState("createdon"); const [fieldSortState, setfieldSortState] = useState("desc"); const [loginToWatch, setLoginToWatch] = useState("true"); 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(); const myportal = false; const advancedSearch = false; const searchString = ""; const spinnerState = () => { setShowSpinnerState((prev) => !prev); }; const pagesCount = Math.ceil(searchResultsObj["@odata.count"] / 10); let currentPage = 0; try { currentPage = decodeURI(searchResultsObj["@odata.nextLink"]).split( "skiptoken=" )[1]; currentPage = typeof currentPage !== "undefined" ? parseInt( decodeURI(currentPage) .split('pagenumber="')[1] .slice( 0, decodeURI(currentPage) .split('pagenumber="')[1] .indexOf('"') ) - 1 ) : pagesCount; } catch (e) { currentPage = pagesCount; } const getSearchPageResults = useCallback( (pageNumber, orderBy, fieldSort) => { getNewAppealsPage( searchString, pageNumber, orderBy, fieldSort, selectedOption ).then((data) => { setSearchResults(data); return getSearchDetailsPaged(data).then((details) => { setSearchDetails(details); setShowSpinnerState(false); }); }); }, [selectedOption, setSearchDetails, setSearchResults] ); useEffect(() => { if (searchLoaded) { if (selectedOption) { setShowSpinnerState(true); getSearchPageResults(1, orderByState, fieldSortState); } } else { setSearchLoaded(true); } }, [ selectedOption, fieldSortState, orderByState, searchLoaded, getSearchPageResults, router.query ]); const ResultsView = (resultsArr) => { return ( <>
{t("search:searchresults-site-address-label")}
{/* {t("search:searchresults-status-label")} */}
Origin
{showSpinnerState == true ? (
{t("common:spinner-fetching-data")} {
) : ( resultsArr.map((item, key) => { let detailsObj = jsonpath({ path: '$..[?(@ && @.ticketnumber=="' + item.ticketnumber + '")]', json: searchDetailsObj, eval: true }); detailsObj = detailsObj[0] || {}; return (
{item.pinswg_publishtoweb == true ? ( { setCurrentReference({ "statuscode": item.statuscode, "ticketnumber": item.ticketnumber, "currentReference": item.title, "currentType": "searchResultsObj", "incidentid": item.incidentid, "appealType": item.pinswg_appealcasetype, "showLoginCheck": props.showLoginCheck, "specialistProcess": detailsObj.hasOwnProperty( "pinswg_speacialistcaseprocess" ) ? detailsObj.pinswg_speacialistcaseprocess : detailsObj.hasOwnProperty( "pinswg_specialistcaseprocess" ) ? detailsObj.pinswg_specialistcaseprocess : "" }); }} > {t( "search:searchresults-case-reference-label" )} : {item.title} ) : ( item.title )}
{new Date( item.createdon ).toLocaleString()}
{t( "search:searchresults-site-address-label" )} : {hasOwn( detailsObj, "pinswg_projectlocation" ) ? detailsObj.pinswg_projectlocation != null ? detailsObj.pinswg_projectlocation.indexOf( ";" ) < 0 ? detailsObj.pinswg_projectlocation : router.locale == "cy" ? detailsObj.pinswg_projectlocation.split( ";" )[1] : detailsObj.pinswg_projectlocation.split( ";" )[0] : "" : ""} {hasOwn( detailsObj, "pinswg_siteaddressline1" ) ? detailsObj.pinswg_siteaddressline1 : ""} {/* {detailsObj.pinswg_siteaddressline1 != null &&
} */} {hasOwn( detailsObj, "pinswg_siteaddressline1" ) && detailsObj.pinswg_siteaddressline1 != null &&
} {hasOwn( detailsObj, "pinswg_siteaddressline1" ) ? detailsObj.pinswg_siteaddressline2 : ""} {hasOwn( detailsObj, "pinswg_siteaddressline2" ) && detailsObj.pinswg_siteaddressline2 != null &&
} {hasOwn( detailsObj, "pinswg_siteaddresstown" ) ? detailsObj.pinswg_siteaddresstown : ""} {hasOwn( detailsObj, "pinswg_siteaddresstown" ) && detailsObj.pinswg_siteaddresstown != null &&
} {hasOwn( detailsObj, "pinswg_siteaddresscounty" ) ? detailsObj.pinswg_siteaddresscounty : ""} {hasOwn( detailsObj, "pinswg_siteaddresscounty" ) && detailsObj.pinswg_siteaddresscounty != null &&
} {hasOwn( detailsObj, "pinswg_siteaddresspostcode" ) ? detailsObj.pinswg_siteaddresspostcode : ""}
{t( "search:searchresults-applicant-label" )} : {item.pinswg_appellantagent == 846040001 ? item.pinswg_appellantfirstname + " " + item.pinswg_appellantlastname : hasOwn(detailsObj, [ "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" ]) ? detailsObj[ "_pinswg_appellant_value@OData.Community.Display.V1.FormattedValue" ] : ""}
{t( "search:searchresults-authority-label" )} : {hasOwn(item, [ "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" ]) ? resolveCrmDisplayValue({ value: item[ "_pinswg_associatedlpa_value@OData.Community.Display.V1.FormattedValue" ], locale: router.locale, translations: transLookup, fallbackValue: "N/A" }) : ""}
{t( "search:searchresults-case-type-label" )} : {resolveCrmDisplayValue({ value: item[ "pinswg_appealcasetype@OData.Community.Display.V1.FormattedValue" ], locale: router.locale, translations: transLookup, fallbackValue: "N/A" })}
{t( "search:searchresults-status-label" )} : {resolveCrmDisplayValue({ value: item[ "statuscode@OData.Community.Display.V1.FormattedValue" ], locale: router.locale, translations: transLookup, fallbackValue: "N/A" })}
{item[ "caseorigincode@OData.Community.Display.V1.FormattedValue" ] || "N/A"}
); }) )}
); }; return (

Appeals

{searchResultsObj["@odata.count"] > 5 && (
)} {resultsArr.length > 0 ? ( ResultsView(resultsArr) ) : (

{t("search:searchresults-no-records-label")}

)}
); } const mapDispatchToProps = (dispatch) => { return { setCurrentReference: (currentReference) => { dispatch(setCurrentReference(currentReference)); }, setSearchResults: (searchResultsObj) => { dispatch(setSearchResults(searchResultsObj)); }, setSearchDetails: (searchDetailsObj) => { dispatch(setSearchDetails(searchDetailsObj)); }, setCurrentPage: (currentPage) => { dispatch(setCurrentPage(currentPage)); } }; }; const mapStateToProps = (state) => { return { searchResultsObj: state.searchResultsObj }; }; export default connect(mapStateToProps, mapDispatchToProps)(AppealsTab);