Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a secret route #279

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/node_modules
/.pnp
.pnp.js
*package-lock.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should remove this line from here, and use 'yarn' instead of 'npm'.


# testing
/coverage
Expand Down
1 change: 1 addition & 0 deletions src/locale/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"secret_page_title": "my account",
"realtime_map_explanation": "Location data of buses collected in real time",
"timeline_page_title": "Historical timeline",
"realtime_map_page_title": "Real time map",
Expand Down
1 change: 1 addition & 0 deletions src/locale/he.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"secret_page_title": "החשבון שלי",
"realtime_map_explanation": "נתוני מיקום של אוטובוסים שנאספו בזמן אמת",
"timeline_page_title": "לוח זמנים היסטורי",
"realtime_map_page_title": "מפה בזמן אמת",
Expand Down
9 changes: 9 additions & 0 deletions src/pages/secretPage/SecretPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

const SecretPage = () => {
return (
<div>SecretPage</div>
)
}

export default SecretPage
13 changes: 13 additions & 0 deletions src/routes/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react'
import { Navigate } from 'react-router-dom';

const ProtectedRoute = ({children}:any) => {
Copy link
Collaborator

@ArkadiK94 ArkadiK94 Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we don't have authentication on the site so we don't need a Protected Route, the option to get to this page will be through "hidden secret egg" as the storybook.
Please, follow the instructions that were specified in the issue.


const isAuth:boolean = false;

return (
isAuth ? children : <Navigate to="/dashboard" replace/>
)
}

export default ProtectedRoute
31 changes: 29 additions & 2 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const SingleLineMapPage = lazy(() => import('../pages/SingleLineMapPage'))
const About = lazy(() => import('../pages/About'))
const Profile = lazy(() => import('../pages/Profile'))
const BugReportForm = lazy(() => import('../pages/BugReportForm '))
const SecretPage = lazy(() => import('../pages/secretPage/SecretPage'))
import ProtectedRoute from './ProtectedRoute'
import CircularProgress from '@mui/material/CircularProgress'

import {
Expand All @@ -22,67 +24,84 @@ import {
BugOutlined,
BarChartOutlined,
LineChartOutlined,
VerifiedOutlined
} from '@ant-design/icons'

export const usePages = () => {
const { t } = useTranslation()
return [
{
label: t('secret_page_title'),
path: '/secretpage',
icon: <VerifiedOutlined />,
element: <SecretPage />,
isProtected: true,
},
{
label: t('dashboard_page_title'),
path: '/dashboard',
icon: <LaptopOutlined />,
element: <DashboardPage />,
isProtected: false,
},
{
label: t('timeline_page_title'),
path: '/timeline',
searchParamsRequired: true,
icon: <FieldTimeOutlined />,
element: <TimelinePage />,
isProtected: false,
},
{
label: t('gaps_page_title'),
path: '/gaps',
searchParamsRequired: true,
icon: <BarChartOutlined />,
element: <GapsPage />,
isProtected: false,
},
{
label: t('gaps_patterns_page_title'),
path: '/gaps_patterns',
icon: <LineChartOutlined />,
element: <GapsPatternsPage />,
isProtected: false,
},
{
label: t('realtime_map_page_title'),
path: '/map',
icon: <HeatMapOutlined />,
element: <RealtimeMapPage />,
isProtected: false,
},
{
label: t('singleline_map_page_title'),
path: '/single-line-map',
searchParamsRequired: true,
icon: <RadarChartOutlined />,
element: <SingleLineMapPage />,
isProtected: false,
},
{
label: t('about_title'),
path: '/about',
icon: <BellOutlined />,
element: <About />,
isProtected: false,
},
{
label: t('report_a_bug_title'),
path: 'report-a-bug',
icon: <BugOutlined />,
element: <BugReportForm />,
isProtected: false,
},
{
label: t('donate_title'),
path: 'https://www.jgive.com/new/he/ils/donation-targets/3268#donation-modal',
icon: <DollarOutlined />,
element: null,
isProtected: false,
},
]
}
Expand All @@ -94,8 +113,16 @@ const RoutesList = () => {
return (
<Suspense fallback={<CircularProgress />}>
<Routes>
{routes.map(({ path, element }) => (
<Route key={path} path={path} element={element} />
{routes.map(({ path, element, isProtected}) => (
<Route key={path} path={path} element=
{
isProtected ?
<ProtectedRoute>
element
</ProtectedRoute>
:
element
} />
))}
<Route path="/profile" element={<Profile />} />
<Route path="*" element={<RedirectToDashboard />} />
Expand Down
Loading
Loading