Skip to content

Commit

Permalink
Merge pull request #47678 from daledah/fix/47567
Browse files Browse the repository at this point in the history
fix: hide new workspace button to accounts already has workspace
  • Loading branch information
arosiclair authored Aug 23, 2024
2 parents fc0ffc6 + a670ea1 commit eb5f55b
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,24 @@ function getInvoicePrimaryWorkspace(activePolicyID?: OnyxEntry<string>): Policy
/**
* Check if the user has any active free policies (aka workspaces)
*/
function hasActiveChatEnabledPolicies(policies: Array<OnyxEntry<PolicySelector>> | OnyxCollection<PolicySelector>, includeOnlyFreePolicies = false): boolean {
const adminChatEnabledPolicies = Object.values(policies ?? {}).filter(
(policy) =>
policy &&
((policy.type === CONST.POLICY.TYPE.FREE && policy.role === CONST.POLICY.ROLE.ADMIN) ||
(!includeOnlyFreePolicies && policy.type !== CONST.POLICY.TYPE.PERSONAL && policy.role === CONST.POLICY.ROLE.ADMIN && policy.isPolicyExpenseChatEnabled)),
function hasActiveChatEnabledPolicies(policies: Array<OnyxEntry<PolicySelector>> | OnyxCollection<PolicySelector>, includeOnlyAdminPolicies = false): boolean {
const chatEnabledPolicies = Object.values(policies ?? {}).filter(
(policy) => policy?.isPolicyExpenseChatEnabled && (!includeOnlyAdminPolicies || policy.role === CONST.POLICY.ROLE.ADMIN),
);

if (adminChatEnabledPolicies.length === 0) {
if (chatEnabledPolicies.length === 0) {
return false;
}

if (adminChatEnabledPolicies.some((policy) => !policy?.pendingAction)) {
if (chatEnabledPolicies.some((policy) => !policy?.pendingAction)) {
return true;
}

if (adminChatEnabledPolicies.some((policy) => policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD)) {
if (chatEnabledPolicies.some((policy) => policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD)) {
return true;
}

if (adminChatEnabledPolicies.some((policy) => policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)) {
if (chatEnabledPolicies.some((policy) => policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)) {
return false;
}

Expand Down

0 comments on commit eb5f55b

Please sign in to comment.