CEC-2579 Add ability to edit manifest (#226)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user