Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling Invoices as a feature #46567

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
filter disabled workspaces for invoices
  • Loading branch information
rezkiy37 committed Aug 1, 2024
commit 2e079b5d8e6e049c5d03d4b2861afbe66b24be98
9 changes: 8 additions & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,15 @@ function getActiveAdminWorkspaces(policies: OnyxCollection<Policy> | null): Poli
return activePolicies.filter((policy) => shouldShowPolicy(policy, NetworkStore.isOffline()) && isPolicyAdmin(policy));
}

/** Whether the user can send invoice from the workspace */
function canSendInvoiceFromWorkspace(policyID: string | undefined): boolean {
const policy = getPolicy(policyID);
return policy?.areInvoicesEnabled ?? false;
}

/** Whether the user can send invoice */
function canSendInvoice(policies: OnyxCollection<Policy> | null): boolean {
return getActiveAdminWorkspaces(policies).some((policy) => policy?.areInvoicesEnabled);
return getActiveAdminWorkspaces(policies).some((policy) => canSendInvoiceFromWorkspace(policy.id));
}

function hasDependentTags(policy: OnyxEntry<Policy>, policyTagList: OnyxEntry<PolicyTagList>) {
Expand Down Expand Up @@ -924,6 +930,7 @@ export {
isTaxTrackingEnabled,
shouldShowPolicy,
getActiveAdminWorkspaces,
canSendInvoiceFromWorkspace,
canSendInvoice,
hasDependentTags,
getXeroTenants,
Expand Down
9 changes: 7 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,15 @@ function getPolicy(policyID: string | undefined): OnyxEntry<Policy> {
* Returns a primary policy for the user
*/
function getPrimaryPolicy(activePolicyID?: OnyxEntry<string>): Policy | undefined {
const activeAdminWorkspaces = PolicyUtils.getActiveAdminWorkspaces(allPolicies);
if (!PolicyUtils.canSendInvoiceFromWorkspace(activePolicyID)) {
const activeAdminWorkspaces = PolicyUtils.getActiveAdminWorkspaces(allPolicies);

return activeAdminWorkspaces.find((policy) => PolicyUtils.canSendInvoiceFromWorkspace(policy.id));
}

const primaryPolicy: Policy | null | undefined = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${activePolicyID ?? '-1'}`];

return primaryPolicy ?? activeAdminWorkspaces[0];
return primaryPolicy;
}

/**
Expand Down