import React, { useState } from 'react'; import { withRouter } from 'react-router-dom'; import { Switch } from 'react-materialize'; import './Flow.css'; import CashFlow from "./CashFlow"; import WorkFlow from "./WorkFlow"; const Flow = (props) => { const [flowType, setFlowType] = useState('cash'); return (
setFlowType(e.target.checked === true ? 'work' : 'cash')} onLabel="Work" /> const [flow, setFlow] = useState([]); const og = props.og; useEffect( () => { (async () => { try { const response = await axios.get(`/api/money_moves?homie_id=${parseInt(homie_id)}`); if (response.status === 200 && response.data){ setFlow(response.data); } } catch (e) { M.toast({ html: "Yo! It ain't workin'" }); } })(); }, [homie_id]); const dateBlock = (timestamp) => { timestampToDate(timestamp) } const flowData = flow.map( (singleFlowData, index) => (
  • { singleFlowData.description }
    { dateBlock(singleFlowData['created_at']) }
    0 ? 'amount-green' : ''}`}>{ formatMoney(singleFlowData.amount, og) }
    { flowType === 'cash' && } { flowType === 'work' && } return (

    {`${totalCount} Records`}{` • ${fromDate} - ${toDate}`}
    Total flow: {formatMoney(totalFlow, og)}
    ) }
  • ); } export default withRouter(Flow);