[364f27d] | 1 | import React from "react";
|
---|
| 2 | import {useNavigate} from "react-router-dom";
|
---|
| 3 | import CenteredContainer from "../UtilComponents/CenteredContainer";
|
---|
| 4 | import '../UtilComponents/App.css'
|
---|
| 5 |
|
---|
| 6 | const AddCar = (props) => {
|
---|
| 7 |
|
---|
| 8 | // eslint-disable-next-line react-hooks/rules-of-hooks
|
---|
| 9 | const navigate = useNavigate();
|
---|
| 10 | // eslint-disable-next-line react-hooks/rules-of-hooks
|
---|
| 11 | const [formData, updateFormData] = React.useState({
|
---|
| 12 | licensePlate : "",
|
---|
| 13 | make : "",
|
---|
| 14 | model : "",
|
---|
| 15 | year : "",
|
---|
| 16 | })
|
---|
| 17 |
|
---|
| 18 | const handleChange = (e) => {
|
---|
| 19 | updateFormData({
|
---|
| 20 | ...formData,
|
---|
| 21 | [e.target.name]: e.target.value.trim()
|
---|
| 22 | })
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | const onFormSubmit = (e) => {
|
---|
| 26 | e.preventDefault();
|
---|
| 27 | const licensePlate = formData.licensePlate
|
---|
| 28 | const make = formData.make
|
---|
| 29 | const model = formData.model
|
---|
| 30 | const year = formData.year
|
---|
| 31 | const driverId = localStorage.getItem("driverId");
|
---|
| 32 | props.onAddCar(driverId, licensePlate, make, model, year);
|
---|
| 33 | navigate("/home")
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | return(
|
---|
| 37 | <CenteredContainer>
|
---|
| 38 | <h3 style={{textAlign: "center", color: "darkcyan"}}>Add a car</h3>
|
---|
| 39 | <br></br>
|
---|
| 40 | <form onSubmit={onFormSubmit}>
|
---|
| 41 | <div className="form-group">
|
---|
| 42 | <label htmlFor="licensePlate">License Plate</label>
|
---|
| 43 | <input type="text"
|
---|
| 44 | className="form-control"
|
---|
| 45 | id="licensePlate"
|
---|
| 46 | name="licensePlate"
|
---|
| 47 | required
|
---|
| 48 | placeholder="E.g: SK-321-MK"
|
---|
| 49 | style={{height: 100 + "%"}}
|
---|
| 50 | onChange={handleChange}
|
---|
| 51 | />
|
---|
| 52 | </div>
|
---|
| 53 | <br></br>
|
---|
| 54 | <div className="form-group">
|
---|
| 55 | <label htmlFor="make">Make</label>
|
---|
| 56 | <input type="text"
|
---|
| 57 | className="form-control"
|
---|
| 58 | id="make"
|
---|
| 59 | name="make"
|
---|
| 60 | required
|
---|
| 61 | placeholder="E.g: Opel"
|
---|
| 62 | style={{height: 100 + "%"}}
|
---|
| 63 | onChange={handleChange}
|
---|
| 64 | />
|
---|
| 65 | </div>
|
---|
| 66 | <br></br>
|
---|
| 67 | <div className="form-group">
|
---|
| 68 | <label htmlFor="model">Model</label>
|
---|
| 69 | <input type="text"
|
---|
| 70 | className="form-control"
|
---|
| 71 | id="model"
|
---|
| 72 | name="model"
|
---|
| 73 | placeholder="E.g: Astra"
|
---|
| 74 | required
|
---|
| 75 | onChange={handleChange}
|
---|
| 76 | />
|
---|
| 77 | </div>
|
---|
| 78 | <br></br>
|
---|
| 79 | <div className="form-group">
|
---|
| 80 | <label htmlFor="year">Year</label>
|
---|
| 81 | <input type="number"
|
---|
| 82 | className="form-control"
|
---|
| 83 | id="year"
|
---|
| 84 | name="year"
|
---|
| 85 | placeholder="E.g: 2013"
|
---|
| 86 | required
|
---|
| 87 | onChange={handleChange}
|
---|
| 88 | />
|
---|
| 89 | </div>
|
---|
| 90 | <br></br>
|
---|
| 91 | <div className="d-grid gap-2 col-6 mx-auto">
|
---|
| 92 | <button id="submit" type="submit" className="myButton btn btn-primary" style={{backgroundColor: "darkcyan", borderColor: "black", color:'white'}}>Add Car</button>
|
---|
| 93 | </div>
|
---|
| 94 | </form>
|
---|
| 95 | </CenteredContainer>
|
---|
| 96 | )
|
---|
| 97 |
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | export default AddCar; |
---|