Skip to content

Commit

Permalink
feat: display members(admin) and profile only for collect group policy
Browse files Browse the repository at this point in the history
  • Loading branch information
ArekChr committed Feb 16, 2024
1 parent a6fe014 commit 729abf6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ function isExpensifyGuideTeam(email: string): boolean {
*/
const isPolicyAdmin = (policy: OnyxEntry<Policy> | EmptyObject): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN;

const isCollectPolicy = (policy: OnyxEntry<Policy> | EmptyObject): boolean => policy?.type === CONST.POLICY.TYPE.TEAM;

const isFreePolicy = (policy: OnyxEntry<Policy> | EmptyObject): boolean => policy?.type === CONST.POLICY.TYPE.FREE;

const isPolicyMember = (policyID: string, policies: OnyxCollection<Policy>): boolean => Object.values(policies ?? {}).some((policy) => policy?.id === policyID);

/**
Expand Down Expand Up @@ -258,6 +262,8 @@ export {
isExpensifyTeam,
isExpensifyGuideTeam,
isInstantSubmitEnabled,
isCollectPolicy,
isFreePolicy,
isPolicyAdmin,
isSubmitAndClose,
getMemberAccountIDsForWorkspace,
Expand Down
17 changes: 15 additions & 2 deletions src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
const hasGeneralSettingsError = !isEmptyObject(policy?.errorFields?.generalSettings ?? {}) || !isEmptyObject(policy?.errorFields?.avatar ?? {});

const shouldShowProtectedItems = PolicyUtils.isPolicyAdmin(policy);
const isCollectPolicy = PolicyUtils.isCollectPolicy(policy);
const isFreePolicy = PolicyUtils.isFreePolicy(policy);

const protectedMenuItems: WorkspaceMenuItem[] = [
const protectedFreePolicyMenuItems: WorkspaceMenuItem[] = [
{
translationKey: 'workspace.common.card',
icon: Expensicons.ExpensifyCard,
Expand Down Expand Up @@ -148,6 +150,16 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
},
];

const protectedCollectPolicyMenuItems: WorkspaceMenuItem[] = [
{
translationKey: 'workspace.common.members',
icon: Expensicons.Users,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_MEMBERS.getRoute(policyID)))),
brickRoadIndicator: hasMembersError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
routeName: SCREENS.WORKSPACE.MEMBERS,
},
];

const menuItems: WorkspaceMenuItem[] = [
{
translationKey: 'workspace.common.profile',
Expand All @@ -156,7 +168,8 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
brickRoadIndicator: hasGeneralSettingsError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
routeName: SCREENS.WORKSPACE.PROFILE,
},
...(shouldShowProtectedItems ? protectedMenuItems : []),
...(isCollectPolicy && shouldShowProtectedItems ? protectedCollectPolicyMenuItems : []),
...(isFreePolicy && shouldShowProtectedItems ? protectedFreePolicyMenuItems : []),
];

const prevPolicy = usePrevious(policy);
Expand Down

0 comments on commit 729abf6

Please sign in to comment.