Skip to content

Commit fb5177e

Browse files
authored
Merge pull request #8270 from Expensify/jack-updatePDFHandling
2 parents e7565c1 + 4c1380e commit fb5177e

File tree

6 files changed

+118
-47
lines changed

6 files changed

+118
-47
lines changed

ios/NewExpensify.xcodeproj/project.pbxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,11 @@
531531
);
532532
inputPaths = (
533533
"${PODS_ROOT}/Target Support Files/Pods-NewExpensify-NewExpensifyTests/Pods-NewExpensify-NewExpensifyTests-frameworks.sh",
534-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Flipper-DoubleConversion/double-conversion.framework/double-conversion",
534+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/double-conversion/double-conversion.framework/double-conversion",
535535
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Onfido/Onfido.framework/Onfido",
536-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
537-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Plaid/LinkKit.framework/LinkKit",
538-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/hermes.framework/hermes",
536+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL/OpenSSL.framework/OpenSSL",
537+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/LinkKit/LinkKit.framework/LinkKit",
538+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes/hermes.framework/hermes",
539539
);
540540
name = "[CP] Embed Pods Frameworks";
541541
outputPaths = (
@@ -707,11 +707,11 @@
707707
);
708708
inputPaths = (
709709
"${PODS_ROOT}/Target Support Files/Pods-NewExpensify/Pods-NewExpensify-frameworks.sh",
710-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Flipper-DoubleConversion/double-conversion.framework/double-conversion",
710+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/double-conversion/double-conversion.framework/double-conversion",
711711
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Onfido/Onfido.framework/Onfido",
712-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
713-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/Plaid/LinkKit.framework/LinkKit",
714-
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/hermes.framework/hermes",
712+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL/OpenSSL.framework/OpenSSL",
713+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/LinkKit/LinkKit.framework/LinkKit",
714+
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes/hermes.framework/hermes",
715715
);
716716
name = "[CP] Embed Pods Frameworks";
717717
outputPaths = (

ios/Podfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ target 'NewExpensify' do
1717
:hermes_enabled => true
1818
)
1919

20-
pod 'react-native-webview', :path => '../node_modules/react-native-webview'
2120

2221
target 'NewExpensifyTests' do
2322
inherit! :complete

ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ SPEC CHECKSUMS:
878878
Airship: 29d674abeac754f783fc46c7d383d6f046687341
879879
boost: a7c83b31436843459a1961bfd74b96033dc77234
880880
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
881-
DoubleConversion: 831926d9b8bf8166fd87886c4abab286c2422662
881+
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
882882
FBLazyVector: e5569e42a1c79ca00521846c223173a57aca1fe1
883883
FBReactNativeSpec: fe08c1cd7e2e205718d77ad14b34957cce949b58
884884
Firebase: 54cdc8bc9c9b3de54f43dab86e62f5a76b47034f
@@ -900,7 +900,7 @@ SPEC CHECKSUMS:
900900
Flipper-RSocket: d9d9ade67cbecf6ac10730304bf5607266dd2541
901901
FlipperKit: d8d346844eca5d9120c17d441a2f38596e8ed2b9
902902
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
903-
glog: 5337263514dd6f09803962437687240c5dc39aa4
903+
glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62
904904
GoogleAppMeasurement: 6b6a08fd9c71f4dbc89e0e812acca81d797aa342
905905
GoogleDataTransport: 629c20a4d363167143f30ea78320d5a7eb8bd940
906906
GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
@@ -977,6 +977,6 @@ SPEC CHECKSUMS:
977977
Yoga: e7dc4e71caba6472ff48ad7d234389b91dadc280
978978
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
979979

980-
PODFILE CHECKSUM: 1199d07d3ccd1ea23300ad9e27bc9287716223bf
980+
PODFILE CHECKSUM: 431123d7514c52fa4516724b89c20d02c87ad8c8
981981

982982
COCOAPODS: 1.11.2

src/ONYXKEYS.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export default {
134134
// The user's credit cards
135135
CARD_LIST: 'cardList',
136136

137+
// Stores information about the user's saved statements
138+
WALLET_STATEMENT: 'walletStatement',
139+
137140
// Stores information about the active reimbursement account being set up
138141
REIMBURSEMENT_ACCOUNT: 'reimbursementAccount',
139142

src/libs/actions/User.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ import NetworkConnection from '../NetworkConnection';
1515
import redirectToSignIn from './SignInRedirect';
1616
import NameValuePair from './NameValuePair';
1717
import Growl from '../Growl';
18-
import CONFIG from '../../CONFIG';
1918
import * as Localize from '../Localize';
2019
import * as CloseAccountActions from './CloseAccount';
2120
import * as Link from './Link';
2221
import getSkinToneEmojiFromIndex from '../../components/EmojiPicker/getSkinToneEmojiFromIndex';
23-
import fileDownload from '../fileDownload';
2422

2523
let sessionAuthToken = '';
2624
let sessionEmail = '';
@@ -403,20 +401,21 @@ function joinScreenShare(accessToken, roomName) {
403401
/**
404402
* Downloads the statement PDF for the provided period
405403
* @param {String} period YYYYMM format
404+
* @returns {Promise<Void>}
406405
*/
407-
function downloadStatementPDF(period) {
408-
API.GetStatementPDF({period})
406+
function generateStatementPDF(period) {
407+
Onyx.merge(ONYXKEYS.WALLET_STATEMENT, {isGenerating: true});
408+
return API.GetStatementPDF({period})
409409
.then((response) => {
410-
if (response.jsonCode === 200 && response.filename) {
411-
const downloadFileName = `Expensify_Statement_${response.period}.pdf`;
412-
const pdfURL = `${CONFIG.EXPENSIFY.EXPENSIFY_URL}secure?secureType=pdfreport&filename=${response.filename}&downloadName=${downloadFileName}`;
413-
414-
fileDownload(pdfURL, downloadFileName);
415-
} else {
416-
Growl.show(Localize.translateLocal('common.genericErrorMessage'), CONST.GROWL.ERROR, 3000);
410+
if (response.jsonCode !== 200 || !response.filename) {
411+
Log.info('[User] Failed to generate statement PDF', false, {response});
412+
return;
417413
}
418-
})
419-
.catch(() => Growl.show(Localize.translateLocal('common.genericErrorMessage'), CONST.GROWL.ERROR, 3000));
414+
415+
Onyx.merge(ONYXKEYS.WALLET_STATEMENT, {[period]: response.filename});
416+
}).finally(() => {
417+
Onyx.merge(ONYXKEYS.WALLET_STATEMENT, {isGenerating: false});
418+
});
420419
}
421420

422421
export {
@@ -438,5 +437,5 @@ export {
438437
setFrequentlyUsedEmojis,
439438
joinScreenShare,
440439
clearScreenShareRequest,
441-
downloadStatementPDF,
440+
generateStatementPDF,
442441
};

src/pages/wallet/WalletStatementPage.js

Lines changed: 91 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import compose from '../../libs/compose';
1313
import CONFIG from '../../CONFIG';
1414
import WalletStatementModal from '../../components/WalletStatementModal';
1515
import * as User from '../../libs/actions/User';
16+
import fileDownload from '../../libs/fileDownload';
17+
import Growl from '../../libs/Growl';
18+
import CONST from '../../CONST';
19+
import makeCancellablePromise from '../../libs/MakeCancellablePromise';
1620

1721
const propTypes = {
1822
/** The route object passed to this page from the navigator */
@@ -26,39 +30,105 @@ const propTypes = {
2630
}).isRequired,
2731
}).isRequired,
2832

33+
walletStatement: PropTypes.shape({
34+
/** Whether the PDF file available for download or not */
35+
isGenerating: PropTypes.bool,
36+
}),
37+
2938
...withLocalizePropTypes,
3039
};
3140

32-
const WalletStatementPage = (props) => {
33-
moment.locale(lodashGet(props, 'preferredLocale', 'en'));
34-
const yearMonth = lodashGet(props.route.params, 'yearMonth', null);
35-
const year = yearMonth.substring(0, 4) || moment().year();
36-
const month = yearMonth.substring(4) || moment().month();
37-
const monthName = moment(month, 'M').format('MMMM');
38-
const title = `${monthName} ${year} statement`;
39-
const url = `${CONFIG.EXPENSIFY.EXPENSIFY_URL}statement.php?period=${yearMonth}`;
40-
return (
41-
<ScreenWrapper>
42-
<HeaderWithCloseButton
43-
title={Str.recapitalize(title)}
44-
shouldShowDownloadButton
45-
onCloseButtonPress={() => Navigation.dismissModal(true)}
46-
onDownloadButtonPress={() => User.downloadStatementPDF(yearMonth)}
47-
/>
48-
<WalletStatementModal
49-
statementPageURL={url}
50-
/>
51-
</ScreenWrapper>
52-
);
41+
const defaultProps = {
42+
walletStatement: {
43+
isGenerating: false,
44+
},
5345
};
5446

47+
class WalletStatementPage extends React.Component {
48+
constructor(props) {
49+
super(props);
50+
51+
this.state = {
52+
isDownloading: false,
53+
};
54+
this.processDownload = this.processDownload.bind(this);
55+
this.yearMonth = lodashGet(this.props.route.params, 'yearMonth', null);
56+
this.generatePDFPromise = null;
57+
}
58+
59+
componentDidMount() {
60+
this.generatePDFPromise = makeCancellablePromise(User.generateStatementPDF(this.yearMonth));
61+
}
62+
63+
componentWillUnmount() {
64+
if (!this.generatePDFPromise) {
65+
return;
66+
}
67+
68+
this.generatePDFPromise.cancel();
69+
this.generatePDFPromise = null;
70+
}
71+
72+
processDownload(yearMonth) {
73+
if (this.state.isDownloading) {
74+
return;
75+
}
76+
77+
this.setState({
78+
isDownloading: true,
79+
});
80+
81+
if (!this.props.walletStatement[yearMonth] || this.props.walletStatement.isGenerating) {
82+
Growl.show(this.props.translate('common.genericErrorMessage'), CONST.GROWL.ERROR, 5000);
83+
this.setState({
84+
isDownloading: false,
85+
});
86+
} else {
87+
const fileName = `Expensify_Statement_${yearMonth}.pdf`;
88+
const pdfURL = `${CONFIG.EXPENSIFY.EXPENSIFY_URL}secure?secureType=pdfreport&filename=${this.props.walletStatement[yearMonth]}&downloadName=${fileName}`;
89+
fileDownload(pdfURL, fileName).then(() => {
90+
this.setState({
91+
isDownloading: false,
92+
});
93+
});
94+
}
95+
}
96+
97+
render() {
98+
moment.locale(lodashGet(this.props, 'preferredLocale', 'en'));
99+
const year = this.yearMonth.substring(0, 4) || moment().year();
100+
const month = this.yearMonth.substring(4) || moment().month();
101+
const monthName = moment(month, 'M').format('MMMM');
102+
const title = `${monthName} ${year} statement`;
103+
const url = `${CONFIG.EXPENSIFY.EXPENSIFY_URL}statement.php?period=${this.yearMonth}`;
104+
105+
return (
106+
<ScreenWrapper>
107+
<HeaderWithCloseButton
108+
title={Str.recapitalize(title)}
109+
shouldShowDownloadButton
110+
onCloseButtonPress={() => Navigation.dismissModal(true)}
111+
onDownloadButtonPress={() => this.processDownload(this.yearMonth)}
112+
/>
113+
<WalletStatementModal
114+
statementPageURL={url}
115+
/>
116+
</ScreenWrapper>
117+
);
118+
}
119+
}
120+
55121
WalletStatementPage.propTypes = propTypes;
122+
WalletStatementPage.defaultProps = defaultProps;
56123
WalletStatementPage.displayName = 'WalletStatementPage';
57124
export default compose(
58125
withLocalize,
59126
withOnyx({
60127
preferredLocale: {
61128
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
62129
},
130+
walletStatement: {
131+
key: ONYXKEYS.WALLET_STATEMENT,
132+
},
63133
}),
64134
)(WalletStatementPage);

0 commit comments

Comments
 (0)