Add package updates, car updates, and vehicle screens (#25)

This commit is contained in:
John Wu
2021-03-31 17:42:31 -07:00
committed by GitHub
parent 2d1faa8fb7
commit 17f81822c0
33 changed files with 2409 additions and 699 deletions

View File

@@ -15,11 +15,20 @@ const validateAdd = (vehicle) => {
if (vehicle.vin.length > 17) {
throw new Error("VIN cannot be larger than 17 characters");
}
if (!vehicle.model || vehicle.model.length === 0) {
throw new Error("model required");
}
if (!vehicle.year || vehicle.year < 2000 || vehicle.year > 9999) {
throw new Error("year required");
}
};
export const VehicleProvider = ({ children }) => {
const [busy, setBusy] = useState(false);
const [vehicles, setVehicles] = useState([]);
const [totalVehicles, setTotalVehicles] = useState(0);
const getVehicles = async (search, token) => {
try {
@@ -30,6 +39,9 @@ export const VehicleProvider = ({ children }) => {
throw new Error(`Get vehicles error. ${result.message}`);
} else {
setVehicles(result.data);
if (result.total) {
setTotalVehicles(result.total);
}
}
} finally {
setBusy(false);
@@ -53,6 +65,7 @@ export const VehicleProvider = ({ children }) => {
value={{
busy,
vehicles,
totalVehicles,
getVehicles,
addVehicle,
}}