Change main UI layout and add VINs to add and upload forms (#16)

* Add new upload update package form
Add new add vehicle form
Add new side menu layout
Add new toolbar layout
Update and add unit tests

* Enable add get and add vehicles

* Integration issues with ota_update service

* Update get vehicle JSON format

* Fix related unit test
Add release notes field

* Add StatusContext to display error and status messages
This commit is contained in:
John Wu
2021-03-11 12:53:29 -08:00
committed by GitHub
parent 39e779dc1d
commit 2e1f4a7a7c
31 changed files with 2666 additions and 377 deletions

View File

@@ -0,0 +1,60 @@
import React, { useContext, useState } from "react";
import api from "../../services/vehicles";
const VehicleContext = React.createContext();
const validateAdd = (vehicle) => {
if (vehicle === null) {
throw new Error("No vehicle data");
}
if (!vehicle.vin || vehicle.vin.length === 0) {
throw new Error("VIN required");
}
if (vehicle.vin.length > 17) {
throw new Error("VIN cannot be larger than 17 characters");
}
};
export const VehicleProvider = ({ children }) => {
const [busy, setBusy] = useState(false);
const [vehicles, setVehicles] = useState([]);
const getVehicles = async (search, token) => {
try {
setBusy(true);
const {
data: { data },
} = await api.getVehicles(search, token);
setVehicles(data);
} finally {
setBusy(false);
}
};
const addVehicle = async (vehicle, token) => {
try {
setBusy(true);
validateAdd(vehicle);
await api.addVehicle(vehicle, token);
} finally {
setBusy(false);
}
};
return (
<VehicleContext.Provider
value={{
busy,
vehicles,
getVehicles,
addVehicle,
}}
>
{children}
</VehicleContext.Provider>
);
};
export const useVehicleContext = () => useContext(VehicleContext);