import React, { useState, useEffect, useReducer } from 'react'; import { Button, Table } from 'react-materialize'; import './Cash.css'; 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 { errorToast } from "../common/errorHelpers"; import M from 'materialize-css'; const Cash = (props) => { const [homiesCash, setHomiesCash] = useState([]); const [, forceUpdate] = useReducer(x => x + 1, 0); //const [importance, setImportance] = useState(10); const og = props.og; useEffect( () => { const getCashForHomies = async () => { try { const cash = await axios.get(`/api/homies/cash`); setHomiesCash(cash.data); } catch (e) { console.log("Error fetching", e); } }; getCashForHomies(); }, []); const settleFlowForHomie = async (id) => { try { const response = await axios.delete(`/api/homies/${id}/settle`); if (response.status === 200 && response.data) { M.toast({ html: 'Settled' }); }else{ errorToast(); } } catch(e) { errorToast(); } forceUpdate(); } const cashTableBody = homiesCash.map( (homieLine) => { return (
| Homie | Cash | Actions |
|---|