feat(delete): Improve delete functionality - Don't allow deletion of regex / format in use - Add confirmation for deleting before allowing request

This commit is contained in:
santiagosayshey
2024-08-24 02:06:17 +09:30
committed by Sam Chau
parent 8cb3d7a827
commit 174e4ec82d
8 changed files with 582 additions and 412 deletions

View File

@@ -32,11 +32,11 @@ export const updateRegex = async (id, regex) => {
}
};
export const deleteRegex = async (id) => {
export const deleteRegex = async (id, force = false) => {
try {
const response = await axios.delete(`${API_BASE_URL}/regex/${id}`, {
const response = await axios.delete(`${API_BASE_URL}/regex/${id}${force ? '?force=true' : ''}`, {
validateStatus: (status) => {
return status >= 200 && status < 300 || status === 409; // Accept 200-299 or 409 Conflict
return status >= 200 && status < 300 || status === 400 || status === 409;
}
});
return response.data;
@@ -76,9 +76,13 @@ export const updateFormat = async (id, format) => {
}
};
export const deleteFormat = async (id) => {
export const deleteFormat = async (id, force = false) => {
try {
const response = await axios.delete(`${API_BASE_URL}/format/${id}`);
const response = await axios.delete(`${API_BASE_URL}/format/${id}${force ? '?force=true' : ''}`, {
validateStatus: (status) => {
return status >= 200 && status < 300 || status === 400 || status === 409;
}
});
return response.data;
} catch (error) {
console.error('Error deleting format:', error);