Allow entering custom settle value in input modal

This commit is contained in:
Bilal
2020-10-05 14:25:04 +03:00
parent 51ad1d817e
commit 6a6f650538
2 changed files with 58 additions and 5 deletions

View File

@@ -5,7 +5,7 @@ import axios from 'axios';
import { MAKE_MONEY_MOVE } from '../RouteNames';
import { withRouter } from 'react-router-dom';
import { formatMoney } from '../common/formatting';
import YesNoModal from "../common/YesNoModal";
import InputModal from "../common/InputModal";
import { errorToast } from "../common/errorHelpers";
import M from 'materialize-css';
@@ -26,9 +26,10 @@ const Cash = (props) => {
getCashForHomies();
}, []);
const settleFlowForHomie = async (id) => {
const settleFlowForHomie = async (id, amountToSettle) => {
console.log('Amount to settle : ', amountToSettle);
try {
const response = await axios.delete(`/api/homies/${id}/settle`);
const response = await axios.post(`/api/homies/${id}/settle`, { amount: amountToSettle });
if (response.status === 200 && response.data) {
M.toast({ html: 'Settled' });
}else{
@@ -51,9 +52,11 @@ const Cash = (props) => {
</td>
<td className="cash-cell-left">
[
<YesNoModal
<InputModal
body={"Maan, y'a sure about this? Flow history goes bye bye!"}
yesAction={() => settleFlowForHomie(homieLine.homie.id)}
inputLabel={'Settle to'}
defaultInputValue={homieLine.amount}
confirmAction={(settleAmount) => settleFlowForHomie(homieLine.homie.id, settleAmount)}
triggerNode={<a href='#'>Settle</a>}
/>
]