more
This commit is contained in:
@@ -17,15 +17,16 @@ const Vehicles = () => {
|
|||||||
const [inputs, setInputs] = useState({});
|
const [inputs, setInputs] = useState({});
|
||||||
const [vehId, setVehId] = useState();
|
const [vehId, setVehId] = useState();
|
||||||
const [fetchedVeh, setfetchedVeh] = useState([]);
|
const [fetchedVeh, setfetchedVeh] = useState([]);
|
||||||
|
const [alert, setAlert] = useState(false);
|
||||||
const inputTypes = [
|
const inputTypes = [
|
||||||
"Make",
|
"Make",
|
||||||
"Model",
|
"Model",
|
||||||
"Trim Package",
|
"Trim",
|
||||||
"Color",
|
"Color",
|
||||||
"Prod Year",
|
"Prod Year",
|
||||||
"Category",
|
"Category",
|
||||||
"Mileage",
|
"Mileage",
|
||||||
"Pre-QR Price",
|
"Pre-QRV-Price",
|
||||||
];
|
];
|
||||||
const handleIdInput = (e) => setVehId(e.target.value);
|
const handleIdInput = (e) => setVehId(e.target.value);
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ const Vehicles = () => {
|
|||||||
const formatMiles = parseFloat(inputs.mileage.replace(/,/g, ""));
|
const formatMiles = parseFloat(inputs.mileage.replace(/,/g, ""));
|
||||||
const formatPrice = parseFloat(inputs.price.replace(/,/g, "") * 100);
|
const formatPrice = parseFloat(inputs.price.replace(/,/g, "") * 100);
|
||||||
inputs.Mileage = formatMiles;
|
inputs.Mileage = formatMiles;
|
||||||
inputs.price = formatPrice;
|
//inputs.price = formatPrice;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -91,17 +92,32 @@ const Vehicles = () => {
|
|||||||
setVehId("");
|
setVehId("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
const make = inputs.Make;
|
||||||
|
const model = inputs.Model;
|
||||||
|
const trim = inputs.Trim;
|
||||||
|
const color = inputs.Color;
|
||||||
|
if (!make || !model || !trim || !color) {
|
||||||
|
setAlert("Please fill out all fields");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
async function addData(e) {
|
async function addData(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
//format(e);
|
//format(e);
|
||||||
setSavedVehicles([...savedVehicles, inputs]);
|
const valid = validate();
|
||||||
try {
|
if (valid) {
|
||||||
const docRef = await addDoc(collection(db, "hdepot"), inputs);
|
|
||||||
inputs.id = docRef.id;
|
|
||||||
setSavedVehicles([...savedVehicles, inputs]);
|
setSavedVehicles([...savedVehicles, inputs]);
|
||||||
setInputs({});
|
try {
|
||||||
} catch (error) {
|
const docRef = await addDoc(collection(db, "hdepot"), inputs);
|
||||||
console.log(`Error saving vehicle to db: ${error}`);
|
inputs.id = docRef.id;
|
||||||
|
setSavedVehicles([...savedVehicles, inputs]);
|
||||||
|
setInputs({});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`Error saving vehicle to db: ${error}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,6 +155,7 @@ const Vehicles = () => {
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div>{alert ? <div className="alert">{alert}</div> : <></>}</div>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
className="auxButton"
|
className="auxButton"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ body {
|
|||||||
|
|
||||||
.vehiclesRow {
|
.vehiclesRow {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
@@ -60,11 +60,10 @@ body {
|
|||||||
.vehBox {
|
.vehBox {
|
||||||
padding: 5px 5px 8px 8px;
|
padding: 5px 5px 8px 8px;
|
||||||
border: 1px solid #5d86a8;
|
border: 1px solid #5d86a8;
|
||||||
background-color: #fff;
|
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
max-width: 535px;
|
max-width: 535px;
|
||||||
flex: 1 0 auto;
|
flex: 1 0 auto;
|
||||||
background-color: #fcf6ff;
|
background-color: #f9f5ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.veh-text {
|
.veh-text {
|
||||||
@@ -85,26 +84,32 @@ body {
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.alert {
|
||||||
|
color: red;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
padding-top: 8px;
|
||||||
|
margin: 8px 0px;
|
||||||
|
}
|
||||||
|
|
||||||
.auxButton {
|
.auxButton {
|
||||||
height: 30px;
|
height: 30px;
|
||||||
width: 125px;
|
width: 125px;
|
||||||
border: 1px solid #c0c8cf;
|
border: 1px solid #c0c8cf;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
background-color: white;
|
|
||||||
color: #0f1111;
|
color: #0f1111;
|
||||||
font-family: "Open Sans", sans-serif;
|
font-family: "Open Sans", sans-serif;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 7px 0px 26px 0px;
|
padding: 7px 0px 26px 0px;
|
||||||
margin: 25px auto;
|
margin: 25px auto;
|
||||||
background-color: #fffef9;
|
background-color: #ffefef;
|
||||||
}
|
}
|
||||||
|
|
||||||
.auxButton2 {
|
.auxButton2 {
|
||||||
height: 30px;
|
height: 30px;
|
||||||
width: 125px;
|
width: 125px;
|
||||||
border: 1px solid #c0c8cf;
|
border: 1px solid #8ac8ff;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
background-color: #fffef9;
|
background-color: #ffefef;
|
||||||
color: #0f1111;
|
color: #0f1111;
|
||||||
font-family: "Open Sans", sans-serif;
|
font-family: "Open Sans", sans-serif;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|||||||
Reference in New Issue
Block a user