import Link from "next/link"; import _ from "lodash"; import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; import { setCurrentReference } from "../../store/currentView/action"; import { connect } from "react-redux"; import { parseCookies } from "nookies"; import { getToken, getWatchedCasesProxy, getPortalModuleDetailsProxy, deleteWatchedCases, } from "../../actions"; import { setWatchedCases, setWatchedCasesDetails, } from "../../store/watchedCases/action"; import { getFormCollectionByID } from "../../components/utils"; const TopThree = (props) => { let { t } = useTranslation(); const { showTopThree, showDetails, setCurrentReference, topThreeType, setWatchedCases, setWatchedCasesDetails, } = props; const router = useRouter(); const { locale } = router; let topthreeRow = []; let showTopThreeArr = showTopThree.value; const deleteItem = (caseID, topThreeType) => { let token = getToken(); let cookies = parseCookies(); topThreeType == "watchedCases" && deleteWatchedCases(caseID) .then((data) => data) .then(() => { getWatchedCasesProxy(token, cookies.pinsUser).then( (data) => { setWatchedCases(data), getDetails(token, data, "myWatchedCases").then( (data) => { setWatchedCasesDetails(data); } ); } ); }); }; const getDetails = (token, resultsObj, detailsType) => { //console.log(resultsObj); let detailsArr = []; resultsObj = resultsObj.value; const detailsObj = resultsObj.map((searchDetail, index) => { if (searchDetail.pinswg_appealcasetype == null) { console.log( detailsType != "myWatchedCases" ? searchDetail.ticketnumber : searchDetail[ "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" ] ); } else { detailsArr.push( getPortalModuleDetailsProxy( token, getFormCollectionByID( searchDetail.pinswg_appealcasetype ).LogicalCollectionName, detailsType != "myWatchedCases" ? searchDetail.ticketnumber : searchDetail[ "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" ] ) ); } }); //console.log(detailsArr); return Promise.all(detailsArr); }; let topThreeOnlyArr = showTopThreeArr.slice(0, 3); Object.keys(topThreeOnlyArr).map((key, index) => { topthreeRow.push(