Files
pedwfrontend/components/search/repsonresults.js
T
Robert Bond c39e4bcc9a Merged PR 2375: update representation policy
## Summary

Introduces a new `representation-policy` domain boundary and incrementally extracts low-risk representation entry policy logic while preserving existing behaviour.

This PR intentionally stops before extracting ROW and Advert entry rules because characterization uncovered behavioural differences between consumers that require a separate business decision.

## What Changed

Added:

```text
lib/domain/representation-policy/
```

Including:

- `resolveRepresentationWindow(...)`
- `isRepresentationWindowOpen(...)`
- `isRepresentationWindowClosed(...)`
- `canShowRepresentationButtonForAppealType(...)`
- `canStartHouseholderRepresentation(...)`
- `canStartCpoRepresentation(...)`

Updated consumers:

```text
components/case/summary/utils/representationEntry.js
components/search/repsonresults.js
```

## Extracted Behaviour

### Representation Window Calculation
Centralised shared representation window logic and adopted it in both consumers.

### Appeal Type Entry Gating
Centralised excluded appeal-type logic while preserving existing behaviour.

### Householder Rule
Centralised Householder (`846040004`) entry rule.

Preserved behaviour:

```text
Householder representations can only be started by LPAs.
```

### CPO Rule
Centralised CPO (`846040019`) entry rule.

Preserved behaviour using:

```text
pinswg_startdate
pinswg_statementduedate
```

No fallback date broadening introduced.

## Characterization Added

### ROW (`846040015`)
Documented:
- hearing vs non-hearing behaviour
- specialist-process field behaviour
- date gating
- appeal-type coercion behaviour

### Advert (`846040018`)
Documented:
- LPA/non-LPA behaviour
- specialist-process behaviour
- appeal-type coercion behaviour

## Important Findings

### ROW Divergence
Summary and Search consumers currently behave differently when only:

```text
pinswg_speacialistcaseprocess
```

exists.

### Advert Divergence
Summary and Search consumers currently use different specialist-process resolution paths.

### CRM Compatibility
Both fields remain in production use and must be preserved:

```text
pinswg_specialistcaseprocess
pinswg_speacialistcaseprocess
```

## Documentation

Added:

```text
lib/domain/representation-policy/README.md
```

Documenting:
- ownership
- non-goals
- CRM compatibility requirements
- ROW divergence
- Advert divergence
- future extraction constraints

## Validation

Executed during the slice series:

```bash
node tests/phase22/representation-window.test.cjs
node tests/phase22/representation-appeal-type-entry-gating.test.cjs
node tests/phase22/representation-householder-entry-rule.test.cjs
node tests/phase22/representation-cpo-entry-rule.test.cjs
node tests/phase22/representation-row-entry-rule.test.cjs
node tests/phase22/representation-advert-entry-rule.test.cjs
npm run lint
```

All passing.

## Out of Scope

No changes to:

- submission/finalisation
- uploads
- dashboards
- CRM/OData queries
- API routes
- Redux state
- translations
- blocked-message rendering
- CTA l...
2026-06-08 10:51:02 +00:00

182 lines
8.1 KiB
JavaScript

import useTranslation from "next-translate/useTranslation";
import { useRouter } from "next/router";
import _ from "lodash";
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);
function showRepButton(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 />
{(_.has(detailsObj, "pinswg_startdate") ||
_.has(detailsObj, "pinswg_applicationacceptedasvalid") ||
_.has(detailsObj, "pinswg_consultationopen")) &&
((representationWindow.hasStartDate &&
representationWindow.isOpen) ||
isRepresentationWindowOpen(
detailsObj.pinswg_consultationopen,
detailsObj.pinswg_consultationclose
)) && (
<>
{showRepButton(detailsObj.appealType) ? (
<>
{/* <Link
href={{
pathname:
"/myportal/representation",
query: {
case: detailsObj.pinswg_name,
},
}}
className="govuk-button"
>
{t(
"case:summary-make-representation-label"
)}
</Link> */}
<div className="govuk-body govuk-!-font-size-14">
{appealType == 846040002
? t(
"case:summary-consultation-open-label"
)
: t(
"case:summary-representation-open-label"
)}{" "}
</div>
</>
) : !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>
</>
)}
</>
)}{" "}
{_.has(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;