diff --git a/client/src/App.js b/client/src/App.js index 8996e1c..88b0ceb 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -13,7 +13,7 @@ import { HOMIE_FLOW, HOMIES, HOMIE_MOVE_MONEY, - PUT_IN_WORK + HOMIE_PUT_IN_WORK } from './RouteNames'; import PutInWork from "./cash/PutInWork"; import GangOnboarding from "./gangOnboarding/GangOnboarding"; @@ -51,7 +51,7 @@ const App = (props) => { } />, } />, } />, - } /> + } /> ] ); @@ -124,10 +124,6 @@ const App = (props) => { Homies - - - Put in Work - diff --git a/client/src/RouteNames.js b/client/src/RouteNames.js index 756433d..c14e14e 100644 --- a/client/src/RouteNames.js +++ b/client/src/RouteNames.js @@ -1,6 +1,6 @@ export const CRIB = '/'; export const HOMIES = '/homies'; export const HOMIE_MOVE_MONEY = '/homie/:homie_id/move-money'; -export const PUT_IN_WORK = '/put-in-work'; +export const HOMIE_PUT_IN_WORK = '/homie/:homie_id/put-in-work'; export const HOMIE_FLOW = '/homie/:homie_id/flow'; export const GANGS = '/gangs'; diff --git a/client/src/cash/Cash.js b/client/src/cash/Cash.js index 02ff8c4..c14bd80 100644 --- a/client/src/cash/Cash.js +++ b/client/src/cash/Cash.js @@ -41,6 +41,12 @@ const Cash = (props) => { monetization_on + + + ); diff --git a/client/src/cash/PutInWork.js b/client/src/cash/PutInWork.js index c0fe49b..f8f8490 100644 --- a/client/src/cash/PutInWork.js +++ b/client/src/cash/PutInWork.js @@ -1,70 +1,88 @@ import React, {useState, useEffect} from 'react'; import M from 'materialize-css'; -import {Icon, Select, Button, Textarea} from 'react-materialize'; +import {Icon, Select, Button, Textarea, Switch} from 'react-materialize'; import './Cash.css'; import axios from 'axios'; import {errorToast} from "../common/errorHelpers"; +import {useParams, withRouter} from "react-router-dom"; const PutInWork = (props) => { - const [homies, setHomies] = useState([]); - const [selectedTo, setSelectedTo] = useState(''); + const { homie_id } = useParams(); + + const [selectedHomie, setSelectedHomie] = useState(null); const [amountToAdd, setAmountToAdd] = useState(''); const [workDescription, setWorkDescription] = useState(''); const [submitInProgress, setSubmitInProgress] = useState(false); + const [workType, setWorkType] = useState('put-in'); const gang = props.gang; useEffect(() => { (async () => { try { - const response = await axios.get(`/api/gangs/${gang.id}/homies`); - if (response.status === 200 && response.data){ - setHomies(response.data); + const homie = await axios.get(`/api/gangs/${gang.id}/homies/${homie_id}`); + if (homie.status === 200 && homie.data){ + setSelectedHomie(homie.data); } } catch (e) { errorToast(); } })(); - }, [gang]); - - const homieOptions = homies.map(homie => ); - - const clearForm = () => { - setAmountToAdd(''); - setSelectedTo(''); - setWorkDescription(''); - } + }, [gang, homie_id]); const handleSubmit = async (e) => { e.preventDefault(); setSubmitInProgress(true); - const workRequest = { - work: { - amount: parseInt(amountToAdd), - homie_id: selectedTo, - description: workDescription + + let workRequest = {}; + if (workType === 'put-in') { + workRequest = { + work: { + amount: parseInt(amountToAdd), + homie_id: homie_id, + description: workDescription + } + } + }else{ + workRequest = { + work: { + amount: -parseInt(amountToAdd), + homie_id: homie_id, + description: workDescription + } } } + const submitResponse = await axios.post('/api/work', workRequest); if (submitResponse && submitResponse.status === 200 && submitResponse.data && submitResponse.data.ok === true) { M.toast({html: "Alright"}); - clearForm(); + props.history.push(`/homie/${homie_id}/flow`); } else { errorToast(); } setSubmitInProgress(false); } - const formComplete = () => selectedTo !== '' && parseInt(amountToAdd) !== 0 && !isNaN(parseInt(amountToAdd)); + const formComplete = () => parseInt(amountToAdd) > 0 && !isNaN(parseInt(amountToAdd)); const disableSubmit = () => (!formComplete() || submitInProgress); return (
-

Put in Work

+

{selectedHomie && selectedHomie.name}

+ +
+ setWorkType(e.target.checked === true ? 'owe' : 'put-in')} + onLabel="Owe work" + /> +
+ +
setAmountToAdd(parseInt(e.target.value))} /> @@ -72,12 +90,6 @@ const PutInWork = (props) => {
- - -