Skip to content

Commit 832f3bb

Browse files
committed
add custom IS templates to new expensify
1 parent 473797c commit 832f3bb

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

src/components/MoneyReportHeader.tsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,9 @@ function MoneyReportHeader({
526526

527527
const [offlineModalVisible, setOfflineModalVisible] = useState(false);
528528

529-
const exportSubmenuOptions: Record<ValueOf<typeof CONST.REPORT.EXPORT_OPTIONS>, DropdownOption<ValueOf<typeof CONST.REPORT.EXPORT_OPTIONS>>> = useMemo(
530-
() => ({
529+
const [integrationsExportTemplates] = useOnyx(ONYXKEYS.NVP_INTEGRATION_SERVER_EXPORT_TEMPLATES, {initialValue: [], canBeMissing: false});
530+
const exportSubmenuOptions = useMemo(() => {
531+
const options: Record<string, DropdownOption<string>> = {
531532
[CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV]: {
532533
text: translate('export.basicExport'),
533534
icon: Expensicons.Table,
@@ -588,9 +589,22 @@ function MoneyReportHeader({
588589
markAsManuallyExported(moneyRequestReport?.reportID, connectedIntegration);
589590
},
590591
},
591-
}),
592-
[translate, connectedIntegrationFallback, connectedIntegration, moneyRequestReport, isOffline, transactionIDs, isExported, beginExportWithTemplate],
593-
);
592+
};
593+
594+
// If the user has any custom integration export templates, add them as export options
595+
if (integrationsExportTemplates && integrationsExportTemplates.length > 0) {
596+
for (const template of integrationsExportTemplates) {
597+
options[template.name] = {
598+
text: template.name,
599+
icon: Expensicons.Table,
600+
value: template.name,
601+
onSelected: () => beginExportWithTemplate(template.name, CONST.EXPORT_TEMPLATE_TYPES.INTEGRATIONS, transactionIDs),
602+
};
603+
}
604+
}
605+
606+
return options;
607+
}, [translate, connectedIntegrationFallback, connectedIntegration, moneyRequestReport, isOffline, transactionIDs, isExported, beginExportWithTemplate, integrationsExportTemplates]);
594608

595609
const primaryActionsImplementation = {
596610
[CONST.REPORT.PRIMARY_ACTIONS.SUBMIT]: (
@@ -732,8 +746,8 @@ function MoneyReportHeader({
732746
if (!moneyRequestReport) {
733747
return [];
734748
}
735-
return getSecondaryExportReportActions(moneyRequestReport, policy, reportActions);
736-
}, [moneyRequestReport, policy, reportActions]);
749+
return getSecondaryExportReportActions(moneyRequestReport, policy, reportActions, integrationsExportTemplates);
750+
}, [moneyRequestReport, policy, reportActions, integrationsExportTemplates]);
737751

738752
const secondaryActionsImplementation: Record<
739753
ValueOf<typeof CONST.REPORT.SECONDARY_ACTIONS>,

src/libs/ReportSecondaryActionUtils.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
22
import type {ValueOf} from 'type-fest';
33
import CONST from '@src/CONST';
44
import ONYXKEYS from '@src/ONYXKEYS';
5-
import type {Policy, Report, ReportAction, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
5+
import type {IntegrationServerExportTemplate, Policy, Report, ReportAction, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
66
import {isApprover as isApproverUtils} from './actions/Policy/Member';
77
import {getCurrentUserAccountID} from './actions/Report';
88
import {
@@ -563,9 +563,8 @@ function getSecondaryReportActions({
563563
return options;
564564
}
565565

566-
function getSecondaryExportReportActions(report: Report, policy?: Policy, reportActions?: ReportAction[]): Array<ValueOf<typeof CONST.REPORT.EXPORT_OPTIONS>> {
567-
const options: Array<ValueOf<typeof CONST.REPORT.EXPORT_OPTIONS>> = [];
568-
566+
function getSecondaryExportReportActions(report: Report, policy?: Policy, reportActions?: ReportAction[], integrationsExportTemplates?: IntegrationServerExportTemplate[]): Array<ValueOf<typeof CONST.REPORT.EXPORT_OPTIONS> | string> {
567+
const options: Array<ValueOf<typeof CONST.REPORT.EXPORT_OPTIONS> | string> = [];
569568
if (isExportAction(report, policy, reportActions)) {
570569
options.push(CONST.REPORT.EXPORT_OPTIONS.EXPORT_TO_INTEGRATION);
571570
}
@@ -576,6 +575,13 @@ function getSecondaryExportReportActions(report: Report, policy?: Policy, report
576575

577576
options.push(CONST.REPORT.EXPORT_OPTIONS.DOWNLOAD_CSV, CONST.REPORT.EXPORT_OPTIONS.EXPENSE_LEVEL_EXPORT, CONST.REPORT.EXPORT_OPTIONS.REPORT_LEVEL_EXPORT);
578577

578+
if (integrationsExportTemplates && integrationsExportTemplates.length > 0) {
579+
for (const template of integrationsExportTemplates) {
580+
options.push(template.name);
581+
}
582+
}
583+
584+
579585
return options;
580586
}
581587

0 commit comments

Comments
 (0)