Skip to content
Snippets Groups Projects
Head.js 4.27 KiB
Newer Older
  • Learn to ignore specific revisions
  • meskio's avatar
    meskio committed
    import React, { useContext } from "react";
    
    meskio's avatar
    meskio committed
    import { Navbar, Nav, NavDropdown, Button, Form, Alert } from "react-bootstrap";
    
    meskio's avatar
    meskio committed
    import { useLocation } from "react-router-dom";
    
    import { LinkContainer } from "react-router-bootstrap";
    
    meskio's avatar
    meskio committed
    import mano from "./mano.svg";
    import AuthContext from "./AuthContext";
    
    meskio's avatar
    meskio committed
    
    function Head(props) {
    
    meskio's avatar
    meskio committed
      const auth = useContext(AuthContext);
      let location = useLocation();
    
    meskio's avatar
    meskio committed
    
    
    meskio's avatar
    meskio committed
      let adminNav;
      if (auth.role === "admin") {
        adminNav = (
          <NavDropdown title="Admin" id="admin">
    
            <LinkContainer to="/members/purchase">
    
              <NavDropdown.Item>Compra</NavDropdown.Item>
    
            </LinkContainer>
            <LinkContainer to="/members">
    
              <NavDropdown.Item>Socias</NavDropdown.Item>
    
            </LinkContainer>
            <LinkContainer to="/topup">
    
              <NavDropdown.Item>Recarga</NavDropdown.Item>
    
            </LinkContainer>
            <LinkContainer to="/members/add">
    
              <NavDropdown.Item>Nueva socia</NavDropdown.Item>
    
    meskio's avatar
    meskio committed
            <LinkContainer to="/transaction">
              <NavDropdown.Item>Transacciones</NavDropdown.Item>
            </LinkContainer>
    
    meskio's avatar
    meskio committed
            <LinkContainer to="/dues/report">
              <NavDropdown.Item>Cuotas</NavDropdown.Item>
            </LinkContainer>
    
    meskio's avatar
    meskio committed
            <LinkContainer to="/annual">
              <NavDropdown.Item>Listado Anual</NavDropdown.Item>
            </LinkContainer>
    
    meskio's avatar
    meskio committed
          </NavDropdown>
        );
      }
    
    meskio's avatar
    meskio committed
    
    
    meskio's avatar
    meskio committed
      const productNav = (
        <NavDropdown title="Almacen" id="almacen">
          <LinkContainer to="/products">
            <NavDropdown.Item>Productos</NavDropdown.Item>
          </LinkContainer>
          <LinkContainer to="/purchases">
            <NavDropdown.Item>Compras</NavDropdown.Item>
          </LinkContainer>
          {auth.role === "admin" && (
            <div>
              <LinkContainer to="/inventary">
                <NavDropdown.Item>Entradas Almacén</NavDropdown.Item>
              </LinkContainer>
              <LinkContainer to="/supplier/add">
                <NavDropdown.Item>Alta Proveedores</NavDropdown.Item>
              </LinkContainer>
              <LinkContainer to="/product/add">
                <NavDropdown.Item>Alta Codigos</NavDropdown.Item>
              </LinkContainer>
            </div>
          )}
        </NavDropdown>
    
    meskio's avatar
    meskio committed
      );
    
    
    meskio's avatar
    meskio committed
      let orderNav = (
        <LinkContainer to="/orders">
          <Nav.Link>Pedidos</Nav.Link>
        </LinkContainer>
      );
      if (auth.role === "order" || auth.role === "admin") {
        orderNav = (
          <NavDropdown title="Pedidos" id="admin">
            <LinkContainer to="/orders">
              <NavDropdown.Item>Pedidos</NavDropdown.Item>
            </LinkContainer>
            <LinkContainer to="/order/create">
              <NavDropdown.Item>Abrir pedido</NavDropdown.Item>
            </LinkContainer>
          </NavDropdown>
        );
      }
    
    
    meskio's avatar
    meskio committed
      let alert;
      let buyNav;
      if (auth.disabled) {
        alert = (
          <Alert variant="warning">
            Tu cuenta esta bloqueada pendiente de pagar la cuota mensual. Haz una
            recarga para activarla.
          </Alert>
        );
      } else {
        buyNav = (
          <LinkContainer to="/purchase">
            <Nav.Link>Comprar</Nav.Link>
    
    meskio's avatar
    meskio committed
        );
      }
    
      return (
        <div>
          <Navbar bg="light" expand="sm">
            <LinkContainer to="/">
              <Navbar.Brand>
                <img
                  src={mano}
                  width="30"
                  height="30"
                  className="d-inline-block align-top"
                  alt="Garbanzo Negro"
                />
              </Navbar.Brand>
            </LinkContainer>
            <Navbar.Toggle aria-controls="basic-navbar-nav" />
            <Navbar.Collapse id="basic-navbar-nav">
              <Nav className="justify-content-start" activeKey={location.pathname}>
                {buyNav}
                {productNav}
                {orderNav}
              </Nav>
    
    meskio's avatar
    meskio committed
              <Nav
                className="justify-content-end flex-grow-1 pre-3"
                activeKey={location.pathname}
              >
                <NavDropdown title="Ajustes" id="ajustes">
                  <LinkContainer to="/password">
                    <NavDropdown.Item>Cambiar contraseña</NavDropdown.Item>
                  </LinkContainer>
                </NavDropdown>
    
    meskio's avatar
    meskio committed
                {adminNav}
              </Nav>
              <Form className="d-flex">
                <Button variant="outline-success" onClick={props.onLogout}>
                  Salir
                </Button>
              </Form>
            </Navbar.Collapse>
          </Navbar>
          {alert}
        </div>
    
    meskio's avatar
    meskio committed
      );
    
    meskio's avatar
    meskio committed
    }
    
    export default Head;