All files / react-app/src/features/faq Faq.tsx

91.66% Statements 22/24
70% Branches 7/10
85.71% Functions 6/7
91.3% Lines 21/23

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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134                                2x 8x   8x   8x   8x 1x 1x 2x   1x     8x 4x 3x 3x 3x 3x                 8x 8x                   8x 10x           10x     8x                                                                                                                                      
import { useCallback, useEffect, useState } from "react";
import { Navigate, useParams } from "react-router";
 
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger,
  Button,
  CardWithTopBorder,
  SubNavHeader,
} from "@/components";
import { useFeatureFlag } from "@/hooks/useFeatureFlag";
 
import { helpDeskContact, oneMACFAQContent } from "./content/oneMACFAQContent";
 
export const Faq = () => {
  const isFAQHidden = useFeatureFlag("TOGGLE_FAQ");
 
  const { id } = useParams<{ id: string }>();
 
  const [openItems, setOpenItems] = useState<string[]>([]);
 
  const expandAll = useCallback(() => {
    const allIds = [];
    oneMACFAQContent.forEach(({ qanda }) => {
      qanda.forEach(({ anchorText }) => allIds.push(anchorText));
    });
    setOpenItems(allIds);
  }, [setOpenItems]);
 
  useEffect(() => {
    if (id) {
      const element = document.getElementById(id);
      Eif (element) {
        setOpenItems([id]);
        window.scrollTo({
          top: element.offsetTop,
          behavior: "smooth",
        });
      }
    }
  }, [id]);
 
  // Get the flag value for hiding the MMDL banner.
  const isBannerHidden = useFeatureFlag("UAT_HIDE_MMDL_BANNER");
  const anchorsToHide = [
    "spa-admendments",
    "abp-spa-templates",
    "abp-implementation-guides-spa",
    "mpc-spa-templates",
    "mpc-spa-implementation-guides",
    "chip-spa-templates",
    "chip-spa-implentation-guides",
  ];
 
  const filteredFAQContent = oneMACFAQContent.map((section) => {
    Iif (section.sectionTitle === "State Plan Amendments (SPAs)" && isBannerHidden) {
      return {
        ...section,
        qanda: section.qanda.filter((qa) => !anchorsToHide.includes(qa.anchorText)),
      };
    }
    return section;
  });
 
  Iif (isFAQHidden) {
    return <Navigate to="/" replace />;
  }
  return (
    <>
      <SubNavHeader>
        <h1 className="text-xl font-medium">Frequently Asked Questions</h1>
      </SubNavHeader>
      <section className="block md:flex md:flex-row max-w-screen-xl m-auto px-4 lg:px-8 pt-8 gap-10">
        <div className="flex-1">
          <article className="mb-8">
            {/* BUTTON */}
            <Button
              onClick={expandAll}
              variant="outline"
              data-testid="expand-all"
              className="w-full xs:w-fit hover:bg-transparent mb-5"
            >
              Expand all to search with CTRL + F
            </Button>
 
            {/* FAQ */}
            <Accordion type="multiple" value={openItems} onValueChange={setOpenItems}>
              {filteredFAQContent.map(({ sectionTitle, qanda }) => (
                <article key={sectionTitle} className="mb-8">
                  <h2 className="text-2xl mb-4 text-primary">{sectionTitle}</h2>
                  {qanda.map(({ anchorText, answerJSX, question }) => (
                    <AccordionItem
                      value={anchorText}
                      id={anchorText}
                      key={anchorText}
                      data-testid={anchorText}
                    >
                      <AccordionTrigger className="text-left">{question}</AccordionTrigger>
                      <AccordionContent>{answerJSX}</AccordionContent>
                    </AccordionItem>
                  ))}
                </article>
              ))}
            </Accordion>
          </article>
        </div>
        <div>
          <CardWithTopBorder>
            <div className="p-4">
              <h3 className="text-lg text-bold mb-4">OneMAC Help Desk Contact Info</h3>
              <div>
                <b>Phone Number</b>
                <p className="mb-4 text-primary">
                  <a className="underline" href={`tel:${helpDeskContact.phone}`}>
                    {helpDeskContact.phone}
                  </a>
                </p>
                <b>Email</b>
                <p className="text-primary">
                  <a className="underline" href={`mailto:${helpDeskContact.email}`}>
                    {helpDeskContact.email}
                  </a>
                </p>
              </div>
            </div>
          </CardWithTopBorder>
        </div>
      </section>
    </>
  );
};