diff --git a/api/auth.js b/api/auth.js index 4e26980..0c29044 100644 --- a/api/auth.js +++ b/api/auth.js @@ -30,7 +30,6 @@ export const login = async (email, password) => { return await axios .post(AUTH_LOGIN, user) .then(res => res.data) - // .catch(error => this.handleErrorResponse(error)); } export const logout = () => { diff --git a/components/Header/index.js b/components/Header/index.js index ef48e76..17572de 100644 --- a/components/Header/index.js +++ b/components/Header/index.js @@ -109,7 +109,7 @@ class Header extends React.Component { Add Apiary } - {user.role === "beelover" && + {/* {user.role === "beelover" && - } + } */} {"Hello " + user.name} diff --git a/components/Hero/index.js b/components/Hero/index.js index ac86b7a..e737d10 100644 --- a/components/Hero/index.js +++ b/components/Hero/index.js @@ -1,15 +1,9 @@ -import { Container, Typography } from "@material-ui/core"; +import { Container } from "@material-ui/core"; import { makeStyles } from '@material-ui/core/styles'; -import Card from "@material-ui/core/Card"; -import CardHeader from "@material-ui/core/CardHeader"; -import StarIcon from "@material-ui/core/SvgIcon/SvgIcon"; -import CardContent from "@material-ui/core/CardContent"; import Grid from "@material-ui/core/Grid"; import React from "react"; import taxiWaiting from '../../assets/images/taxiWaiting.png'; -import vector from '../../assets/images/Vector.png'; -import Logo from "../../assets/images/logo/black_on_yellow.png"; const useStyles = makeStyles(theme => ({ heroContent: { @@ -33,27 +27,7 @@ const useStyles = makeStyles(theme => ({ textAlign: 'center' } })); -/* - - Hero Message - - - Quickly build an effective pricing table for your potential customers -with this layout. It's built with default Material-UI components -with little customization. - -*/ + function Hero() { const classes = useStyles(); return ( diff --git a/components/LineChart/index.js b/components/LineChart/index.js index 3a239a5..1a077b5 100644 --- a/components/LineChart/index.js +++ b/components/LineChart/index.js @@ -1,7 +1,6 @@ // import React, { Component } from "react"; import Button from "@material-ui/core/Button"; -//import "react-vis/dist/style.css"; import { XYPlot, XAxis, @@ -18,12 +17,16 @@ const styles = theme => ({ ButtonContent: { padding: theme.spacing(1, 5, 6), marginTop: 6 + }, + button: { + margin: theme.spacing(1, 0.5), + alignSelf: "center" } }); class LineChart extends Component { render() { - const { labels, values } = this.props; + const { labels, values, x_axis, y_axis } = this.props; const { classes } = this.props; const error = this.props.labels.length == 0 && this.props.values.length == 0; @@ -34,7 +37,7 @@ class LineChart extends Component { labels[v]} tickLabelAngle={-45} style={{ @@ -44,12 +47,13 @@ class LineChart extends Component { }} /> - + @@ -58,53 +62,88 @@ class LineChart extends Component { {!error ? ( + + + + + ) : ( "" diff --git a/components/OverallChart/index.js b/components/OverallChart/index.js index f6efa64..d70f24b 100644 --- a/components/OverallChart/index.js +++ b/components/OverallChart/index.js @@ -10,6 +10,9 @@ class OverallChart extends Component { this.props.values.length != 0 ? this.props.values : new Array(6).fill("loading"); + var status_color = ""; + if (this.props.status == "healthy") status_color = "#4bb543"; + else status_color = "#ff0000"; const newData = [ { x: 3.2, y: 2.4, reading: values[0], type: "Temperature", unity: "ºC" }, @@ -97,9 +100,9 @@ class OverallChart extends Component { animation className="hexbin-example" style={{ - stroke: "black", + stroke: status_color, strokeLinejoin: "round", - strokeWidth: 3 + strokeWidth: 2 }} xOffset={0} yOffset={0} diff --git a/pages/beekeeper/hives/add.js b/pages/beekeeper/hives/add.js index 5c90072..43882f8 100644 --- a/pages/beekeeper/hives/add.js +++ b/pages/beekeeper/hives/add.js @@ -192,7 +192,7 @@ class AddHivePage extends Component { onChange={this.handleHiveInputChange("bee_number")} /> - Apiary ID + Apiary diff --git a/pages/beekeeper/hives/index.js b/pages/beekeeper/hives/index.js index 54abee9..73c65d4 100644 --- a/pages/beekeeper/hives/index.js +++ b/pages/beekeeper/hives/index.js @@ -1,5 +1,5 @@ import React, { Component } from "react"; -import Router from "next/router"; +import Router from "next/router"; import axios from "axios"; import { CssBaseline, @@ -36,6 +36,9 @@ const styles = theme => ({ marginTop: 0, marginBottom: 50 }, + card: { + color: theme.palette.primary.main, + }, hives: { marginTop: theme.spacing(5), marginBottom: theme.spacing(10) @@ -54,6 +57,7 @@ const styles = theme => ({ // todo: put in .env => process.env.APIARIES_API const APIARIES_API = "http://localhost:3001/api/v1/beekeeper/apiaries/"; +const FUNDINGS_API = "http://localhost:3001/api/v1/beekeeper/fundings/"; class BeekeeperHivesPage extends Component { static contextType = AuthContext; @@ -77,7 +81,7 @@ class BeekeeperHivesPage extends Component { if (!user || user.role != "beekeeper") { Router.push("/login"); } - + let config = { headers: { Authorization: "Bearer " + localStorage.token, @@ -115,18 +119,51 @@ class BeekeeperHivesPage extends Component { try { const res = await axios.get(HIVES_API, config); - await Promise.all( - res.data.hives.map(hive => { - hive.apiary_id = apiary_id; - hive.apiary_name = apiary_name; - }) - ); - return res.data.hives; + const hives = await Promise.all(res.data.hives.map(hive => + this.getHiveFunding(hive, apiary_id, apiary_name) + )) + return hives; } catch (error) { this.setState({ error: "Error Get Hives" }); } }; + getHiveFunding = async (hive, apiary_id, apiary_name) => { + const HIVE_FUNDING_API = APIARIES_API + apiary_id + "/hives/" + hive.id; + + let config = { + headers: { + Authorization: "Bearer " + localStorage.getItem("token"), + "Content-Type": "application/json" + } + }; + + const res = await axios.get(HIVE_FUNDING_API, config); + + const fundingInfo = res.data.fundings.reduce(function (accFundings, fund) { + const idx = accFundings.findIndex(h => h.beelover === fund.user_name); + if (idx >= 0) { + accFundings[idx].funded += fund.price; + } + else { + accFundings.push({ beelover: fund.user_name, funded: fund.price }); + } + return accFundings; + }, []); + + const funding = fundingInfo.reduce(function (nFundings, fund) { + nFundings.beelovers++; + nFundings.funded += fund.funded; + return nFundings; + }, { beelovers: 0, funded: 0 }); + + const hiveInfo = { ...hive, apiary_id, apiary_name, beelovers: funding.beelovers, funded: funding.funded }; + + return hiveInfo; + } + + + handleApiaryErrorResponse(error) { if (error.response && error.response.data.hasOwnProperty("errors")) { this.setState({ error: "Error Get Apiaries" }); @@ -135,6 +172,21 @@ class BeekeeperHivesPage extends Component { } } + handleStatistics(n, status, desc, id1, id2, n_bees) { + Router.push({ + pathname: "/statistics", + query: { + name: n, + status: status, + description: desc, + hive: id1, + apiary: id2, + bee_number: n_bees + }, + shallow: true + }); + } + render() { const { classes, state } = this.props; const { hives } = this.state; @@ -148,7 +200,7 @@ class BeekeeperHivesPage extends Component { - + {hives.map(hive => ( - + - Apiary {hive.apiary_name} + {hive.apiary_name} + + + {hive.beelovers} {hive.beelovers === 1 ? "beelover" : "beelovers"} funded {hive.funded}€ + {this.state.error && ( + + Fund was not successful + + )} + + +