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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | 2x 56x 2x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 7x 20x 6x 2x 20x 2x 20x 20x 20x 20x 16x 20x 20x 2x 2x 2x 2x 20x 7x 7x 7x 7x 7x 20x 10x 1x 1x 1x 1x 1x 10x 10x 10x 18x | import { useCallback, useEffect, useMemo, useState } from "react"; import { Navigate, useNavigate, useParams } from "react-router"; import { isCmsUser } from "shared-utils"; import { useGetUser } from "@/api/useGetUser"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, BreadCrumbBar, BreadCrumbSeperator, ContactHelpDesk, ExpandCollapseBtn, LeftNavigation, SearchContent, StatusLabel, SupportSubNavHeader, ToggleGroup, ToggleGroupItem, } from "@/components"; import { FAQContentType } from "@/features/support/SupportMockContent"; import { useFeatureFlag } from "@/hooks/useFeatureFlag"; import { cn } from "@/utils"; import { oneMACCMSContent, oneMACStateFAQContent, QuestionAnswer } from "./SupportMockContent"; const FaqAccordion = ({ question, latestOpened, }: { question: QuestionAnswer[]; latestOpened: string; }) => { return ( <> {question.map(({ anchorText, answerJSX, question, statusLabel }) => { const oulineLatest = latestOpened === anchorText ? "border-blue-500 border-2 " : ""; return ( <AccordionItem value={anchorText} id={`${anchorText}-support`} data-testid={`${anchorText}-support`} key={anchorText} className="my-6 border-none" > <AccordionTrigger showPlusMinus className={cn( "text-left font-bold bg-neutral-100 px-5 hover:no-underline", oulineLatest, )} > <div className="flex"> {statusLabel && <StatusLabel type={statusLabel} />}{" "} <span className="hover:underline">{question}</span> </div> </AccordionTrigger> <AccordionContent className="bg-white pt-4">{answerJSX}</AccordionContent> </AccordionItem> ); })} </> ); }; export const SupportPage = () => { const { id } = useParams<{ id: string }>(); const isSupportPageShown = useFeatureFlag("TOGGLE_FAQ"); const [openAccordions, setOpenAccordions] = useState<string[]>([]); const { data: userObj } = useGetUser(); const isCmsView = isCmsUser(userObj.user); const navigate = useNavigate(); const [supportContent, setSupportContent] = useState( isCmsView ? oneMACCMSContent : oneMACStateFAQContent, ); const [tgValue, setTGValue] = useState<"cms" | "state">(isCmsView ? "cms" : "state"); const [isSearching, setIsSearching] = useState<boolean>(false); const startingSupportContent = useMemo(() => { Eif (tgValue === "cms") return oneMACCMSContent; return oneMACStateFAQContent; }, [tgValue]); const expandAll = () => { const allIds = supportContent.flatMap(({ qanda }) => qanda.map(({ anchorText }) => anchorText)); setOpenAccordions(allIds); }; const collapseAll = useCallback(() => { setOpenAccordions([]); }, [setOpenAccordions]); const areAllAccordionsOpen = (function () { const totalQandas = supportContent.reduce((total, section) => { return total + section.qanda.length; }, 0); if (openAccordions.length >= totalQandas) return true; return false; })(); const latestOpenedFAQ = areAllAccordionsOpen ? "" : openAccordions[openAccordions.length - 1]; const setSearchResults = (searchResults: FAQContentType[], isSearching?: boolean) => { setIsSearching(isSearching); if (isSearching && searchResults[0].qanda.length) { setSupportContent(searchResults); setOpenAccordions([searchResults[0].qanda[0].anchorText]); } else Eif (isSearching) setSupportContent(searchResults); else { collapseAll(); setSupportContent(startingSupportContent); } }; useEffect(() => { Eif (id) { const element = document.getElementById(id); Eif (element) { setOpenAccordions([id]); window.scrollTo({ top: element.offsetTop, behavior: "smooth", }); } } }, [id]); // since the search page is mimicing a new "page", // this will allow the user to go "back" to the original support page when searching useEffect(() => { const handlePopState = () => { if (isSearching) { navigate("/support", { replace: true }); setIsSearching(false); collapseAll(); setSupportContent(startingSupportContent); } else E{ navigate("/dashboard"); } }; window.addEventListener("popstate", handlePopState); return () => { window.removeEventListener("popstate", handlePopState); }; }, [ isSearching, navigate, setIsSearching, collapseAll, setSupportContent, startingSupportContent, ]); if (!isSupportPageShown || !userObj?.user) return <Navigate to="/" replace />; return ( <div className="min-h-screen flex flex-col"> <SupportSubNavHeader className="z-10"> <h1 className="text-4xl font-semibold">OneMAC Support</h1> <SearchContent placeholderText="Search OneMAC support" supportContent={startingSupportContent} setSearchResults={setSearchResults} isSearching={isSearching} /> </SupportSubNavHeader> {/* only display the toggle CMS/State view when the user is CMS */} {isCmsView && !isSearching && ( <div className="max-w-screen-xl m-auto px-4 lg:px-8 w-full pt-8"> <div className="flex justify-end"> <div className="w-2/3 px-4 lg:px-8"> <ToggleGroup type="single" aria-label="CMS State Toggle" data-testid="cms-toggle-group" value={tgValue} onValueChange={(value: "cms" | "state") => { if (value) { setTGValue(value); if (value === "cms") setSupportContent(oneMACCMSContent); else setSupportContent(oneMACStateFAQContent); } }} > <ToggleGroupItem value="cms" aria-label="cms"> CMS </ToggleGroupItem> <ToggleGroupItem value="state" aria-label="state"> States </ToggleGroupItem> </ToggleGroup> </div> </div> <hr className="bg-slate-100 h-[1.2px]" /> </div> )} {/* Main Layout Wrapper with explicit widths */} <div className="max-w-screen-xl m-auto px-4 lg:px-8 pt-4 w-full"> <div className="flex"> {/* Left Navigation - Fixed width with explicit max-width */} <div className="w-1/3 sticky top-20 h-[calc(100vh-5rem)]"> {isSearching && ( <BreadCrumbBar> <li> <a onClick={() => setSearchResults([], false)} className="underline cursor-pointer text-sky-700 hover:text-sky-800 flex items-center text-sm" > Support </a> </li> <BreadCrumbSeperator /> <li className="flex items-center text-sm">Search Results</li> </BreadCrumbBar> )} {!isSearching && ( <LeftNavigation topics={supportContent.flatMap(({ sectionTitle }) => sectionTitle)} /> )} <ContactHelpDesk /> </div> {/* Content - Force minimum width */} <section className="w-2/3 block max-w-screen-xl px-4 lg:px-8 gap-10"> {supportContent[0].qanda.length ? ( <div className=""> <div className="flex justify-end py-4"> <ExpandCollapseBtn collapseAll={collapseAll} expandAll={expandAll} areAllOpen={areAllAccordionsOpen} /> </div> <hr className="bg-gray-300 h-[1.2px]" /> </div> ) : ( <div></div> )} <div className="flex-1 mt-8"> <Accordion type="multiple" value={openAccordions} onValueChange={setOpenAccordions}> {supportContent.map(({ sectionTitle, qanda }) => ( <article key={sectionTitle} className="mb-8"> <h2 className="text-2xl font-bold mb-4">{sectionTitle}</h2> {!isSearching && <hr className="bg-gray-300 h-[1.7px]" />} <FaqAccordion question={qanda} latestOpened={latestOpenedFAQ} /> </article> ))} </Accordion> </div> </section> </div> </div> </div> ); }; |