From 06fa3f6d29d4d8c920ae87b4c0c140f13bb02df9 Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Mon, 19 Aug 2024 18:02:39 -0400 Subject: [PATCH 1/9] OV-9: + ProtectedRoute component --- .../bundles/common/enums/app-route.enum.ts | 2 ++ frontend/src/index.tsx | 25 +------------------ .../src/router/components/protected-route.tsx | 17 +++++++++++++ frontend/src/router/routes.tsx | 19 ++++++++++++++ .../src/router/routes/protected-routes.tsx | 23 +++++++++++++++++ frontend/src/router/routes/public-routes.tsx | 21 ++++++++++++++++ 6 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 frontend/src/router/components/protected-route.tsx create mode 100644 frontend/src/router/routes.tsx create mode 100644 frontend/src/router/routes/protected-routes.tsx create mode 100644 frontend/src/router/routes/public-routes.tsx diff --git a/frontend/src/bundles/common/enums/app-route.enum.ts b/frontend/src/bundles/common/enums/app-route.enum.ts index dfc5352ec..dc23303d1 100644 --- a/frontend/src/bundles/common/enums/app-route.enum.ts +++ b/frontend/src/bundles/common/enums/app-route.enum.ts @@ -2,6 +2,8 @@ const AppRoute = { ROOT: '/', SIGN_IN: '/sign-in', SIGN_UP: '/sign-up', + PROTECTED:'/protected', + ANY: '*' } as const; export { AppRoute }; diff --git a/frontend/src/index.tsx b/frontend/src/index.tsx index 1412d521b..b07af5537 100644 --- a/frontend/src/index.tsx +++ b/frontend/src/index.tsx @@ -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: , - children: [ - { - path: AppRoute.ROOT, - element: 'Root', - }, - { - path: AppRoute.SIGN_IN, - element: , - }, - { - path: AppRoute.SIGN_UP, - element: , - }, - ], - }, -]; +import { routes } from '~/router/routes.js'; createRoot(document.querySelector('#root') as HTMLElement).render( diff --git a/frontend/src/router/components/protected-route.tsx b/frontend/src/router/components/protected-route.tsx new file mode 100644 index 000000000..d021f5cdc --- /dev/null +++ b/frontend/src/router/components/protected-route.tsx @@ -0,0 +1,17 @@ +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 ; + } + + return ; +}; + +export { ProtectedRoute }; diff --git a/frontend/src/router/routes.tsx b/frontend/src/router/routes.tsx new file mode 100644 index 000000000..e77d8ed47 --- /dev/null +++ b/frontend/src/router/routes.tsx @@ -0,0 +1,19 @@ +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: , + children: [ + protectedRoutes, + ...publicRoutes, + ], + }, + ]; + + export { routes }; + \ No newline at end of file diff --git a/frontend/src/router/routes/protected-routes.tsx b/frontend/src/router/routes/protected-routes.tsx new file mode 100644 index 000000000..be641e859 --- /dev/null +++ b/frontend/src/router/routes/protected-routes.tsx @@ -0,0 +1,23 @@ +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: , + children: [ + //TODO Add protected routes here in element property and specify the correct path + { + path: AppRoute.PROTECTED, + element: (
test
) + }, + { + path: AppRoute.ANY, + element: + }, + ] +}; + +export { protectedRoutes }; diff --git a/frontend/src/router/routes/public-routes.tsx b/frontend/src/router/routes/public-routes.tsx new file mode 100644 index 000000000..e87c6614f --- /dev/null +++ b/frontend/src/router/routes/public-routes.tsx @@ -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: , + }, + { + path: AppRoute.SIGN_UP, + element: , + }, + { + path: AppRoute.ANY, + element: , + } +]; + +export { publicRoutes }; \ No newline at end of file From d32bc9f66c4711ea608189c254e066dfa1b8802a Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Mon, 19 Aug 2024 20:13:05 -0400 Subject: [PATCH 2/9] OV-9: * format correction --- .../src/router/components/protected-route.tsx | 1 - frontend/src/router/routes.tsx | 22 +++++++++---------- .../src/router/routes/protected-routes.tsx | 8 +++---- frontend/src/router/routes/public-routes.tsx | 8 +++---- 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/frontend/src/router/components/protected-route.tsx b/frontend/src/router/components/protected-route.tsx index d021f5cdc..2f55ae9d6 100644 --- a/frontend/src/router/components/protected-route.tsx +++ b/frontend/src/router/components/protected-route.tsx @@ -10,7 +10,6 @@ const ProtectedRoute: React.FC = () => { if (dataStatus !== DataStatus.FULFILLED) { return ; } - return ; }; diff --git a/frontend/src/router/routes.tsx b/frontend/src/router/routes.tsx index e77d8ed47..142ff054b 100644 --- a/frontend/src/router/routes.tsx +++ b/frontend/src/router/routes.tsx @@ -4,16 +4,14 @@ 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: , - children: [ - protectedRoutes, - ...publicRoutes, - ], - }, - ]; - - export { routes }; +const routes = [{ + path: AppRoute.ROOT, + element: , + children: [ + protectedRoutes, + ...publicRoutes, + ], +}]; + +export { routes }; \ No newline at end of file diff --git a/frontend/src/router/routes/protected-routes.tsx b/frontend/src/router/routes/protected-routes.tsx index be641e859..212994025 100644 --- a/frontend/src/router/routes/protected-routes.tsx +++ b/frontend/src/router/routes/protected-routes.tsx @@ -10,12 +10,12 @@ const protectedRoutes = { children: [ //TODO Add protected routes here in element property and specify the correct path { - path: AppRoute.PROTECTED, - element: (
test
) + path: AppRoute.PROTECTED, + element: (
test
) }, { - path: AppRoute.ANY, - element: + path: AppRoute.ANY, + element: }, ] }; diff --git a/frontend/src/router/routes/public-routes.tsx b/frontend/src/router/routes/public-routes.tsx index e87c6614f..33c9fcf6c 100644 --- a/frontend/src/router/routes/public-routes.tsx +++ b/frontend/src/router/routes/public-routes.tsx @@ -6,16 +6,16 @@ import { AppRoute } from '~/bundles/common/enums/app-route.enum.js'; const publicRoutes = [ { path: AppRoute.SIGN_IN, - element: , + element: }, { path: AppRoute.SIGN_UP, - element: , + element: }, { path: AppRoute.ANY, - element: , + element: } ]; -export { publicRoutes }; \ No newline at end of file +export { publicRoutes }; From 3f8f21bb0346003f4476a1bebc8ddb78fc697cda Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Mon, 19 Aug 2024 20:23:12 -0400 Subject: [PATCH 3/9] OV-9: * format correction-2 --- frontend/src/router/routes.tsx | 3 +-- frontend/src/router/routes/protected-routes.tsx | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/src/router/routes.tsx b/frontend/src/router/routes.tsx index 142ff054b..d728f93e1 100644 --- a/frontend/src/router/routes.tsx +++ b/frontend/src/router/routes.tsx @@ -12,6 +12,5 @@ const routes = [{ ...publicRoutes, ], }]; - + export { routes }; - \ No newline at end of file diff --git a/frontend/src/router/routes/protected-routes.tsx b/frontend/src/router/routes/protected-routes.tsx index 212994025..ec64a52c1 100644 --- a/frontend/src/router/routes/protected-routes.tsx +++ b/frontend/src/router/routes/protected-routes.tsx @@ -10,7 +10,7 @@ const protectedRoutes = { children: [ //TODO Add protected routes here in element property and specify the correct path { - path: AppRoute.PROTECTED, + path: AppRoute.PROTECTED, element: (
test
) }, { From 779c789985b29cd8651c646d05f24cda947eca21 Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Mon, 19 Aug 2024 20:31:20 -0400 Subject: [PATCH 4/9] OV-9: * format correction --- .github/ISSUE_TEMPLATE/bug-report.yml | 2 +- .github/ISSUE_TEMPLATE/feature.yml | 38 +++++++++---------- .../bundles/common/enums/app-route.enum.ts | 4 +- .../framework/config/base-config.package.ts | 4 +- .../config/types/environment-schema.type.ts | 2 +- .../http-api/types/http-api-options.type.ts | 2 +- frontend/src/router/routes.tsx | 15 ++++---- .../src/router/routes/protected-routes.tsx | 6 +-- frontend/src/router/routes/public-routes.tsx | 8 ++-- 9 files changed, 39 insertions(+), 42 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml index c4efbf503..d14de0c2e 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.yml +++ b/.github/ISSUE_TEMPLATE/bug-report.yml @@ -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: diff --git a/.github/ISSUE_TEMPLATE/feature.yml b/.github/ISSUE_TEMPLATE/feature.yml index c793c4684..a628b3881 100644 --- a/.github/ISSUE_TEMPLATE/feature.yml +++ b/.github/ISSUE_TEMPLATE/feature.yml @@ -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. diff --git a/frontend/src/bundles/common/enums/app-route.enum.ts b/frontend/src/bundles/common/enums/app-route.enum.ts index dc23303d1..55af18edb 100644 --- a/frontend/src/bundles/common/enums/app-route.enum.ts +++ b/frontend/src/bundles/common/enums/app-route.enum.ts @@ -2,8 +2,8 @@ const AppRoute = { ROOT: '/', SIGN_IN: '/sign-in', SIGN_UP: '/sign-up', - PROTECTED:'/protected', - ANY: '*' + PROTECTED: '/protected', + ANY: '*', } as const; export { AppRoute }; diff --git a/frontend/src/framework/config/base-config.package.ts b/frontend/src/framework/config/base-config.package.ts index 2b2a35e0e..1224b76c5 100644 --- a/frontend/src/framework/config/base-config.package.ts +++ b/frontend/src/framework/config/base-config.package.ts @@ -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[ diff --git a/frontend/src/framework/config/types/environment-schema.type.ts b/frontend/src/framework/config/types/environment-schema.type.ts index 47109076d..6f8f4df7c 100644 --- a/frontend/src/framework/config/types/environment-schema.type.ts +++ b/frontend/src/framework/config/types/environment-schema.type.ts @@ -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: { diff --git a/frontend/src/framework/http-api/types/http-api-options.type.ts b/frontend/src/framework/http-api/types/http-api-options.type.ts index 88cda053c..ba7f07184 100644 --- a/frontend/src/framework/http-api/types/http-api-options.type.ts +++ b/frontend/src/framework/http-api/types/http-api-options.type.ts @@ -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 & { diff --git a/frontend/src/router/routes.tsx b/frontend/src/router/routes.tsx index d728f93e1..9131d0b2c 100644 --- a/frontend/src/router/routes.tsx +++ b/frontend/src/router/routes.tsx @@ -4,13 +4,12 @@ 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: , - children: [ - protectedRoutes, - ...publicRoutes, - ], -}]; +const routes = [ + { + path: AppRoute.ROOT, + element: , + children: [protectedRoutes, ...publicRoutes], + }, +]; export { routes }; diff --git a/frontend/src/router/routes/protected-routes.tsx b/frontend/src/router/routes/protected-routes.tsx index ec64a52c1..875924b1d 100644 --- a/frontend/src/router/routes/protected-routes.tsx +++ b/frontend/src/router/routes/protected-routes.tsx @@ -11,13 +11,13 @@ const protectedRoutes = { //TODO Add protected routes here in element property and specify the correct path { path: AppRoute.PROTECTED, - element: (
test
) + element:
test
, }, { path: AppRoute.ANY, - element: + element: , }, - ] + ], }; export { protectedRoutes }; diff --git a/frontend/src/router/routes/public-routes.tsx b/frontend/src/router/routes/public-routes.tsx index 33c9fcf6c..523cd1e99 100644 --- a/frontend/src/router/routes/public-routes.tsx +++ b/frontend/src/router/routes/public-routes.tsx @@ -6,16 +6,16 @@ import { AppRoute } from '~/bundles/common/enums/app-route.enum.js'; const publicRoutes = [ { path: AppRoute.SIGN_IN, - element: + element: , }, { path: AppRoute.SIGN_UP, - element: + element: , }, { path: AppRoute.ANY, - element: - } + element: , + }, ]; export { publicRoutes }; From 22077c2bb20d20eefd6c66ff9c6145efc44f1607 Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Tue, 20 Aug 2024 09:30:50 -0400 Subject: [PATCH 5/9] OV-9: - test AppRoute --- frontend/src/bundles/common/enums/app-route.enum.ts | 1 - frontend/src/router/routes/protected-routes.tsx | 4 ---- 2 files changed, 5 deletions(-) diff --git a/frontend/src/bundles/common/enums/app-route.enum.ts b/frontend/src/bundles/common/enums/app-route.enum.ts index 55af18edb..ed4d402ae 100644 --- a/frontend/src/bundles/common/enums/app-route.enum.ts +++ b/frontend/src/bundles/common/enums/app-route.enum.ts @@ -2,7 +2,6 @@ const AppRoute = { ROOT: '/', SIGN_IN: '/sign-in', SIGN_UP: '/sign-up', - PROTECTED: '/protected', ANY: '*', } as const; diff --git a/frontend/src/router/routes/protected-routes.tsx b/frontend/src/router/routes/protected-routes.tsx index 875924b1d..f4eb298f1 100644 --- a/frontend/src/router/routes/protected-routes.tsx +++ b/frontend/src/router/routes/protected-routes.tsx @@ -9,10 +9,6 @@ const protectedRoutes = { element: , children: [ //TODO Add protected routes here in element property and specify the correct path - { - path: AppRoute.PROTECTED, - element:
test
, - }, { path: AppRoute.ANY, element: , From 9db4df8e7d435ab7c0de0e18680771012e50601b Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Tue, 20 Aug 2024 13:56:17 -0400 Subject: [PATCH 6/9] OV-9: + Add replace to 'ANY' routes. --- frontend/src/router/routes/protected-routes.tsx | 2 +- frontend/src/router/routes/public-routes.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/router/routes/protected-routes.tsx b/frontend/src/router/routes/protected-routes.tsx index f4eb298f1..86474b5c1 100644 --- a/frontend/src/router/routes/protected-routes.tsx +++ b/frontend/src/router/routes/protected-routes.tsx @@ -11,7 +11,7 @@ const protectedRoutes = { //TODO Add protected routes here in element property and specify the correct path { path: AppRoute.ANY, - element: , + element: , }, ], }; diff --git a/frontend/src/router/routes/public-routes.tsx b/frontend/src/router/routes/public-routes.tsx index 523cd1e99..d40fcbd80 100644 --- a/frontend/src/router/routes/public-routes.tsx +++ b/frontend/src/router/routes/public-routes.tsx @@ -14,7 +14,7 @@ const publicRoutes = [ }, { path: AppRoute.ANY, - element: , + element: , }, ]; From 611061b2ae3adc08bda674b0d26118ca4f00b9e3 Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Tue, 20 Aug 2024 13:57:16 -0400 Subject: [PATCH 7/9] OV-9: + Add replace to 'ANY' routes. --- frontend/src/router/routes/protected-routes.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/router/routes/protected-routes.tsx b/frontend/src/router/routes/protected-routes.tsx index 86474b5c1..0d2711817 100644 --- a/frontend/src/router/routes/protected-routes.tsx +++ b/frontend/src/router/routes/protected-routes.tsx @@ -11,7 +11,7 @@ const protectedRoutes = { //TODO Add protected routes here in element property and specify the correct path { path: AppRoute.ANY, - element: , + element: , }, ], }; From 5bff40770ce1bc4388e3cff036019a7c76ede0b6 Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Wed, 21 Aug 2024 10:25:56 -0400 Subject: [PATCH 8/9] OV-9: - Unused wildcard route --- frontend/src/router/routes/public-routes.tsx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/frontend/src/router/routes/public-routes.tsx b/frontend/src/router/routes/public-routes.tsx index d40fcbd80..ead9cf5ff 100644 --- a/frontend/src/router/routes/public-routes.tsx +++ b/frontend/src/router/routes/public-routes.tsx @@ -1,5 +1,3 @@ -import { Navigate } from 'react-router-dom'; - import { Auth } from '~/bundles/auth/pages/auth.js'; import { AppRoute } from '~/bundles/common/enums/app-route.enum.js'; @@ -12,10 +10,6 @@ const publicRoutes = [ path: AppRoute.SIGN_UP, element: , }, - { - path: AppRoute.ANY, - element: , - }, ]; export { publicRoutes }; From 713d6171655a99bc4c2ae93b1a5ce0de4b2f4f68 Mon Sep 17 00:00:00 2001 From: XCODE89 Date: Thu, 22 Aug 2024 13:31:50 -0400 Subject: [PATCH 9/9] OV-9: * get the user from store --- frontend/src/router/components/protected-route.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/router/components/protected-route.tsx b/frontend/src/router/components/protected-route.tsx index 86f6486c0..130755f91 100644 --- a/frontend/src/router/components/protected-route.tsx +++ b/frontend/src/router/components/protected-route.tsx @@ -2,13 +2,15 @@ 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 { useAppSelector } from '~/bundles/common/hooks/hooks.js'; const ProtectedRoute: React.FC = () => { - // TODO: When the JWT is implemented and the token is stored in local storage, it should be activated. - // const isAuth = !!localStorage.getItem('token'); - const isAuth = true; + // const user = useAppSelector((state) => state.auth.user); - if (!isAuth) { + // TODO: for implementing persistence. The following line is temporary + const user = true; + + if (!user) { return ; }