1 | import React, { useState } from "react";
|
---|
2 | import { useNavigate, Link } from 'react-router-dom'
|
---|
3 | import CenteredContainer from "../UtilComponents/CenteredContainer";
|
---|
4 | import axios from "../../custom-axios/axios";
|
---|
5 | import '../UtilComponents/App.css'
|
---|
6 |
|
---|
7 | const DriverProfile = (props) => {
|
---|
8 |
|
---|
9 | const navigate = useNavigate();
|
---|
10 |
|
---|
11 | const [profilePicture, setProfilePicture] = useState(null)
|
---|
12 |
|
---|
13 | const uploadProfilePicture = async (driverId) => {
|
---|
14 | await props.onChangeProfilePicture(driverId, profilePicture);
|
---|
15 | navigate("/home");
|
---|
16 | }
|
---|
17 |
|
---|
18 | const onFileChange = (e) => {
|
---|
19 | e.preventDefault();
|
---|
20 | const fileData = new FormData();
|
---|
21 | fileData.append('picture', e.target.files[0]);
|
---|
22 | setProfilePicture(fileData);
|
---|
23 | }
|
---|
24 | const checkDriversCar = async () => {
|
---|
25 | const driverId = localStorage.getItem("driverId")
|
---|
26 | const carResponse = await axios.get(`/car/driver/${driverId}`).catch(function (error) {
|
---|
27 | if (error.response) {
|
---|
28 | alert("You haven't registered a car yet. Click on Add Car to do so.")
|
---|
29 | }
|
---|
30 | })
|
---|
31 | navigate("/car", {state: {car: carResponse.data}})
|
---|
32 | }
|
---|
33 |
|
---|
34 | const IMAGE_SRC = `http://localhost:8080/driver/${props.driver.id}/profile/picture`;
|
---|
35 |
|
---|
36 | return(
|
---|
37 | <CenteredContainer>
|
---|
38 | <h3 style={{textAlign: "center", color: "darkcyan"}}>Welcome to your profile</h3>
|
---|
39 | <div class="col">
|
---|
40 | <div class="card" >
|
---|
41 | <img src={IMAGE_SRC} class="card-img-top" alt="NOT AVAILABLE" style={{height: '285px', padding: '15px'}}/>
|
---|
42 | <div class="card-body">
|
---|
43 | <h5 class="card-title">{props.driver.name} {props.driver.surname}</h5>
|
---|
44 | <p style={props.driver.status !== 'AVAILABLE' ? { color: 'red' } : {color: 'green'}}>
|
---|
45 | Status: {props.driver.status}</p>
|
---|
46 | <p class="card-text">
|
---|
47 | Price per kilometer: {props.driver.pricePerKm} MKD
|
---|
48 | <br></br>
|
---|
49 | Level: {props.driver.level}
|
---|
50 | <br></br>
|
---|
51 | Number of grades: {props.driver.numGrades}
|
---|
52 | <br></br>
|
---|
53 | Grade: {(Math.round(props.driver.grade * 100) / 100).toFixed(2)}
|
---|
54 | </p>
|
---|
55 | <hr></hr>
|
---|
56 | Upload or change your profile picture:
|
---|
57 | <br></br>
|
---|
58 | <span style={{fontSize: '12px'}}>Supported files .png and .jpeg</span>
|
---|
59 | <input
|
---|
60 | style={{backgroundColor: 'cyan'}}
|
---|
61 | type="file"
|
---|
62 | name="myImage"
|
---|
63 | onChange={onFileChange}
|
---|
64 | />
|
---|
65 | <a
|
---|
66 | style={{backgroundColor: "cyan", borderColor: "black", color: "black", marginTop: "10px"}}
|
---|
67 | className="myButton btn btn-primary"
|
---|
68 | onClick={() => uploadProfilePicture(props.driver.id)}>
|
---|
69 | Change picture
|
---|
70 | </a>
|
---|
71 | <hr></hr>
|
---|
72 | <Link style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "45%"}}
|
---|
73 | className="myButton btn btn-primary" to={"/add-car"}>Add car</Link>
|
---|
74 | <a style={{backgroundColor: "#00CED1", borderColor: "black", color: "black", width: "45%", float: 'right'}}
|
---|
75 | className="btn btn-primary" onClick={() => checkDriversCar()}>Check car</a>
|
---|
76 | </div>
|
---|
77 | </div>
|
---|
78 | </div>
|
---|
79 | </CenteredContainer>
|
---|
80 | )
|
---|
81 | }
|
---|
82 |
|
---|
83 | export default DriverProfile; |
---|