From 729abf651db9a3640849ae30956504d7f4dac6f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Chrab=C4=85szczewski?= Date: Fri, 16 Feb 2024 12:24:28 +0100 Subject: [PATCH 1/2] feat: display members(admin) and profile only for collect group policy --- src/libs/PolicyUtils.ts | 6 ++++++ src/pages/workspace/WorkspaceInitialPage.tsx | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index a8c0508e30b6..f24a10070cd1 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -108,6 +108,10 @@ function isExpensifyGuideTeam(email: string): boolean { */ const isPolicyAdmin = (policy: OnyxEntry | EmptyObject): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; +const isCollectPolicy = (policy: OnyxEntry | EmptyObject): boolean => policy?.type === CONST.POLICY.TYPE.TEAM; + +const isFreePolicy = (policy: OnyxEntry | EmptyObject): boolean => policy?.type === CONST.POLICY.TYPE.FREE; + const isPolicyMember = (policyID: string, policies: OnyxCollection): boolean => Object.values(policies ?? {}).some((policy) => policy?.id === policyID); /** @@ -258,6 +262,8 @@ export { isExpensifyTeam, isExpensifyGuideTeam, isInstantSubmitEnabled, + isCollectPolicy, + isFreePolicy, isPolicyAdmin, isSubmitAndClose, getMemberAccountIDsForWorkspace, diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 07049a91bee9..3a75c000b7db 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -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, @@ -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', @@ -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); From 7d3eadd01a4209e1043d3f75891ee0e6fb325db4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arkadiusz=20Chrab=C4=85szczewski?= Date: Tue, 20 Feb 2024 09:57:58 +0100 Subject: [PATCH 2/2] refactor: change & rename logic isCollectPolicy to isPaidPolicy --- src/libs/PolicyUtils.ts | 10 +++++----- src/pages/workspace/WorkspaceInitialPage.tsx | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index f24a10070cd1..a85e97a4cf05 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -108,9 +108,10 @@ function isExpensifyGuideTeam(email: string): boolean { */ const isPolicyAdmin = (policy: OnyxEntry | EmptyObject): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; -const isCollectPolicy = (policy: OnyxEntry | EmptyObject): boolean => policy?.type === CONST.POLICY.TYPE.TEAM; - -const isFreePolicy = (policy: OnyxEntry | EmptyObject): boolean => policy?.type === CONST.POLICY.TYPE.FREE; +/** + * Checks if the policy is a free group policy. + */ +const isFreeGroupPolicy = (policy: OnyxEntry | EmptyObject): boolean => policy?.type === CONST.POLICY.TYPE.FREE; const isPolicyMember = (policyID: string, policies: OnyxCollection): boolean => Object.values(policies ?? {}).some((policy) => policy?.id === policyID); @@ -262,8 +263,7 @@ export { isExpensifyTeam, isExpensifyGuideTeam, isInstantSubmitEnabled, - isCollectPolicy, - isFreePolicy, + isFreeGroupPolicy, isPolicyAdmin, isSubmitAndClose, getMemberAccountIDsForWorkspace, diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index 3a75c000b7db..70d871849ee6 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -98,8 +98,8 @@ 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 isPaidGroupPolicy = PolicyUtils.isPaidGroupPolicy(policy); + const isFreeGroupPolicy = PolicyUtils.isFreeGroupPolicy(policy); const protectedFreePolicyMenuItems: WorkspaceMenuItem[] = [ { @@ -168,8 +168,8 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r brickRoadIndicator: hasGeneralSettingsError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, routeName: SCREENS.WORKSPACE.PROFILE, }, - ...(isCollectPolicy && shouldShowProtectedItems ? protectedCollectPolicyMenuItems : []), - ...(isFreePolicy && shouldShowProtectedItems ? protectedFreePolicyMenuItems : []), + ...(isPaidGroupPolicy && shouldShowProtectedItems ? protectedCollectPolicyMenuItems : []), + ...(isFreeGroupPolicy && shouldShowProtectedItems ? protectedFreePolicyMenuItems : []), ]; const prevPolicy = usePrevious(policy);