From f03a01a4697ed9753617a22ed7d3e6010aac09f0 Mon Sep 17 00:00:00 2001 From: Brian Schroer Date: Fri, 12 Apr 2024 15:00:46 -0700 Subject: [PATCH] =?UTF-8?q?1321=20move=20routing=20logic=20to=20its=20own?= =?UTF-8?q?=20file=20so=20that=20it=20is=20a=20child=20compone=E2=80=A6=20?= =?UTF-8?q?(#1337)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 1321 move routing logic to its own file so that it is a child component of the AppProvider component and will thus have access to the auth state * 1321 add Redirect import to Router file * Move Router component to top level app directory --- app/App.tsx | 152 ++-------------------------------- app/Router.tsx | 120 +++++++++++++++++++++++++++ app/components/utils/index.ts | 0 3 files changed, 126 insertions(+), 146 deletions(-) create mode 100644 app/Router.tsx create mode 100644 app/components/utils/index.ts diff --git a/app/App.tsx b/app/App.tsx index a79f3d8de..97cb39738 100644 --- a/app/App.tsx +++ b/app/App.tsx @@ -8,7 +8,7 @@ import ReactGA_4 from "react-ga4"; import Intercom from "react-intercom"; import { Helmet } from "react-helmet-async"; -import { Redirect, Route, Switch, useHistory } from "react-router-dom"; +import { useHistory } from "react-router-dom"; import { GeoCoordinates, getLocation, whiteLabel, AppProvider } from "./utils"; import { @@ -20,54 +20,19 @@ import { UserWay, } from "./components/ui"; +import { Router } from "./Router"; + import config from "./config"; import MetaImage from "./assets/img/sfsg-preview.png"; -import { HomePage } from "./pages/HomePage"; -import { AboutPage } from "./pages/AboutPage"; -import { ListingDebugPage } from "./pages/debug/ListingDemoPage"; -import { OrganizationListingPage } from "./pages/OrganizationListingPage"; -import { PrivacyPolicyPage } from "./pages/legal/PrivacyPolicy"; -import { - RedirectToOrganizations, - RedirectToOrganizationsEdit, -} from "./pages/LegacyRedirects"; -import { ResourceGuides, ResourceGuide } from "./pages/ResourceGuides"; -import { SearchResultsPage } from "./pages/SearchResultsPage/SearchResultsPage"; -import { ServiceListingPage } from "./pages/ServiceListingPage"; -import { ServicePdfPage } from "./pages/Pdf/ServicePdfPage"; -import { IntimatePartnerViolencePdfPage } from "./pages/Pdf/IntimatePartnerViolencePdfPage"; -import { TermsOfServicePage } from "./pages/legal/TermsOfService"; -import { UcsfHomePage } from "./pages/UcsfHomePage/UcsfHomePage"; -import { UcsfDiscoveryForm } from "./pages/UcsfDiscoveryForm/UcsfDiscoveryForm"; -import OrganizationEditPage from "./pages/OrganizationEditPage"; -import { EditBreakingNewsPage } from "./pages/EditBreakingNewsPage"; -import { ServiceDiscoveryForm } from "./pages/ServiceDiscoveryForm"; -import { ServiceDiscoveryResults } from "./pages/ServiceDiscoveryResults"; -import { LoginPage } from "./pages/Auth/LoginPage"; -import { SignUpPage } from "./pages/Auth/SignUpPage"; -import { LogoutPage } from "./pages/Auth/LogoutPage"; - import styles from "./App.module.scss"; -const { - homePageComponent, - intercom, - showBanner, - showSearch, - siteUrl, - title, - userWay, -} = whiteLabel; +const { intercom, showBanner, showSearch, siteUrl, title, userWay } = + whiteLabel; const outerContainerId = "outer-container"; const pageWrapId = "page-wrap"; export const App = () => { - const homePageDictionary = { - HomePage, - UcsfHomePage, - }; - const history = useHistory(); const [hamburgerOpen, setHamburgerOpen] = useState(false); const [popUpMessage, setPopUpMessage] = useState({ @@ -139,112 +104,7 @@ export const App = () => { /> {showBanner && }
- - - - - {/* NB: /organizations/new must be listed before /organizations/:id or else the /new - step will be interpreted as an ID and will thus break the OrganizationEditPage */} - ( - - )} - /> - - ( - - )} - /> - - - - - - - - - - - - - - - - {/* UCSF white label paths */} - - {/* Legacy redirects */} - - - - - +
{popUpMessage && } diff --git a/app/Router.tsx b/app/Router.tsx new file mode 100644 index 000000000..aa7c6eefc --- /dev/null +++ b/app/Router.tsx @@ -0,0 +1,120 @@ +import type { PopupMessageProp } from "components/ui"; +import React from "react"; +import { Switch, Route, Redirect } from "react-router-dom"; + +import { whiteLabel } from "utils"; + +import { HomePage } from "pages/HomePage"; +import { AboutPage } from "pages/AboutPage"; +import { ListingDebugPage } from "pages/debug/ListingDemoPage"; +import { OrganizationListingPage } from "pages/OrganizationListingPage"; +import { PrivacyPolicyPage } from "pages/legal/PrivacyPolicy"; +import { + RedirectToOrganizations, + RedirectToOrganizationsEdit, +} from "pages/LegacyRedirects"; +import { ResourceGuides, ResourceGuide } from "pages/ResourceGuides"; +import { SearchResultsPage } from "pages/SearchResultsPage/SearchResultsPage"; +import { ServiceListingPage } from "pages/ServiceListingPage"; +import { ServicePdfPage } from "pages/Pdf/ServicePdfPage"; +import { IntimatePartnerViolencePdfPage } from "pages/Pdf/IntimatePartnerViolencePdfPage"; +import { TermsOfServicePage } from "pages/legal/TermsOfService"; +import { UcsfHomePage } from "pages/UcsfHomePage/UcsfHomePage"; +import { UcsfDiscoveryForm } from "pages/UcsfDiscoveryForm/UcsfDiscoveryForm"; +import OrganizationEditPage from "pages/OrganizationEditPage"; +import { EditBreakingNewsPage } from "pages/EditBreakingNewsPage"; +import { ServiceDiscoveryForm } from "pages/ServiceDiscoveryForm"; +import { ServiceDiscoveryResults } from "pages/ServiceDiscoveryResults"; +import { LoginPage } from "pages/Auth/LoginPage"; +import { SignUpPage } from "pages/Auth/SignUpPage"; +import { LogoutPage } from "pages/Auth/LogoutPage"; + +const { homePageComponent } = whiteLabel; + +const homePageDictionary = { + HomePage, + UcsfHomePage, +}; + +const homePage = homePageDictionary[homePageComponent]; + +export const Router = ({ + setPopUpMessage, +}: { + setPopUpMessage: (msg: PopupMessageProp) => void; +}) => { + return ( + + + + + {/* NB: /organizations/new must be listed before /organizations/:id or else the /new + step will be interpreted as an ID and will thus break the OrganizationEditPage */} + ( + + )} + /> + + ( + + )} + /> + + + + + + + + + + + + + + + + {/* UCSF white label paths */} + + {/* Legacy redirects */} + + + + + + ); +}; diff --git a/app/components/utils/index.ts b/app/components/utils/index.ts new file mode 100644 index 000000000..e69de29bb