Allow entering custom settle value in input modal
This commit is contained in:
@@ -5,7 +5,7 @@ import axios from 'axios';
|
|||||||
import { MAKE_MONEY_MOVE } from '../RouteNames';
|
import { MAKE_MONEY_MOVE } from '../RouteNames';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { formatMoney } from '../common/formatting';
|
import { formatMoney } from '../common/formatting';
|
||||||
import YesNoModal from "../common/YesNoModal";
|
import InputModal from "../common/InputModal";
|
||||||
import { errorToast } from "../common/errorHelpers";
|
import { errorToast } from "../common/errorHelpers";
|
||||||
import M from 'materialize-css';
|
import M from 'materialize-css';
|
||||||
|
|
||||||
@@ -26,9 +26,10 @@ const Cash = (props) => {
|
|||||||
getCashForHomies();
|
getCashForHomies();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const settleFlowForHomie = async (id) => {
|
const settleFlowForHomie = async (id, amountToSettle) => {
|
||||||
|
console.log('Amount to settle : ', amountToSettle);
|
||||||
try {
|
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) {
|
if (response.status === 200 && response.data) {
|
||||||
M.toast({ html: 'Settled' });
|
M.toast({ html: 'Settled' });
|
||||||
}else{
|
}else{
|
||||||
@@ -51,9 +52,11 @@ const Cash = (props) => {
|
|||||||
</td>
|
</td>
|
||||||
<td className="cash-cell-left">
|
<td className="cash-cell-left">
|
||||||
[
|
[
|
||||||
<YesNoModal
|
<InputModal
|
||||||
body={"Maan, y'a sure about this? Flow history goes bye bye!"}
|
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>}
|
triggerNode={<a href='#'>Settle</a>}
|
||||||
/>
|
/>
|
||||||
]
|
]
|
||||||
|
|||||||
50
client/src/common/InputModal.js
Normal file
50
client/src/common/InputModal.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import React, { useRef } from 'react';
|
||||||
|
import {Modal, Button, Row, Col} from 'react-materialize';
|
||||||
|
|
||||||
|
const InputModal = (props) => {
|
||||||
|
const { title, body, confirmAction, stopAction, triggerNode, defaultInputValue, inputLabel } = props;
|
||||||
|
const inputField = useRef(null);
|
||||||
|
|
||||||
|
return(
|
||||||
|
<Modal
|
||||||
|
actions={[
|
||||||
|
<Row>
|
||||||
|
<Col s={3}>
|
||||||
|
<Button modal="confirm" node="button" waves="green" onClick={() => confirmAction(inputField.current.value)}>Do it</Button>
|
||||||
|
</Col>
|
||||||
|
<Col s={3}>
|
||||||
|
<Button modal="close" node="button" waves="red" onClick={stopAction}>Stop</Button>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
]}
|
||||||
|
bottomSheet
|
||||||
|
fixedFooter={false}
|
||||||
|
header={title}
|
||||||
|
id="Modal-1"
|
||||||
|
open={false}
|
||||||
|
options={{
|
||||||
|
dismissible: true,
|
||||||
|
endingTop: '10%',
|
||||||
|
inDuration: 250,
|
||||||
|
onCloseEnd: null,
|
||||||
|
onCloseStart: null,
|
||||||
|
onOpenEnd: null,
|
||||||
|
onOpenStart: null,
|
||||||
|
opacity: 0.5,
|
||||||
|
outDuration: 250,
|
||||||
|
preventScrolling: true,
|
||||||
|
startingTop: '4%'
|
||||||
|
}}
|
||||||
|
trigger={triggerNode}
|
||||||
|
>
|
||||||
|
<p><strong>{body}</strong></p>
|
||||||
|
<br/>
|
||||||
|
<div className="input-field col s6">
|
||||||
|
<input ref={inputField} defaultValue={defaultInputValue} id="input-num" type="number" className="validate" />
|
||||||
|
<label className="active" htmlFor="input-num">{inputLabel}</label>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default InputModal;
|
||||||
Reference in New Issue
Block a user