-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Accept receipt in request money #23770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
89ce236
94ccccc
eafded7
af581b4
1f7f7bd
3715973
991fc6a
7c88271
c075113
0a3cd9b
448813c
43922f7
551af16
b595397
bbeb8cc
71a8481
0c5f0c2
576c4de
601dccc
68afecf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,4 +131,35 @@ function appendTimeToFileName(fileName) { | |
| return newFileName; | ||
| } | ||
|
|
||
| export {showGeneralErrorAlert, showSuccessAlert, showPermissionErrorAlert, splitExtensionFromFileName, getAttachmentName, getFileType, cleanFileName, appendTimeToFileName}; | ||
| /** | ||
| * Reads a locally uploaded file | ||
| * | ||
| * @param {String} path - the blob url of the locally uplodaded file | ||
| * @param {String} fileName | ||
| * @returns {Promise} | ||
| */ | ||
| const readFileAsync = (path, fileName) => | ||
| new Promise((resolve) => { | ||
| if (!path) { | ||
| resolve(); | ||
| } | ||
|
|
||
| return fetch(path) | ||
| .then((res) => { | ||
| if (!res.ok) { | ||
| throw Error(res.statusText); | ||
| } | ||
| return res.blob(); | ||
| }) | ||
| .then((blob) => { | ||
| const file = new File([blob], cleanFileName(fileName)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This caused a bug #26940. On Android the File API constructor needs the type to be specified otherwise network uploads would fail. |
||
| file.source = path; | ||
| resolve(file); | ||
| }) | ||
| .catch((e) => { | ||
| console.debug('[FileUtils] Could not read uploaded file', e); | ||
| resolve(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are resolving even on failures? Shouldn't we reject?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We resolve with an undefined receipt file and the call to RequestMoney proceeds without the receipt. I agree that we should eventually reject and display some error to the user, but I didn't see anything about it in the doc. Since this PR is blocking others in this project and we currently don't display errors in MoneyRequestConfirmPage, I think we should keep the scope of this PR smaller and tackle displaying an error as a follow up once we align on what error will be displayed.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Fine by me then. |
||
| }); | ||
| }); | ||
|
|
||
| export {showGeneralErrorAlert, showSuccessAlert, showPermissionErrorAlert, splitExtensionFromFileName, getAttachmentName, getFileType, cleanFileName, appendTimeToFileName, readFileAsync}; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ import ONYXKEYS from '../../../ONYXKEYS'; | |
| import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../../../components/withCurrentUserPersonalDetails'; | ||
| import reportPropTypes from '../../reportPropTypes'; | ||
| import personalDetailsPropType from '../../personalDetailsPropType'; | ||
| import * as FileUtils from '../../../libs/fileDownload/FileUtils'; | ||
|
|
||
| const propTypes = { | ||
| report: reportPropTypes, | ||
|
|
@@ -109,6 +110,27 @@ function MoneyRequestConfirmPage(props) { | |
| Navigation.goBack(fallback); | ||
| }; | ||
|
|
||
| /** | ||
| * @param {Array} selectedParticipants | ||
| * @param {String} trimmedComment | ||
| * @param {File} [receipt] | ||
| */ | ||
| const requestMoney = useCallback( | ||
| (selectedParticipants, trimmedComment, receipt) => { | ||
| IOU.requestMoney( | ||
| props.report, | ||
| props.iou.amount, | ||
| props.iou.currency, | ||
| props.currentUserPersonalDetails.login, | ||
| props.currentUserPersonalDetails.accountID, | ||
| selectedParticipants[0], | ||
| trimmedComment, | ||
| receipt, | ||
| ); | ||
| }, | ||
| [props.report, props.iou.amount, props.iou.currency, props.currentUserPersonalDetails.login, props.currentUserPersonalDetails.accountID], | ||
| ); | ||
|
|
||
| const createTransaction = useCallback( | ||
| (selectedParticipants) => { | ||
| const trimmedComment = props.iou.comment.trim(); | ||
|
|
@@ -141,17 +163,25 @@ function MoneyRequestConfirmPage(props) { | |
| return; | ||
| } | ||
|
|
||
| IOU.requestMoney( | ||
| props.report, | ||
| props.iou.amount, | ||
| props.iou.currency, | ||
| props.currentUserPersonalDetails.login, | ||
| props.currentUserPersonalDetails.accountID, | ||
| selectedParticipants[0], | ||
| trimmedComment, | ||
| ); | ||
| if (props.iou.receiptPath && props.iou.receiptSource) { | ||
| FileUtils.readFileAsync(props.iou.receiptPath, props.iou.receiptSource).then((receipt) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✋ Coming from #28347 The transaction creation with receipt upload won't work after uploading the receipt and refreshing the page because the file is removed. So we decided to check the file, if the file is not available then we navigated back the user to the main request money page. |
||
| requestMoney(selectedParticipants, trimmedComment, receipt); | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| requestMoney(selectedParticipants, trimmedComment); | ||
| }, | ||
| [props.iou.amount, props.iou.comment, props.currentUserPersonalDetails.login, props.currentUserPersonalDetails.accountID, props.iou.currency, props.report], | ||
| [ | ||
| props.iou.amount, | ||
| props.iou.comment, | ||
| props.currentUserPersonalDetails.login, | ||
| props.currentUserPersonalDetails.accountID, | ||
| props.iou.currency, | ||
| props.iou.receiptPath, | ||
| props.iou.receiptSource, | ||
| requestMoney, | ||
| ], | ||
| ); | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.