Skip to content
Snippets Groups Projects
Dashboard.js 1.32 KiB
Newer Older
  • Learn to ignore specific revisions
  • meskio's avatar
    meskio committed
    import React, { useState, useContext } from "react";
    
    import { Row, Col, Button } from "react-bootstrap";
    
    import { LinkContainer } from "react-router-bootstrap";
    
    meskio's avatar
    meskio committed
    import Fetcher from "./Fetcher";
    
    meskio's avatar
    meskio committed
    import OrderCards from "./order/OrderCards";
    
    meskio's avatar
    meskio committed
    import MyTransactions from "./transaction/MyTransactions";
    
    meskio's avatar
    meskio committed
    import AuthContext from "./AuthContext";
    
    meskio's avatar
    meskio committed
    import { printMoney } from "./util";
    
    meskio's avatar
    meskio committed
    
    
    function Dashboard() {
      const [name, setName] = useState(null);
      const [balance, setBalance] = useState(null);
    
    meskio's avatar
    meskio committed
      const auth = useContext(AuthContext);
    
    meskio's avatar
    meskio committed
    
    
      const onFetch = (member) => {
    
    meskio's avatar
    meskio committed
        if (member.name !== name) {
    
          setName(member.name);
        }
    
    meskio's avatar
    meskio committed
        if (member.balance !== balance) {
    
          setBalance(member.balance);
        }
      };
    
    meskio's avatar
    meskio committed
    
    
    meskio's avatar
    meskio committed
      let buyButton;
      if (!auth.disabled) {
        buyButton = (
          <LinkContainer to="/purchase">
            <Button variant="success">Comprar</Button>
          </LinkContainer>
        );
      }
    
    
      return (
        <Fetcher url={"/api/member/me"} onFetch={onFetch}>
          <Row>
            <Col xs>
              <div className="text-right">
                <h6>{name}</h6>
                <h1>{printMoney(balance)}</h1>
              </div>
            </Col>
            <Col xs={{ offset: 0 }} md={{ offset: 1 }}>
              <br />
    
    meskio's avatar
    meskio committed
              {buyButton}
    
            </Col>
          </Row>
          <OrderCards />
          <MyTransactions />
        </Fetcher>
      );
    
    meskio's avatar
    meskio committed
    }
    
    export default Dashboard;