From 553df2e50d5729dac0c19c4819794b4352e3647d Mon Sep 17 00:00:00 2001 From: Bilal Date: Thu, 8 Oct 2020 09:44:18 +0300 Subject: [PATCH 1/3] send money moves on settle action --- app/controllers/chips_controller.rb | 2 +- app/controllers/homies_controller.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/chips_controller.rb b/app/controllers/chips_controller.rb index c1c6add..e2a03d1 100644 --- a/app/controllers/chips_controller.rb +++ b/app/controllers/chips_controller.rb @@ -22,7 +22,7 @@ class ChipsController < ApplicationController name: 'Euro', symbol: '€', code: 'EUR', - scale: 3, + scale: 2, prefixed: false } ] diff --git a/app/controllers/homies_controller.rb b/app/controllers/homies_controller.rb index ff64f42..8d5770c 100644 --- a/app/controllers/homies_controller.rb +++ b/app/controllers/homies_controller.rb @@ -35,7 +35,8 @@ class HomiesController < ApplicationController homie = Homie.find(homie_id) if homie.settle(amount) - info + money_moves = MoneyMove.where(homie_id: params[:homie_id].to_i).all.order(created_at: :desc) + json_response money_moves else error_response :bad_request end -- 2.47.3 From 5249fe9629f2e0dff5c56c51f7e6016b01f08ca6 Mon Sep 17 00:00:00 2001 From: Bilal Date: Thu, 8 Oct 2020 09:44:35 +0300 Subject: [PATCH 2/3] move settle action to the homie cash flow details --- client/src/cash/Cash.js | 28 +----------------------- client/src/common/InputModal.js | 2 +- client/src/homies/CashFlow.js | 38 ++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/client/src/cash/Cash.js b/client/src/cash/Cash.js index c3848b0..91fa203 100644 --- a/client/src/cash/Cash.js +++ b/client/src/cash/Cash.js @@ -1,13 +1,10 @@ -import React, { useState, useEffect, useReducer } from 'react'; +import React, { useState, useEffect } 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, formatTime } from '../common/formatting'; -import InputModal from "../common/InputModal"; -import { errorToast } from "../common/errorHelpers"; -import M from 'materialize-css'; const Cash = (props) => { const [homiesCash, setHomiesCash] = useState([]); @@ -25,20 +22,6 @@ const Cash = (props) => { getCashForHomies(); }, []); - const settleFlowForHomie = async (id, amountToSettle) => { - try { - const response = await axios.post(`/api/gangs/${gang.id}/homies/${id}/settle`, { amount: amountToSettle }); - if (response.status === 200 && response.data) { - M.toast({ html: 'Settled' }); - setHomiesCash(response.data); - }else{ - errorToast(); - } - } catch(e) { - errorToast(); - } - } - const cashTableBody = homiesCash.map( (homieLine) => { return ( @@ -52,15 +35,6 @@ const Cash = (props) => { { formatMoney(homieLine.amount, gang) } - [ - settleFlowForHomie(homieLine.homie.id, settleAmount)} - triggerNode={Settle} - /> - ] ); diff --git a/client/src/common/InputModal.js b/client/src/common/InputModal.js index 48df526..dae5eaf 100644 --- a/client/src/common/InputModal.js +++ b/client/src/common/InputModal.js @@ -40,7 +40,7 @@ const InputModal = (props) => {

{body}


- +
diff --git a/client/src/homies/CashFlow.js b/client/src/homies/CashFlow.js index c71a229..8c924a4 100644 --- a/client/src/homies/CashFlow.js +++ b/client/src/homies/CashFlow.js @@ -4,19 +4,28 @@ import axios from "axios"; import './Flow.css'; import { formatMoney, timestampToDate } from "../common/formatting"; import {errorToast} from "../common/errorHelpers"; +import InputModal from "../common/InputModal"; +import M from "materialize-css"; +import { Button } from 'react-materialize'; const CashFlow = (props) => { const { homie_id } = useParams(); const gang = props.gang; const [cashFlow, setCashFlow] = useState([]); + const [totalCashFlowAmount, setTotalCashFlowAmount] = useState(0); + + const updateData = (data) => { + setCashFlow(data); + setTotalCashFlowAmount(data.reduce((sum, record) => sum + parseInt(record.amount), 0)); + } useEffect( () => { (async () => { try { const response = await axios.get(`/api/money_moves?homie_id=${parseInt(homie_id)}`); if (response.status === 200 && response.data){ - setCashFlow(response.data); + updateData(response.data); } } catch (e) { errorToast(); @@ -45,7 +54,6 @@ const CashFlow = (props) => { const totalCount = cashFlow.length; const firstFlowRow = totalCount > 0 ? cashFlow[0] : undefined; const lastFlowRow = totalCount > 0 ? cashFlow[cashFlow.length - 1] : undefined; - const totalFlow = cashFlow.reduce((sum, record) => sum + parseInt(record.amount), 0); const fromDate = lastFlowRow ? timestampToDate(lastFlowRow['created_at']) : ''; const toDate = firstFlowRow ? timestampToDate(firstFlowRow['created_at']) : ''; @@ -58,19 +66,43 @@ const CashFlow = (props) => { {`${totalCount} Records`}{` • ${fromDate} - ${toDate}`}
- Total cash flow: {formatMoney(totalFlow, gang)} + Total cash flow: {formatMoney(totalCashFlowAmount, gang)}
) } + const settleFlowForHomie = async (id, amountToSettle) => { + try { + const response = await axios.post(`/api/gangs/${gang.id}/homies/${id}/settle`, { amount: amountToSettle }); + if (response.status === 200 && response.data) { + M.toast({ html: 'Settled' }); + updateData(response.data); + }else{ + errorToast(); + } + } catch(e) { + errorToast(); + } + } + return (
{ totalStats() }
    { flowData }
+ +
+ + settleFlowForHomie(homie_id, settleAmount)} + triggerNode={} + />
); } -- 2.47.3 From 8ec99343c3a900c1cb93151b89424b3f1a38753f Mon Sep 17 00:00:00 2001 From: Bilal Date: Thu, 8 Oct 2020 10:03:59 +0300 Subject: [PATCH 3/3] do not change gang on homie details click --- client/src/App.js | 2 +- client/src/cash/Cash.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index 8f50db0..81566dd 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -79,7 +79,7 @@ const App = (props) => { const navbarLogoWithGang = (
- GKS + GKS { const [homiesCash, setHomiesCash] = useState([]); @@ -26,7 +27,7 @@ const Cash = (props) => { return ( - { homieLine.homie.name } + {homieLine.homie.name} { formatTime(homieLine.work) } -- 2.47.3