import useTranslation from "next-translate/useTranslation"; import Link from "next/link"; import { useRouter } from "next/router"; import { connect } from "react-redux"; import { useSession } from "next-auth/react"; import { setCurrentView } from "../store/currentView/action"; import { change } from "redux-form"; import { setCurrentSection } from "../store/appealType/action"; import { setRepresentationCapacity, setRepresentationSubmit } from "../store/currentView/action"; import { resolveCaseBreadcrumbState } from "../lib/routing/routeState"; const Breadcrumbs = (props) => { const { currentView, setCurrentSection, setRepresentationSubmit, appealType, showQuestionnaireSection, setShowQuestionnaireSection } = props; const router = useRouter(); let { t } = useTranslation(); const { data: session } = useSession(); const nestedProps = props?.props || {}; const nestedSearchString = nestedProps?.search?.searchString || ""; const nestedCurrentReference = nestedProps?.currentView?.caseReference?.currentReference || ""; const isWelsh = router.locale === "cy"; const localisedPath = (englishPath, welshSuffixPath) => isWelsh ? `/${router.locale}${welshSuffixPath}` : englishPath; const currentReference = currentView?.caseReference?.currentReference || nestedCurrentReference; const fallbackSearchTitle = props?.searchResultsObj?.searchResultsObj?.value?.[0]?.title || ""; const caseReferenceDisplay = currentReference || fallbackSearchTitle; const myPortalHref = localisedPath("/myportal", "/fymhorth"); const cyMyPortalHref = myPortalHref; const pathname = router.pathname; const isPath = (path) => pathname === path; const caseReference = currentView?.caseReference || {}; const currentViewState = currentView?.currentView || {}; const repDetails = caseReference?.repDetails; const hasRepDetails = Object.prototype.hasOwnProperty.call( caseReference, "repDetails" ); const qcount = caseReference.appealType === 846040000 || caseReference.appealType === 846040001 || caseReference.appealType === 846040025 || caseReference.appealType === 846040004 || caseReference.appealType === 846040018 || caseReference.appealType === 846040003 || caseReference.appealType === 846040009 || caseReference.appealType === 846040008 ? 7 : caseReference.appealType === 846040005 || caseReference.appealType === 846040006 || caseReference.appealType === 846040007 ? 9 : ""; const hideServiceNamePaths = [ "/myportal/[appealtypes]", "/newappeal", "/newappeal/[appealtypes]", "/myportal/representation" ]; const shouldShowServiceName = !hideServiceNamePaths.includes(pathname); const getViewAllLabel = (viewKey) => { const labelsByKey = { awaitingSubmissionDetails: t( "myportal:awatitingsubmission-card-title" ), watchedCases: t("myportal:watchedcases-card-title"), myCases: t("myportal:mycases-card-title"), myRepresentations: t("myportal:myrepresentations-card-title"), mySubmittedReps: "Submitted representations" }; return labelsByKey[viewKey] || null; }; const getStaticTextCrumbLabel = (path) => { const staticTextCrumbByPath = { "/account/register": t("account:register-new-account-heading"), "/dns": t("dnsCommon:service-name"), "/dnsapplications": t("dnsCommon:service-name"), "/dns/application-process": "Guidance", "/dns/help": "Help", "/dns/contact-us": t("common:footer-contact-us-link-label"), "/dns/applications": t("dnsApplications:page-title"), "/help/cookies": t("cookies:cookie-breadcrumb"), "/privacy": t("common:footer-privacy-link-label"), "/accessibility": t("common:footer-accessibility-link-label"), "/details-about-cookies": t("cookies:cookie-policy-title-heading"), "/auth/signin": t("auth:auth-page-title"), "/auth/verify-request": t("auth:auth-check-email-page-title"), "/auth/error": t("auth:auth-error-signin-error-title") }; return staticTextCrumbByPath[path] || null; }; const getSimpleRouteRenderer = (path) => { const simpleRouteRenderersByPath = { "/myportal": () => renderTextCrumb(t("myportal:page-title")), "/searchresults": () => renderTextCrumb(t("common:breadcrumb-search-results")), "/advancedsearch": () => renderTextCrumb(t("common:breadcrumb-advanced-search")), "/addresssearch": () => renderTextCrumb(t("common:breadcrumb-address-search")), "/contactus": () => renderTextCrumb(t("common:footer-contact-us-link-label")), "/viewall": () => renderMyPortalSectionCrumbs(t("common:breadcrumb-your-cases")), "/myportal/dnsapplications": () => renderMyPortalSectionCrumbs(t("dnsCommon:service-name")) }; return simpleRouteRenderersByPath[path] || null; }; const renderMyPortalCrumb = () => (
  • {t("common:breadcrumb-my-portal")}
  • ); const renderMyPortalSectionCrumbs = (sectionLabel) => ( <> {renderMyPortalCrumb()} {renderTextCrumb(sectionLabel)} ); const renderCaseReferenceCrumb = (referenceValue) => (
  • {t("common:breadcrumb-case-reference")}: {referenceValue}
  • ); const renderTextCrumb = (label) => (
  • {label}
  • ); const renderLinkCrumb = (href, label, onClick) => (
  • {label}
  • ); const renderAnchorCrumb = ( href, label, onClick, listItemClass = "govuk-breadcrumbs__list-item" ) => (
  • {label}
  • ); const renderBackCrumb = ( onClick, listItemClass = "govuk-breadcrumbs__link-item backChevron" ) => renderAnchorCrumb("#", t("common:back-link"), onClick, listItemClass); const renderDnsCaseReferenceCrumbs = (referenceValue) => ( <> {renderLinkCrumb( isWelsh ? router.locale + "/dnsapplications" : "/dnsapplications", t("dnsCommon:service-name") )} {renderCaseReferenceCrumb(referenceValue)} ); const { breadcrumbHref, caseResultsHref, breadcrumbLabel } = resolveCaseBreadcrumbState({ query: router.query, hasSession: Boolean(session), getViewAllLabel, advancedLabel: t("common:breadcrumb-advanced-search-results"), addressLabel: t("common:breadcrumb-address-search-results"), defaultLabel: t("common:breadcrumb-search-results") }); return ( <> ); }; const mapStateToProps = (state) => ({ currentView: state.currentView, appealType: state.appealType, searchResultsObj: state.searchResultsObj, search: state.search }); const mapDispatchToProps = (dispatch) => { return { updateField: (form, field, newValue) => dispatch(change(form, field, newValue)), setRepresentationCapacity: (representationCapacity) => { //dispatch(reset("representationForm")); dispatch(setRepresentationCapacity(representationCapacity)); }, setRepresentationSubmit: (representationSubmit) => { dispatch(setRepresentationSubmit(representationSubmit)); }, setCurrentView: (currentView) => { dispatch(setCurrentView(currentView)); }, setCurrentSection: (currentSection) => { dispatch(setCurrentSection(currentSection)); } }; }; export default connect(mapStateToProps, mapDispatchToProps)(Breadcrumbs);