Skip to content

Commit

Permalink
refactor: remove error logic from router PE-5161
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Dec 8, 2023
1 parent f32c254 commit c6bd0a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
26 changes: 10 additions & 16 deletions src/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { GiftForm } from "./GiftForm";
import { RouterPage } from "./components/RouterPage";
import { useErrorMessage } from "./hooks/useErrorMessage";
import { Page } from "./components/RouterPage";

export function Router() {
const [errorMessage, setErrorMessage] = useErrorMessage();

return (
<BrowserRouter basename={`${import.meta.env.BASE_URL}`}>
<Routes>
<Route
path="/gift"
element={
<RouterPage
page={<GiftForm errorCallback={setErrorMessage} />}
errorMessage={errorMessage}
<Page
page={(errorCallback) => (
<GiftForm errorCallback={errorCallback} />
)}
/>
}
/>
<Route
path="/redeem"
element={
<RouterPage page={<p>TODO</p>} errorMessage={errorMessage} />
}
/>
<Route path="/redeem" element={<Page page={() => <p>TODO</p>} />} />
<Route
path="/"
element={
/* Put gift element at baseUrl for now */
<RouterPage
page={<GiftForm errorCallback={setErrorMessage} />}
errorMessage={errorMessage}
<Page
page={(errorCallback) => (
<GiftForm errorCallback={errorCallback} />
)}
/>
}
/>
Expand Down
12 changes: 7 additions & 5 deletions src/components/RouterPage.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { termsOfServiceUrl } from "../constants";
import { useErrorMessage } from "../hooks/useErrorMessage";
import { LogoHeader } from "./LogoHeader";
import "./RouterPage.css";

interface RouterPageProps {
page: JSX.Element;
errorMessage?: string;
interface PageProps {
page: (errorCallback: (message: string) => void) => JSX.Element;
}

export function RouterPage({ page, errorMessage }: RouterPageProps) {
export function Page({ page }: PageProps) {
const [errorMessage, errorCallback] = useErrorMessage();

return (
<>
<LogoHeader errorMessage={errorMessage} />
{page}
{page(errorCallback)}
<span id="version-footer">
<a href={termsOfServiceUrl}>Terms</a> | v
{import.meta.env.PACKAGE_VERSION}
Expand Down

0 comments on commit c6bd0a4

Please sign in to comment.