1 | import React from "react";
|
---|
2 | import { useLocation, useNavigate } 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 GradeDrive = (props) => {
|
---|
8 | const location = useLocation();
|
---|
9 | const navigate = useNavigate();
|
---|
10 |
|
---|
11 | const [formData, updateFormData] = React.useState({
|
---|
12 | grade : 0,
|
---|
13 | })
|
---|
14 |
|
---|
15 | const handleChange = (e) => {
|
---|
16 | updateFormData({
|
---|
17 | ...formData,
|
---|
18 | [e.target.name]: e.target.value.trim()
|
---|
19 | })
|
---|
20 | }
|
---|
21 |
|
---|
22 | const onFormSubmit = async (e) => {
|
---|
23 | e.preventDefault()
|
---|
24 | const gradeNum = formData.grade
|
---|
25 | const driveId = location.state.driveId
|
---|
26 | const updatedDrive = await axios.post(`/drive/grade/${driveId}`, null, { params: {
|
---|
27 | gradeNum
|
---|
28 | }
|
---|
29 | })
|
---|
30 | const requestForDrive = await axios.get(`/request/${updatedDrive.data.request.id}`)
|
---|
31 | console.log(requestForDrive.data.latitude, requestForDrive.data.longitude)
|
---|
32 | navigate("/started-drive", {state: {startedDrive: updatedDrive.data,
|
---|
33 | startLatitude: requestForDrive.data.latitude,
|
---|
34 | startLongitude: requestForDrive.data.longitude}})
|
---|
35 | }
|
---|
36 |
|
---|
37 | return (
|
---|
38 | <CenteredContainer>
|
---|
39 | <div className="card text-center">
|
---|
40 | <form onSubmit={onFormSubmit}>
|
---|
41 | <div className="form-group" style={{textAlign: 'center'}}>
|
---|
42 | <br></br>
|
---|
43 | <h3>Grade Driver</h3>
|
---|
44 | <input type="float"
|
---|
45 | className="form-control"
|
---|
46 | id="grade"
|
---|
47 | name="grade"
|
---|
48 | required
|
---|
49 | placeholder="Enter value between 0 and 5"
|
---|
50 | style={{height: "100%", width: "90%", margin: 'auto'}}
|
---|
51 | onChange={handleChange}
|
---|
52 | />
|
---|
53 | </div>
|
---|
54 | <br></br>
|
---|
55 | <button id="submit" type="submit" className="myButton btn btn-primary" style={{backgroundColor: "darkcyan", borderColor: 'black', color: 'white'}}>Grade</button>
|
---|
56 | <br></br>
|
---|
57 | <br></br>
|
---|
58 | </form>
|
---|
59 | </div>
|
---|
60 | </CenteredContainer>
|
---|
61 | )
|
---|
62 | }
|
---|
63 |
|
---|
64 | export default GradeDrive; |
---|