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
9 changes: 9 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ const CONST = {
READY: 'ready',
FAILED: 'failed',
},
TYPE: {
CSV: 'csv',
PDF: 'pdf',
},
},

SECURE_DOWNLOAD_TYPE: {
CSV_EXPORT: 'csvexport',
PDF_REPORT: 'pdfreport',
},

EXPORT_LABELS: {
Expand Down
29 changes: 23 additions & 6 deletions src/components/ExportDownloadStatusModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import {isMobileSafari} from '@libs/Browser';
import {getOldDotURLFromEnvironment} from '@libs/Environment/Environment';
import fileDownload from '@libs/fileDownload';
import Navigation from '@libs/Navigation/Navigation';
import addTrailingForwardSlash from '@libs/UrlUtils';
import {buildSecureDownloadURL} from '@libs/UrlUtils';
import {sendExportFileFromConcierge} from '@userActions/Export';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import ActivityIndicator from './ActivityIndicator';
import Button from './Button';
import Modal from './Modal';
import RenderHTML from './RenderHTML';
import Text from './Text';

type ExportDownloadStatusModalProps = {
Expand Down Expand Up @@ -54,10 +55,14 @@ function ExportDownloadStatusModal({exportID, isVisible, onClose, failedBody}: E
const state = displayedExport?.state;
const shouldSendFromConcierge = displayedExport?.shouldSendFromConcierge;
const fileName = displayedExport?.fileName;
const exportType = displayedExport?.exportType;
const failedReportCount = displayedExport?.failedReportCount ?? 0;
const reportCount = displayedExport?.reportCount ?? 0;
const isPreparing = state === CONST.EXPORT_DOWNLOAD.STATE.PREPARING && !shouldSendFromConcierge;
const isConcierge = !!shouldSendFromConcierge;
const isReady = state === CONST.EXPORT_DOWNLOAD.STATE.READY;
const isFailed = state === CONST.EXPORT_DOWNLOAD.STATE.FAILED;
const isPartialFailure = isReady && failedReportCount > 0;

// Build the secure download URL the same way downloadReportPDF does, so the host always follows
// the app's current environment (instead of the env baked into a backend-built URL) and authenticates
Expand All @@ -66,10 +71,10 @@ function ExportDownloadStatusModal({exportID, isVisible, onClose, failedBody}: E
if (!fileName || !currentUserLogin) {
return;
}
const baseURL = addTrailingForwardSlash(getOldDotURLFromEnvironment(environment));
const baseURL = getOldDotURLFromEnvironment(environment);
const isCSV = fileName.endsWith('.csv');
const secureType = isCSV ? 'csvexport' : 'pdfreport';
const url = `${baseURL}secure?secureType=${secureType}&filename=${encodeURIComponent(fileName)}&downloadName=${encodeURIComponent(fileName)}&email=${encodeURIComponent(currentUserLogin)}`;
const secureType = isCSV ? CONST.SECURE_DOWNLOAD_TYPE.CSV_EXPORT : CONST.SECURE_DOWNLOAD_TYPE.PDF_REPORT;
const url = buildSecureDownloadURL({baseURL, secureType, fileName, downloadName: fileName, email: currentUserLogin});
fileDownload(translate, addEncryptedAuthTokenToURL(url, encryptedAuthToken ?? '', true), fileName, '', isMobileSafari());
};

Expand Down Expand Up @@ -146,7 +151,18 @@ function ExportDownloadStatusModal({exportID, isVisible, onClose, failedBody}: E
return (
<>
<Text style={[styles.exportDownloadTitle, styles.mb2]}>{translate('exportDownload.readyTitle')}</Text>
<Text style={styles.mb5}>{translate('exportDownload.readyBody')}</Text>
{isPartialFailure ? (
<View style={styles.mb5}>
<RenderHTML
html={translate('exportDownload.readyPartialBody', {
count: reportCount,
total: reportCount + failedReportCount,
})}
/>
</View>
) : (
<Text style={styles.mb5}>{translate('exportDownload.readyBody')}</Text>
)}
<Button
success
text={translate('exportDownload.downloadFile')}
Expand All @@ -158,10 +174,11 @@ function ExportDownloadStatusModal({exportID, isVisible, onClose, failedBody}: E
}

if (isFailed) {
const resolvedFailedBody = failedBody ?? (exportType === CONST.EXPORT_DOWNLOAD.TYPE.CSV ? translate('exportDownload.csvFailedBody') : translate('exportDownload.pdfFailedBody'));
return (
<>
<Text style={[styles.exportDownloadTitle, styles.mb2]}>{translate('exportDownload.failedTitle')}</Text>
{!!failedBody && <Text style={styles.mb5}>{failedBody}</Text>}
{!!resolvedFailedBody && <Text style={styles.mb5}>{resolvedFailedBody}</Text>}
<Button
text={translate('exportDownload.close')}
onPress={onClose}
Expand Down
5 changes: 2 additions & 3 deletions src/components/Search/SearchBulkActionsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
setIsPdfModalVisible,
pdfReportID,
handlePdfModalHide,
activeExportID,
handleExportModalClose,
dismissModalAndUpdateUseHold,
dismissRejectModalBasedOnAction,
isDuplicateOptionVisible,
Expand All @@ -81,8 +83,6 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
allTransactions,
allReports,
searchData,
activeExportID,
handleExportModalClose,
} = useSearchBulkActions({queryJSON});
const currentSelectedPolicyID = selectedPolicyIDs?.at(0);
const currentSelectedReportID = selectedTransactionReportIDs?.at(0) ?? selectedReportIDs?.at(0);
Expand Down Expand Up @@ -281,7 +281,6 @@ function SearchBulkActionsButton({queryJSON}: SearchBulkActionsButtonProps) {
exportID={activeExportID}
isVisible
onClose={handleExportModalClose}
failedBody={translate('exportDownload.csvFailedBody')}
/>
)}
</>
Expand Down
25 changes: 14 additions & 11 deletions src/hooks/useSearchBulkActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {ModalActions} from '@components/Modal/Global/ModalContext';
import type {PopoverMenuItem} from '@components/PopoverMenu';
import {useSearchQueryContext, useSearchResultsContext, useSearchSelectionActions, useSearchSelectionContext} from '@components/Search/SearchContext';
import type {BulkPaySelectionData, PaymentData, SearchColumnType, SearchFilterKey, SearchQueryJSON, SelectedTransactions} from '@components/Search/types';
import {clearExportDownload} from '@libs/actions/Export';
import {clearExportDownload, exportReportsToPDF} from '@libs/actions/Export';
import {unholdRequest} from '@libs/actions/IOU/Hold';
import {payInvoice, payMoneyRequest} from '@libs/actions/IOU/PayMoneyRequest';
import {setupMergeTransactionDataAndNavigate} from '@libs/actions/MergeTransaction';
Expand Down Expand Up @@ -1742,8 +1742,7 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {

options.push(exportButtonOption);

if (isExpenseReportSearch && selectedReportIDs.length === 1) {
const reportIDForPDF = selectedReportIDs.at(0);
if (isExpenseReportSearch && selectedReportIDs.length > 0) {
options.push({
icon: expensifyIcons.Download,
text: translate('common.downloadAsPDF'),
Expand All @@ -1754,14 +1753,18 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
setIsOfflineModalVisible(true);
return;
}
if (!reportIDForPDF) {
if (selectedReportIDs.length === 1) {
const reportIDForPDF = selectedReportIDs.at(0);
if (!reportIDForPDF) {
return;
}
await exportReportToPDF({reportID: reportIDForPDF});
setPdfReportID(reportIDForPDF);
setIsPdfModalVisible(true);
return;
}
// Using await prevent the double-download on the second PDF export
// by clearing Onyx filename before modal is visible
await exportReportToPDF({reportID: reportIDForPDF});
setPdfReportID(reportIDForPDF);
setIsPdfModalVisible(true);
const exportID = exportReportsToPDF(selectedReportIDs);
setActiveExportID(exportID);
},
});
}
Expand Down Expand Up @@ -2127,6 +2130,8 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
setIsPdfModalVisible,
pdfReportID,
handlePdfModalHide,
activeExportID,
handleExportModalClose,
dismissModalAndUpdateUseHold,
dismissRejectModalBasedOnAction,
isDuplicateOptionVisible,
Expand All @@ -2136,8 +2141,6 @@ function useSearchBulkActions({queryJSON}: UseSearchBulkActionsParams) {
allTransactions: allTransactionsForDuplicate,
allReports,
searchData: currentSearchResults?.data,
activeExportID,
handleExportModalClose,
};
}

Expand Down
4 changes: 4 additions & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9675,6 +9675,10 @@ Hier ist ein *Testbeleg*, um dir zu zeigen, wie es funktioniert:`,
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,

close: 'Close',
},
domain: {
Expand Down
3 changes: 3 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9735,6 +9735,9 @@ const translations = {
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,
close: 'Close',
},
domain: {
Expand Down
3 changes: 3 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9828,6 +9828,9 @@ ${amount} para ${merchant} - ${date}`,
downloadFile: 'Descargar archivo',
failedTitle: 'Exportación fallida',
csvFailedBody: 'No se pudo completar la exportación. Inténtalo de nuevo más tarde.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,
close: 'Cerrar',
},
openAppFailureModal: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9707,6 +9707,10 @@ Voici un *reçu test* pour vous montrer comment ça fonctionne :`,
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,

close: 'Close',
},
domain: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9663,6 +9663,10 @@ Ecco una *ricevuta di prova* per mostrarti come funziona:`,
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,

close: 'Close',
},
domain: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9540,6 +9540,10 @@ ${reportName}`,
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,

close: 'Close',
},
domain: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9629,6 +9629,10 @@ Hier is een *proefbon* om je te laten zien hoe het werkt:`,
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,

close: 'Close',
},
domain: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9614,6 +9614,10 @@ Oto *paragon testowy*, żeby pokazać Ci, jak to działa:`,
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,

close: 'Close',
},
domain: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9618,6 +9618,10 @@ Aqui está um *comprovante de teste* para mostrar como funciona:`,
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,

close: 'Close',
},
domain: {
Expand Down
4 changes: 4 additions & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9363,6 +9363,10 @@ ${reportName}`,
downloadFile: 'Download file',
failedTitle: 'Export failed',
csvFailedBody: 'Your export could not be completed. Please try again later.',
pdfFailedBody: 'Your file could not be generated. Try again, or reach out to Concierge for help.',
readyPartialBody: ({count, total}: {count: number; total: number}) =>
`${count} of ${total} reports exported. If it didn't automatically download, use the button below. See which reports failed in <concierge-link>Concierge</concierge-link>.`,

close: 'Close',
},
domain: {
Expand Down
6 changes: 6 additions & 0 deletions src/libs/API/parameters/ExportReportsToPDFParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type ExportReportsToPDFParams = {
reportIDs: string;
exportID: string;
};

export default ExportReportsToPDFParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ export type {default as AskToJoinPolicyParams} from './AskToJoinPolicyParams';
export type {default as ImportPerDiemRatesParams} from './ImportPerDiemRatesParams';
export type {default as ExportPerDiemCSVParams} from './ExportPerDiemCSVParams';
export type {default as ExportReportPDFParams} from './ExportReportPDFParams';
export type {default as ExportReportsToPDFParams} from './ExportReportsToPDFParams';
export type {default as UpdateWorkspaceCustomUnitParams} from './UpdateWorkspaceCustomUnitParams';
export type {default as DismissProductTrainingParams} from './DismissProductTraining';
export type {default as AddWorkEmailParams} from './AddWorkEmailParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ const WRITE_COMMANDS = {
EXPORT_REPORT_TO_CSV: 'ExportReportToCSV',
MOVE_IOU_REPORT_TO_EXISTING_POLICY: 'MoveIOUReportToExistingPolicy',
EXPORT_REPORT_TO_PDF: 'ExportReportToPDF',
EXPORT_REPORTS_TO_PDF: 'ExportReportsToPDF',
RENAME_WORKSPACE_CATEGORY: 'RenameWorkspaceCategory',
CREATE_POLICY_TAG: 'CreatePolicyTag',
RENAME_POLICY_TAG: 'RenamePolicyTag',
Expand Down Expand Up @@ -803,6 +804,7 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.EXPORT_MULTI_LEVEL_DEPENDENT_TAGS_CSV]: Parameters.ExportMultiLevelTagsSpreadSheetParams;
[WRITE_COMMANDS.EXPORT_PER_DIEM_CSV]: Parameters.ExportPerDiemCSVParams;
[WRITE_COMMANDS.EXPORT_REPORT_TO_PDF]: Parameters.ExportReportPDFParams;
[WRITE_COMMANDS.EXPORT_REPORTS_TO_PDF]: Parameters.ExportReportsToPDFParams;
[WRITE_COMMANDS.RENAME_WORKSPACE_CATEGORY]: Parameters.RenameWorkspaceCategoriesParams;
[WRITE_COMMANDS.SET_WORKSPACE_REQUIRES_CATEGORY]: Parameters.SetWorkspaceRequiresCategoryParams;
[WRITE_COMMANDS.DELETE_WORKSPACE_CATEGORIES]: Parameters.DeleteWorkspaceCategoriesParams;
Expand Down
3 changes: 2 additions & 1 deletion src/libs/TravelInvoicingUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {ExpensifyCardSettingsBase} from '@src/types/onyx/ExpensifyCardSetti
import addEncryptedAuthTokenToURL from './addEncryptedAuthTokenToURL';
import {getLastFourDigits} from './BankAccountUtils';
import fileDownload from './fileDownload';
import {buildSecureDownloadURL} from './UrlUtils';

/**
* Checks whether Travel Invoicing is enabled based on the card settings.
Expand Down Expand Up @@ -147,7 +148,7 @@ function downloadTravelInvoiceStatementPDF(
encryptedAuthToken: string,
): Promise<void> {
const downloadFileName = `Travel_Statement_${startDate}_${endDate}.pdf`;
const pdfURL = `${baseURL}secure?secureType=pdfreport&filename=${fileName}&downloadName=${downloadFileName}&email=${encodeURIComponent(currentUserEmail)}`;
const pdfURL = buildSecureDownloadURL({baseURL, secureType: CONST.SECURE_DOWNLOAD_TYPE.PDF_REPORT, fileName, downloadName: downloadFileName, email: currentUserEmail});
return fileDownload(translate, addEncryptedAuthTokenToURL(pdfURL, encryptedAuthToken, true), downloadFileName, '');
}

Expand Down
19 changes: 19 additions & 0 deletions src/libs/UrlUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type {ValueOf} from 'type-fest';
import type CONST from '@src/CONST';

/**
* Add / to the end of any URL if not present
*/
Expand All @@ -8,4 +11,20 @@ function addTrailingForwardSlash(url: string): string {
return url;
}

type BuildSecureDownloadURLParams = {
baseURL: string;
secureType: ValueOf<typeof CONST.SECURE_DOWNLOAD_TYPE>;
fileName: string;
downloadName: string;
email: string;
};

/**
* Builds a secure download URL for OldDot file downloads (PDF reports, CSV exports, etc.).
*/
function buildSecureDownloadURL({baseURL, secureType, fileName, downloadName, email}: BuildSecureDownloadURLParams): string {
return `${addTrailingForwardSlash(baseURL)}secure?secureType=${secureType}&filename=${encodeURIComponent(fileName)}&downloadName=${encodeURIComponent(downloadName)}&email=${encodeURIComponent(email)}`;
}

export default addTrailingForwardSlash;
export {buildSecureDownloadURL};
Loading
Loading