Skip to content

Commit

Permalink
Change icon of switcher button based on active workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuuszzzzz committed Jan 11, 2024
1 parent a092248 commit e77d1a0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 24 additions & 4 deletions src/components/WorkspaceSwitcherButton.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<PressableWithFeedback
Expand All @@ -20,7 +40,7 @@ function WorkspaceSwitcherButton() {
}}
>
<SubscriptAvatar
mainAvatar={{source: Expensicons.ExpensifyAppIcon, name: CONST.WORKSPACE_SWITCHER.NAME, type: CONST.ICON_TYPE_AVATAR}}
mainAvatar={{source, name, type}}
subscriptIcon={{source: Expensicons.DownArrow, width: CONST.WORKSPACE_SWITCHER.SUBSCRIPT_ICON_SIZE, height: CONST.WORKSPACE_SWITCHER.SUBSCRIPT_ICON_SIZE}}
showTooltip={false}
noMargin
Expand Down
2 changes: 0 additions & 2 deletions src/pages/WorkspaceSwitcherPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {getWorkspacesBrickRoads, getWorkspacesUnreadStatuses} from '@libs/WorkspacesUtils';
import * as App from '@userActions/App';
import * as Policy from '@userActions/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -105,7 +104,6 @@ function WorkspaceSwitcherPage({policies}) {

const selectPolicy = useCallback((option) => {
const policyID = option.policyID;
Policy.selectWorkspace(policyID);

if (policyID) {
setSelectedOption(option);
Expand Down

0 comments on commit e77d1a0

Please sign in to comment.