diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 093c41d0460279155a420c7c65065b00e3a7f661..a34d4e30155b91408b702ebe8940cfb71e280926 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -137,12 +137,12 @@ sonarqube-mr: script: - > sonar-scanner - -Dsonar.projectName="ecolyo" + -Dsonar.projectName="ecolyo-mr" -Dsonar.projectVersion=1.0 -Dsonar.sourceEncoding=UTF-8 -Dsonar.projectBaseDir=. -Dsonar.host.url=${SONAR_URL} - -Dsonar.projectKey=${CI_PROJECT_PATH_SLUG} + -Dsonar.projectKey=ecolyo-mr -Dsonar.login=${SONAR_MR_TOKEN} -Dsonar.cpd.exclusions=tests/**,src/**/*.spec.ts* -Dsonar.qualitygate.wait=true diff --git a/src/components/App.tsx b/src/components/App.tsx index 9ed422054cd9d7995a7fe4f1c23bd711f9a1718d..35bc76ef164e09926bf3ee20ff3207ca2fdf7233 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -20,6 +20,7 @@ export const App = () => { const { isLastTermAccepted } = useSelector( (state: AppStore) => state.ecolyo.global ) + return ( <HashRouter {...history}> <Layout> @@ -27,15 +28,13 @@ export const App = () => { splashComponent={SplashScreen} splashErrorComponent={SplashScreenError} > - <> - <TutorialWelcome open={!tutorial.isWelcomeSeen} /> - {isLastTermAccepted && <Navbar />} - <Main> - <Content className="app-content"> - <Routes /> - </Content> - </Main> - </> + <TutorialWelcome open={!tutorial.isWelcomeSeen} /> + {isLastTermAccepted && <Navbar />} + <Main> + <Content className="app-content"> + <Routes isLastTermAccepted={isLastTermAccepted} /> + </Content> + </Main> </SplashRoot> </Layout> </HashRouter> diff --git a/src/components/Routes/PrivateRoute.tsx b/src/components/Routes/PrivateRoute.tsx deleted file mode 100644 index 08e37df237db4c33353cc8b7a700abe173a7e4ce..0000000000000000000000000000000000000000 --- a/src/components/Routes/PrivateRoute.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react' -import { useSelector } from 'react-redux' -import { Route, Redirect } from 'react-router-dom' -import { AppStore } from 'store' - -interface PrivateRouteProps { - component?: React.FC - path: string - exact?: boolean - render?: ({ match: { url } }: { match: { url: string } }) => JSX.Element -} - -const PrivateRoute: React.FC<PrivateRouteProps> = ({ - component, - path, - exact, - render, -}: PrivateRouteProps) => { - const { isLastTermAccepted } = useSelector( - (state: AppStore) => state.ecolyo.global - ) - - return isLastTermAccepted ? ( - <Route path={path} exact={exact} component={component} render={render} /> - ) : ( - <Redirect to="/terms" /> - ) -} -export default PrivateRoute diff --git a/src/components/Routes/Routes.tsx b/src/components/Routes/Routes.tsx index 5072f8292f90c79f5f1db6f2910b506e1863d17f..687b6fda7addf0ae0f01e21a2caf9de793abb564 100644 --- a/src/components/Routes/Routes.tsx +++ b/src/components/Routes/Routes.tsx @@ -1,110 +1,96 @@ -import React, { Suspense, lazy } from 'react' -import { Route, Switch, Redirect } from 'react-router-dom' -import { FluidType } from 'enum/fluid.enum' -import ChallengeView from 'components/Challenge/ChallengeView' -import DuelView from 'components/Duel/DuelView' -import QuizView from 'components/Quiz/QuizView' -import ExplorationView from 'components/Exploration/ExplorationView' -import ActionView from 'components/Action/ActionView' -import UnSubscribe from 'components/Options/UnSubscribe' -import PrivateRoute from './PrivateRoute' - -const HomeView = lazy(() => import('components/Home/HomeView')) -const SingleFluidView = lazy(() => - import('components/SingleFluid/SingleFluidView') -) - -const EcogestureView = lazy(() => - import('components/Ecogesture/EcogestureView') -) -const OptionsView = lazy(() => import('components/Options/OptionsView')) -const FAQView = lazy(() => import('components/FAQ/FAQView')) -const LegalNoticeView = lazy(() => - import('components/LegalNotice/LegalNoticeView') -) -const GCUView = lazy(() => import('components/GCU/GCUView')) -const AnalysisView = lazy(() => import('components/Analysis/AnalysisView')) -const ProfileTypeView = lazy(() => - import('components/ProfileType/ProfileTypeView') -) -const TermsView = lazy(() => import('components/Terms/TermsView')) -const LegalNoticePublic = lazy(() => - import('components/Terms/LegalNoticePublic') -) -const CGUPublic = lazy(() => import('components/Terms/CGUPublic')) - -const Routes = () => { - return ( - <Suspense fallback={<div></div>}> - <Switch> - <Route path="/terms" component={TermsView} /> - <Route path="/legal" component={LegalNoticePublic} /> - <Route path="/cgu" component={CGUPublic} /> - <PrivateRoute - path="/consumption" - render={({ match: { url } }) => ( - <> - <PrivateRoute - path={`${url}/electricité`} - component={() => ( - <SingleFluidView fluidType={FluidType.ELECTRICITY} /> - )} - /> - <PrivateRoute - path={`${url}/eau`} - component={() => ( - <SingleFluidView fluidType={FluidType.WATER} /> - )} - /> - <PrivateRoute - path={`${url}/gaz`} - component={() => <SingleFluidView fluidType={FluidType.GAS} />} - /> - <PrivateRoute path={`${url}/`} component={HomeView} exact /> - </> - )} - /> - <PrivateRoute - path="/challenges" - render={({ match: { url } }) => ( - <> - <PrivateRoute path={`${url}/duel`} component={DuelView} /> - <PrivateRoute path={`${url}/quiz`} component={QuizView} /> - <PrivateRoute - path={`${url}/exploration`} - component={ExplorationView} - /> - <PrivateRoute - path={`${url}/action`} - exact - component={ActionView} - /> - <PrivateRoute path={`${url}/`} component={ChallengeView} exact /> - </> - )} - /> - <PrivateRoute path="/ecogestures" component={EcogestureView} /> - <PrivateRoute path={'/options/FAQ'} component={FAQView} /> - <PrivateRoute - path={`/options/legalnotice`} - component={LegalNoticeView} - /> - <PrivateRoute path={`/options/gcu`} component={GCUView} /> - <PrivateRoute - path={'/options/:connectParam'} - exact - component={OptionsView} - /> - <PrivateRoute path={'/options'} exact component={OptionsView} /> - <PrivateRoute path="/analysis" component={AnalysisView} /> - <PrivateRoute path="/profiletype" component={ProfileTypeView} /> - <PrivateRoute path="/unsubscribe" component={UnSubscribe} /> - - <Redirect from="/" to="/consumption" /> - <Redirect from="*" to="/consumption" /> - </Switch> - </Suspense> - ) -} - -export default Routes +import React, { Suspense, lazy } from 'react' +import { Route, Switch, Redirect } from 'react-router-dom' +import { FluidType } from 'enum/fluid.enum' +import ChallengeView from 'components/Challenge/ChallengeView' +import DuelView from 'components/Duel/DuelView' +import QuizView from 'components/Quiz/QuizView' +import ExplorationView from 'components/Exploration/ExplorationView' +import ActionView from 'components/Action/ActionView' +import UnSubscribe from 'components/Options/UnSubscribe' + +const HomeView = lazy(() => import('components/Home/HomeView')) +const SingleFluidView = lazy(() => + import('components/SingleFluid/SingleFluidView') +) + +const EcogestureView = lazy(() => + import('components/Ecogesture/EcogestureView') +) +const OptionsView = lazy(() => import('components/Options/OptionsView')) +const FAQView = lazy(() => import('components/FAQ/FAQView')) +const LegalNoticeView = lazy(() => + import('components/LegalNotice/LegalNoticeView') +) +const GCUView = lazy(() => import('components/GCU/GCUView')) +const AnalysisView = lazy(() => import('components/Analysis/AnalysisView')) +const ProfileTypeView = lazy(() => + import('components/ProfileType/ProfileTypeView') +) +const TermsView = lazy(() => import('components/Terms/TermsView')) +const LegalNoticePublic = lazy(() => + import('components/Terms/LegalNoticePublic') +) +const CGUPublic = lazy(() => import('components/Terms/CGUPublic')) + +interface RouteProps { + isLastTermAccepted: boolean +} +const Routes: React.FC<RouteProps> = ({ isLastTermAccepted }: RouteProps) => { + return ( + <Suspense fallback={<div></div>}> + <Switch> + {!isLastTermAccepted && ( + <> + <Route path="/terms" component={TermsView} /> + <Redirect from="*" to="/terms" /> + </> + )} + <Route path="/legal" component={LegalNoticePublic} /> + <Route path="/cgu" component={CGUPublic} /> + <Route + path="/consumption" + render={({ match: { url } }) => ( + <> + <Route path={`${url}/electricité`} exact> + <SingleFluidView fluidType={FluidType.ELECTRICITY} /> + </Route> + <Route path={`${url}/eau`} exact> + <SingleFluidView fluidType={FluidType.WATER} /> + </Route> + <Route path={`${url}/gaz`} exact> + <SingleFluidView fluidType={FluidType.GAS} /> + </Route> + <Route path={`${url}/`} component={HomeView} exact /> + </> + )} + /> + <Route + path="/challenges" + render={({ match: { url } }) => ( + <> + <Route path={`${url}/duel`} component={DuelView} /> + <Route path={`${url}/quiz`} component={QuizView} /> + <Route path={`${url}/exploration`} component={ExplorationView} /> + <Route path={`${url}/action`} exact component={ActionView} /> + <Route path={`${url}/`} component={ChallengeView} exact /> + </> + )} + /> + <Route path="/ecogestures" component={EcogestureView} /> + <Route path={'/options/FAQ'} component={FAQView} /> + <Route path={`/options/legalnotice`} component={LegalNoticeView} /> + <Route path={`/options/gcu`} component={GCUView} /> + <Route path={'/options/:connectParam'} exact component={OptionsView} /> + <Route path={'/options'} exact component={OptionsView} /> + <Route path="/analysis" component={AnalysisView} /> + <Route path="/profiletype" component={ProfileTypeView} /> + <Route path="/unsubscribe" component={UnSubscribe} /> + + <Redirect from="/" to="/consumption" /> + <Redirect from="*" to="/consumption" /> + </Switch> + </Suspense> + ) +} + +export default Routes diff --git a/src/db/profileData.json b/src/db/profileData.json index 405f0892079dde6fd9a45c5919650a82511acda1..991a1bfb43578f714bdca972ab49668b4824c919 100644 --- a/src/db/profileData.json +++ b/src/db/profileData.json @@ -11,6 +11,7 @@ "haveSeenLastAnalysis": true, "sendAnalysisNotification": false, "monthlyAnalysisDate": "0000-01-01T00:00:00.000Z", + "isLastTermAccepted": false, "isProfileTypeCompleted": false, "tutorial": { "isWelcomeSeen": false