diff --git a/src/components/WorkspaceSwitcherButton.tsx b/src/components/WorkspaceSwitcherButton.tsx index bd091140fb95..6decdfedc032 100644 --- a/src/components/WorkspaceSwitcherButton.tsx +++ b/src/components/WorkspaceSwitcherButton.tsx @@ -1,14 +1,34 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import useLocalize from '@hooks/useLocalize'; import CONST from '@src/CONST'; +import Navigation from '@libs/Navigation/Navigation'; +import ROUTES from '@src/ROUTES'; +import useActiveWorkspace from '@hooks/useActiveWorkspace'; +import {getPolicy, getDefaultWorkspaceAvatar} from "@libs/ReportUtils" import * as Expensicons from './Icon/Expensicons'; import {PressableWithFeedback} from './Pressable'; import SubscriptAvatar from './SubscriptAvatar'; -import Navigation from '@libs/Navigation/Navigation'; -import ROUTES from '@src/ROUTES'; function WorkspaceSwitcherButton() { const {translate} = useLocalize(); + const {activeWorkspaceID} = useActiveWorkspace(); + + + const {source, name, type} = useMemo(() => { + + if(!activeWorkspaceID) { + return {source: Expensicons.ExpensifyAppIcon, name: CONST.WORKSPACE_SWITCHER.NAME, type: CONST.ICON_TYPE_AVATAR} + } + + const policy = getPolicy(activeWorkspaceID); + const avatar = policy?.avatar && policy?.avatar?.length > 0 ? policy.avatar : getDefaultWorkspaceAvatar(policy?.name); + return { + source: avatar, + name: policy?.name, + type: CONST.ICON_TYPE_WORKSPACE, + } + }, [activeWorkspaceID]); + return ( { const policyID = option.policyID; - Policy.selectWorkspace(policyID); if (policyID) { setSelectedOption(option);