From 4e3d75feb09a552bf46af8727766b01e31491882 Mon Sep 17 00:00:00 2001 From: Bastien DUMONT <bdumont@grandlyon.com> Date: Wed, 24 May 2023 12:23:25 +0000 Subject: [PATCH] chore(splash screen): cleanup initialization --- src/components/Splash/SplashRoot.tsx | 3 +- src/services/initialization.service.ts | 56 ++++++++++---------------- 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/components/Splash/SplashRoot.tsx b/src/components/Splash/SplashRoot.tsx index a4f030fa5..7c6563f4b 100644 --- a/src/components/Splash/SplashRoot.tsx +++ b/src/components/Splash/SplashRoot.tsx @@ -228,8 +228,7 @@ const SplashRoot = ({ fadeTimer = 1000, children }: SplashRootProps) => { initializationService.initChallengeEntity(profile.explorationHash), initializationService.initAnalysis(profile), ]) - const updatedProfile: Profile = { - ...profile, + const updatedProfile: Partial<Profile> = { duelHash, quizHash, challengeHash, diff --git a/src/services/initialization.service.ts b/src/services/initialization.service.ts index 9a4634559..56b3b9fc6 100644 --- a/src/services/initialization.service.ts +++ b/src/services/initialization.service.ts @@ -657,10 +657,6 @@ export default class InitializationService { } public async initConsent(): Promise<TermsStatus> { - const termsStatus: TermsStatus = { - accepted: false, - versionType: 'init', - } const startTime = performance.now() try { this._setInitStep(InitSteps.CONSENT) @@ -668,39 +664,31 @@ export default class InitializationService { const isUpToDate = await termService.isConsentVersionUpToDate() const lastTerm = await termService.getLastTerm() - if (lastTerm) { - if (isUpToDate) { - const isLastConsentValidated = await termService.isLastTermValidated() - if (isLastConsentValidated) { - termsStatus.accepted = true - termsStatus.versionType = 'init' - logApp.info( - '[Initialization] Last Consent successfully loaded and valid' - ) - } else { - termsStatus.versionType = 'init' - termsStatus.accepted = false - logApp.info('[Initialization] Consent not up-to-date') - } - } else { - const versionType = await termService.getTermsVersionType() - if (versionType === 'minor') { - termsStatus.accepted = false - termsStatus.versionType = 'minor' - logApp.info('[Initialization] Minor Terms update detected') - } else { - termsStatus.accepted = false - termsStatus.versionType = 'major' - logApp.info('[Initialization] Major Terms update detected') - } - } - } else { - termsStatus.accepted = false - termsStatus.versionType = 'init' + if (!lastTerm) { logApp.info('[Initialization] Init first terms') + return { accepted: false, versionType: 'init' } + } + + if (isUpToDate) { + const isLastConsentValidated = await termService.isLastTermValidated() + if (isLastConsentValidated) { + logApp.info( + '[Initialization] Last Consent successfully loaded and valid' + ) + return { accepted: true, versionType: 'init' } + } + logApp.info('[Initialization] Consent not up-to-date') + return { accepted: false, versionType: 'init' } + } + + const versionType = await termService.getTermsVersionType() + if (versionType === 'minor') { + logApp.info('[Initialization] Minor Terms update detected') + return { accepted: false, versionType: 'minor' } } - return termsStatus + logApp.info('[Initialization] Major Terms update detected') + return { accepted: false, versionType: 'major' } } catch (error) { this._setInitStepError(InitStepsErrors.CONSENT_ERROR) const errorMessage = `Initialization error - initConsent: ${JSON.stringify( -- GitLab