Revert "Merge branch 'transform-currency-support' into 'master'"
This reverts merge request !14
This commit is contained in:
@@ -1,29 +1,6 @@
|
||||
class ChipsController < ApplicationController
|
||||
def index
|
||||
all_chips = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'US Dollar',
|
||||
symbol: '$',
|
||||
code: 'USD',
|
||||
prefixed: true
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Bosnian Convertible Mark',
|
||||
symbol: 'KM',
|
||||
code: 'BAM',
|
||||
prefixed: false
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Euro',
|
||||
symbol: '€',
|
||||
code: 'EUR',
|
||||
prefixed: false
|
||||
}
|
||||
]
|
||||
json_response all_chips
|
||||
json_response Chip.where(enabled: true).order(:name).to_json(include: :base_chip_values)
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -45,7 +45,8 @@ class HomiesController < ApplicationController
|
||||
params.require(:homie).permit(
|
||||
:name,
|
||||
:importance,
|
||||
:about
|
||||
:about,
|
||||
:chip_id
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
class OgsController < ApplicationController
|
||||
def show
|
||||
if Og.count.zero?
|
||||
Og.create.save
|
||||
end
|
||||
|
||||
json_response Og.first
|
||||
end
|
||||
|
||||
def update
|
||||
if og_params[:chip_scale].to_i.positive?
|
||||
Og.update(og_params)
|
||||
json_response onboarded: true
|
||||
else
|
||||
error_response :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def og_params
|
||||
params.require(:og).permit :chip_name,
|
||||
:chip_code,
|
||||
:chip_symbol,
|
||||
:chip_scale,
|
||||
:chip_prefixed
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
class Homie < ApplicationRecord
|
||||
has_many :money_moves
|
||||
has_many :work
|
||||
belongs_to :chip
|
||||
|
||||
def self.cash(importance)
|
||||
totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
class Og < ApplicationRecord
|
||||
|
||||
end
|
||||
@@ -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;
|
||||
@@ -1,7 +1,6 @@
|
||||
Rails.application.routes.draw do
|
||||
constraints format: :json do
|
||||
scope :api do
|
||||
resource :og, only: [:show, :update]
|
||||
resources :money_moves
|
||||
resources :work
|
||||
resources :chips, only: %i[index create destroy]
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
class RemoveDefaultChipFromHomies < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
remove_reference :homies, :chip
|
||||
end
|
||||
end
|
||||
@@ -1,13 +0,0 @@
|
||||
class CreateOgs < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :ogs do |t|
|
||||
t.text :chip_name
|
||||
t.text :chip_code
|
||||
t.text :chip_symbol
|
||||
t.boolean :chip_prefixed
|
||||
t.integer :chip_scale
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
12
db/schema.rb
12
db/schema.rb
@@ -41,6 +41,8 @@ ActiveRecord::Schema.define(version: 2020_09_19_023237) do
|
||||
t.text "about"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.bigint "chip_id"
|
||||
t.index ["chip_id"], name: "index_homies_on_chip_id"
|
||||
end
|
||||
|
||||
create_table "money_moves", force: :cascade do |t|
|
||||
@@ -59,16 +61,6 @@ ActiveRecord::Schema.define(version: 2020_09_19_023237) do
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "ogs", force: :cascade do |t|
|
||||
t.text "chip_name"
|
||||
t.text "chip_code"
|
||||
t.text "chip_symbol"
|
||||
t.boolean "chip_prefixed"
|
||||
t.integer "chip_scale"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_foreign_key "chip_values", "chips", column: "base_chip_id"
|
||||
add_foreign_key "chip_values", "chips", column: "secondary_chip_id"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user