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

OV-9: + ProtectedRoute component #19

Merged
merged 14 commits into from
Aug 23, 2024
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Bug Report
description: Report a bug
title: 'BUG:'
labels: ['BUG']
projects: "BinaryStudioAcademy/30"
projects: 'BinaryStudioAcademy/30'
body:
- type: markdown
attributes:
Expand Down
38 changes: 19 additions & 19 deletions .github/ISSUE_TEMPLATE/feature.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
name: Feature
description: Abstract feature description
title: "FEAT:"
projects: "BinaryStudioAcademy/30"
title: 'FEAT:'
projects: 'BinaryStudioAcademy/30'
body:
- type: textarea
id: what-feature
attributes:
label: What feature?
placeholder: Add descriptions
validations:
required: true
- type: textarea
id: screenshots
attributes:
label: Add screenshots
placeholder: Add screenshots, mockups, etc.
- type: textarea
id: acceptance-criteria
attributes:
label: Acceptance criteria
placeholder: Add acceptance criteria.
- type: textarea
id: what-feature
attributes:
label: What feature?
placeholder: Add descriptions
validations:
required: true
- type: textarea
id: screenshots
attributes:
label: Add screenshots
placeholder: Add screenshots, mockups, etc.
- type: textarea
id: acceptance-criteria
attributes:
label: Acceptance criteria
placeholder: Add acceptance criteria.
1 change: 1 addition & 0 deletions frontend/src/bundles/common/enums/app-route.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const AppRoute = {
ROOT: '/',
SIGN_IN: '/sign-in',
SIGN_UP: '/sign-up',
ANY: '*',
} as const;

export { AppRoute };
4 changes: 1 addition & 3 deletions frontend/src/framework/config/base-config.package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class BaseConfig implements Config {
private get envSchema(): EnvironmentSchema {
return {
APP: {
ENVIRONMENT: import.meta.env[
'VITE_APP_NODE_ENV'
],
ENVIRONMENT: import.meta.env['VITE_APP_NODE_ENV'],
},
API: {
ORIGIN_URL: import.meta.env[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type AppEnvironment } from '~/bundles/common/enums/enums.js';
import { type ValueOf } from '~/bundles/common/types/types.js';
import { type ValueOf } from '~/bundles/common/types/types.js';

type EnvironmentSchema = {
APP: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ContentType } from '~/bundles/common/enums/enums.js';
import { type ValueOf } from '~/bundles/common/types/types.js';
import { type ValueOf } from '~/bundles/common/types/types.js';
import { type HttpOptions } from '~/framework/http/http.js';

type HttpApiOptions = Omit<HttpOptions, 'headers' | 'payload'> & {
Expand Down
25 changes: 1 addition & 24 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';

import { App } from '~/app/app.js';
import { Auth } from '~/bundles/auth/pages/auth.js';
import {
ComponentsProvider,
RouterProvider,
StoreProvider,
} from '~/bundles/common/components/components.js';
import { AppRoute } from '~/bundles/common/enums/enums.js';
import { store } from '~/framework/store/store.js';
import { theme } from '~/framework/theme/theme.js';

const routes = [
{
path: AppRoute.ROOT,
element: <App />,
children: [
{
path: AppRoute.ROOT,
element: 'Root',
},
{
path: AppRoute.SIGN_IN,
element: <Auth />,
},
{
path: AppRoute.SIGN_UP,
element: <Auth />,
},
],
},
];
import { routes } from '~/router/routes.js';

createRoot(document.querySelector('#root') as HTMLElement).render(
<StrictMode>
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/router/components/protected-route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Navigate } from 'react-router-dom';

import { RouterOutlet } from '~/bundles/common/components/components.js';
import { AppRoute } from '~/bundles/common/enums/app-route.enum.js';
import { DataStatus } from '~/bundles/common/enums/data-status.enum.js';
import { useAppSelector } from '~/bundles/common/hooks/hooks.js';

const ProtectedRoute: React.FC = () => {
const dataStatus = useAppSelector((state) => state.auth.dataStatus);
if (dataStatus !== DataStatus.FULFILLED) {
return <Navigate to={AppRoute.SIGN_IN} replace />;
}
return <RouterOutlet />;
};

export { ProtectedRoute };
15 changes: 15 additions & 0 deletions frontend/src/router/routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { App } from '~/app/app.js';
import { AppRoute } from '~/bundles/common/enums/app-route.enum.js';

import { protectedRoutes } from './routes/protected-routes.js';
import { publicRoutes } from './routes/public-routes.js';

const routes = [
{
path: AppRoute.ROOT,
element: <App />,
children: [protectedRoutes, ...publicRoutes],
},
];

export { routes };
19 changes: 19 additions & 0 deletions frontend/src/router/routes/protected-routes.tsx
XCODE89 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Navigate } from 'react-router-dom';

import { AppRoute } from '~/bundles/common/enums/app-route.enum.js';

import { ProtectedRoute } from '../components/protected-route.js';

const protectedRoutes = {
path: AppRoute.ROOT,
element: <ProtectedRoute />,
children: [
//TODO Add protected routes here in element property and specify the correct path
{
path: AppRoute.ANY,
element: <Navigate to={AppRoute.ROOT} replace />,
},
],
};

export { protectedRoutes };
21 changes: 21 additions & 0 deletions frontend/src/router/routes/public-routes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Navigate } from 'react-router-dom';

import { Auth } from '~/bundles/auth/pages/auth.js';
import { AppRoute } from '~/bundles/common/enums/app-route.enum.js';

const publicRoutes = [
{
path: AppRoute.SIGN_IN,
element: <Auth />,
},
{
path: AppRoute.SIGN_UP,
element: <Auth />,
},
{
path: AppRoute.ANY,
element: <Navigate to={AppRoute.SIGN_IN} replace />,
o-nedashkivska marked this conversation as resolved.
Show resolved Hide resolved
},
];

export { publicRoutes };
Loading