%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emergentqj/actioncivile/pre-auth/.f81b4c9eb38fd76cdf20462cf2027aa3/static/js/components/
Upload File :
Create Path :
Current File : /home/emergentqj/actioncivile/pre-auth/.f81b4c9eb38fd76cdf20462cf2027aa3/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;

Zerion Mini Shell 1.0