170 lines
7.2 KiB
JavaScript
170 lines
7.2 KiB
JavaScript
import useTranslation from "next-translate/useTranslation";
|
|
import { useRouter } from "next/router";
|
|
import Link from "next/link";
|
|
import {
|
|
resolveRepresentationWindow,
|
|
isRepresentationWindowOpen,
|
|
isRepresentationWindowClosed,
|
|
canShowRepresentationButtonForAppealType,
|
|
canStartHouseholderRepresentation,
|
|
canStartCpoRepresentation
|
|
} from "../../lib/domain/representation-policy";
|
|
|
|
const RepsOnResults = (props) => {
|
|
let { t } = useTranslation();
|
|
|
|
const detailsObj = props.detailsObj;
|
|
const isLPA = Boolean(props?.isLPA);
|
|
const appealType = props?.appealType || detailsObj?.appealType;
|
|
const specialistProcess =
|
|
detailsObj?.pinswg_speacialistcaseprocess ||
|
|
detailsObj?.pinswg_specialistcaseprocess;
|
|
const representationWindow = resolveRepresentationWindow(detailsObj);
|
|
const hasOwn = (obj, key) =>
|
|
Object.prototype.hasOwnProperty.call(obj || {}, key);
|
|
|
|
function showRepButton(appealType) {
|
|
appealType = Number(appealType);
|
|
if (!canShowRepresentationButtonForAppealType(appealType)) {
|
|
return false;
|
|
}
|
|
|
|
switch (appealType) {
|
|
case 846040004:
|
|
return canStartHouseholderRepresentation(appealType, isLPA);
|
|
|
|
case 846040015:
|
|
return specialistProcess == 846040001
|
|
? isRepresentationWindowOpen(
|
|
detailsObj.pinswg_startdate,
|
|
detailsObj.pinswg_finalcommentsduedate
|
|
)
|
|
: true;
|
|
|
|
case 846040018:
|
|
let shouldShow =
|
|
specialistProcess == 846040000 && isLPA
|
|
? true
|
|
: specialistProcess == 846040001
|
|
? true
|
|
: false;
|
|
|
|
return shouldShow;
|
|
|
|
case 846040019:
|
|
return canStartCpoRepresentation(appealType, detailsObj);
|
|
|
|
default:
|
|
return true;
|
|
}
|
|
}
|
|
|
|
function formatDates(dateObj, showTime) {
|
|
var dateObj = new Date(dateObj);
|
|
var dd = String(dateObj.getDate()).padStart(2, "0");
|
|
var mm = String(dateObj.getMonth() + 1).padStart(2, "0"); //January is 0!
|
|
var yyyy = dateObj.getFullYear();
|
|
var hh = dateObj.getHours();
|
|
hh = ("0" + hh).slice(-2);
|
|
var mins = dateObj.getMinutes();
|
|
mins = ("0" + mins).slice(-2);
|
|
|
|
const dateStr = showTime
|
|
? hh == 0 && mins == 0
|
|
? ""
|
|
: hh + ":" + mins
|
|
: dd + "/" + mm + "/" + yyyy + " ";
|
|
return dateStr;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<br />
|
|
{(hasOwn(detailsObj, "pinswg_startdate") ||
|
|
hasOwn(detailsObj, "pinswg_startdates") ||
|
|
hasOwn(detailsObj, "pinswg_applicationacceptedasvalid") ||
|
|
hasOwn(detailsObj, "pinswg_consultationopen")) &&
|
|
((representationWindow.hasStartDate &&
|
|
representationWindow.isOpen) ||
|
|
isRepresentationWindowOpen(
|
|
detailsObj.pinswg_consultationopen,
|
|
detailsObj.pinswg_consultationclose
|
|
)) && (
|
|
<>
|
|
{showRepButton(Number(appealType)) ? (
|
|
<div className="govuk-body govuk-!-font-size-14">
|
|
{appealType == 846040002
|
|
? t("case:summary-consultation-open-label")
|
|
: t(
|
|
"case:summary-representation-open-label"
|
|
)}{" "}
|
|
</div>
|
|
) : !canShowRepresentationButtonForAppealType(
|
|
appealType
|
|
) ||
|
|
(!isLPA && appealType == 846040004) ? (
|
|
""
|
|
) : (
|
|
<>
|
|
<div className="govuk-grid-column-full govuk-!-padding-left-0">
|
|
<div className="govuk-button-group">
|
|
<p className="govuk-body">
|
|
{t(
|
|
"case:representation-date-passed-label",
|
|
{
|
|
startDate: formatDates(
|
|
detailsObj.pinswg_startdate
|
|
),
|
|
endDate:
|
|
appealType == 846040019
|
|
? formatDates(
|
|
detailsObj.pinswg_statementduedate
|
|
)
|
|
: formatDates(
|
|
detailsObj.pinswg_finalcommentsduedate
|
|
)
|
|
}
|
|
)}
|
|
<br />{" "}
|
|
{t(
|
|
"case:representation-date-passed-additional-label"
|
|
)}{" "}
|
|
<Link
|
|
href={
|
|
"mailto:" +
|
|
t(
|
|
"home:login-contact-email"
|
|
)
|
|
}
|
|
>
|
|
{t("home:login-contact-email")}
|
|
</Link>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</>
|
|
)}{" "}
|
|
{hasOwn(detailsObj, "pinswg_startdate") &&
|
|
(detailsObj.pinswg_startdate != null ||
|
|
detailsObj.pinswg_finalcommentsduedate != null) &&
|
|
isRepresentationWindowClosed(
|
|
detailsObj.pinswg_startdate,
|
|
detailsObj.pinswg_finalcommentsduedate
|
|
) && (
|
|
<div className="govuk-body govuk-!-font-size-14">
|
|
{t("case:representation-period-ended-on-label")}
|
|
{detailsObj.appealType == 846040019
|
|
? formatDates(detailsObj.pinswg_statementduedate)
|
|
: formatDates(
|
|
detailsObj.pinswg_finalcommentsduedate
|
|
)}
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default RepsOnResults;
|