added watched cases and remove watched cases
This commit is contained in:
+124
-64
@@ -4,77 +4,93 @@ 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 {
|
||||
getSASToken,
|
||||
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 } =
|
||||
props;
|
||||
const {
|
||||
showTopThree,
|
||||
showDetails,
|
||||
setCurrentReference,
|
||||
topThreeType,
|
||||
setWatchedCases,
|
||||
setWatchedCasesDetails,
|
||||
} = props;
|
||||
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
let topthreeRow = [];
|
||||
|
||||
// for (var i = 0; i < 3; i++) {
|
||||
// (function (i) {
|
||||
// topthreeRow.push(
|
||||
// <div className="cardModuleItem" key={i}>
|
||||
// <div className="cardModuleDetails">
|
||||
// <div className="cardModuleReference">
|
||||
// <b>Case reference:</b>{" "}
|
||||
// <Link
|
||||
// href={
|
||||
// topThreeType == "awaitingSubmission"
|
||||
// ? "/representation"
|
||||
// : "/case"
|
||||
// }
|
||||
// >
|
||||
// <a
|
||||
// data-id={i}
|
||||
// onClick={() => {
|
||||
// setCurrentReference({
|
||||
// "currentReference":
|
||||
// showTopThree.value[i]
|
||||
// .ticketnumber,
|
||||
// "currentType": topThreeType,
|
||||
// });
|
||||
// }}
|
||||
// >
|
||||
// {showTopThree.value[i].ticketnumber}
|
||||
// </a>
|
||||
// </Link>
|
||||
// </div>
|
||||
// {topThreeType != "awaitingSubmission" ? (
|
||||
// <div className="carModuleAddress">
|
||||
// <b>Addressaa: </b>
|
||||
// {showDetails[i].value[0]
|
||||
// .pinswg_siteaddressline1 == null
|
||||
// ? "not entered"
|
||||
// : showDetails[i].value[0]
|
||||
// .pinswg_siteaddressline1}
|
||||
// </div>
|
||||
// ) : (
|
||||
// ""
|
||||
// )}
|
||||
|
||||
// {topThreeType == "awaitingSubmission" ? (
|
||||
// <div className="carModuleAddress">
|
||||
// Make Representation on Case Incomplete, not
|
||||
// submitted
|
||||
// </div>
|
||||
// ) : (
|
||||
// ""
|
||||
// )}
|
||||
// </div>
|
||||
// <div className="cardModuleRemoveCase"> —</div>
|
||||
// </div>
|
||||
// );
|
||||
// })(i);
|
||||
// }
|
||||
|
||||
let showTopThreeArr = showTopThree.value;
|
||||
|
||||
Object.keys(showTopThreeArr).map((key, index) => {
|
||||
const deleteItem = (caseID, topThreeType) => {
|
||||
let token = getSASToken();
|
||||
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(
|
||||
<div className="cardModuleItem" key={index}>
|
||||
<div className="cardModuleDetails">
|
||||
@@ -96,17 +112,32 @@ const TopThree = (props) => {
|
||||
onClick={() => {
|
||||
setCurrentReference({
|
||||
"currentReference":
|
||||
showTopThreeArr[key].ticketnumber,
|
||||
topThreeType != "watchedCases"
|
||||
? showTopThreeArr[key]
|
||||
.ticketnumber
|
||||
: showTopThreeArr[key][
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
],
|
||||
"currentType": topThreeType,
|
||||
"incidentid":
|
||||
showTopThreeArr[key].incidentid,
|
||||
topThreeType != "watchedCases"
|
||||
? showTopThreeArr[key]
|
||||
.incidentid
|
||||
: showTopThreeArr[key][
|
||||
" _pinswg_watchedcase_value"
|
||||
],
|
||||
|
||||
"appealType":
|
||||
showTopThreeArr[key]
|
||||
.pinswg_appealcasetype,
|
||||
});
|
||||
}}
|
||||
>
|
||||
{showTopThreeArr[key].ticketnumber}
|
||||
{topThreeType != "watchedCases"
|
||||
? showTopThreeArr[key].ticketnumber
|
||||
: showTopThreeArr[key][
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
]}
|
||||
</a>
|
||||
</Link>
|
||||
</div>
|
||||
@@ -140,7 +171,30 @@ const TopThree = (props) => {
|
||||
""
|
||||
)}
|
||||
</div>
|
||||
<div className="cardModuleRemoveCase"> —</div>
|
||||
|
||||
{topThreeType == "watchedCases" && (
|
||||
<div className="">
|
||||
<a
|
||||
href="#"
|
||||
className=" cardModuleRemoveCase govuk-link govuk-link--no-underline govuk-link--inverse "
|
||||
onClick={() => {
|
||||
event.preventDefault();
|
||||
deleteItem(
|
||||
showTopThreeArr[key].pinswg_watchlistid,
|
||||
"watchedCases"
|
||||
);
|
||||
alert(
|
||||
"You have stopped watching case " +
|
||||
showTopThreeArr[key][
|
||||
"_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
);
|
||||
}}
|
||||
>
|
||||
—
|
||||
</a>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
@@ -176,6 +230,12 @@ const mapDispatchToProps = (dispatch) => {
|
||||
setCurrentReference: (currentReference) => {
|
||||
dispatch(setCurrentReference(currentReference));
|
||||
},
|
||||
setWatchedCases: (watchedCases) => {
|
||||
dispatch(setWatchedCases(watchedCases));
|
||||
},
|
||||
setWatchedCasesDetails: (watchedCasesDetails) => {
|
||||
dispatch(setWatchedCasesDetails(watchedCasesDetails));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user