diff --git a/src/containers/Profiles/CreateProfile.tsx b/src/containers/Profiles/CreateProfile.tsx index 6d503acec..8193c19c4 100644 --- a/src/containers/Profiles/CreateProfile.tsx +++ b/src/containers/Profiles/CreateProfile.tsx @@ -52,7 +52,7 @@ const CreateProfile = () => { }, ); - if (loadingProfilesList) return ; + if (loadingProfilesList) return ; return (
diff --git a/src/containers/Profiles/DeleteProfile.tsx b/src/containers/Profiles/DeleteProfile.tsx index a159eb58e..72e291a73 100644 --- a/src/containers/Profiles/DeleteProfile.tsx +++ b/src/containers/Profiles/DeleteProfile.tsx @@ -50,7 +50,7 @@ const DeleteProfile = () => { return (
- {isDeleting && } + {isDeleting && }

{t('profile.delete')}

diff --git a/src/containers/Profiles/EditProfile.tsx b/src/containers/Profiles/EditProfile.tsx index a0256d050..5bb937cb3 100644 --- a/src/containers/Profiles/EditProfile.tsx +++ b/src/containers/Profiles/EditProfile.tsx @@ -78,7 +78,7 @@ const EditProfile = ({ contained = false }: EditProfileProps) => { }, ); - if (isLoading || isFetching) return ; + if (isLoading || isFetching) return ; return (
diff --git a/src/containers/Profiles/Form.tsx b/src/containers/Profiles/Form.tsx index b6a441516..37aaac0ac 100644 --- a/src/containers/Profiles/Form.tsx +++ b/src/containers/Profiles/Form.tsx @@ -66,7 +66,7 @@ const Form = ({ initialValues, formHandler, selectedAvatar, showCancelButton = t
{t('profile.description')}
{errors.form ? {errors.form} : null} - {submitting && } + {submitting && }

{t('name')}

{ const createdProfileData = data?.responseData.collection.find((profile: Profile) => profile.id === createdProfileId); - if (loading || isLoading || isFetching) return ; + if (loading || isLoading || isFetching) return ; return ( <> diff --git a/src/stores/AccountController.ts b/src/stores/AccountController.ts index dc65d947c..615272276 100644 --- a/src/stores/AccountController.ts +++ b/src/stores/AccountController.ts @@ -3,6 +3,17 @@ import i18next from 'i18next'; import { useProfileStore } from './ProfileStore'; import { unpersistProfile } from './ProfileController'; +import type { + Profile, + Capture, + Customer, + CustomerConsent, + EmailConfirmPasswordInput, + FirstLastNameInput, + GetCaptureStatusResponse, + GetCustomerConsentsResponse, + GetPublisherConsentsResponse, +} from '#types/account'; import { queryClient } from '#src/containers/QueryProvider/QueryProvider'; import useAccount from '#src/hooks/useAccount'; import useService from '#src/hooks/useService'; @@ -14,21 +25,11 @@ import { restoreWatchHistory, serializeWatchHistory } from '#src/stores/WatchHis import { useWatchHistoryStore } from '#src/stores/WatchHistoryStore'; import { logDev } from '#src/utils/common'; import * as persist from '#src/utils/persist'; -import type { - Capture, - Customer, - CustomerConsent, - EmailConfirmPasswordInput, - FirstLastNameInput, - GetCaptureStatusResponse, - GetCustomerConsentsResponse, - GetPublisherConsentsResponse, -} from '#types/account'; import type { Offer } from '#types/checkout'; const PERSIST_PROFILE = 'profile'; -export const initializeAccount = async () => { +export const initializeAccount = async ({ profile }: { profile?: Profile } = {}) => { await useService(async ({ accountService, config }) => { if (!accountService) { useAccountStore.setState({ loading: false }); @@ -52,6 +53,9 @@ export const initializeAccount = async () => { await accountService.initialize(config, logout); try { + if (profile?.credentials?.access_token) { + loadProfile(profile); + } const authData = await accountService.getAuthData(); if (authData) { @@ -73,6 +77,18 @@ export const initializeAccount = async () => { }); }; +const loadProfile = (profile: Profile) => { + persist.setItem(PERSIST_PROFILE, profile); + persist.setItemStorage('inplayer_token', { + expires: profile.credentials.expires, + token: profile.credentials.access_token, + refreshToken: '', + }); + useFavoritesStore.setState({ favorites: [] }); + useWatchHistoryStore.setState({ watchHistory: [] }); + useProfileStore.getState().setProfile(profile); +}; + export async function updateUser(values: FirstLastNameInput | EmailConfirmPasswordInput): Promise> { return await useService(async ({ accountService, sandbox = true }) => { useAccountStore.setState({ loading: true }); diff --git a/src/stores/ProfileController.ts b/src/stores/ProfileController.ts index b20f008e8..fe914a33c 100644 --- a/src/stores/ProfileController.ts +++ b/src/stores/ProfileController.ts @@ -1,6 +1,3 @@ -import { useFavoritesStore } from './FavoritesStore'; -import { useProfileStore } from './ProfileStore'; -import { useWatchHistoryStore } from './WatchHistoryStore'; import { initializeAccount } from './AccountController'; import { useAccountStore } from './AccountStore'; @@ -41,18 +38,9 @@ export const enterProfile = async ({ id, pin }: EnterProfilePayload) => { return await useService(async ({ profileService, sandbox }) => { const response = await profileService?.enterProfile({ id, pin }, sandbox ?? true); const profile = response?.responseData; - if (profile?.credentials?.access_token) { - persist.setItem(PERSIST_PROFILE, profile); - persist.setItemStorage('inplayer_token', { - expires: profile.credentials.expires, - token: profile.credentials.access_token, - refreshToken: '', - }); - useFavoritesStore.setState({ favorites: [] }); - useWatchHistoryStore.setState({ watchHistory: [] }); - useProfileStore.getState().setProfile(profile); - } - return initializeAccount(); + return initializeAccount({ + profile, + }); }); };