-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from tgstation/RouterWork
Setup Routing
- Loading branch information
Showing
39 changed files
with
797 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import NotFound from "./NotFound"; | ||
const config: Meta<typeof NotFound> = { | ||
component: NotFound, | ||
title: "Core/Not Found" | ||
}; | ||
|
||
export default config; | ||
|
||
type Story = StoryObj<typeof config>; | ||
|
||
export const Default: Story = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
import Pkg from "@/../package.json"; | ||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; | ||
|
||
const NotFound = () => ( | ||
<Card className="bg-transparent text-transparent-foreground mb-4"> | ||
<CardHeader> | ||
<CardTitle> | ||
<FormattedMessage id="error.somethingwentwrong" /> | ||
</CardTitle> | ||
<CardDescription> | ||
<FormattedMessage id="error.notfound" /> | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="bg-transparent text-danger"> | ||
<code className="block whitespace-pre-wrap" data-chromatic="ignore"> | ||
{`Webpanel Version: ${Pkg.version}\nWebpanel Mode: ${ | ||
import.meta.env.VITE_DEV_MODE ? "DEV" : "PROD" | ||
}\nCurrent route: ${window.location.toString()}`} | ||
</code> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
|
||
export default NotFound; |
17 changes: 17 additions & 0 deletions
17
src/components/core/Router/ProtectedRoute/ProtectedRoute.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Navigate, Outlet, useLocation } from "react-router-dom"; | ||
|
||
import ILocationState from "@/components/routed/Login/LocationState"; | ||
import useSession from "@/context/session/useSession"; | ||
|
||
const ProtectedRoute = () => { | ||
const session = useSession(); | ||
const location = useLocation(); | ||
if (session.currentSession == null) { | ||
const state: ILocationState = { from: location }; | ||
return <Navigate to="/login" state={state} />; | ||
} | ||
|
||
return <Outlet />; | ||
}; | ||
|
||
export default ProtectedRoute; |
8 changes: 8 additions & 0 deletions
8
src/components/core/Router/RethrowRouteError/RethrowRouteError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useRouteError } from "react-router-dom"; | ||
|
||
const RethrowRouteError = () => { | ||
const error = useRouteError(); | ||
throw error; | ||
}; | ||
|
||
export default RethrowRouteError; |
Oops, something went wrong.