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"; 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 { va, adv, ads, key } = router.query; const isAdv = adv === "true"; const isAds = ads === "true"; 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 breadcrumbHref = (() => { if (va === "true") { return { pathname: "/myportal/viewall", query: { key } }; } const base = session ? "/myportal" : ""; if (!va && !adv && !ads) { return { pathname: "/myportal" }; } if (adv === "true") { return { pathname: `${base}/advancedsearchresults`, query: router.query }; } if (ads === "true") { return { pathname: `${base}/addresssearchresults`, query: router.query }; } return { pathname: `${base}/searchresults`, query: router.query }; })(); const breadcrumbLabel = (() => { if (va === "true") { return getViewAllLabel(key); } const keyedLabel = getViewAllLabel(key); if (keyedLabel) return keyedLabel; if (isAdv) { return t("common:breadcrumb-advanced-search-results"); } if (isAds) { return t("common:breadcrumb-address-search-results"); } return 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);