Skip to content

Commit

Permalink
add rejectTransaction API call and IOU Action function
Browse files Browse the repository at this point in the history
  • Loading branch information
Julesssss committed Apr 26, 2021
1 parent b063b9c commit f15262e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 18 deletions.
7 changes: 7 additions & 0 deletions src/components/TransactionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { View, Text, Pressable } from 'react-native-web';
import ReportActionPropTypes from '../pages/home/report/ReportActionPropTypes';
import ReportActionItemIOUPreview from '../components/ReportActionItemIOUPreview';
import styles from '../styles/styles';
import {rejectTransaction} from '../libs/actions/IOU';

const propTypes = {
action: PropTypes.shape(ReportActionPropTypes).isRequired,
Expand Down Expand Up @@ -39,7 +40,13 @@ class TransactionItem extends Component {
}

removeTransaction() {
// TODO: delegate to parent
console.debug('removeTransaction');
rejectTransaction({
reportID: 999,
transactionID: 999999,
comment: 'NO!'
});
}

render() {
Expand Down
7 changes: 7 additions & 0 deletions src/libs/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ function Push_Authenticate(parameters) {
return Network.post(commandName, parameters);
}

function RejectTransaction(parameters) {
const commandName = 'RejectTransaction';
requireParameters(['reportID', 'transactionID'], parameters, commandName);
return Network.post(commandName, parameters);
}

/**
* @param {Object} parameters
* @param {String} parameters.reportComment
Expand Down Expand Up @@ -719,6 +725,7 @@ export {
PersonalDetails_GetForEmails,
PersonalDetails_Update,
Push_Authenticate,
RejectTransaction,
Report_AddComment,
Report_GetHistory,
Report_TogglePinned,
Expand Down
53 changes: 35 additions & 18 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,35 @@ function createIOUSplit({
.then(reportIDList => getIOUReportsForNewTransaction(reportIDList));
}

/**
* Retrieve an IOU report using a transactionID, then navigate to the page.
* @param {Int} transactionID
*/
function getIOUReportDetailFromTransactionID(transactionID) {
API.Get({
returnValueList: 'transactionList',
transactionID,
})
.then((data) => {
const chatReportID = data.transactionList[0].reportID;
if (!chatReportID) {
return;
}
Navigation.navigate(ROUTES.getIouDetailsRoute(chatReportID));
})
.catch((error) => {
console.error('Error retrieving Transaction: ', error);
});
}

/**
* Settles an IOU Report
*/
function settleIOUReport({
function settleIOUReport({
reportID, paymentMethodType,
}) {
// Onyx.merge(ONYXKEYS.IOU, {loading: true, creatingIOUTransaction: true, error: false});
console.debug('juless: settleIOUReport', {reportID, paymentMethodType});
return;

API.PayIOU({
reportID,
Expand All @@ -129,30 +149,27 @@ function settleIOUReport({
}

/**
* Retrieve an IOU report using a transactionID, then navigate to the page.
* @param {Int} transactionID
* Decline or cancel a transaction
*/
function getIOUReportDetailFromTransactionID(transactionID) {
API.Get({
returnValueList: 'transactionList',
function rejectTransaction({
reportID, transactionID, comment
}) {
console.debug('juless: rejectTransaction', {reportID, transactionID, comment});

API.RejectTransaction({
reportID,
transactionID,
})
.then((data) => {
const chatReportID = data.transactionList[0].reportID;
if (!chatReportID) {
return;
}
Navigation.navigate(ROUTES.getIouDetailsRoute(chatReportID));
})
.catch((error) => {
console.error('Error retrieving Transaction: ', error);
});
comment,
}).then((data) => {
console.debug('juless: rejectedTransaction response: ', data);
});
}

export {
getPreferredCurrency,
createIOUTransaction,
createIOUSplit,
getIOUReportDetailFromTransactionID,
rejectTransaction,
settleIOUReport,
};
2 changes: 2 additions & 0 deletions src/pages/iou/IOUDetailsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class IOUDetailsModal extends Component {
<TransactionItem
transaction={transaction}
action={actionForTransaction}
iouReportID={}
transactionID={}
/>
);
})}
Expand Down

0 comments on commit f15262e

Please sign in to comment.