[364f27d] | 1 | import React from 'react';
|
---|
| 2 | import { Link, useNavigate } from 'react-router-dom';
|
---|
| 3 | import axios from '../../custom-axios/axios';
|
---|
| 4 | import CenteredContainer from '../UtilComponents/CenteredContainer';
|
---|
| 5 | import '../UtilComponents/App.css'
|
---|
| 6 |
|
---|
| 7 | const Home = (props) => {
|
---|
| 8 |
|
---|
| 9 | const navigate = useNavigate();
|
---|
| 10 |
|
---|
| 11 | const goToOngoingRequest = async () => {
|
---|
| 12 | const madeRequestId = localStorage.getItem("madeRequestId")
|
---|
| 13 | const response = await axios.get(`/request/${madeRequestId}`);
|
---|
| 14 | navigate("/made-request", {state : {madeRequest: response.data}})
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | let drivers = (<Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" to={"/drivers"}>See drivers</Link>);
|
---|
| 18 | let unapprovedDrivers = (<Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" to={"/unapproved-drivers"}>Unapproved drivers</Link>);
|
---|
| 19 | let payments = (<Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" to={"/payments"}>Payments</Link>);
|
---|
| 20 | let makeRequest = (<Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" to={"/make-request"}>Make Request</Link>);
|
---|
| 21 | let ongoingRequest = (<a style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" onClick={() => goToOngoingRequest()}>Ongoing Request</a>);
|
---|
| 22 | let requests = (<Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" to={"/requests"}>See Requests</Link>)
|
---|
| 23 | let register = (<Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" to={"/register"}>Register</Link>);
|
---|
| 24 | let login = (<Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" to={"/login"}>Login</Link>);
|
---|
| 25 | let profile = (<Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "55%"}} className="myButton btn btn-primary" to={"/driver/profile"}>Profile</Link>);
|
---|
| 26 |
|
---|
| 27 | let buttonOne
|
---|
| 28 | let buttonTwo
|
---|
| 29 |
|
---|
| 30 | if(localStorage.getItem("driverId")){
|
---|
| 31 | buttonOne = requests;
|
---|
| 32 | buttonTwo = profile;
|
---|
| 33 | } else if(localStorage.getItem("passengerId")) {
|
---|
| 34 | buttonOne = drivers
|
---|
| 35 | if(localStorage.getItem("madeRequestId")){
|
---|
| 36 | buttonTwo = ongoingRequest
|
---|
| 37 | } else {
|
---|
| 38 | buttonTwo = makeRequest
|
---|
| 39 | }
|
---|
| 40 | } else if(localStorage.getItem("adminId")){
|
---|
| 41 | buttonOne = unapprovedDrivers
|
---|
| 42 | buttonTwo = payments
|
---|
| 43 | } else {
|
---|
| 44 | buttonOne = login
|
---|
| 45 | buttonTwo = register
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 | return (
|
---|
| 50 | <CenteredContainer>
|
---|
| 51 | <h2 style={{textAlign: "center", color: "darkcyan"}}>Welcome to RebuMK</h2>
|
---|
| 52 | <hr></hr>
|
---|
| 53 | <p style={{textAlign: "center"}}> {buttonOne}</p>
|
---|
| 54 | <hr></hr>
|
---|
| 55 | <p style={{textAlign: "center"}}> {buttonTwo}</p>
|
---|
| 56 | </CenteredContainer>
|
---|
| 57 | )
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | export default Home; |
---|