%PDF- %PDF-
Direktori : /home/emergentqj/actioncivile/pre-auth/.8352c036a19b0051d0217d27d25e3f4a/static/js/components/ |
Current File : /home/emergentqj/actioncivile/pre-auth/.8352c036a19b0051d0217d27d25e3f4a/static/js/components/Head.jsx |
import { string } from "prop-types"; import React from "react"; import { useLocation } from "react-router-dom"; import metadata from "config/metadata"; import { Helmet } from "react-helmet"; import { useSelector } from "react-redux"; import { useTranslation } from "react-i18next"; function Head({ path }) { const location = useLocation(); const [, { language }] = useTranslation(); const countryCode = useSelector((state) => state.config.getIn(["config", "countryConstant"])); // Sign up has other route names, but they all should conclude under '/sign-up' const locationPath = location.pathname.indexOf("sign-up") > -1 ? "/sign-up" : location.pathname; // Check if path and meta are valid const isValidPath = locationPath === path; const isValidMeta = metadata?.[countryCode]?.[language]?.[path]; // Assign the default meta for fallback let meta = metadata.default; if (isValidPath && isValidMeta) meta = metadata[countryCode][language][path]; const { title, description, keywords } = meta || {}; return ( <Helmet htmlAttributes={{ lang: language }}> {title && <title>{title}</title>} {description && <meta name="description" content={description} />} {keywords && <meta name="keywords" content={keywords} />} </Helmet> ); } Head.propTypes = { path: string.isRequired, }; export default Head;