Skip to content

fix: 'Add approval' can be disabled even when 'Smart limit' are enabled #57006

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

Merged
merged 9 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3848,6 +3848,8 @@ const translations = {
workflows: {
title: 'Workflows',
subtitle: 'Configure how spend is approved and paid.',
disableApprovalPrompt:
'Expensify Cards from this workspace currently rely on approval to define their Smart Limits. Please amend the limit types of any Expensify Cards with Smart Limits before disabling approvals.',
},
invoices: {
title: 'Invoices',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3894,6 +3894,8 @@ const translations = {
workflows: {
title: 'Flujos de trabajo',
subtitle: 'Configura cómo se aprueba y paga los gastos.',
disableApprovalPrompt:
'Las Tarjetas Expensify de este espacio de trabajo dependen actualmente de la aprobación para definir sus Límites Inteligentes. Por favor, modifica los tipos de límite de cualquier Tarjeta Expensify con Límites Inteligentes antes de deshabilitar las aprobaciones.',
},
invoices: {
title: 'Facturas',
Expand Down
5 changes: 5 additions & 0 deletions src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,10 @@ function getAllCardsForWorkspace(workspaceAccountID: number, allCardList: OnyxCo
return cards;
}

function isSmartLimitEnabled(cards: CardList) {
return Object.values(cards).some((card) => card.nameValuePairs?.limitType === CONST.EXPENSIFY_CARD.LIMIT_TYPES.SMART);
}

const CUSTOM_FEEDS = [CONST.COMPANY_CARD.FEED_BANK_NAME.MASTER_CARD, CONST.COMPANY_CARD.FEED_BANK_NAME.VISA, CONST.COMPANY_CARD.FEED_BANK_NAME.AMEX];

function getFeedType(feedKey: CompanyCardFeed, cardFeeds: OnyxEntry<CardFeeds>): CompanyCardFeedWithNumber {
Expand Down Expand Up @@ -585,6 +589,7 @@ export {
getFeedType,
flatAllCardsList,
checkIfFeedConnectionIsBroken,
isSmartLimitEnabled,
hasIssuedExpensifyCard,
hasCardListObject,
isExpensifyCardFullySetUp,
Expand Down
17 changes: 12 additions & 5 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import {
updateGeneralSettings,
} from '@libs/actions/Policy/Policy';
import {setApprovalWorkflow} from '@libs/actions/Workflow';
import {getAllCardsForWorkspace, isSmartLimitEnabled as isSmartLimitEnabledUtil} from '@libs/CardUtils';
import {getLatestErrorField} from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types';
import {getPaymentMethodDescription} from '@libs/PaymentUtils';
import {getPersonalDetailByEmail} from '@libs/PersonalDetailsUtils';
import {getCorrectedAutoReportingFrequency, isControlPolicy, isPaidGroupPolicy as isPaidGroupPolicyUtil, isPolicyAdmin as isPolicyAdminUtil} from '@libs/PolicyUtils';
import {getCorrectedAutoReportingFrequency, getWorkspaceAccountID, isControlPolicy, isPaidGroupPolicy as isPaidGroupPolicyUtil, isPolicyAdmin as isPolicyAdminUtil} from '@libs/PolicyUtils';
import {convertPolicyEmployeesToApprovalWorkflows, INITIAL_APPROVAL_WORKFLOW} from '@libs/WorkflowUtils';
import type {WorkspaceSplitNavigatorParamList} from '@navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
Expand Down Expand Up @@ -63,7 +64,10 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
const {isDevelopment} = useEnvironment();
const [isDebugModeEnabled] = useOnyx(ONYXKEYS.USER, {selector: (user) => !!user?.isDebugModeEnabled});

const workspaceAccountID = getWorkspaceAccountID(route.params.policyID);
const [cardList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}`);
const workspaceCards = getAllCardsForWorkspace(workspaceAccountID, cardList);
const isSmartLimitEnabled = isSmartLimitEnabledUtil(workspaceCards);
const policyApproverEmail = policy?.approver;
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useDismissModalForUSD(policy?.outputCurrency);
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
Expand Down Expand Up @@ -173,8 +177,8 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
},
{
title: translate('workflowsPage.addApprovalsTitle'),
subtitle: translate('workflowsPage.addApprovalsDescription'),
switchAccessibilityLabel: translate('workflowsPage.addApprovalsDescription'),
subtitle: isSmartLimitEnabled ? translate('workspace.moreFeatures.workflows.disableApprovalPrompt') : translate('workflowsPage.addApprovalsDescription'),
switchAccessibilityLabel: isSmartLimitEnabled ? translate('workspace.moreFeatures.workflows.disableApprovalPrompt') : translate('workflowsPage.addApprovalsDescription'),
onToggle: (isEnabled: boolean) => {
setWorkspaceApprovalMode(route.params.policyID, policy?.owner ?? '', isEnabled ? updateApprovalMode : CONST.POLICY.APPROVAL_MODE.OPTIONAL);
},
Expand Down Expand Up @@ -203,6 +207,7 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
/>
</>
),
disabled: isSmartLimitEnabled,
isActive:
([CONST.POLICY.APPROVAL_MODE.BASIC, CONST.POLICY.APPROVAL_MODE.ADVANCED].some((approvalMode) => approvalMode === policy?.approvalMode) && !hasApprovalError) ?? false,
pendingAction: policy?.pendingFields?.approvalMode,
Expand Down Expand Up @@ -305,6 +310,7 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
onPressAutoReportingFrequency,
approvalWorkflows,
addApprovalAction,
isSmartLimitEnabled,
isOffline,
theme.spinner,
isPolicyAdmin,
Expand All @@ -326,14 +332,15 @@ function WorkspaceWorkflowsPage({policy, route}: WorkspaceWorkflowsPageProps) {
title={item.title}
titleStyle={[styles.textHeadline, styles.cardSectionTitle, styles.accountSettingsSectionTitle, styles.mb1]}
subtitle={item.subtitle}
subtitleStyle={[styles.textLabelSupportingEmptyValue]}
subtitleStyle={[styles.textLabelSupportingEmptyValue, styles.lh20]}
switchAccessibilityLabel={item.switchAccessibilityLabel}
onToggle={item.onToggle}
subMenuItems={item.subMenuItems}
isActive={item.isActive}
pendingAction={item.pendingAction}
errors={item.errors}
onCloseError={item.onCloseError}
disabled={item.disabled}
/>
</Section>
);
Expand Down