From 14e7d171dbc63e7edc93e1b35d9c1edc930979be Mon Sep 17 00:00:00 2001 From: Ramon Candel Date: Thu, 15 Feb 2024 17:24:19 +0100 Subject: [PATCH] Change way to check if user has completed the tutorial --- src/app/auth/components/SignUp/SignUp.tsx | 2 -- src/app/banners/BannerWrapper.tsx | 6 ++++-- src/app/core/services/local-storage.service.ts | 9 ++++----- src/app/drive/components/DriveExplorer/DriveExplorer.tsx | 5 +++-- .../views/SharedGuestSignUp/ShareGuestSingUpView.tsx | 2 -- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/app/auth/components/SignUp/SignUp.tsx b/src/app/auth/components/SignUp/SignUp.tsx index 6e9b2bde2..8cbfac2e3 100644 --- a/src/app/auth/components/SignUp/SignUp.tsx +++ b/src/app/auth/components/SignUp/SignUp.tsx @@ -147,8 +147,6 @@ function SignUp(props: SignUpProps): JSX.Element { ? await doRegister(email, password, token) : await updateInfo(email, password); - localStorageService.removeItem(STORAGE_KEYS.SIGN_UP_TUTORIAL_COMPLETED); - localStorageService.clear(); localStorageService.set('xToken', xToken); diff --git a/src/app/banners/BannerWrapper.tsx b/src/app/banners/BannerWrapper.tsx index 576441398..ffd682ea8 100644 --- a/src/app/banners/BannerWrapper.tsx +++ b/src/app/banners/BannerWrapper.tsx @@ -1,4 +1,4 @@ -import localStorageService, { STORAGE_KEYS } from '../core/services/local-storage.service'; +import localStorageService from '../core/services/local-storage.service'; import { RootState } from '../store'; import { useAppSelector } from '../store/hooks'; import { PlanState } from '../store/slices/plan'; @@ -6,14 +6,16 @@ import { userSelectors } from '../store/slices/user'; import { useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; import FeaturesBanner from './FeaturesBanner'; +import { UserSettings } from '@internxt/sdk/dist/shared/types/userSettings'; const SHOW_BANNER_COOKIE_NAME = 'show_valentines_banner_sale'; const OFFER_OFF_DAY = new Date('2024-02-25'); const BannerWrapper = (): JSX.Element => { const [showBanner, setShowBanner] = useState(false); + const user = useSelector((state: RootState) => state.user.user) as UserSettings; const plan = useSelector((state) => state.plan); - const isTutorialCompleted = localStorageService.get(STORAGE_KEYS.SIGN_UP_TUTORIAL_COMPLETED); + const isTutorialCompleted = localStorageService.hasCompletedTutorial(user.userId); const userPlan = plan.subscription?.type; const isNewAccount = useAppSelector(userSelectors.hasSignedToday); const isLocalStorage = localStorageService.get(SHOW_BANNER_COOKIE_NAME); diff --git a/src/app/core/services/local-storage.service.ts b/src/app/core/services/local-storage.service.ts index 329a41e5e..018dd2be0 100644 --- a/src/app/core/services/local-storage.service.ts +++ b/src/app/core/services/local-storage.service.ts @@ -3,7 +3,7 @@ import { TeamsSettings } from '../../teams/types'; import { Workspace } from '../types'; export const STORAGE_KEYS = { - SIGN_UP_TUTORIAL_COMPLETED: 'signUpTutorialCompleted', + TUTORIAL_COMPLETED_ID: 'signUpTutorialCompleted', }; function get(key: string): string | null { @@ -38,8 +38,8 @@ function exists(key: string): boolean { return !!localStorage.getItem(key); } -function getIsSignUpTutorialCompleted(): boolean { - return localStorage.getItem(STORAGE_KEYS.SIGN_UP_TUTORIAL_COMPLETED) === 'true'; +function hasCompletedTutorial(id?: string): boolean { + return localStorage.getItem(STORAGE_KEYS.TUTORIAL_COMPLETED_ID) === id; } function clear(): void { @@ -51,7 +51,6 @@ function clear(): void { localStorage.removeItem('xTokenTeam'); localStorage.removeItem('workspace'); localStorage.removeItem('language'); - localStorage.removeItem(STORAGE_KEYS.SIGN_UP_TUTORIAL_COMPLETED); localStorage.removeItem('showSummerBanner'); localStorage.removeItem('xInvitedToken'); localStorage.removeItem('xResourcesToken'); @@ -63,7 +62,7 @@ const localStorageService = { getUser, getTeams, getWorkspace, - getIsSignUpTutorialCompleted, + hasCompletedTutorial, removeItem, exists, clear, diff --git a/src/app/drive/components/DriveExplorer/DriveExplorer.tsx b/src/app/drive/components/DriveExplorer/DriveExplorer.tsx index 28f1fd596..341399982 100644 --- a/src/app/drive/components/DriveExplorer/DriveExplorer.tsx +++ b/src/app/drive/components/DriveExplorer/DriveExplorer.tsx @@ -125,6 +125,7 @@ const DriveExplorer = (props: DriveExplorerProps): JSX.Element => { filesOnTrashLength, hasMoreFolders, hasMoreFiles, + user, } = props; const dispatch = useAppDispatch(); const { translate } = useTranslationContext(); @@ -175,7 +176,7 @@ const DriveExplorer = (props: DriveExplorerProps): JSX.Element => { const [currentTutorialStep, setCurrentTutorialStep] = useState(0); const [showSecondTutorialStep, setShowSecondTutorialStep] = useState(false); const stepOneTutorialRef = useRef(null); - const isSignUpTutorialCompleted = localStorageService.getIsSignUpTutorialCompleted(); + const isSignUpTutorialCompleted = localStorageService.hasCompletedTutorial(user?.userId); const successNotifications = useTaskManagerGetNotifications({ status: [TaskStatus.Success], }); @@ -197,7 +198,7 @@ const DriveExplorer = (props: DriveExplorerProps): JSX.Element => { { onNextStepClicked: () => { passToNextStep(); - localStorageService.set(STORAGE_KEYS.SIGN_UP_TUTORIAL_COMPLETED, 'true'); + localStorageService.set(STORAGE_KEYS.TUTORIAL_COMPLETED_ID, user?.userId as string); }, }, ); diff --git a/src/app/share/views/SharedGuestSignUp/ShareGuestSingUpView.tsx b/src/app/share/views/SharedGuestSignUp/ShareGuestSingUpView.tsx index 137fd28f4..9d0caea3c 100644 --- a/src/app/share/views/SharedGuestSignUp/ShareGuestSingUpView.tsx +++ b/src/app/share/views/SharedGuestSignUp/ShareGuestSingUpView.tsx @@ -158,8 +158,6 @@ function ShareGuestSingUpView(): JSX.Element { const { email, password, token } = formData; const { xUser, xToken, mnemonic } = await doRegisterPreCreatedUser(email, password, invitationId ?? '', token); - localStorageService.removeItem(STORAGE_KEYS.SIGN_UP_TUTORIAL_COMPLETED); - localStorageService.clear(); localStorageService.set('xToken', xToken);