All files / src/components AppTitleComponent.tsx

0% Statements 0/15
0% Branches 0/10
0% Functions 0/2
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                                                                                                             
import { capitalizeFirstLetter } from "@common/Table/helpers";
import { AccountData } from "@customTypes/data.types";
import { useAppSelector } from "@redux/hooks";
import { selectSelectedAccount } from "@redux/slices/auth/accounts";
import { selectCurrentCampaign } from "@redux/slices/checkout";
import { useEffect, useState } from "react";
import { Helmet } from "react-helmet";
import { useLocation } from "react-router-dom";
 
const AppTitle = () => {
  const [title, setTitle] = useState<string>("");
  const selectedAccount = useAppSelector(selectSelectedAccount);
  const { title: campaignTitle } = useAppSelector(selectCurrentCampaign);
  const location = useLocation();
  const isPublicForm = location.pathname.match(/^\/[0-9]*$/);
  const url = window.location.hostname;
 
  const urlPattern = /^(?!.*:3000)(?!.*portal)(.*?)(\.\w+)\.givepayments\.com$/;
  const isNotLocal = url.match(urlPattern);
 
  useEffect(() => {
    if (!isNotLocal) {
      const _selectedAccount =
        selectedAccount as AccountData["data"][number] & { role: string };
 
      const title = !isPublicForm
        ? _selectedAccount?.role
          ? `GIVE ${capitalizeFirstLetter(_selectedAccount.role)} Portal`
          : "GIVE Portal"
        : campaignTitle;
      setTitle(title);
    }
  }, [selectedAccount, campaignTitle, isNotLocal, location.pathname]);
 
  return (
    <Helmet>
      {title && <title>{title}</title>}
      {isPublicForm ? (
        <meta
          name="description"
          content={campaignTitle}
          data-react-helmet="true"
        />
      ) : (
        <meta
          name="description"
          content="Web site created using create-react-app"
        />
      )}
    </Helmet>
  );
};
 
export default AppTitle;