Skip to content
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: 1 addition & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ const CONST = {
VIOLATIONS: 'violations',
DUPE_DETECTION: 'dupeDetection',
P2P_DISTANCE_REQUESTS: 'p2pDistanceRequests',
WORKFLOWS_DELAYED_SUBMISSION: 'workflowsDelayedSubmission',
WORKFLOWS_ADVANCED_APPROVAL: 'workflowsAdvancedApproval',
SPOTNANA_TRAVEL: 'spotnanaTravel',
NETSUITE_ON_NEW_EXPENSIFY: 'netsuiteOnNewExpensify',
REPORT_FIELDS_FEATURE: 'reportFieldsFeature',
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ export default {
submissionFrequency: 'Submission frequency',
submissionFrequencyDateOfMonth: 'Date of month',
addApprovalsTitle: 'Add approvals',
addApprovalButton: 'Add approval workflow',
approver: 'Approver',
connectBankAccount: 'Connect bank account',
addApprovalsDescription: 'Require additional approval before authorizing a payment.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,7 @@ export default {
submissionFrequency: 'Frecuencia de envíos',
submissionFrequencyDateOfMonth: 'Fecha del mes',
addApprovalsTitle: 'Requerir aprobaciones',
addApprovalButton: 'Añadir flujo de aprobación',
approver: 'Aprobador',
connectBankAccount: 'Conectar cuenta bancaria',
addApprovalsDescription: 'Requiere una aprobación adicional antes de autorizar un pago.',
Expand Down
6 changes: 3 additions & 3 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ function canUseP2PDistanceRequests(betas: OnyxEntry<Beta[]>, iouType: IOUType |
return !!betas?.includes(CONST.BETAS.P2P_DISTANCE_REQUESTS) || canUseAllBetas(betas) || iouType === CONST.IOU.TYPE.TRACK;
}

function canUseWorkflowsDelayedSubmission(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.WORKFLOWS_DELAYED_SUBMISSION) || canUseAllBetas(betas);
function canUseWorkflowsAdvancedApproval(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.WORKFLOWS_ADVANCED_APPROVAL) || canUseAllBetas(betas);
}

function canUseSpotnanaTravel(betas: OnyxEntry<Beta[]>): boolean {
Expand Down Expand Up @@ -70,7 +70,7 @@ export default {
canUseViolations,
canUseDupeDetection,
canUseP2PDistanceRequests,
canUseWorkflowsDelayedSubmission,
canUseWorkflowsAdvancedApproval,
canUseSpotnanaTravel,
canUseNetSuiteIntegration,
canUseSageIntacctIntegration,
Expand Down
122 changes: 67 additions & 55 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {ActivityIndicator, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import ConfirmModal from '@components/ConfirmModal';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import MenuItem from '@components/MenuItem';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
Expand Down Expand Up @@ -52,7 +53,7 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
const policyApproverEmail = policy?.approver;
const policyApproverName = useMemo(() => PersonalDetailsUtils.getPersonalDetailByEmail(policyApproverEmail ?? '')?.displayName ?? policyApproverEmail, [policyApproverEmail]);
const containerStyle = useMemo(() => [styles.ph8, styles.mhn8, styles.ml11, styles.pv3, styles.pr0, styles.pl4, styles.mr0, styles.widthAuto, styles.mt4], [styles]);
const canUseDelayedSubmission = Permissions.canUseWorkflowsDelayedSubmission(betas);
const canUseAdvancedApproval = Permissions.canUseWorkflowsAdvancedApproval(betas);
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false);

const displayNameForAuthorizedPayer = useMemo(
Expand Down Expand Up @@ -97,65 +98,76 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting;

return [
...(canUseDelayedSubmission
? [
{
icon: Illustrations.ReceiptEnvelope,
title: translate('workflowsPage.delaySubmissionTitle'),
subtitle: translate('workflowsPage.delaySubmissionDescription'),
switchAccessibilityLabel: translate('workflowsPage.delaySubmissionDescription'),
onToggle: (isEnabled: boolean) => {
Policy.setWorkspaceAutoReportingFrequency(
route.params.policyID,
isEnabled ? CONST.POLICY.AUTO_REPORTING_FREQUENCIES.WEEKLY : CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
);
},
subMenuItems: (
<MenuItem
title={translate('workflowsPage.submissionFrequency')}
titleStyle={styles.textLabelSupportingNormal}
descriptionTextStyle={styles.textNormalThemeText}
onPress={onPressAutoReportingFrequency}
// Instant submit is the equivalent of delayed submissions being turned off, so we show the feature as disabled if the frequency is instant
description={
getAutoReportingFrequencyDisplayNames(preferredLocale)[
(PolicyUtils.getCorrectedAutoReportingFrequency(policy) as AutoReportingFrequencyKey) ?? CONST.POLICY.AUTO_REPORTING_FREQUENCIES.WEEKLY
]
}
shouldShowRightIcon
wrapperStyle={containerStyle}
hoverAndPressStyle={[styles.mr0, styles.br2]}
brickRoadIndicator={hasDelayedSubmissionError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
),
isActive: (policy?.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT && !hasDelayedSubmissionError) ?? false,
pendingAction: policy?.pendingFields?.autoReporting,
errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
onCloseError: () => Policy.clearPolicyErrorField(policy?.id ?? '-1', CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
},
]
: []),
{
icon: Illustrations.Approval,
title: translate('workflowsPage.addApprovalsTitle'),
subtitle: translate('workflowsPage.addApprovalsDescription'),
switchAccessibilityLabel: translate('workflowsPage.addApprovalsDescription'),
icon: Illustrations.ReceiptEnvelope,
title: translate('workflowsPage.delaySubmissionTitle'),
subtitle: translate('workflowsPage.delaySubmissionDescription'),
switchAccessibilityLabel: translate('workflowsPage.delaySubmissionDescription'),
onToggle: (isEnabled: boolean) => {
Policy.setWorkspaceApprovalMode(route.params.policyID, policy?.owner ?? '', isEnabled ? CONST.POLICY.APPROVAL_MODE.BASIC : CONST.POLICY.APPROVAL_MODE.OPTIONAL);
Policy.setWorkspaceAutoReportingFrequency(
route.params.policyID,
isEnabled ? CONST.POLICY.AUTO_REPORTING_FREQUENCIES.WEEKLY : CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the way we passed CONST.POLICY.AUTO_REPORTING_FREQUENCIES.WEEKLY here when isEnabled is true led to this issue:

which was fixed by PR #54678, more details in proposal.

);
},
subMenuItems: (
<MenuItem
title={translate('workflowsPage.approver')}
title={translate('workflowsPage.submissionFrequency')}
titleStyle={styles.textLabelSupportingNormal}
descriptionTextStyle={styles.textNormalThemeText}
description={policyApproverName ?? ''}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVER.getRoute(route.params.policyID))}
onPress={onPressAutoReportingFrequency}
// Instant submit is the equivalent of delayed submissions being turned off, so we show the feature as disabled if the frequency is instant
description={
getAutoReportingFrequencyDisplayNames(preferredLocale)[
(PolicyUtils.getCorrectedAutoReportingFrequency(policy) as AutoReportingFrequencyKey) ?? CONST.POLICY.AUTO_REPORTING_FREQUENCIES.WEEKLY
]
}
shouldShowRightIcon
wrapperStyle={containerStyle}
hoverAndPressStyle={[styles.mr0, styles.br2]}
brickRoadIndicator={hasApprovalError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
brickRoadIndicator={hasDelayedSubmissionError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
),
isActive: (policy?.autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT && !hasDelayedSubmissionError) ?? false,
pendingAction: policy?.pendingFields?.autoReporting,
errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
onCloseError: () => Policy.clearPolicyErrorField(policy?.id ?? '-1', CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING),
},
{
icon: Illustrations.Approval,
title: translate('workflowsPage.addApprovalsTitle'),
subtitle: translate('workflowsPage.addApprovalsDescription'),
switchAccessibilityLabel: translate('workflowsPage.addApprovalsDescription'),
onToggle: (isEnabled: boolean) => {
Policy.setWorkspaceApprovalMode(route.params.policyID, policy?.owner ?? '', isEnabled ? CONST.POLICY.APPROVAL_MODE.BASIC : CONST.POLICY.APPROVAL_MODE.OPTIONAL);
},
subMenuItems: (
<>
<MenuItem
title={translate('workflowsPage.approver')}
titleStyle={styles.textLabelSupportingNormal}
descriptionTextStyle={styles.textNormalThemeText}
description={policyApproverName ?? ''}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVER.getRoute(route.params.policyID))}
shouldShowRightIcon
wrapperStyle={containerStyle}
hoverAndPressStyle={[styles.mr0, styles.br2]}
brickRoadIndicator={hasApprovalError ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
/>
{/* TODO: Functionality for this button will be added in a future PR (https://github.com/Expensify/App/issues/45954) */}
{canUseAdvancedApproval && (
<MenuItem
title={translate('workflowsPage.addApprovalButton')}
titleStyle={styles.textStrong}
icon={Expensicons.Plus}
iconHeight={20}
iconWidth={20}
iconFill={theme.success}
style={[styles.ph2, styles.ml11, styles.widthAuto]}
hoverAndPressStyle={[styles.mr0, styles.br2]}
/>
)}
</>
),
isActive: (policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.BASIC && !hasApprovalError) ?? false,
pendingAction: policy?.pendingFields?.approvalMode,
errors: ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.APPROVAL_MODE),
Expand Down Expand Up @@ -238,18 +250,18 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
];
}, [
policy,
route.params.policyID,
styles,
translate,
policyApproverName,
containerStyle,
styles,
onPressAutoReportingFrequency,
preferredLocale,
canUseDelayedSubmission,
displayNameForAuthorizedPayer,
containerStyle,
policyApproverName,
canUseAdvancedApproval,
theme,
isOffline,
isPolicyAdmin,
theme,
displayNameForAuthorizedPayer,
route.params.policyID,
]);

const renderOptionItem = (item: ToggleSettingOptionRowProps, index: number) => (
Expand Down