diff --git a/src/components/Action/ActionDone.tsx b/src/components/Action/ActionDone.tsx index 099c9465febbb923f08efee022b1547078387524..b1ee82f5b446e46c0a157b5908804c326163ed20 100644 --- a/src/components/Action/ActionDone.tsx +++ b/src/components/Action/ActionDone.tsx @@ -13,7 +13,7 @@ import ChallengeService from 'services/challenge.service' import UsageEventService from 'services/usageEvent.service' import { AppActionsTypes } from 'store' import { updateUserChallengeList } from 'store/challenge/challenge.slice' -import { toggleChallengeActionNotification } from 'store/global/global.actions' +import { toggleChallengeActionNotification } from 'store/global/global.slice' import './actionDone.scss' const ActionDone = ({ diff --git a/src/components/Analysis/AnalysisView.spec.tsx b/src/components/Analysis/AnalysisView.spec.tsx index 26f19004286e1d84ef8bf7c62570f21d7ff3577c..253e7a9f965bd67a52797f51ca794c5276d243ec 100644 --- a/src/components/Analysis/AnalysisView.spec.tsx +++ b/src/components/Analysis/AnalysisView.spec.tsx @@ -3,7 +3,7 @@ import { mount } from 'enzyme' import React from 'react' import * as reactRedux from 'react-redux' import { Provider } from 'react-redux' -import * as globalActions from 'store/global/global.actions' +import * as globalActions from 'store/global/global.slice' import * as profileActions from 'store/profile/profile.actions' import { globalStateData } from '../../../tests/__mocks__/globalStateData.mock' import { profileData } from '../../../tests/__mocks__/profileData.mock' diff --git a/src/components/Analysis/AnalysisView.tsx b/src/components/Analysis/AnalysisView.tsx index 528b6b87706ae8408abd1a34f3972fc61bcfc273..58ef3f06c7fe886c55457ab32356216fd2dc6dc0 100644 --- a/src/components/Analysis/AnalysisView.tsx +++ b/src/components/Analysis/AnalysisView.tsx @@ -14,7 +14,7 @@ import DateChartService from 'services/dateChart.service' import UsageEventService from 'services/usageEvent.service' import { AppActionsTypes, AppStore } from 'store' import { setAnalysisMonth } from 'store/analysis/analysis.slice' -import { toggleAnalysisNotification } from 'store/global/global.actions' +import { toggleAnalysisNotification } from 'store/global/global.slice' import { updateProfile } from 'store/profile/profile.actions' import { isLastDateReached } from 'utils/date' import './analysisView.scss' diff --git a/src/components/Connection/Connection.tsx b/src/components/Connection/Connection.tsx index 3e0aedc0f10ce68b2ec0df6c396c7be7b5f58bc8..bf29cd77bfb42391eff47d60a1db908da2d616c1 100644 --- a/src/components/Connection/Connection.tsx +++ b/src/components/Connection/Connection.tsx @@ -3,7 +3,7 @@ import { FluidConnection, FluidStatus } from 'models' import React, { Dispatch, useCallback } from 'react' import { useDispatch } from 'react-redux' import { AppActionsTypes } from 'store' -import { updatedFluidConnection } from 'store/global/global.actions' +import { updateFluidConnection } from 'store/global/global.slice' import EpglInit from './EPGLConnect/EpglInit' import GrdfInit from './GRDFConnect/GrdfInit' import SgeInit from './SGEConnect/SgeInit' @@ -17,7 +17,12 @@ const Connection = ({ fluidStatus }: { fluidStatus: FluidStatus }) => { ...fluidStatus.connection, shouldLaunchKonnector: true, } - dispatch(updatedFluidConnection(fluidStatus.fluidType, updatedConnection)) + dispatch( + updateFluidConnection({ + fluidType: fluidStatus.fluidType, + fluidConnection: updatedConnection, + }) + ) }, [dispatch, fluidStatus.fluidType, fluidStatus.connection]) return ( <div className="konnector-form"> diff --git a/src/components/Connection/ConnectionResult.tsx b/src/components/Connection/ConnectionResult.tsx index 27263a062697e937d31d5184a94fea4e0d43825d..5a5390ec3a4a91b8c916f1ef592d0896586aaece 100644 --- a/src/components/Connection/ConnectionResult.tsx +++ b/src/components/Connection/ConnectionResult.tsx @@ -22,9 +22,9 @@ import TriggerService from 'services/triggers.service' import { AppActionsTypes } from 'store' import { setShouldRefreshConsent, + updateFluidConnection, updateSgeStore, - updatedFluidConnection, -} from 'store/global/global.actions' +} from 'store/global/global.slice' import { getKonnectorUpdateError } from 'utils/utils' import DeleteGRDFAccountModal from './DeleteGRDFAccountModal' import './connectionResult.scss' @@ -69,7 +69,12 @@ const ConnectionResult = ({ shouldLaunchKonnector: true, isUpdating: true, } - dispatch(updatedFluidConnection(fluidStatus.fluidType, updatedConnection)) + dispatch( + updateFluidConnection({ + fluidType: fluidStatus.fluidType, + fluidConnection: updatedConnection, + }) + ) setUpdating(false) } diff --git a/src/components/Connection/ExpiredConsentModal.tsx b/src/components/Connection/ExpiredConsentModal.tsx index 194ee25246f29f482eded5ffa267aa9fceaeb08e..38b0f3c4bcc587acd85fb96513091be75d56e341 100644 --- a/src/components/Connection/ExpiredConsentModal.tsx +++ b/src/components/Connection/ExpiredConsentModal.tsx @@ -14,7 +14,7 @@ import { AppActionsTypes, AppStore } from 'store' import { setShouldRefreshConsent, updateSgeStore, -} from 'store/global/global.actions' +} from 'store/global/global.slice' import { getFluidName } from 'utils/utils' import './expiredConsentModal.scss' diff --git a/src/components/Connection/FormOAuth.tsx b/src/components/Connection/FormOAuth.tsx index 736bd4ab02b1ac37523fa4b95ed769afae25ea14..09fd2b99e645e170cf879826f53261c989609667 100644 --- a/src/components/Connection/FormOAuth.tsx +++ b/src/components/Connection/FormOAuth.tsx @@ -8,7 +8,7 @@ import React, { Dispatch, useCallback, useEffect, useState } from 'react' import { useDispatch, useSelector } from 'react-redux' import UsageEventService from 'services/usageEvent.service' import { AppActionsTypes, AppStore } from 'store' -import { setShouldRefreshConsent } from 'store/global/global.actions' +import { setShouldRefreshConsent } from 'store/global/global.slice' interface FormOAuthProps { konnector: Konnector | null diff --git a/src/components/Connection/GRDFConnect/GrdfInit.tsx b/src/components/Connection/GRDFConnect/GrdfInit.tsx index d47625171b37b485ac722f1e80bfdb00734d81f0..764509c9a7f42028eb3c12e93ca25ddf7a17f3c7 100644 --- a/src/components/Connection/GRDFConnect/GrdfInit.tsx +++ b/src/components/Connection/GRDFConnect/GrdfInit.tsx @@ -8,7 +8,7 @@ import AccountService from 'services/account.service' import TriggerService from 'services/triggers.service' import UsageEventService from 'services/usageEvent.service' import { AppActionsTypes, AppStore } from 'store' -import { updatedFluidConnection } from 'store/global/global.actions' +import { updateFluidConnection } from 'store/global/global.slice' import { openConnectionModal } from 'store/modal/modal.slice' import '../connection.scss' import GrdfBill from './GrdfBill' @@ -44,7 +44,10 @@ const GrdfInit = ({ fluidStatus, onSuccess }: GrdfInitProps) => { trigger: null, } dispatch( - updatedFluidConnection(fluidStatus.fluidType, updatedConnection) + updateFluidConnection({ + fluidType: fluidStatus.fluidType, + fluidConnection: updatedConnection, + }) ) await UsageEventService.addEvent(client, { type: UsageEventType.KONNECTOR_CONNECT_EVENT, @@ -63,7 +66,10 @@ const GrdfInit = ({ fluidStatus, onSuccess }: GrdfInitProps) => { trigger: trigger, } dispatch( - updatedFluidConnection(fluidStatus.fluidType, updatedConnection) + updateFluidConnection({ + fluidType: fluidStatus.fluidType, + fluidConnection: updatedConnection, + }) ) onSuccess() } diff --git a/src/components/Connection/SGEConnect/SgeConnectView.tsx b/src/components/Connection/SGEConnect/SgeConnectView.tsx index c2e0c11cb5e007a0bc673c5de238a245bd71e110..9619c6b72aa8ba9b69c8eac8d02b415d4e102021 100644 --- a/src/components/Connection/SGEConnect/SgeConnectView.tsx +++ b/src/components/Connection/SGEConnect/SgeConnectView.tsx @@ -8,7 +8,7 @@ import { SgeStore } from 'models/sgeStore.model' import React, { Dispatch, useCallback, useState } from 'react' import { useDispatch, useSelector } from 'react-redux' import { AppActionsTypes, AppStore } from 'store' -import { updateSgeStore } from 'store/global/global.actions' +import { updateSgeStore } from 'store/global/global.slice' import './SgeConnect.scss' import StepAddress from './StepAddress' import StepConsent from './StepConsent' diff --git a/src/components/Connection/SGEConnect/SgeInit.tsx b/src/components/Connection/SGEConnect/SgeInit.tsx index 530045358d0eb2b7be18a649e5640dfb10e0ca61..ecec4ebab48cff9c64a784a8daaaed0c4db066be 100644 --- a/src/components/Connection/SGEConnect/SgeInit.tsx +++ b/src/components/Connection/SGEConnect/SgeInit.tsx @@ -12,7 +12,7 @@ import { setShowOfflineData } from 'store/chart/chart.slice' import { setShouldRefreshConsent, updateSgeStore, -} from 'store/global/global.actions' +} from 'store/global/global.slice' import { decoreText } from 'utils/decoreText' const SgeInit = ({ fluidStatus }: { fluidStatus: FluidStatus }) => { diff --git a/src/components/Content/Content.tsx b/src/components/Content/Content.tsx index caf29cd956b6185a27e3130d7256889265622533..da2111065187f3f116f51a620c5469d43eb2910a 100644 --- a/src/components/Content/Content.tsx +++ b/src/components/Content/Content.tsx @@ -3,7 +3,7 @@ import { ScreenType } from 'enum/screen.enum' import React, { Dispatch, useCallback, useEffect } from 'react' import { useDispatch, useSelector } from 'react-redux' import { AppActionsTypes, AppStore } from 'store' -import { changeScreenType } from 'store/global/global.actions' +import { changeScreenType } from 'store/global/global.slice' import { openFeedbackModal } from 'store/modal/modal.slice' import './content.scss' interface ContentProps { diff --git a/src/components/Duel/DuelOngoing.tsx b/src/components/Duel/DuelOngoing.tsx index 2b9eef56d7f14ae68c3c88dd54efa43485acc919..98f13ec4bef5cfed2a2e840e4c6e3b2c0b4adc33 100644 --- a/src/components/Duel/DuelOngoing.tsx +++ b/src/components/Duel/DuelOngoing.tsx @@ -32,7 +32,7 @@ import { unlockNextUserChallenge, updateUserChallengeList, } from 'store/challenge/challenge.slice' -import { toggleChallengeDuelNotification } from 'store/global/global.actions' +import { toggleChallengeDuelNotification } from 'store/global/global.slice' import { formatNumberValues } from 'utils/utils' import './duelOngoing.scss' diff --git a/src/components/Exploration/ExplorationFinished.tsx b/src/components/Exploration/ExplorationFinished.tsx index bbc2d5365db2528cd646f224d497c56ba32c63b8..d0382020c075a760250522d2e7f19f7950eec678 100644 --- a/src/components/Exploration/ExplorationFinished.tsx +++ b/src/components/Exploration/ExplorationFinished.tsx @@ -14,7 +14,7 @@ import ChallengeService from 'services/challenge.service' import UsageEventService from 'services/usageEvent.service' import { AppActionsTypes } from 'store' import { updateUserChallengeList } from 'store/challenge/challenge.slice' -import { toggleChallengeExplorationNotification } from 'store/global/global.actions' +import { toggleChallengeExplorationNotification } from 'store/global/global.slice' import './explorationFinished.scss' interface ExplorationFinishedProps { diff --git a/src/components/Home/ConsumptionView.tsx b/src/components/Home/ConsumptionView.tsx index f823dbdf2100188ecb1ffa58acf755c296d60af3..c34985012334adde67c4d2c1013feee68e059aa1 100644 --- a/src/components/Home/ConsumptionView.tsx +++ b/src/components/Home/ConsumptionView.tsx @@ -28,7 +28,7 @@ import { setSelectedDate, setShowOfflineData, } from 'store/chart/chart.slice' -import { showReleaseNotes } from 'store/global/global.actions' +import { showReleaseNotes } from 'store/global/global.slice' import { openPartnersModal, setCustomPopup } from 'store/modal/modal.slice' import { isLastDateReached } from 'utils/date' import { @@ -88,7 +88,11 @@ const ConsumptionView = ({ fluidType }: { fluidType: FluidType }) => { const handleCloseReleaseNoteModal = useCallback(() => { setOpenReleaseNoteModal(false) dispatch( - showReleaseNotes(false, releaseNotes.notes, releaseNotes.redirectLink) + showReleaseNotes({ + show: false, + notes: releaseNotes.notes, + redirectLink: releaseNotes.redirectLink, + }) ) if (releaseNotes.redirectLink) { navigate(releaseNotes.redirectLink) diff --git a/src/components/Hooks/useExploration.tsx b/src/components/Hooks/useExploration.tsx index a42e644f23f0b7807f8badc83361f100124988d2..8874651fd3d64c6d4f88a096e8117d958cb798d1 100644 --- a/src/components/Hooks/useExploration.tsx +++ b/src/components/Hooks/useExploration.tsx @@ -6,7 +6,7 @@ import { useDispatch, useSelector } from 'react-redux' import ExplorationService from 'services/exploration.service' import { AppActionsTypes, AppStore } from 'store' import { updateUserChallengeList } from 'store/challenge/challenge.slice' -import { toggleChallengeExplorationNotification } from 'store/global/global.actions' +import { toggleChallengeExplorationNotification } from 'store/global/global.slice' const useExploration = (): [string, Dispatch<SetStateAction<string>>] => { const client: Client = useClient() diff --git a/src/components/Hooks/useKonnectorAuth.tsx b/src/components/Hooks/useKonnectorAuth.tsx index d1d1c0bf9bea1937fdb12a4a0feae1f674b127a3..8d34bc5bfe44a77aa7e5d342888a18a9aabc2856 100644 --- a/src/components/Hooks/useKonnectorAuth.tsx +++ b/src/components/Hooks/useKonnectorAuth.tsx @@ -17,7 +17,7 @@ import ConnectionService from 'services/connection.service' import UsageEventService from 'services/usageEvent.service' import { AppActionsTypes, AppStore } from 'store' import { setLoading } from 'store/chart/chart.slice' -import { updatedFluidConnection } from 'store/global/global.actions' +import { updateFluidConnection } from 'store/global/global.slice' import logApp from 'utils/logger' const useKonnectorAuth = ( @@ -39,7 +39,12 @@ const useKonnectorAuth = ( ...fluidStatus.connection, shouldLaunchKonnector: true, } - dispatch(updatedFluidConnection(fluidStatus.fluidType, updatedConnection)) + dispatch( + updateFluidConnection({ + fluidType: fluidStatus.fluidType, + fluidConnection: updatedConnection, + }) + ) }, [dispatch, fluidStatus.fluidType, fluidStatus.connection]) const sendUsageEventError = async (slug: string): Promise<UsageEvent> => { @@ -81,7 +86,12 @@ const useKonnectorAuth = ( trigger: _trigger, } setLoading(false) - dispatch(updatedFluidConnection(fluidStatus.fluidType, updatedConnection)) + dispatch( + updateFluidConnection({ + fluidType: fluidStatus.fluidType, + fluidConnection: updatedConnection, + }) + ) onSuccess() } catch (error) { setLoading(false) @@ -117,7 +127,12 @@ const useKonnectorAuth = ( ...fluidStatus.connection, account: updatedAccount, } - dispatch(updatedFluidConnection(fluidStatus.fluidType, updatedConnection)) + dispatch( + updateFluidConnection({ + fluidType: fluidStatus.fluidType, + fluidConnection: updatedConnection, + }) + ) onSuccess() } } diff --git a/src/components/Konnector/KonnectorViewerCard.tsx b/src/components/Konnector/KonnectorViewerCard.tsx index e5249c3d07572d46e7a8cb09ca4ab93b427bc76f..fb5d5e4dc24055dd600080cd3085e23066cf253b 100644 --- a/src/components/Konnector/KonnectorViewerCard.tsx +++ b/src/components/Konnector/KonnectorViewerCard.tsx @@ -63,7 +63,7 @@ import { setFluidStatus, toggleChallengeDuelNotification, updatedFluidConnection, -} from 'store/global/global.actions' +} from 'store/global/global.slice' import { openConnectionModal } from 'store/modal/modal.slice' import { getAddPicto, getParamPicto } from 'utils/picto' import { getKonnectorSlug } from 'utils/utils' diff --git a/src/components/Splash/SplashRoot.tsx b/src/components/Splash/SplashRoot.tsx index 6559550039424c1254a815af1257d65b8e675e4e..8dc9e0c7807355bc29a4ed74739a7390d11eade5 100644 --- a/src/components/Splash/SplashRoot.tsx +++ b/src/components/Splash/SplashRoot.tsx @@ -53,8 +53,8 @@ import { toggleChallengeActionNotification, toggleChallengeDuelNotification, toggleChallengeExplorationNotification, - updateTermValidation, -} from 'store/global/global.actions' + updateTermsStatus, +} from 'store/global/global.slice' import { openPartnersModal, setCustomPopup } from 'store/modal/modal.slice' import { updateProfile } from 'store/profile/profile.actions' import { updateProfileEcogestureSuccess } from 'store/profileEcogesture/profileEcogesture.actions' @@ -208,7 +208,7 @@ const SplashRoot = ({ fadeTimer = 1000, children }: SplashRootProps) => { try { // init Terms const termsStatus = await initializationService.initConsent() - if (subscribed) dispatch(updateTermValidation(termsStatus)) + if (subscribed) dispatch(updateTermsStatus(termsStatus)) // Init fluidPrices await initializationService.initFluidPrices() @@ -222,11 +222,11 @@ const SplashRoot = ({ fadeTimer = 1000, children }: SplashRootProps) => { const migrationsResult = await ms.runMigrations(migrations) // Init last release notes when they exist dispatch( - showReleaseNotes( - migrationsResult.show, - migrationsResult.notes, - migrationsResult.redirectLink - ) + showReleaseNotes({ + notes: migrationsResult.notes, + redirectLink: migrationsResult.redirectLink, + show: migrationsResult.show, + }) ) if (subscribed && profile) { setValidExploration(UserExplorationID.EXPLORATION007) diff --git a/src/components/Terms/TermsView.tsx b/src/components/Terms/TermsView.tsx index 5ce7b5a0c550ee620b257ffbeeb3ba17e5f46783..113ec79c8cf8802b9ed4099e00293c8498f7b65e 100644 --- a/src/components/Terms/TermsView.tsx +++ b/src/components/Terms/TermsView.tsx @@ -7,7 +7,7 @@ import { useDispatch, useSelector } from 'react-redux' import { useNavigate } from 'react-router-dom' import TermsService from 'services/terms.service' import { AppActionsTypes, AppStore } from 'store' -import { updateTermValidation } from 'store/global/global.actions' +import { updateTermsStatus } from 'store/global/global.slice' import { decoreText } from 'utils/decoreText' import CGUModal from './CGUModal' import DataShareConsentContent from './DataShareConsentContent' @@ -48,7 +48,7 @@ const TermsView = () => { const createdTerm = await termsService.createTerm() if (createdTerm) { dispatch( - updateTermValidation({ + updateTermsStatus({ accepted: true, versionType: await termsService.getTermsVersionType(), }) diff --git a/src/store/global/global.action.spec.ts b/src/store/global/global.action.spec.ts deleted file mode 100644 index 255bdc56ca394e2e97bf2970aded58109bd10a7f..0000000000000000000000000000000000000000 --- a/src/store/global/global.action.spec.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { ScreenType } from 'enum/screen.enum' -import { mockInitialGlobalState } from '../../../tests/__mocks__/store' -import { - CHANGE_SCREEN_TYPE, - GlobalActionTypes, - SET_FLUID_STATUS, - TOGGLE_ANALYSIS_NOTIFICATION, - TOGGLE_CHALLENGE_ACTION_NOTIFICATION, - TOGGLE_CHALLENGE_DUEL_NOTIFICATION, - TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION, - changeScreenType, - setFluidStatus, - toggleAnalysisNotification, - toggleChallengeActionNotification, - toggleChallengeDuelNotification, - toggleChallengeExplorationNotification, -} from './global.actions' - -describe('global actions', () => { - it('should create an action to change screenType', () => { - const screenType = ScreenType.DESKTOP - const expectedAction: GlobalActionTypes = { - type: CHANGE_SCREEN_TYPE, - payload: screenType, - } - expect(changeScreenType(screenType)).toEqual(expectedAction) - }) - - it('should create an action to toggle challenge exploration notification', () => { - const notification = true - const expectedAction: GlobalActionTypes = { - type: TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION, - payload: notification, - } - expect(toggleChallengeExplorationNotification(notification)).toEqual( - expectedAction - ) - }) - - it('should create an action to toggle challenge action notification', () => { - const notification = true - const expectedAction: GlobalActionTypes = { - type: TOGGLE_CHALLENGE_ACTION_NOTIFICATION, - payload: notification, - } - expect(toggleChallengeActionNotification(notification)).toEqual( - expectedAction - ) - }) - - it('should create an action to toggle challenge duel notification', () => { - const notification = true - const expectedAction: GlobalActionTypes = { - type: TOGGLE_CHALLENGE_DUEL_NOTIFICATION, - payload: notification, - } - expect(toggleChallengeDuelNotification(notification)).toEqual( - expectedAction - ) - }) - - it('should create an action to toggle analysis notification', () => { - const notification = true - const expectedAction: GlobalActionTypes = { - type: TOGGLE_ANALYSIS_NOTIFICATION, - payload: notification, - } - expect(toggleAnalysisNotification(notification)).toEqual(expectedAction) - }) - - it('should create an action to set fluid status', () => { - const fluidStatus = mockInitialGlobalState.fluidStatus - const expectedAction: GlobalActionTypes = { - type: SET_FLUID_STATUS, - payload: fluidStatus, - } - expect(setFluidStatus(fluidStatus)).toEqual(expectedAction) - }) -}) diff --git a/src/store/global/global.actions.ts b/src/store/global/global.actions.ts deleted file mode 100644 index 77a9fda4ef0157c3e7e4d90de942a82214d31260..0000000000000000000000000000000000000000 --- a/src/store/global/global.actions.ts +++ /dev/null @@ -1,204 +0,0 @@ -import { FluidType } from 'enum/fluid.enum' -import { ScreenType } from 'enum/screen.enum' -import { FluidConnection, FluidStatus, TermsStatus } from 'models' -import { PartnersInfo } from 'models/partnersInfo.model' -import { Notes } from 'models/releaseNotes.model' -import { SgeStore } from 'models/sgeStore.model' -import { defaultAction } from 'store' - -export const CHANGE_SCREEN_TYPE = 'CHANGE_SCREEN_TYPE' -export const SET_FLUID_STATUS = 'SET_FLUID_STATUS' -export const SET_PARTNERS_INFO = 'SET_PARTNERS_INFO' -export const SET_SHOULD_REFRESH_CONSENT = 'SET_SHOULD_REFRESH_CONSENT' -export const SHOW_RELEASE_NOTES = 'SHOW_RELEASE_NOTES' -export const TOGGLE_ANALYSIS_NOTIFICATION = 'TOGGLE_ANALYSIS_NOTIFICATION' -export const TOGGLE_CHALLENGE_ACTION_NOTIFICATION = - 'TOGGLE_CHALLENGE_ACTION_NOTIFICATION' -export const TOGGLE_CHALLENGE_DUEL_NOTIFICATION = - 'TOGGLE_CHALLENGE_DUEL_NOTIFICATION' -export const TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION = - 'TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION' -export const UPDATE_FLUID_CONNECTION = 'UPDATE_FLUID_CONNECTION' -export const UPDATE_SGE_CONNECT = 'UPDATE_SGE_CONNECT' -export const UPDATE_TERMS_VALIDATION = 'UPDATE_TERMS_VALIDATION' - -interface ChangeScreenType { - type: typeof CHANGE_SCREEN_TYPE - payload?: ScreenType -} - -interface SetPartnersInfo { - type: typeof SET_PARTNERS_INFO - payload?: PartnersInfo -} - -interface SetPartnersInfo { - type: typeof SET_PARTNERS_INFO - payload?: PartnersInfo -} - -interface ToggleChallengeExplorationNotification { - type: typeof TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION - payload?: boolean -} - -interface ToggleChallengeActionNotification { - type: typeof TOGGLE_CHALLENGE_ACTION_NOTIFICATION - payload?: boolean -} - -interface ToggleChallengeDuelNotification { - type: typeof TOGGLE_CHALLENGE_DUEL_NOTIFICATION - payload?: boolean -} - -interface ToggleAnalysisNotification { - type: typeof TOGGLE_ANALYSIS_NOTIFICATION - payload?: boolean -} - -interface SetFluidStatus { - type: typeof SET_FLUID_STATUS - payload?: FluidStatus[] -} - -interface UpdatedFluidConnection { - type: typeof UPDATE_FLUID_CONNECTION - payload?: { fluidType: FluidType; fluidConnection: FluidConnection } -} - -interface UpdateTermValidation { - type: typeof UPDATE_TERMS_VALIDATION - payload?: TermsStatus -} - -interface ShowReleaseNotes { - type: typeof SHOW_RELEASE_NOTES - payload?: { show: boolean; notes: Notes[]; redirectLink?: string } -} - -interface SetShouldRefreshConsent { - type: typeof SET_SHOULD_REFRESH_CONSENT - payload?: boolean -} -interface UpdateSGEConnect { - type: typeof UPDATE_SGE_CONNECT - payload?: SgeStore -} - -export function changeScreenType(screenType: ScreenType): ChangeScreenType { - return { - type: CHANGE_SCREEN_TYPE, - payload: screenType, - } -} - -export function showReleaseNotes( - show: boolean, - notes: Notes[], - redirectLink?: string -): ShowReleaseNotes { - return { - type: SHOW_RELEASE_NOTES, - payload: { show, notes, redirectLink }, - } -} - -export function toggleChallengeExplorationNotification( - notification: boolean -): ToggleChallengeExplorationNotification { - return { - type: TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION, - payload: notification, - } -} - -export function toggleChallengeActionNotification( - notification: boolean -): ToggleChallengeActionNotification { - return { - type: TOGGLE_CHALLENGE_ACTION_NOTIFICATION, - payload: notification, - } -} - -export function toggleChallengeDuelNotification( - notification: boolean -): ToggleChallengeDuelNotification { - return { - type: TOGGLE_CHALLENGE_DUEL_NOTIFICATION, - payload: notification, - } -} - -export function toggleAnalysisNotification( - notification: boolean -): ToggleAnalysisNotification { - return { - type: TOGGLE_ANALYSIS_NOTIFICATION, - payload: notification, - } -} - -export function setFluidStatus(fluidStatus: FluidStatus[]): SetFluidStatus { - return { - type: SET_FLUID_STATUS, - payload: fluidStatus, - } -} -export function updatedFluidConnection( - fluidType: FluidType, - fluidConnection: FluidConnection -): UpdatedFluidConnection { - return { - type: UPDATE_FLUID_CONNECTION, - payload: { fluidType, fluidConnection }, - } -} - -export function updateTermValidation( - termsStatus: TermsStatus -): UpdateTermValidation { - return { - type: UPDATE_TERMS_VALIDATION, - payload: termsStatus, - } -} - -export function setPartnersInfo(partnersInfo: PartnersInfo): SetPartnersInfo { - return { - type: SET_PARTNERS_INFO, - payload: partnersInfo, - } -} - -export function setShouldRefreshConsent( - shouldRefreshConsent: boolean -): SetShouldRefreshConsent { - return { - type: SET_SHOULD_REFRESH_CONSENT, - payload: shouldRefreshConsent, - } -} - -export function updateSgeStore(sgeStore: SgeStore): UpdateSGEConnect { - return { - type: UPDATE_SGE_CONNECT, - payload: sgeStore, - } -} - -export type GlobalActionTypes = - | ChangeScreenType - | ToggleChallengeExplorationNotification - | ToggleChallengeActionNotification - | ToggleChallengeDuelNotification - | ToggleAnalysisNotification - | SetFluidStatus - | UpdatedFluidConnection - | UpdateTermValidation - | ShowReleaseNotes - | SetShouldRefreshConsent - | UpdateSGEConnect - | SetPartnersInfo - | typeof defaultAction diff --git a/src/store/global/global.reducer.spec.ts b/src/store/global/global.reducer.spec.ts deleted file mode 100644 index b97675431307e3b08589a453d901050d830b00f8..0000000000000000000000000000000000000000 --- a/src/store/global/global.reducer.spec.ts +++ /dev/null @@ -1,213 +0,0 @@ -import { FluidState, FluidType } from 'enum/fluid.enum' -import { FluidSlugType } from 'enum/fluidSlug.enum' -import { ScreenType } from 'enum/screen.enum' -import { DateTime } from 'luxon' -import { FluidStatus } from 'models' -import { defaultAction } from 'store' -import { accountsData } from '../../../tests/__mocks__/accountsData.mock' -import { konnectorsData } from '../../../tests/__mocks__/konnectorsData.mock' -import { mockInitialGlobalState } from '../../../tests/__mocks__/store' -import { triggersData } from '../../../tests/__mocks__/triggersData.mock' -import { - CHANGE_SCREEN_TYPE, - SET_FLUID_STATUS, - TOGGLE_ANALYSIS_NOTIFICATION, - TOGGLE_CHALLENGE_ACTION_NOTIFICATION, - TOGGLE_CHALLENGE_DUEL_NOTIFICATION, - TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION, -} from './global.actions' -import { globalReducer } from './global.reducer' - -const nowUtc = DateTime.local().setZone('utc', { keepLocalTime: true }) -const mockDataDates = Array(3).fill(nowUtc) - -describe('global reducer', () => { - it('should return the initial state', () => { - const state = globalReducer(undefined, { ...defaultAction }) - expect(state).toEqual(mockInitialGlobalState) - }) - - describe('CHANGE_SCREEN_TYPE', () => { - it('should handle CHANGE_SCREEN_TYPE with payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: CHANGE_SCREEN_TYPE, - payload: ScreenType.DESKTOP, - }) - expect(state).toEqual({ - ...mockInitialGlobalState, - screenType: ScreenType.DESKTOP, - }) - }) - it('should handle CHANGE_SCREEN_TYPE without payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: CHANGE_SCREEN_TYPE, - }) - expect(state).toEqual(mockInitialGlobalState) - }) - }) - - describe('TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION', () => { - it('should handle TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION with payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION, - payload: true, - }) - expect(state).toEqual({ - ...mockInitialGlobalState, - challengeExplorationNotification: true, - }) - }) - - it('should handle TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION without payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION, - }) - expect(state).toEqual(mockInitialGlobalState) - }) - }) - - describe('TOGGLE_CHALLENGE_ACTION_NOTIFICATION', () => { - it('should handle TOGGLE_CHALLENGE_ACTION_NOTIFICATION with payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: TOGGLE_CHALLENGE_ACTION_NOTIFICATION, - payload: true, - }) - expect(state).toEqual({ - ...mockInitialGlobalState, - challengeActionNotification: true, - }) - }) - it('should handle TOGGLE_CHALLENGE_ACTION_NOTIFICATION without payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: TOGGLE_CHALLENGE_ACTION_NOTIFICATION, - }) - expect(state).toEqual(mockInitialGlobalState) - }) - }) - - describe('TOGGLE_CHALLENGE_DUEL_NOTIFICATION', () => { - it('should handle TOGGLE_CHALLENGE_DUEL_NOTIFICATION with payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: TOGGLE_CHALLENGE_DUEL_NOTIFICATION, - payload: true, - }) - expect(state).toEqual({ - ...mockInitialGlobalState, - challengeDuelNotification: true, - }) - }) - it('should handle TOGGLE_CHALLENGE_DUEL_NOTIFICATION without payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: TOGGLE_CHALLENGE_DUEL_NOTIFICATION, - }) - expect(state).toEqual(mockInitialGlobalState) - }) - }) - - describe('TOGGLE_ANALYSIS_NOTIFICATION', () => { - it('should handle TOGGLE_ANALYSIS_NOTIFICATION with payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: TOGGLE_ANALYSIS_NOTIFICATION, - payload: true, - }) - expect(state).toEqual({ - ...mockInitialGlobalState, - analysisNotification: true, - }) - }) - it('should handle TOGGLE_ANALYSIS_NOTIFICATION without payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: TOGGLE_ANALYSIS_NOTIFICATION, - }) - expect(state).toEqual(mockInitialGlobalState) - }) - }) - - it('should handle SET_FLUID_STATUS with payload', () => { - const fluidStatus: FluidStatus[] = [ - { - fluidType: FluidType.ELECTRICITY, - status: FluidState.ERROR, - maintenance: false, - firstDataDate: mockDataDates[FluidType.ELECTRICITY], - lastDataDate: mockDataDates[FluidType.ELECTRICITY], - connection: { - konnector: konnectorsData[0], - account: accountsData[0], - trigger: triggersData[0], - triggerState: null, - shouldLaunchKonnector: false, - isUpdating: false, - konnectorConfig: { - name: 'Enedis', - oauth: true, - slug: FluidSlugType.ELECTRICITY, - siteLink: 'https://mon-compte-particulier.enedis.fr/donnees/', - activation: 'https://mon-compte-particulier.enedis.fr/donnees/', - }, - }, - }, - { - fluidType: FluidType.WATER, - status: FluidState.ERROR, - maintenance: false, - firstDataDate: mockDataDates[FluidType.WATER], - lastDataDate: mockDataDates[FluidType.WATER], - connection: { - konnector: konnectorsData[1], - account: accountsData[1], - trigger: triggersData[1], - triggerState: null, - shouldLaunchKonnector: false, - isUpdating: false, - konnectorConfig: { - name: 'Eau Publique du Grand Lyon', - oauth: false, - slug: FluidSlugType.WATER, - siteLink: - 'https://agence.eaudugrandlyon.com/inscription.aspx#subc-now', - activation: '', - }, - }, - }, - { - fluidType: FluidType.GAS, - status: FluidState.KONNECTOR_NOT_FOUND, - maintenance: false, - firstDataDate: mockDataDates[FluidType.GAS], - lastDataDate: mockDataDates[FluidType.GAS], - connection: { - konnector: null, - account: accountsData[2], - trigger: null, - triggerState: null, - shouldLaunchKonnector: false, - isUpdating: false, - konnectorConfig: { - name: 'GRDF', - oauth: true, - slug: FluidSlugType.GAS, - siteLink: 'https://monespace.grdf.fr/creation-particulier', - activation: '', - }, - }, - }, - ] - const state = globalReducer(mockInitialGlobalState, { - type: SET_FLUID_STATUS, - payload: fluidStatus, - }) - expect(state).toEqual({ - ...mockInitialGlobalState, - fluidStatus: fluidStatus, - fluidTypes: [FluidType.ELECTRICITY, FluidType.WATER], - }) - }) - - it('should handle SET_FLUID_STATUS without payload', () => { - const state = globalReducer(mockInitialGlobalState, { - type: SET_FLUID_STATUS, - }) - expect(state).toEqual(mockInitialGlobalState) - }) -}) diff --git a/src/store/global/global.slice.spec.ts b/src/store/global/global.slice.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..0f04a90e365fba7d4389c58491b5779e336a4cf4 --- /dev/null +++ b/src/store/global/global.slice.spec.ts @@ -0,0 +1,300 @@ +/* eslint-disable camelcase */ +import { FluidState, FluidType } from 'enum/fluid.enum' +import { FluidSlugType } from 'enum/fluidSlug.enum' +import { ScreenType } from 'enum/screen.enum' +import { DateTime } from 'luxon' +import { FluidStatus, PartnersInfo, TermsStatus } from 'models' +import { SgeStore } from 'models/sgeStore.model' +import { accountsData } from '../../../tests/__mocks__/accountsData.mock' +import { konnectorsData } from '../../../tests/__mocks__/konnectorsData.mock' +import { mockInitialGlobalState } from '../../../tests/__mocks__/store' +import { triggersData } from '../../../tests/__mocks__/triggersData.mock' +import { + changeScreenType, + globalSlice, + setFluidStatus, + setPartnersInfo, + setShouldRefreshConsent, + showReleaseNotes, + toggleAnalysisNotification, + toggleChallengeActionNotification, + toggleChallengeDuelNotification, + toggleChallengeExplorationNotification, + updateFluidConnection, + updateSgeStore, + updateTermsStatus, +} from './global.slice' + +const nowUtc = DateTime.local().setZone('utc', { keepLocalTime: true }) +const mockDataDates = Array(3).fill(nowUtc) + +const fluidStatus: FluidStatus[] = [ + { + fluidType: FluidType.ELECTRICITY, + status: FluidState.ERROR, + maintenance: false, + firstDataDate: mockDataDates[FluidType.ELECTRICITY], + lastDataDate: mockDataDates[FluidType.ELECTRICITY], + connection: { + konnector: konnectorsData[0], + account: accountsData[0], + trigger: triggersData[0], + triggerState: null, + shouldLaunchKonnector: false, + isUpdating: false, + konnectorConfig: { + name: 'Enedis', + oauth: true, + slug: FluidSlugType.ELECTRICITY, + siteLink: 'https://mon-compte-particulier.enedis.fr/donnees/', + activation: 'https://mon-compte-particulier.enedis.fr/donnees/', + }, + }, + }, + { + fluidType: FluidType.WATER, + status: FluidState.ERROR, + maintenance: false, + firstDataDate: mockDataDates[FluidType.WATER], + lastDataDate: mockDataDates[FluidType.WATER], + connection: { + konnector: konnectorsData[1], + account: accountsData[1], + trigger: triggersData[1], + triggerState: null, + shouldLaunchKonnector: false, + isUpdating: false, + konnectorConfig: { + name: 'Eau Publique du Grand Lyon', + oauth: false, + slug: FluidSlugType.WATER, + siteLink: 'https://agence.eaudugrandlyon.com/inscription.aspx#subc-now', + activation: '', + }, + }, + }, + { + fluidType: FluidType.GAS, + status: FluidState.KONNECTOR_NOT_FOUND, + maintenance: false, + firstDataDate: mockDataDates[FluidType.GAS], + lastDataDate: mockDataDates[FluidType.GAS], + connection: { + konnector: null, + account: accountsData[2], + trigger: null, + triggerState: null, + shouldLaunchKonnector: false, + isUpdating: false, + konnectorConfig: { + name: 'GRDF', + oauth: true, + slug: FluidSlugType.GAS, + siteLink: 'https://monespace.grdf.fr/creation-particulier', + activation: '', + }, + }, + }, +] + +describe('globalSlice', () => { + it('should return the initial state', () => { + const initialState = globalSlice.reducer(undefined, { type: undefined }) + expect(initialState).toEqual(mockInitialGlobalState) + }) + + it('should handle changeScreenType', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + changeScreenType(ScreenType.DESKTOP) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + screenType: ScreenType.DESKTOP, + }) + }) + it('should handle toggleChallengeExplorationNotification', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + toggleChallengeExplorationNotification(true) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + challengeExplorationNotification: true, + }) + }) + it('should handle toggleChallengeActionNotification', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + toggleChallengeActionNotification(true) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + challengeActionNotification: true, + }) + }) + it('should handle toggleChallengeDuelNotification', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + toggleChallengeDuelNotification(true) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + challengeDuelNotification: true, + }) + }) + it('should handle toggleAnalysisNotification', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + toggleAnalysisNotification(true) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + analysisNotification: true, + }) + }) + it('should handle setFluidStatus', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + setFluidStatus(fluidStatus) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + fluidStatus: fluidStatus, + fluidTypes: [FluidType.ELECTRICITY, FluidType.WATER], + }) + }) + + it('should handle updateTermsStatus', () => { + const expectedTermsStatus: TermsStatus = { + accepted: false, + versionType: 'major', + } + const state = globalSlice.reducer( + mockInitialGlobalState, + updateTermsStatus(expectedTermsStatus) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + termsStatus: expectedTermsStatus, + }) + }) + + it('should handle showReleaseNotes', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + showReleaseNotes({ + show: true, + notes: [{ description: 'desc', title: 'Title' }], + }) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + releaseNotes: { + show: true, + notes: [{ description: 'desc', title: 'Title' }], + }, + }) + }) + + it('should handle setPartnersInfo', () => { + const expectedPartnersInfo: PartnersInfo = { + egl_failure: true, + enedis_failure: true, + grdf_failure: true, + notification_activated: true, + } + const state = globalSlice.reducer( + mockInitialGlobalState, + setPartnersInfo(expectedPartnersInfo) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + partnersInfo: expectedPartnersInfo, + }) + }) + + it('should handle setShouldRefreshConsent', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + setShouldRefreshConsent(true) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + shouldRefreshConsent: true, + }) + }) + it('should handle setSgeConnect', () => { + const expectedSgeConnect: SgeStore = { + address: 'address', + city: 'city', + currentStep: 1, + dataConsent: true, + firstName: 'firstName', + lastName: 'lastName', + pdl: 12345678901234, + pdlConfirm: true, + shouldLaunchAccount: true, + zipCode: 99999, + } + const state = globalSlice.reducer( + mockInitialGlobalState, + updateSgeStore(expectedSgeConnect) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + sgeConnect: expectedSgeConnect, + }) + }) + it('should handle updateFluidConnection', () => { + const state = globalSlice.reducer( + mockInitialGlobalState, + updateFluidConnection({ + fluidType: FluidType.ELECTRICITY, + fluidConnection: { + shouldLaunchKonnector: true, + isUpdating: true, + konnector: null, + account: null, + trigger: null, + triggerState: null, + konnectorConfig: { + name: 'config', + oauth: false, + slug: FluidSlugType.ELECTRICITY, + siteLink: 'link', + activation: 'activation', + }, + }, + }) + ) + expect(state).toEqual({ + ...mockInitialGlobalState, + fluidStatus: [ + { + fluidType: FluidType.ELECTRICITY, + firstDataDate: null, + lastDataDate: null, + maintenance: false, + status: 0, + connection: { + shouldLaunchKonnector: true, + isUpdating: true, + konnector: null, + account: null, + trigger: null, + triggerState: null, + konnectorConfig: { + name: 'config', + oauth: false, + slug: FluidSlugType.ELECTRICITY, + siteLink: 'link', + activation: 'activation', + }, + }, + }, + ...mockInitialGlobalState.fluidStatus.slice(1), + ], + }) + }) +}) diff --git a/src/store/global/global.reducer.ts b/src/store/global/global.slice.ts similarity index 50% rename from src/store/global/global.reducer.ts rename to src/store/global/global.slice.ts index 7736b81b29f6bba534254812fbc998440020df79..0c3bfc0972b40f8a7f59f1afba613b7823acb09a 100644 --- a/src/store/global/global.reducer.ts +++ b/src/store/global/global.slice.ts @@ -1,24 +1,16 @@ -/* eslint-disable camelcase */ +import { PayloadAction, createSlice } from '@reduxjs/toolkit' import { FluidState, FluidType } from 'enum/fluid.enum' import { FluidSlugType } from 'enum/fluidSlug.enum' import { ScreenType } from 'enum/screen.enum' -import { FluidStatus, GlobalState } from 'models' -import { Reducer } from 'redux' import { - CHANGE_SCREEN_TYPE, - GlobalActionTypes, - SET_FLUID_STATUS, - SET_PARTNERS_INFO, - SET_SHOULD_REFRESH_CONSENT, - SHOW_RELEASE_NOTES, - TOGGLE_ANALYSIS_NOTIFICATION, - TOGGLE_CHALLENGE_ACTION_NOTIFICATION, - TOGGLE_CHALLENGE_DUEL_NOTIFICATION, - TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION, - UPDATE_FLUID_CONNECTION, - UPDATE_SGE_CONNECT, - UPDATE_TERMS_VALIDATION, -} from 'store/global/global.actions' + FluidConnection, + FluidStatus, + GlobalState, + PartnersInfo, + TermsStatus, +} from 'models' +import { Notes } from 'models/releaseNotes.model' +import { SgeStore } from 'models/sgeStore.model' const initialState: GlobalState = { screenType: ScreenType.MOBILE, @@ -129,6 +121,40 @@ const initialState: GlobalState = { }, } +type ChangeScreenType = PayloadAction<ScreenType> +type SetPartnersInfo = PayloadAction<PartnersInfo> +type ToggleChallengeExplorationNotification = PayloadAction<boolean> +type ToggleChallengeActionNotification = PayloadAction<boolean> +type ToggleChallengeDuelNotification = PayloadAction<boolean> +type ToggleAnalysisNotification = PayloadAction<boolean> +type SetFluidStatus = PayloadAction<FluidStatus[]> +type UpdatedFluidConnection = PayloadAction<{ + fluidType: FluidType + fluidConnection: FluidConnection +}> +type UpdateTermValidation = PayloadAction<TermsStatus> +type ShowReleaseNote = PayloadAction<{ + show: boolean + notes: Notes[] + redirectLink?: string +}> +type SetShouldRefreshConsent = PayloadAction<boolean> +type SetSgeConnect = PayloadAction<SgeStore> + +export type GlobalActionTypes = + | ChangeScreenType + | SetPartnersInfo + | ToggleChallengeExplorationNotification + | ToggleChallengeActionNotification + | ToggleChallengeDuelNotification + | ToggleAnalysisNotification + | SetFluidStatus + | UpdatedFluidConnection + | UpdateTermValidation + | ShowReleaseNote + | SetShouldRefreshConsent + | SetSgeConnect + const getFluidTypesFromStatus = (fluidStatus: FluidStatus[]): FluidType[] => { const fluidTypes: FluidType[] = [] fluidStatus.forEach(fluid => { @@ -146,66 +172,77 @@ const getFluidTypesFromStatus = (fluidStatus: FluidStatus[]): FluidType[] => { return fluidTypes.sort() } -export const globalReducer: Reducer<GlobalState, GlobalActionTypes> = ( - state = initialState, - action -) => { - if (action.payload == undefined) return state - - const updateState = (updates: Partial<GlobalState>): GlobalState => ({ - ...state, - ...updates, - }) - - switch (action.type) { - case CHANGE_SCREEN_TYPE: - return updateState({ screenType: action.payload }) - - case TOGGLE_CHALLENGE_EXPLORATION_NOTIFICATION: - return updateState({ challengeExplorationNotification: action.payload }) - - case TOGGLE_CHALLENGE_ACTION_NOTIFICATION: - return updateState({ challengeActionNotification: action.payload }) - - case TOGGLE_CHALLENGE_DUEL_NOTIFICATION: - return updateState({ challengeDuelNotification: action.payload }) - - case TOGGLE_ANALYSIS_NOTIFICATION: - return updateState({ analysisNotification: action.payload }) - - case SET_FLUID_STATUS: - return updateState({ - fluidStatus: action.payload, - fluidTypes: getFluidTypesFromStatus(action.payload), - }) - - case UPDATE_TERMS_VALIDATION: - return updateState({ termsStatus: action.payload }) - - case SHOW_RELEASE_NOTES: - return updateState({ releaseNotes: action.payload }) - - case SET_PARTNERS_INFO: - return updateState({ partnersInfo: action.payload }) - - case SET_SHOULD_REFRESH_CONSENT: - return updateState({ shouldRefreshConsent: action.payload }) +export const globalSlice = createSlice({ + name: 'global', + initialState, + reducers: { + changeScreenType: (state, action: ChangeScreenType) => { + state.screenType = action.payload + }, + toggleChallengeExplorationNotification: ( + state, + action: ToggleChallengeExplorationNotification + ) => { + state.challengeExplorationNotification = action.payload + }, - case UPDATE_FLUID_CONNECTION: + toggleChallengeActionNotification: ( + state, + action: ToggleChallengeActionNotification + ) => { + state.challengeActionNotification = action.payload + }, + toggleChallengeDuelNotification: ( + state, + action: ToggleChallengeDuelNotification + ) => { + state.challengeDuelNotification = action.payload + }, + toggleAnalysisNotification: (state, action: ToggleAnalysisNotification) => { + state.analysisNotification = action.payload + }, + setFluidStatus: (state, action: SetFluidStatus) => { + state.fluidStatus = action.payload + state.fluidTypes = getFluidTypesFromStatus(action.payload) + }, + updateTermsStatus: (state, action: UpdateTermValidation) => { + state.termsStatus = action.payload + }, + showReleaseNotes: (state, action: ShowReleaseNote) => { + state.releaseNotes = action.payload + }, + setPartnersInfo: (state, action: SetPartnersInfo) => { + state.partnersInfo = action.payload + }, + setShouldRefreshConsent: (state, action: SetShouldRefreshConsent) => { + state.shouldRefreshConsent = action.payload + }, + updateFluidConnection: (state, action: UpdatedFluidConnection) => { const updatedFluidStatus = [...state.fluidStatus] const fluidType: FluidType = action.payload.fluidType const findIndex = state.fluidStatus.findIndex( fluid => fluid.fluidType === fluidType ) updatedFluidStatus[findIndex].connection = action.payload.fluidConnection - return { - ...state, - fluidStatus: updatedFluidStatus, - } - case UPDATE_SGE_CONNECT: - return updateState({ sgeConnect: action.payload }) - - default: - return state - } -} + state.fluidStatus = updatedFluidStatus + }, + updateSgeStore: (state, action: SetSgeConnect) => { + state.sgeConnect = action.payload + }, + }, +}) + +export const { + changeScreenType, + setFluidStatus, + setPartnersInfo, + updateSgeStore, + setShouldRefreshConsent, + showReleaseNotes, + toggleAnalysisNotification, + toggleChallengeActionNotification, + toggleChallengeDuelNotification, + toggleChallengeExplorationNotification, + updateFluidConnection, + updateTermsStatus, +} = globalSlice.actions diff --git a/src/store/index.ts b/src/store/index.ts index b703e919b028617eb7997a7dfe0a307c17ea0b75..25d8ce3b78a794d3f5f7950bb8257600b6a0f08e 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -19,14 +19,13 @@ import { } from 'redux' import { composeWithDevTools } from 'redux-devtools-extension' import thunkMiddleware from 'redux-thunk' -import { globalReducer } from 'store/global/global.reducer' import { AnalysisActionTypes, analysisSlice } from './analysis/analysis.slice' import { ChallengeActionTypes, challengeSlice, } from './challenge/challenge.slice' import { ChartActionTypes, chartSlice } from './chart/chart.slice' -import { GlobalActionTypes } from './global/global.actions' +import { GlobalActionTypes, globalSlice } from './global/global.slice' import { ModalActionTypes, modalSlice } from './modal/modal.slice' import { ProfileActionTypes } from './profile/profile.actions' import { profileReducer } from './profile/profile.reducer' @@ -54,7 +53,7 @@ const ecolyoReducer = combineReducers({ analysis: analysisSlice.reducer, challenge: challengeSlice.reducer, chart: chartSlice.reducer, - global: globalReducer, + global: globalSlice.reducer, modal: modalSlice.reducer, profile: profileReducer, profileEcogesture: profileEcogestureReducer, @@ -72,6 +71,7 @@ const appActions = { ...chartSlice.actions, ...modalSlice.actions, ...profileTypeSlice.actions, + ...globalSlice.actions, } // TODO refactor types with AppActionsTypes = typeof appActions diff --git a/tests/__mocks__/store.ts b/tests/__mocks__/store.ts index d3540b60bbc3d2eecdb72a8a97d28905891c600d..26367ba71186e3dd310f12817855bf2b2c579580 100644 --- a/tests/__mocks__/store.ts +++ b/tests/__mocks__/store.ts @@ -132,8 +132,8 @@ export const mockInitialGlobalState: GlobalState = { lastName: '', pdl: null, pdlConfirm: false, - zipCode: null, shouldLaunchAccount: false, + zipCode: null, }, } export const mockExpiredElec: FluidStatus = {