Skip to content

Commit

Permalink
Merge pull request #38318 from Expensify/lucien/fix-worklows-error-me…
Browse files Browse the repository at this point in the history
…ssages

[Wave Collect] [Workflows] Display meaningful message when currency is not available for Direct Reimbursement
  • Loading branch information
luacmartins authored Mar 20, 2024
2 parents 8707d29 + adb5d5e commit 399077f
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 27 deletions.
12 changes: 11 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ const CONST = {
EUR: 'EUR',
},
get DIRECT_REIMBURSEMENT_CURRENCIES() {
return [this.CURRENCY.USD, this.CURRENCY.AUD, this.CURRENCY.CAD, this.CURRENCY.GBP, this.CURRENCY.NZD, this.CURRENCY.EUR];
return [this.CURRENCY.USD, this.CURRENCY.AUD, this.CURRENCY.CAD, this.CURRENCY.GBP, this.CURRENCY.EUR];
},
EXAMPLE_PHONE_NUMBER: '+15005550006',
CONCIERGE_CHAT_NAME: 'Concierge',
Expand Down Expand Up @@ -1501,6 +1501,16 @@ const CONST = {
DISABLE: 'disable',
ENABLE: 'enable',
},
COLLECTION_KEYS: {
DESCRIPTION: 'description',
REIMBURSER_EMAIL: 'reimburserEmail',
REIMBURSEMENT_CHOICE: 'reimbursementChoice',
APPROVAL_MODE: 'approvalMode',
AUTOREPORTING: 'autoReporting',
AUTOREPORTING_FREQUENCY: 'autoReportingFrequency',
AUTOREPORTING_OFFSET: 'autoReportingOffset',
GENERAL_SETTINGS: 'generalSettings',
},
},

CUSTOM_UNITS: {
Expand Down
8 changes: 8 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,14 @@ export default {
},
},
},
workflowsDelayedSubmissionPage: {
autoReportingErrorMessage: 'The delayed submission parameter could not be changed. Please try again or contact support.',
autoReportingFrequencyErrorMessage: 'The submission frequency could not be changed. Please try again or contact support.',
monthlyOffsetErrorMessage: 'The monthly frequency could not be changed. Please try again or contact support.',
},
workflowsApprovalPage: {
genericErrorMessage: 'The approver could not be changed. Please try again or contact support.',
},
workflowsPayerPage: {
title: 'Authorized payer',
genericErrorMessage: 'The authorized payer could not be changed. Please try again.',
Expand Down
8 changes: 8 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,14 @@ export default {
},
},
},
workflowsDelayedSubmissionPage: {
autoReportingErrorMessage: 'El parámetro de envío retrasado no pudo ser cambiado. Por favor, inténtelo de nuevo o contacte al soporte.',
autoReportingFrequencyErrorMessage: 'La frecuencia de envío no pudo ser cambiada. Por favor, inténtelo de nuevo o contacte al soporte.',
monthlyOffsetErrorMessage: 'La frecuencia mensual no pudo ser cambiada. Por favor, inténtelo de nuevo o contacte al soporte.',
},
workflowsApprovalPage: {
genericErrorMessage: 'El aprobador no pudo ser cambiado. Por favor, inténtelo de nuevo o contacte al soporte.',
},
workflowsPayerPage: {
title: 'Pagador autorizado',
genericErrorMessage: 'El pagador autorizado no se pudo cambiar. Por favor, inténtalo mas tarde.',
Expand Down
20 changes: 17 additions & 3 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ function updateLastAccessedWorkspace(policyID: OnyxEntry<string>) {
Onyx.set(ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID, policyID);
}

/**
* Checks if the currency is supported for direct reimbursement
* USD currency is the only one supported in NewDot for now
*/
function isCurrencySupportedForDirectReimbursement(currency: string) {
return currency === CONST.CURRENCY.USD;
}

/**
* Check if the user has any active free policies (aka workspaces)
*/
Expand Down Expand Up @@ -471,6 +479,7 @@ function setWorkspaceAutoReporting(policyID: string, enabled: boolean, frequency
},
autoReportingFrequency: policy.autoReportingFrequency ?? null,
pendingFields: {autoReporting: null},
errorFields: {autoReporting: ErrorUtils.getMicroSecondOnyxError('workflowsDelayedSubmissionPage.autoReportingErrorMessage')},
},
},
];
Expand Down Expand Up @@ -511,6 +520,7 @@ function setWorkspaceAutoReportingFrequency(policyID: string, frequency: ValueOf
value: {
autoReportingFrequency: policy.autoReportingFrequency ?? null,
pendingFields: {autoReportingFrequency: null},
errorFields: {autoReportingFrequency: ErrorUtils.getMicroSecondOnyxError('workflowsDelayedSubmissionPage.autoReportingFrequencyErrorMessage')},
},
},
];
Expand Down Expand Up @@ -551,6 +561,7 @@ function setWorkspaceAutoReportingMonthlyOffset(policyID: string, autoReportingO
value: {
autoReportingOffset: policy.autoReportingOffset ?? null,
pendingFields: {autoReportingOffset: null},
errorFields: {autoReportingOffset: ErrorUtils.getMicroSecondOnyxError('workflowsDelayedSubmissionPage.monthlyOffsetErrorMessage')},
},
},
];
Expand Down Expand Up @@ -596,6 +607,7 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
approver: policy.approver ?? null,
approvalMode: policy.approvalMode ?? null,
pendingFields: {approvalMode: null},
errorFields: {approvalMode: ErrorUtils.getMicroSecondOnyxError('workflowsApprovalPage.genericErrorMessage')},
},
},
];
Expand Down Expand Up @@ -666,8 +678,8 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburser
API.write(WRITE_COMMANDS.SET_WORKSPACE_PAYER, params, {optimisticData, failureData, successData});
}

function clearWorkspacePayerError(policyID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errorFields: {reimburserEmail: null}});
function clearPolicyErrorField(policyID: string, fieldName: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errorFields: {[fieldName]: null}});
}

function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueOf<typeof CONST.POLICY.REIMBURSEMENT_CHOICES>, reimburserAccountID: number, reimburserEmail: string) {
Expand Down Expand Up @@ -1367,6 +1379,7 @@ function updateGeneralSettings(policyID: string, name: string, currency: string)
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -4305,7 +4318,6 @@ export {
renamePolicyCategory,
clearCategoryErrors,
setWorkspacePayer,
clearWorkspacePayerError,
setWorkspaceReimbursement,
openPolicyWorkflowsPage,
setPolicyRequiresTag,
Expand Down Expand Up @@ -4334,5 +4346,7 @@ export {
setWorkspaceCurrencyDefault,
setForeignCurrencyDefault,
setPolicyCustomTaxName,
clearPolicyErrorField,
isCurrencySupportedForDirectReimbursement,
clearPolicyDistanceRatesErrorFields,
};
14 changes: 12 additions & 2 deletions src/pages/workspace/WorkspaceProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import useLocalize from '@hooks/useLocalize';
import useThemeIllustrations from '@hooks/useThemeIllustrations';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as ErrorUtils from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
Expand Down Expand Up @@ -173,7 +174,11 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi
/>
</OfflineWithFeedback>
{(!StringUtils.isEmptyString(policy?.description ?? '') || !readOnly) && (
<OfflineWithFeedback pendingAction={policy?.pendingFields?.description}>
<OfflineWithFeedback
pendingAction={policy?.pendingFields?.description}
errors={ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.DESCRIPTION)}
onClose={() => Policy.clearPolicyErrorField(policy?.id ?? '', CONST.POLICY.COLLECTION_KEYS.DESCRIPTION)}
>
<MenuItemWithTopDescription
title={policyDescription}
description={translate('workspace.editor.descriptionInputLabel')}
Expand All @@ -187,7 +192,12 @@ function WorkspaceProfilePage({policy, currencyList = {}, route}: WorkSpaceProfi
/>
</OfflineWithFeedback>
)}
<OfflineWithFeedback pendingAction={policy?.pendingFields?.generalSettings}>
<OfflineWithFeedback
pendingAction={policy?.pendingFields?.generalSettings}
errors={ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.GENERAL_SETTINGS)}
onClose={() => Policy.clearPolicyErrorField(policy?.id ?? '', CONST.POLICY.COLLECTION_KEYS.GENERAL_SETTINGS)}
errorRowStyles={[styles.mt2]}
>
<View>
<MenuItemWithTopDescription
title={formattedCurrency}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import RadioListItem from '@components/SelectionList/RadioListItem';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as Localize from '@libs/Localize';
import Navigation from '@libs/Navigation/Navigation';
import type {WorkspacesCentralPaneNavigatorParamList} from '@libs/Navigation/types';
Expand Down Expand Up @@ -84,7 +85,12 @@ function WorkspaceAutoReportingFrequencyPage({policy, route}: WorkspaceAutoRepor
};

const monthlyFrequencyDetails = () => (
<OfflineWithFeedback pendingAction={policy?.pendingFields?.autoReportingOffset}>
<OfflineWithFeedback
pendingAction={policy?.pendingFields?.autoReportingOffset}
errors={ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_OFFSET)}
onClose={() => Policy.clearPolicyErrorField(policy?.id ?? '', CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_OFFSET)}
errorRowStyles={[styles.ml7]}
>
<MenuItem
title={translate('workflowsPage.submissionFrequencyDateOfMonth')}
titleStyle={styles.textLabelSupportingNormal}
Expand Down Expand Up @@ -127,12 +133,17 @@ function WorkspaceAutoReportingFrequencyPage({policy, route}: WorkspaceAutoRepor
title={translate('workflowsPage.submissionFrequency')}
onBackButtonPress={Navigation.goBack}
/>

<FlatList
data={autoReportingFrequencyItems}
renderItem={renderItem}
keyExtractor={(item: WorkspaceAutoReportingFrequencyPageItem) => item.text}
/>
<OfflineWithFeedback
pendingAction={policy?.pendingFields?.autoReportingFrequency}
errors={ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_FREQUENCY)}
onClose={() => Policy.clearPolicyErrorField(policy?.id ?? '', CONST.POLICY.COLLECTION_KEYS.AUTOREPORTING_FREQUENCY)}
>
<FlatList
data={autoReportingFrequencyItems}
renderItem={renderItem}
keyExtractor={(item: WorkspaceAutoReportingFrequencyPageItem) => item.text}
/>
</OfflineWithFeedback>
</FullPageNotFoundView>
</ScreenWrapper>
</FeatureEnabledAccessOrNotFoundWrapper>
Expand Down
Loading

0 comments on commit 399077f

Please sign in to comment.