Revert "Merge branch 'transform-currency-support' into 'master'"
This reverts merge request !14
This commit is contained in:
@@ -48,10 +48,4 @@
|
||||
.required:before {
|
||||
color: red;
|
||||
content: "* ";
|
||||
}
|
||||
|
||||
.preloader-circle {
|
||||
position: absolute;
|
||||
height: 90%;
|
||||
margin-left: 40%;
|
||||
}
|
||||
@@ -1,75 +1,24 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import React from 'react';
|
||||
import './App.css';
|
||||
import { Navbar } from 'react-materialize';
|
||||
import MakeMoneyMove from './cash/MakeMoneyMove';
|
||||
import Flow from "./homies/Flow";
|
||||
import Cash from './cash/Cash';
|
||||
import Chips from './chips/Chips';
|
||||
import Homies from './homies/Homies';
|
||||
import { BrowserRouter as Router, Route } from "react-router-dom";
|
||||
import RoutableNavItem from './common/RoutableNavItem';
|
||||
import axios from 'axios';
|
||||
import {
|
||||
CRIB,
|
||||
CHIPS,
|
||||
MAKE_MONEY_MOVE,
|
||||
HOMIE_FLOW,
|
||||
HOMIES, PUT_IN_WORK
|
||||
} from './RouteNames';
|
||||
import PutInWork from "./cash/PutInWork";
|
||||
import ChipSelection from "./ogOnboarding/ChipSelection";
|
||||
import {errorToast} from "./common/errorHelpers";
|
||||
|
||||
|
||||
const App = (props) => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [og, setOg] = useState({});
|
||||
|
||||
useEffect(() => {
|
||||
(async() => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await axios.get(`/api/og`);
|
||||
if (response.status === 200 && response.data){
|
||||
setOg(response.data);
|
||||
}else{
|
||||
errorToast();
|
||||
}
|
||||
} catch (e) {
|
||||
errorToast();
|
||||
}
|
||||
setLoading(false);
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const routes = ([
|
||||
<Route key='1' exact path={CRIB} component={() => <Cash og={og} />} />,
|
||||
<Route key='2' exact path={HOMIES} component={() => <Homies og={og} />} />,
|
||||
<Route key='3' path={HOMIE_FLOW} component={() => <Flow og={og} />} />,
|
||||
<Route key='4' path={MAKE_MONEY_MOVE} component={() => <MakeMoneyMove og={og} />} />
|
||||
]
|
||||
);
|
||||
|
||||
const onboarded = () => og.chip_name && og.chip_name.length > 0;
|
||||
|
||||
const preloaderCircle = (
|
||||
<div className="container">
|
||||
<div className="valign-wrapper center-align preloader-circle">
|
||||
<div className="preloader-wrapper big active">
|
||||
<div className="spinner-layer spinner-blue-only">
|
||||
<div className="circle-clipper left">
|
||||
<div className="circle" />
|
||||
</div>
|
||||
<div className="gap-patch">
|
||||
<div className="circle" />
|
||||
</div>
|
||||
<div className="circle-clipper right">
|
||||
<div className="circle" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<Router>
|
||||
<div className="navbar-fixed">
|
||||
@@ -82,6 +31,10 @@ const App = (props) => {
|
||||
Homies
|
||||
</RoutableNavItem>
|
||||
|
||||
<RoutableNavItem href={CHIPS}>
|
||||
Chips
|
||||
</RoutableNavItem>
|
||||
|
||||
<RoutableNavItem href={MAKE_MONEY_MOVE}>
|
||||
Make Money Move
|
||||
</RoutableNavItem>
|
||||
@@ -96,11 +49,9 @@ const App = (props) => {
|
||||
<Route exact path={CRIB} component={Cash} />
|
||||
<Route exact path={HOMIES} component={Homies} />
|
||||
<Route path={HOMIE_FLOW} component={Flow} />
|
||||
<Route path={CHIPS} component={Chips} />
|
||||
<Route path={MAKE_MONEY_MOVE} component={MakeMoneyMove} />
|
||||
<Route path={PUT_IN_WORK} component={PutInWork} />
|
||||
{ loading && preloaderCircle }
|
||||
{ !loading && !onboarded() && <ChipSelection /> }
|
||||
{ !loading && onboarded() && routes }
|
||||
</div>
|
||||
</Router>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
export const CRIB = '/';
|
||||
export const HOMIES = '/homies';
|
||||
export const CHIPS = '/chips';
|
||||
export const MAKE_MONEY_MOVE = '/make-money-move';
|
||||
export const PUT_IN_WORK = '/put-in-work';
|
||||
export const HOMIE_FLOW = '/homie/:homie_id/flow';
|
||||
|
||||
@@ -13,7 +13,6 @@ 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 () => {
|
||||
@@ -48,7 +47,7 @@ const Cash = (props) => {
|
||||
<a href={`/homie/${homieLine.homie.id}/flow`}>{ homieLine.homie.name }</a>
|
||||
</td>
|
||||
<td className="cash-cell-right">
|
||||
{ formatMoney(homieLine.amount, og) }
|
||||
{ formatMoney(homieLine.amount) }
|
||||
</td>
|
||||
<td className="cash-cell-left">
|
||||
[
|
||||
|
||||
@@ -9,7 +9,7 @@ const MakeMoneyMove = (props) => {
|
||||
const [selectedFrom, setSelectedFrom] = useState("");
|
||||
const [selectedTo, setSelectedTo] = useState("");
|
||||
const [homiesCash, setHomiesCash] = useState([]);
|
||||
const [amountToMove, setAmountToMove] = useState('');
|
||||
const [amountToMove, setAmountToMove] = useState(null);
|
||||
const [moveDescription, setMoveDescription] = useState("");
|
||||
const [submitInProgress, setSubmitInProgress] = useState(false);
|
||||
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
const formatMoney = (amount, og) => {
|
||||
const decimalPlaces = parseInt(og['chip_scale']);
|
||||
const symbol = og['chip_symbol'];
|
||||
const prefixed = og['chip_prefixed'];
|
||||
|
||||
const formatted = Number.parseFloat(amount).toFixed(decimalPlaces);
|
||||
return prefixed ? `${symbol} ${formatted}` : `${formatted} ${symbol}`;
|
||||
const formatMoney = (amount) => {
|
||||
const formatted = Number.parseFloat(amount).toFixed(2);
|
||||
return `${formatted} KM`;
|
||||
}
|
||||
|
||||
const formatTime = (amount) => {
|
||||
|
||||
@@ -16,58 +16,13 @@ const Flow = (props) => {
|
||||
onChange={(e) => 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) => <span className="grey-text">{ timestampToDate(timestamp) }</span>
|
||||
|
||||
|
||||
const flowData = flow.map( (singleFlowData, index) => (
|
||||
<li key={index}>
|
||||
<div className="collapsible-header record">
|
||||
<div className="flex-row opposite-sides-content">
|
||||
<div className="flex-col">
|
||||
<div>{ singleFlowData.description }</div>
|
||||
<div>{ dateBlock(singleFlowData['created_at']) }</div>
|
||||
</div>
|
||||
|
||||
<div className={`flex-center ${singleFlowData.amount > 0 ? 'amount-green' : ''}`}>{ formatMoney(singleFlowData.amount, og) }</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{ flowType === 'cash' && <CashFlow /> }
|
||||
{ flowType === 'work' && <WorkFlow /> }
|
||||
return (
|
||||
<div>
|
||||
<br />
|
||||
<div className="row">
|
||||
<div className="col s6">
|
||||
<strong>{`${totalCount} Records`}</strong><span className="grey-text">{` • ${fromDate} - ${toDate}`}</span>
|
||||
</div>
|
||||
<div className="col s6 right-align">
|
||||
<span className="grey-text">Total flow:</span> <strong>{formatMoney(totalFlow, og)}</strong>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default withRouter(Flow);
|
||||
export default withRouter(Flow);
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Button, Collapsible, CollapsibleItem, Select, TextInput } from 'react-materialize';
|
||||
import axios from 'axios';
|
||||
import { errorToast } from "../common/errorHelpers";
|
||||
@@ -8,11 +8,31 @@ const NewHomieForm = (props) => {
|
||||
const [homieName, setHomieName] = useState("");
|
||||
const [aboutHomie, setAboutHomie] = useState("");
|
||||
const [homieImportance, setHomieImportance] = useState("");
|
||||
const [homieDefaultChip, setHomieDefaultChip] = useState("");
|
||||
const [chips, setChips] = useState([]);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
const response = await axios.get('/api/chips');
|
||||
if (response.status === 200 && response.data) {
|
||||
setChips(response.data);
|
||||
}else {
|
||||
errorToast();
|
||||
}
|
||||
}catch (e) {
|
||||
errorToast();
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const chipOptions = chips.map((chip, index) => <option key={index} value={chip.id}>{ chip.name }</option>);
|
||||
|
||||
const disableAddButton = () => {
|
||||
return homieName.length === 0 ||
|
||||
homieImportance === "" ||
|
||||
homieDefaultChip === "" ||
|
||||
busy;
|
||||
}
|
||||
|
||||
@@ -20,6 +40,7 @@ const NewHomieForm = (props) => {
|
||||
setHomieName("");
|
||||
setAboutHomie("");
|
||||
setHomieImportance("");
|
||||
setHomieDefaultChip("");
|
||||
|
||||
const collapsible = document.getElementById('new-homie-form-container');
|
||||
const collapsibleInstance = M.Collapsible.getInstance(collapsible);
|
||||
@@ -33,7 +54,8 @@ const NewHomieForm = (props) => {
|
||||
homie: {
|
||||
name: homieName,
|
||||
about: aboutHomie,
|
||||
importance: parseInt(homieImportance)
|
||||
importance: parseInt(homieImportance),
|
||||
chip_id: parseInt(homieDefaultChip)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +103,12 @@ const NewHomieForm = (props) => {
|
||||
<option value={0}>Guy from the hood</option>
|
||||
</Select>
|
||||
|
||||
<label className="required">Homie default chip: </label>
|
||||
<Select value={homieDefaultChip} onChange={(e) => setHomieDefaultChip(e.target.value)} name="defaultChip">
|
||||
<option disabled value="">Set default chip</option>
|
||||
{ chipOptions }
|
||||
</Select>
|
||||
|
||||
<br/>
|
||||
|
||||
<Button disabled={disableAddButton()} onClick={addNewHomie}>Add to the hood</Button>
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import axios from "axios";
|
||||
import { errorToast } from "../common/errorHelpers";
|
||||
import {Button, Select, TextInput} from "react-materialize";
|
||||
|
||||
const ChipSelection = (props) => {
|
||||
const [chips, setChips] = useState([]);
|
||||
const [selectedChip, setSelectedChip] = useState('1');
|
||||
const [chipScale, setChipScale] = useState('2');
|
||||
|
||||
useEffect(() => {
|
||||
(async() => {
|
||||
try {
|
||||
const response = await axios.get(`/api/chips`);
|
||||
if (response.status === 200 && response.data){
|
||||
setChips(response.data);
|
||||
}else{
|
||||
errorToast();
|
||||
}
|
||||
} catch (e) {
|
||||
errorToast();
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
|
||||
const chipsToOptions = chips.map( (chip, index) => <option key={index} value={chip.id}>{`${chip.code} • ${chip.name}`}</option>);
|
||||
|
||||
const disableSubmit = () => {
|
||||
return !((parseInt(selectedChip) > 0) && (parseInt(chipScale) > 0));
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const chipData = chips.find(chip => chip.id === parseInt(selectedChip));
|
||||
if (chipData){
|
||||
const og = {
|
||||
chip_name: chipData.name,
|
||||
chip_code: chipData.code,
|
||||
chip_symbol: chipData.symbol,
|
||||
chip_prefixed: chipData.prefixed,
|
||||
chip_scale: parseInt(chipScale)
|
||||
}
|
||||
|
||||
try{
|
||||
const response = await axios.put('/api/og', { og });
|
||||
if (response.status === 200 && response.data && response.data.onboarded) {
|
||||
window.location.reload();
|
||||
}else{
|
||||
errorToast();
|
||||
}
|
||||
}catch (e) {
|
||||
errorToast();
|
||||
}
|
||||
}else{
|
||||
errorToast();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='container'>
|
||||
<Select value={selectedChip} onChange={(e) => setSelectedChip(e.target.value)} name="selected-chip">
|
||||
{ chipsToOptions }
|
||||
</Select>
|
||||
|
||||
<TextInput
|
||||
id='chipScale'
|
||||
label="Chip scale"
|
||||
value={chipScale}
|
||||
type='number'
|
||||
onChange={(e) => setChipScale(e.target.value)}
|
||||
/>
|
||||
|
||||
<Button disabled={disableSubmit()} waves="light" onClick={handleSubmit}>
|
||||
Do It
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ChipSelection;
|
||||
Reference in New Issue
Block a user