CEC-247, CEC-261 Manifest and ECU display (#65)

* CEC-261 Add ECU list control

* CEC-261 Update vehicle service mock

* CEC-247 Manifest screens

* Fix test

* Remove dynamic dates from mocks

* Remove timezone from mock dates

* Fix test for date string timezone difference
This commit is contained in:
John Wu
2021-07-16 10:49:10 -07:00
committed by GitHub
parent ab37cd598f
commit 83105fb7ca
26 changed files with 3626 additions and 240 deletions

View File

@@ -0,0 +1,66 @@
import React, { useContext, useState } from "react";
import api from "../../services/manifests";
const ManifestsContext = React.createContext();
export const ManifestsProvider = ({ children }) => {
const [busy, setBusy] = useState(false);
const [manifests, setManifests] = useState([]);
const [totalManifests, setTotalManifests] = useState(0);
const getManifests = async (search, token) => {
let result;
try {
setBusy(true);
result = await api.getManifests(search, token);
if (result.error)
throw new Error(`Get manifests error. ${result.message}`);
setManifests(result.data);
if (search && search.offset === 0 && result.total) {
setTotalManifests(result.total);
}
} finally {
setBusy(false);
}
return result;
};
const deleteManifest = async (package_id, token) => {
let result;
const index = manifests.findIndex((element) => {
return element.id === package_id;
});
manifests.splice(index, 1);
try {
setBusy(true);
result = await api.deleteManifest(package_id, token);
if (result.error)
throw new Error(`Delete manifest error. ${result.message}`);
} finally {
setBusy(false);
}
return result;
};
return (
<ManifestsContext.Provider
value={{
busy,
manifests,
totalManifests,
getManifests,
deleteManifest,
}}
>
{children}
</ManifestsContext.Provider>
);
};
export const useManifestsContext = () => useContext(ManifestsContext);