From 4ebfb96a856f31312f16cf40d36a81e2fecb43f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Tue, 28 Feb 2023 15:05:28 +0100 Subject: [PATCH] Move global hooks into hooks directory --- site/source/components/App.tsx | 2 +- site/source/components/BetaBanner/index.tsx | 3 +-- site/source/components/PageData.tsx | 4 ++-- site/source/components/QuickLinks.tsx | 3 +-- site/source/components/Simulation/Questions.tsx | 3 +-- site/source/components/Simulation/SimulationGoals.tsx | 2 +- site/source/components/conversation/AnswerList.tsx | 2 +- site/source/components/conversation/useNavigateQuestions.ts | 2 +- site/source/components/utils/DarkModeContext.tsx | 2 +- site/source/components/utils/colors.tsx | 3 +-- site/source/hooks/useCurrentSimulatorData.ts | 2 +- site/source/{components/utils => hooks}/useIsEmbedded.tsx | 0 site/source/{components/utils => hooks}/useNextQuestion.tsx | 2 +- site/source/hooks/useQuestionList.ts | 2 +- .../source/{components/utils => hooks}/useSimulationConfig.ts | 0 site/source/pages/Simulateurs/Home.tsx | 2 +- .../source/pages/Simulateurs/artiste-auteur/ArtisteAuteur.tsx | 2 +- site/source/pages/Simulateurs/index.tsx | 2 +- .../source/pages/Simulateurs/économie-collaborative/index.tsx | 2 +- site/source/pages/gerer/components/Fields.tsx | 2 +- .../gerer/declaration-charges-sociales-independant/index.tsx | 2 +- .../gerer/declaration-revenu-independants/cotisations.tsx | 2 +- .../pages/gerer/declaration-revenu-independants/index.tsx | 4 ++-- site/source/pages/gerer/demande-mobilité/index.tsx | 2 +- site/source/pages/gerer/index.tsx | 2 +- site/test/conversation.test.ts | 2 +- 26 files changed, 26 insertions(+), 30 deletions(-) rename site/source/{components/utils => hooks}/useIsEmbedded.tsx (100%) rename site/source/{components/utils => hooks}/useNextQuestion.tsx (97%) rename site/source/{components/utils => hooks}/useSimulationConfig.ts (100%) diff --git a/site/source/components/App.tsx b/site/source/components/App.tsx index d3b53e5bd..69244fab2 100644 --- a/site/source/components/App.tsx +++ b/site/source/components/App.tsx @@ -16,8 +16,8 @@ import { useEngine, useSetupSafeSituation, } from '@/components/utils/EngineContext' -import { useIsEmbedded } from '@/components/utils/useIsEmbedded' import { Container, Spacing } from '@/design-system/layout' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' import { useAxeCoreAnalysis } from '../hooks/useAxeCoreAnalysis' import { useGetFullURL } from '../hooks/useGetFullURL' diff --git a/site/source/components/BetaBanner/index.tsx b/site/source/components/BetaBanner/index.tsx index 7ad0cdcb1..cebd6a1ae 100644 --- a/site/source/components/BetaBanner/index.tsx +++ b/site/source/components/BetaBanner/index.tsx @@ -7,8 +7,7 @@ import { CloseButton } from '@/design-system/buttons' import { Emoji } from '@/design-system/emoji' import { Strong } from '@/design-system/typography' import { Body } from '@/design-system/typography/paragraphs' - -import { useIsEmbedded } from '../utils/useIsEmbedded' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' export default function BetaBanner() { const isEmbedded = useIsEmbedded() diff --git a/site/source/components/PageData.tsx b/site/source/components/PageData.tsx index 253d443fa..1daa69c12 100644 --- a/site/source/components/PageData.tsx +++ b/site/source/components/PageData.tsx @@ -4,15 +4,15 @@ import { useLocation } from 'react-router-dom' import styled from 'styled-components' import Meta from '@/components/utils/Meta' -import { useIsEmbedded } from '@/components/utils/useIsEmbedded' import useSearchParamsSimulationSharing from '@/components/utils/useSearchParamsSimulationSharing' -import useSimulationConfig from '@/components/utils/useSimulationConfig' import { Chip } from '@/design-system' import { Emoji } from '@/design-system/emoji' import { Spacing } from '@/design-system/layout' import { H1 } from '@/design-system/typography/heading' import { Intro } from '@/design-system/typography/paragraphs' import { useCurrentSimulatorData } from '@/hooks/useCurrentSimulatorData' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' +import useSimulationConfig from '@/hooks/useSimulationConfig' import { situationSelector } from '@/store/selectors/simulationSelectors' import { NextSteps } from '../pages/Simulateurs/NextSteps' diff --git a/site/source/components/QuickLinks.tsx b/site/source/components/QuickLinks.tsx index d66d48317..0aff96f88 100644 --- a/site/source/components/QuickLinks.tsx +++ b/site/source/components/QuickLinks.tsx @@ -5,6 +5,7 @@ import styled from 'styled-components' import { Spacing } from '@/design-system/layout' import { Link } from '@/design-system/typography/link' import { SmallBody } from '@/design-system/typography/paragraphs' +import { useNextQuestions } from '@/hooks/useNextQuestion' import { goToQuestion } from '@/store/actions/actions' import { RootState } from '@/store/reducers/rootReducer' import { @@ -12,8 +13,6 @@ import { currentQuestionSelector, } from '@/store/selectors/simulationSelectors' -import { useNextQuestions } from './utils/useNextQuestion' - export default function QuickLinks() { const currentQuestion = useSelector(currentQuestionSelector) const nextSteps = useNextQuestions() diff --git a/site/source/components/Simulation/Questions.tsx b/site/source/components/Simulation/Questions.tsx index dadf1b594..772f99bf0 100644 --- a/site/source/components/Simulation/Questions.tsx +++ b/site/source/components/Simulation/Questions.tsx @@ -8,8 +8,7 @@ import Conversation, { } from '@/components/conversation/Conversation' import Progress from '@/components/ui/Progress' import { Body } from '@/design-system/typography/paragraphs' - -import { useSimulationProgress } from './../utils/useNextQuestion' +import { useSimulationProgress } from '@/hooks/useNextQuestion' const QuestionsContainer = styled.div` padding: ${({ theme }) => ` ${theme.spacings.xs} ${theme.spacings.lg}`}; diff --git a/site/source/components/Simulation/SimulationGoals.tsx b/site/source/components/Simulation/SimulationGoals.tsx index 89c56647f..ffe1e0dc2 100644 --- a/site/source/components/Simulation/SimulationGoals.tsx +++ b/site/source/components/Simulation/SimulationGoals.tsx @@ -7,11 +7,11 @@ import { ForceThemeProvider } from '@/components/utils/DarkModeContext' import { Grid } from '@/design-system/layout' import { Link } from '@/design-system/typography/link' import { SmallBody } from '@/design-system/typography/paragraphs' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' import { firstStepCompletedSelector } from '@/store/selectors/simulationSelectors' import { Logo } from '../Logo' import { WatchInitialRender } from '../utils/useInitialRender' -import { useIsEmbedded } from '../utils/useIsEmbedded' type SimulationGoalsProps = { legend: string diff --git a/site/source/components/conversation/AnswerList.tsx b/site/source/components/conversation/AnswerList.tsx index e74ec29c5..5093a2925 100644 --- a/site/source/components/conversation/AnswerList.tsx +++ b/site/source/components/conversation/AnswerList.tsx @@ -6,7 +6,6 @@ import { useDispatch, useSelector } from 'react-redux' import styled from 'styled-components' import { EvaluatedRule, useEngine } from '@/components/utils/EngineContext' -import { useNextQuestions } from '@/components/utils/useNextQuestion' import { Message, PopoverWithTrigger } from '@/design-system' import { Button } from '@/design-system/buttons' import { Emoji } from '@/design-system/emoji' @@ -17,6 +16,7 @@ import { H2, H3 } from '@/design-system/typography/heading' import { Link } from '@/design-system/typography/link' import { Body, Intro } from '@/design-system/typography/paragraphs' import { useCurrentSimulatorData } from '@/hooks/useCurrentSimulatorData' +import { useNextQuestions } from '@/hooks/useNextQuestion' import { answerQuestion, resetSimulation } from '@/store/actions/actions' import { resetCompany } from '@/store/actions/companyActions' import { isCompanyDottedName } from '@/store/reducers/companySituationReducer' diff --git a/site/source/components/conversation/useNavigateQuestions.ts b/site/source/components/conversation/useNavigateQuestions.ts index 0b49df7b9..c8b78b37f 100644 --- a/site/source/components/conversation/useNavigateQuestions.ts +++ b/site/source/components/conversation/useNavigateQuestions.ts @@ -4,7 +4,7 @@ import { useEffect } from 'react' import { useDispatch, useSelector } from 'react-redux' import { useEngine } from '@/components/utils/EngineContext' -import { useNextQuestions } from '@/components/utils/useNextQuestion' +import { useNextQuestions } from '@/hooks/useNextQuestion' import { goToQuestion, stepAction, diff --git a/site/source/components/utils/DarkModeContext.tsx b/site/source/components/utils/DarkModeContext.tsx index dc4017498..323e5f085 100644 --- a/site/source/components/utils/DarkModeContext.tsx +++ b/site/source/components/utils/DarkModeContext.tsx @@ -1,8 +1,8 @@ import { ReactNode, createContext, useState } from 'react' import { ThemeProvider } from 'styled-components' -import { useIsEmbedded } from '@/components/utils/useIsEmbedded' import { useDarkMode } from '@/hooks/useDarkMode' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' import { getItem, setItem } from '@/storage/safeLocalStorage' type DarkModeContextType = [boolean, (darkMode: boolean) => void] diff --git a/site/source/components/utils/colors.tsx b/site/source/components/utils/colors.tsx index d4e550a70..0ab4bad8f 100644 --- a/site/source/components/utils/colors.tsx +++ b/site/source/components/utils/colors.tsx @@ -1,10 +1,9 @@ import React, { useEffect, useRef, useState } from 'react' import { ThemeProvider } from 'styled-components' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' import { hexToHSL } from '@/utils/hexToHSL' -import { useIsEmbedded } from './useIsEmbedded' - type ProviderProps = { color?: [number, number, number] children: React.ReactNode diff --git a/site/source/hooks/useCurrentSimulatorData.ts b/site/source/hooks/useCurrentSimulatorData.ts index c933c3eb9..bc7eee174 100644 --- a/site/source/hooks/useCurrentSimulatorData.ts +++ b/site/source/hooks/useCurrentSimulatorData.ts @@ -1,6 +1,6 @@ import { useLocation } from 'react-router-dom' -import { useIsEmbedded } from '@/components/utils/useIsEmbedded' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' import { Merge, ToOptional } from '@/types/utils' import useSimulatorsData, { SimulatorDataValues } from './useSimulatorsData' diff --git a/site/source/components/utils/useIsEmbedded.tsx b/site/source/hooks/useIsEmbedded.tsx similarity index 100% rename from site/source/components/utils/useIsEmbedded.tsx rename to site/source/hooks/useIsEmbedded.tsx diff --git a/site/source/components/utils/useNextQuestion.tsx b/site/source/hooks/useNextQuestion.tsx similarity index 97% rename from site/source/components/utils/useNextQuestion.tsx rename to site/source/hooks/useNextQuestion.tsx index 942cf7aec..fe98a1800 100644 --- a/site/source/components/utils/useNextQuestion.tsx +++ b/site/source/hooks/useNextQuestion.tsx @@ -11,7 +11,7 @@ import { } from '@/store/selectors/simulationSelectors' import { ImmutableType } from '@/types/utils' -import { useEngine } from './EngineContext' +import { useEngine } from '../components/utils/EngineContext' type MissingVariables = Partial> diff --git a/site/source/hooks/useQuestionList.ts b/site/source/hooks/useQuestionList.ts index bd59cc526..955da8305 100644 --- a/site/source/hooks/useQuestionList.ts +++ b/site/source/hooks/useQuestionList.ts @@ -3,7 +3,7 @@ import { PublicodesExpression, RuleNode } from 'publicodes' import { useDispatch, useSelector } from 'react-redux' import { useEngine } from '@/components/utils/EngineContext' -import { useNextQuestions } from '@/components/utils/useNextQuestion' +import { useNextQuestions } from '@/hooks/useNextQuestion' import { stepAction, updateSituation } from '@/store/actions/actions' import { answeredQuestionsSelector } from '@/store/selectors/simulationSelectors' diff --git a/site/source/components/utils/useSimulationConfig.ts b/site/source/hooks/useSimulationConfig.ts similarity index 100% rename from site/source/components/utils/useSimulationConfig.ts rename to site/source/hooks/useSimulationConfig.ts diff --git a/site/source/pages/Simulateurs/Home.tsx b/site/source/pages/Simulateurs/Home.tsx index b8e6607ab..876479d1f 100644 --- a/site/source/pages/Simulateurs/Home.tsx +++ b/site/source/pages/Simulateurs/Home.tsx @@ -2,7 +2,6 @@ import { Trans, useTranslation } from 'react-i18next' import { TrackPage } from '@/components/ATInternetTracking' import PageHeader from '@/components/PageHeader' -import { useIsEmbedded } from '@/components/utils/useIsEmbedded' import { Chip } from '@/design-system' import InfoBulle from '@/design-system/InfoBulle' import { Card } from '@/design-system/card' @@ -15,6 +14,7 @@ import { Link } from '@/design-system/typography/link' import { Li, Ul } from '@/design-system/typography/list' import { Body, Intro } from '@/design-system/typography/paragraphs' import { MergedSimulatorDataValues } from '@/hooks/useCurrentSimulatorData' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' import useSimulatorsData from '@/hooks/useSimulatorsData' import { useSitePaths } from '@/sitePaths' diff --git a/site/source/pages/Simulateurs/artiste-auteur/ArtisteAuteur.tsx b/site/source/pages/Simulateurs/artiste-auteur/ArtisteAuteur.tsx index 4368ff3bb..625b11287 100644 --- a/site/source/pages/Simulateurs/artiste-auteur/ArtisteAuteur.tsx +++ b/site/source/pages/Simulateurs/artiste-auteur/ArtisteAuteur.tsx @@ -11,8 +11,8 @@ import Simulation, { } from '@/components/Simulation' import { InstitutionsPartenairesArtisteAuteur } from '@/components/simulationExplanation/InstitutionsPartenaires' import { EngineContext } from '@/components/utils/EngineContext' -import useSimulationConfig from '@/components/utils/useSimulationConfig' import { H2 } from '@/design-system/typography/heading' +import useSimulationConfig from '@/hooks/useSimulationConfig' import { configArtisteAuteur } from './simulationConfig' diff --git a/site/source/pages/Simulateurs/index.tsx b/site/source/pages/Simulateurs/index.tsx index 42ef6fd98..4326ec904 100644 --- a/site/source/pages/Simulateurs/index.tsx +++ b/site/source/pages/Simulateurs/index.tsx @@ -4,8 +4,8 @@ import { Route, Routes, useLocation } from 'react-router-dom' import { ScrollToTop } from '@/components/utils/Scroll' import { usePersistingState } from '@/components/utils/persistState' -import { useIsEmbedded } from '@/components/utils/useIsEmbedded' import { Link } from '@/design-system/typography/link' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' import useSimulatorsData from '@/hooks/useSimulatorsData' import { useSitePaths } from '@/sitePaths' diff --git a/site/source/pages/Simulateurs/économie-collaborative/index.tsx b/site/source/pages/Simulateurs/économie-collaborative/index.tsx index c8ccd81b4..5480db865 100644 --- a/site/source/pages/Simulateurs/économie-collaborative/index.tsx +++ b/site/source/pages/Simulateurs/économie-collaborative/index.tsx @@ -3,8 +3,8 @@ import { Route, Routes } from 'react-router-dom' import styled from 'styled-components' import { TrackChapter } from '@/components/ATInternetTracking' -import { useIsEmbedded } from '@/components/utils/useIsEmbedded' import { Link } from '@/design-system/typography/link' +import { useIsEmbedded } from '@/hooks/useIsEmbedded' import useSimulatorsData from '@/hooks/useSimulatorsData' import { useSitePaths } from '@/sitePaths' diff --git a/site/source/pages/gerer/components/Fields.tsx b/site/source/pages/gerer/components/Fields.tsx index 1502e4625..0c104b285 100644 --- a/site/source/pages/gerer/components/Fields.tsx +++ b/site/source/pages/gerer/components/Fields.tsx @@ -11,10 +11,10 @@ import RuleInput from '@/components/conversation/RuleInput' import { FadeIn } from '@/components/ui/animate' import { EngineContext } from '@/components/utils/EngineContext' import { Markdown } from '@/components/utils/markdown' -import { useNextQuestions } from '@/components/utils/useNextQuestion' import { Spacing } from '@/design-system/layout' import { H3 } from '@/design-system/typography/heading' import { Intro, SmallBody } from '@/design-system/typography/paragraphs' +import { useNextQuestions } from '@/hooks/useNextQuestion' import { updateSituation } from '@/store/actions/actions' import { situationSelector, diff --git a/site/source/pages/gerer/declaration-charges-sociales-independant/index.tsx b/site/source/pages/gerer/declaration-charges-sociales-independant/index.tsx index 8a8a8b722..10ce92177 100644 --- a/site/source/pages/gerer/declaration-charges-sociales-independant/index.tsx +++ b/site/source/pages/gerer/declaration-charges-sociales-independant/index.tsx @@ -12,12 +12,12 @@ import RuleInput from '@/components/conversation/RuleInput' import Warning from '@/components/ui/WarningBlock' import { FromTop } from '@/components/ui/animate' import DefaultHelmet from '@/components/utils/DefaultHelmet' -import useSimulationConfig from '@/components/utils/useSimulationConfig' import { Grid } from '@/design-system/layout' import { Strong } from '@/design-system/typography' import { H2, H3 } from '@/design-system/typography/heading' import { Li, Ul } from '@/design-system/typography/list' import { Body, Intro, SmallBody } from '@/design-system/typography/paragraphs' +import useSimulationConfig from '@/hooks/useSimulationConfig' import { useSitePaths } from '@/sitePaths' import { updateSituation } from '@/store/actions/actions' import { SimulationConfig } from '@/store/reducers/rootReducer' diff --git a/site/source/pages/gerer/declaration-revenu-independants/cotisations.tsx b/site/source/pages/gerer/declaration-revenu-independants/cotisations.tsx index 052fca720..a676e7728 100644 --- a/site/source/pages/gerer/declaration-revenu-independants/cotisations.tsx +++ b/site/source/pages/gerer/declaration-revenu-independants/cotisations.tsx @@ -5,12 +5,12 @@ import Progress from '@/components/ui/Progress' import { FromTop } from '@/components/ui/animate' import { useEngine } from '@/components/utils/EngineContext' import { Markdown } from '@/components/utils/markdown' -import { useSimulationProgress } from '@/components/utils/useNextQuestion' import { Message } from '@/design-system' import { Container, Grid, Spacing } from '@/design-system/layout' import { Strong } from '@/design-system/typography' import { H2, H3 } from '@/design-system/typography/heading' import { Body, Intro } from '@/design-system/typography/paragraphs' +import { useSimulationProgress } from '@/hooks/useNextQuestion' import { SimpleField } from '../components/Fields' import { DéclarationRevenu } from './components/DéclarationRevenu' diff --git a/site/source/pages/gerer/declaration-revenu-independants/index.tsx b/site/source/pages/gerer/declaration-revenu-independants/index.tsx index fe52b71c7..2e5bdc5ad 100644 --- a/site/source/pages/gerer/declaration-revenu-independants/index.tsx +++ b/site/source/pages/gerer/declaration-revenu-independants/index.tsx @@ -5,10 +5,10 @@ import { Condition } from '@/components/EngineValue' import PrintExportRecover from '@/components/simulationExplanation/PrintExportRecover' import DefaultHelmet from '@/components/utils/DefaultHelmet' import { useEngine } from '@/components/utils/EngineContext' -import { useSimulationProgress } from '@/components/utils/useNextQuestion' -import useSimulationConfig from '@/components/utils/useSimulationConfig' import { Step, Stepper } from '@/design-system' import { Spacing } from '@/design-system/layout' +import { useSimulationProgress } from '@/hooks/useNextQuestion' +import useSimulationConfig from '@/hooks/useSimulationConfig' import { useSitePaths } from '@/sitePaths' import { SimulationConfig } from '@/store/reducers/rootReducer' import { omit } from '@/utils' diff --git a/site/source/pages/gerer/demande-mobilité/index.tsx b/site/source/pages/gerer/demande-mobilité/index.tsx index ae060a7a1..51ee03fdb 100644 --- a/site/source/pages/gerer/demande-mobilité/index.tsx +++ b/site/source/pages/gerer/demande-mobilité/index.tsx @@ -11,13 +11,13 @@ import DefaultHelmet from '@/components/utils/DefaultHelmet' import { EngineContext, EngineProvider } from '@/components/utils/EngineContext' import { Markdown } from '@/components/utils/markdown' import { usePersistingState } from '@/components/utils/persistState' -import useSimulationConfig from '@/components/utils/useSimulationConfig' import { Button } from '@/design-system/buttons' import { Emoji } from '@/design-system/emoji' import { Grid, Spacing } from '@/design-system/layout' import PopoverConfirm from '@/design-system/popover/PopoverConfirm' import { headings } from '@/design-system/typography' import { Intro, SmallBody } from '@/design-system/typography/paragraphs' +import useSimulationConfig from '@/hooks/useSimulationConfig' import { buildSituationFromObject, evaluateQuestion, diff --git a/site/source/pages/gerer/index.tsx b/site/source/pages/gerer/index.tsx index 444769434..3e8dbe360 100644 --- a/site/source/pages/gerer/index.tsx +++ b/site/source/pages/gerer/index.tsx @@ -35,7 +35,6 @@ import DefaultHelmet from '@/components/utils/DefaultHelmet' import { useEngine } from '@/components/utils/EngineContext' import { ScrollToTop } from '@/components/utils/Scroll' import { Markdown } from '@/components/utils/markdown' -import useSimulationConfig from '@/components/utils/useSimulationConfig' import { Message, Popover } from '@/design-system' import { Button } from '@/design-system/buttons' import { Emoji } from '@/design-system/emoji' @@ -46,6 +45,7 @@ import { Link } from '@/design-system/typography/link' import { Body, Intro } from '@/design-system/typography/paragraphs' import { useQuestionList } from '@/hooks/useQuestionList' import { useSetEntreprise } from '@/hooks/useSetEntreprise' +import useSimulationConfig from '@/hooks/useSimulationConfig' import useSimulatorsData, { SimulatorData } from '@/hooks/useSimulatorsData' import { useSitePaths } from '@/sitePaths' import { resetCompany } from '@/store/actions/companyActions' diff --git a/site/test/conversation.test.ts b/site/test/conversation.test.ts index f9c373cea..a79acd8e7 100644 --- a/site/test/conversation.test.ts +++ b/site/test/conversation.test.ts @@ -2,7 +2,7 @@ import rules from 'modele-social' import Engine from 'publicodes' import { describe, expect, it } from 'vitest' -import { getNextQuestions } from '../source/components/utils/useNextQuestion' +import { getNextQuestions } from '../source/hooks/useNextQuestion' describe('conversation', function () { it('should start with the first missing variable', function () {