diff --git a/web/app/components/base/avatar/index.tsx b/web/app/components/base/avatar/index.tsx index 2a08f75f7b..8c638993f0 100644 --- a/web/app/components/base/avatar/index.tsx +++ b/web/app/components/base/avatar/index.tsx @@ -45,7 +45,7 @@ const Avatar = ({ className={cn(textClassName, 'scale-[0.4] text-center text-white')} style={style} > - {name[0].toLocaleUpperCase()} + {name && name[0].toLocaleUpperCase()} ) diff --git a/web/context/app-context.tsx b/web/context/app-context.tsx index efb0251655..ccfdeaf8ff 100644 --- a/web/context/app-context.tsx +++ b/web/context/app-context.tsx @@ -4,7 +4,6 @@ import { createRef, useCallback, useEffect, useMemo, useRef, useState } from 're import useSWR from 'swr' import { createContext, useContext, useContextSelector } from 'use-context-selector' import type { FC, ReactNode } from 'react' -import Loading from '@/app/components/base/loading' import { fetchCurrentWorkspace, fetchLanggeniusVersion, fetchUserProfile } from '@/service/common' import type { ICurrentWorkspace, LangGeniusVersionResponse, UserProfileResponse } from '@/models/common' import MaintenanceNotice from '@/app/components/header/maintenance-notice' @@ -25,6 +24,15 @@ export type AppContextValue = { isLoadingCurrentWorkspace: boolean } +const userProfilePlaceholder = { + id: '', + name: '', + email: '', + avatar: '', + avatar_url: '', + is_password_set: false, + } + const initialLangeniusVersionInfo = { current_env: '', current_version: '', @@ -46,14 +54,7 @@ const initialWorkspaceInfo: ICurrentWorkspace = { } const AppContext = createContext({ - userProfile: { - id: '', - name: '', - email: '', - avatar: '', - avatar_url: '', - is_password_set: false, - }, + userProfile: userProfilePlaceholder, currentWorkspace: initialWorkspaceInfo, isCurrentWorkspaceManager: false, isCurrentWorkspaceOwner: false, @@ -80,7 +81,7 @@ export const AppContextProvider: FC = ({ children }) => const { data: userProfileResponse, mutate: mutateUserProfile } = useSWR({ url: '/account/profile', params: {} }, fetchUserProfile) const { data: currentWorkspaceResponse, mutate: mutateCurrentWorkspace, isLoading: isLoadingCurrentWorkspace } = useSWR({ url: '/workspaces/current', params: {} }, fetchCurrentWorkspace) - const [userProfile, setUserProfile] = useState() + const [userProfile, setUserProfile] = useState(userProfilePlaceholder) const [langeniusVersionInfo, setLangeniusVersionInfo] = useState(initialLangeniusVersionInfo) const [currentWorkspace, setCurrentWorkspace] = useState(initialWorkspaceInfo) const isCurrentWorkspaceManager = useMemo(() => ['owner', 'admin'].includes(currentWorkspace.role), [currentWorkspace.role]) @@ -107,9 +108,6 @@ export const AppContextProvider: FC = ({ children }) => setCurrentWorkspace(currentWorkspaceResponse) }, [currentWorkspaceResponse]) - if (!userProfile) - return - return (