Add package updates, car updates, and vehicle screens (#25)
This commit is contained in:
@@ -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,
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user