import useTranslation from "next-translate/useTranslation"; import { useState } from "react"; import { getLifecycleStagesForCase } from "../../lib/domain/case-lifecycle"; const statusClassMap = { complete: "govuk-tag govuk-!-margin-top-2", "in-progress": "govuk-tag govuk-tag--yellow govuk-!-margin-top-2", "not-started": "govuk-tag govuk-tag--grey govuk-!-margin-top-2", blocked: "govuk-tag govuk-tag--red govuk-!-margin-top-2" }; const statusTextMap = { complete: "status-complete", "in-progress": "status-in-progress", "not-started": "status-not-started", blocked: "status-blocked" }; const StatusDetails = (props) => { let { t } = useTranslation(); const caseResult = props.searchResultsObj?.value?.[0]; const caseDetails = props.searchDetailsObj?.[0]?.value?.[0]; const statusCode = Number(caseResult?.statuscode); const appealType = Number(caseResult?.pinswg_appealcasetype); const specialistProcess = caseDetails?.pinswg_specialistcaseprocess; const stages = getLifecycleStagesForCase( appealType, statusCode, specialistProcess ); function hasOwnPropertyAndNotNull(obj, property) { return obj.hasOwnProperty(property) && obj[property] !== null; } const [expandAll, setExpandAll] = useState(null); // null = use default (in-progress open) // true = force open all // false = force close all const handleToggleAll = () => { setExpandAll((prev) => (prev === true ? false : true)); }; return (

{t("case:status-title")}

    {stages.map((stage) => { const isDefaultOpen = stage.status === "in-progress"; const isOpen = expandAll === null ? isDefaultOpen : expandAll; return (
  • {stage.descriptionKey && (
    {t( `case-stages:${stage.titleKey}` )}
    {t( `case-stages:${stage.descriptionKey}` )}
    )}
    {t( `case-stages:${ statusTextMap[ stage.status ] || "status-not-started" }` )}
  • ); })}
); }; export default StatusDetails;