1 | import React from "react";
|
---|
2 | import {Link} from 'react-router-dom';
|
---|
3 | import Container from 'react-bootstrap/Container';
|
---|
4 | import Form from 'react-bootstrap/Form';
|
---|
5 | import Nav from 'react-bootstrap/Nav';
|
---|
6 | import Navbar from 'react-bootstrap/Navbar';
|
---|
7 | import Offcanvas from 'react-bootstrap/Offcanvas';
|
---|
8 |
|
---|
9 | const header = (props) => {
|
---|
10 |
|
---|
11 | let register = (<Nav.Link style={{backgroundColor: "white", borderColor: "black", color: 'black', padding: '5px', height: '100%'}} className="myButton btn btn-primary" href={"/register"}>Register</Nav.Link>);
|
---|
12 | let login = (<Nav.Link style={{backgroundColor: "white", borderColor: "black", color: 'black', padding: '5px', height: '90%'}} className="myButton btn btn-primary" href={"/login"} type="submit">Log in</Nav.Link>);
|
---|
13 | let adminReport = (<Nav.Link href={"/report/admin"}>Check Report</Nav.Link>);
|
---|
14 | let driverReport = (<Nav.Link href={"/report/driver"}>Check Report</Nav.Link>);
|
---|
15 | let passengerReport = (<Nav.Link href={"/report/passenger"}>Check Report</Nav.Link>);
|
---|
16 |
|
---|
17 | let isLoggedIn = false
|
---|
18 | let showRegister = register
|
---|
19 | let report
|
---|
20 |
|
---|
21 | if(localStorage.getItem("driverId")){
|
---|
22 | report = driverReport;
|
---|
23 | isLoggedIn = true;
|
---|
24 | showRegister = "";
|
---|
25 | } else if(localStorage.getItem("passengerId")) {
|
---|
26 | report = passengerReport;
|
---|
27 | isLoggedIn = true;
|
---|
28 | showRegister = "";
|
---|
29 | } else if(localStorage.getItem("adminId")){
|
---|
30 | report = adminReport
|
---|
31 | isLoggedIn = true
|
---|
32 | showRegister = ""
|
---|
33 | }
|
---|
34 |
|
---|
35 | const logoutUser = () => {
|
---|
36 | localStorage.clear()
|
---|
37 | }
|
---|
38 |
|
---|
39 | let logout = (<a style={{backgroundColor: "white", borderColor: "black", color: 'black'}} onClick={() => logoutUser()} className="myButton btn btn-primary" href={"/home"}>Logout</a>);
|
---|
40 |
|
---|
41 | return (
|
---|
42 | <>
|
---|
43 | <Navbar key="md" expand="md" className="mb-3 rounded-bottom" style={{ width: 'calc(750px - 50vw)', minWidth:'80%', maxWidth: '100%', height:'100px', margin: 'auto', backgroundColor: '#0dbfd3'}}>
|
---|
44 | <Container fluid>
|
---|
45 | <Navbar.Brand href="/home">
|
---|
46 | <img
|
---|
47 | alt=""
|
---|
48 | src={require("../../images/logo.PNG")}
|
---|
49 | width="150"
|
---|
50 | height="50"
|
---|
51 | className="d-inline-block align-center rounded"
|
---|
52 | />{' '}
|
---|
53 | RebuMK
|
---|
54 | </Navbar.Brand>
|
---|
55 | <Navbar.Toggle aria-controls={`offcanvasNavbar-expand-md`} />
|
---|
56 | <Navbar.Offcanvas
|
---|
57 | id={`offcanvasNavbar-expand-md`}
|
---|
58 | aria-labelledby={`offcanvasNavbarLabel-expand-md`}
|
---|
59 | placement="end"
|
---|
60 | style={{backgroundColor: '#0dbfd3'}}
|
---|
61 | >
|
---|
62 | <Offcanvas.Header closeButton>
|
---|
63 | <Offcanvas.Title id={`offcanvasNavbarLabel-expand-md`}>
|
---|
64 | RebuMK
|
---|
65 | </Offcanvas.Title>
|
---|
66 | </Offcanvas.Header>
|
---|
67 | <Offcanvas.Body>
|
---|
68 | <Nav className="justify-content-end flex-grow-1 pe-3">
|
---|
69 | <Nav.Link href="/home" >Home</Nav.Link>
|
---|
70 | {report}
|
---|
71 | </Nav>
|
---|
72 | <Form className="d-flex" style={{marginBottom: '5px', marginRight: '10px',}}>
|
---|
73 | {showRegister}
|
---|
74 | </Form>
|
---|
75 | <Form className="d-flex">
|
---|
76 | {isLoggedIn ? logout : login}
|
---|
77 | </Form>
|
---|
78 | </Offcanvas.Body>
|
---|
79 | </Navbar.Offcanvas>
|
---|
80 | </Container>
|
---|
81 | </Navbar>
|
---|
82 | </>
|
---|
83 | );
|
---|
84 | }
|
---|
85 |
|
---|
86 | export default header; |
---|