CEC-2579 Add ability to edit manifest (#226)

This commit is contained in:
arpanetus
2022-10-26 03:54:20 +06:00
committed by GitHub
parent aaf47f4cc7
commit 9a9766df12
11 changed files with 656 additions and 0 deletions

View File

@@ -43,6 +43,23 @@ export const ManifestsProvider = ({ children }) => {
return result;
};
const updateManifest = async (id, data, token) => {
validateManifestUpdate(data);
let result;
try {
setBusy(true);
result = await api.updateManifest(id, data, token);
if (result.error)
throw new Error(`Update manifest error. ${result.message}`);
} finally {
setBusy(false);
}
return result;
}
const deleteManifest = async (package_id, token) => {
let result;
@@ -69,6 +86,7 @@ export const ManifestsProvider = ({ children }) => {
busy,
manifests,
totalManifests,
updateManifest,
getManifest,
getManifests,
deleteManifest,
@@ -79,4 +97,14 @@ export const ManifestsProvider = ({ children }) => {
);
};
const validateManifestUpdate = (data) => {
if (data == null) throw new Error("No manifest data");
if (data.name == null || data.name.length>255) throw new Error("Invalid manifest name");
if (data.type == null || !["forced", "standard"].includes(data.type)) {
throw new Error("Invalid manifest type");
}
}
export const useManifestsContext = () => useContext(ManifestsContext);