From 8d7716f2e0468ac9d1a67fe3a0d95d5c681da416 Mon Sep 17 00:00:00 2001 From: Bilal Date: Wed, 7 Oct 2020 22:45:34 +0300 Subject: [PATCH] Show gang switch --- client/src/App.css | 4 ++ client/src/App.js | 47 ++++++++++++++----- .../{ChipSelection.js => GangOnboarding.js} | 24 +++++++--- client/src/homies/Homies.js | 2 +- client/src/homies/NewHomieForm.js | 7 ++- 5 files changed, 63 insertions(+), 21 deletions(-) rename client/src/gangOnboarding/{ChipSelection.js => GangOnboarding.js} (68%) diff --git a/client/src/App.css b/client/src/App.css index d5bdbce..2085026 100644 --- a/client/src/App.css +++ b/client/src/App.css @@ -54,4 +54,8 @@ position: absolute; height: 90%; margin-left: 40%; +} + +.bump { + margin-left: 2em; } \ No newline at end of file diff --git a/client/src/App.js b/client/src/App.js index 0ae860a..8d7bb75 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import './App.css'; -import { Navbar } from 'react-materialize'; +import { Navbar, Dropdown, Icon } from 'react-materialize'; import MakeMoneyMove from './cash/MakeMoneyMove'; import Flow from "./homies/Flow"; import Cash from './cash/Cash'; @@ -16,21 +16,23 @@ import { PUT_IN_WORK } from './RouteNames'; import PutInWork from "./cash/PutInWork"; -import ChipSelection from "./gangOnboarding/ChipSelection"; +import GangOnboarding from "./gangOnboarding/GangOnboarding"; import {errorToast} from "./common/errorHelpers"; const App = (props) => { const [loading, setLoading] = useState(true); - const [gang, setGang] = useState({}); + const [gangs, setGangs] = useState([]); + const [selectedGang, setSelectedGang] = useState({}); useEffect(() => { (async() => { try { setLoading(true); - const response = await axios.get(`/api/gangs/0`); + const response = await axios.get(`/api/gangs`); if (response.status === 200 && response.data){ - setGang(response.data); + setGangs(response.data); + setSelectedGang(response.data[0]); }else{ errorToast(); } @@ -42,15 +44,15 @@ const App = (props) => { }, []); const routes = ([ - } />, - } />, - } />, + } />, + } />, + } />, } />, } /> ] ); - const onboarded = () => gang.chip_name && gang.chip_name.length > 0; + const onboarded = () => selectedGang.chip_name && selectedGang.chip_name.length > 0; const preloaderCircle = (
@@ -72,11 +74,34 @@ const App = (props) => {
); + const navbarLogoWithGang = ( +
+ GKS + + {selectedGang && selectedGang.name && selectedGang.name.length > 0 ? `${selectedGang.name} gang` : '[No name gang]'}arrow_drop_down} + > + {gangs.map(gang => {`${gang.name} gang`})} + +
+ ); + return (
- GKS} alignLinks="right"> + Crib @@ -97,7 +122,7 @@ const App = (props) => {
{ loading && preloaderCircle } - { !loading && !onboarded() && } + { !loading && !onboarded() && } { !loading && onboarded() && routes }
diff --git a/client/src/gangOnboarding/ChipSelection.js b/client/src/gangOnboarding/GangOnboarding.js similarity index 68% rename from client/src/gangOnboarding/ChipSelection.js rename to client/src/gangOnboarding/GangOnboarding.js index af7ee9a..5f5dcb3 100644 --- a/client/src/gangOnboarding/ChipSelection.js +++ b/client/src/gangOnboarding/GangOnboarding.js @@ -1,11 +1,14 @@ import React, { useState, useEffect } from 'react'; import axios from "axios"; import { errorToast } from "../common/errorHelpers"; -import {Button, Select, TextInput} from "react-materialize"; +import {Button, Select} from "react-materialize"; -const ChipSelection = (props) => { +const GangOnboarding = (props) => { const [chips, setChips] = useState([]); const [selectedChip, setSelectedChip] = useState('1'); + const [gangName, setGangName] = useState(''); + + const gang = props.gang; useEffect(() => { (async() => { @@ -25,22 +28,23 @@ const ChipSelection = (props) => { const chipsToOptions = chips.map( (chip, index) => ); const disableSubmit = () => { - return !(parseInt(selectedChip) > 0); + return parseInt(selectedChip) === 0 || gangName.length === 0 ; } const handleSubmit = async () => { const chipData = chips.find(chip => chip.id === parseInt(selectedChip)); if (chipData){ - const gang = { + const updatedGang = { chip_name: chipData.name, chip_code: chipData.code, chip_symbol: chipData.symbol, chip_prefixed: chipData.prefixed, - chip_scale: chipData.scale + chip_scale: chipData.scale, + name: gangName } try{ - const response = await axios.put('/api/gangs/0', { 'gang': gang }); + const response = await axios.put(`/api/gangs/${gang.id}`, { 'gang': updatedGang }); if (response.status === 200 && response.data && response.data.onboarded) { window.location.reload(); }else{ @@ -56,6 +60,12 @@ const ChipSelection = (props) => { return (
+ +
+ setGangName(e.target.value)} /> + +
+ @@ -67,4 +77,4 @@ const ChipSelection = (props) => { ) } -export default ChipSelection; \ No newline at end of file +export default GangOnboarding; \ No newline at end of file diff --git a/client/src/homies/Homies.js b/client/src/homies/Homies.js index 3e7ffdd..a68f8d0 100644 --- a/client/src/homies/Homies.js +++ b/client/src/homies/Homies.js @@ -62,7 +62,7 @@ const Homies = (props) => { return (
- +
    { homiesData } diff --git a/client/src/homies/NewHomieForm.js b/client/src/homies/NewHomieForm.js index 04fcec3..cf30f2b 100644 --- a/client/src/homies/NewHomieForm.js +++ b/client/src/homies/NewHomieForm.js @@ -10,6 +10,8 @@ const NewHomieForm = (props) => { const [homieImportance, setHomieImportance] = useState(""); const [busy, setBusy] = useState(false); + const gang = props.gang; + const disableAddButton = () => { return homieName.length === 0 || homieImportance === "" || @@ -33,7 +35,8 @@ const NewHomieForm = (props) => { homie: { name: homieName, about: aboutHomie, - importance: parseInt(homieImportance) + importance: parseInt(homieImportance), + gang_id: gang.id } } @@ -57,7 +60,7 @@ const NewHomieForm = (props) => { return (
    - Introduce new homie to the Hood}> + {`Introduce new homie to the ${gang.name} gang`}}>
    setHomieName(e.target.value)} />