refactor: remoção do htmx do excluir item da comanda | feedback da exclusão

This commit is contained in:
2025-07-01 12:28:47 -03:00
parent 377fac4f1c
commit fe00c4da90
10 changed files with 151 additions and 189 deletions

View File

@@ -9,6 +9,7 @@ const { value: formValues } = await Swal.fire({
title: "Adicionar Produto",
html: htmlModal,
width: '100em',
position:"top",
theme: "dark",
didOpen: () => {
Swal.getPopup().classList.add('swal2-noautoclose');
@@ -451,4 +452,62 @@ function inforOrders(id){
var order = document.getElementById(id+'-obsOrder').value.split('|');
feedback(order[2], "", order[1]+' - '+order[5]);
}
}
async function removeProductComanda(itemId, productName) {
var table = document.getElementById('list-products-comanda');
Swal.fire({
theme: "dark",
title: `Remover ${productName} da comanda?`,
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#3085d6",
confirmButtonText: "Sim, remover!",
cancelButtonText: "Cancelar",
}).then(async (result) => {
if (result.isConfirmed) {
const csrfToken = document.querySelector('[name="csrfmiddlewaretoken"]').value
if (!csrfToken) {
throw new Error('Token de segurança não encontrado');
}
const response = await fetch(`/comandas/removeProductComanda/${itemId}/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
});
if (!response.ok) {
const errorData = await response.json().catch(() => ({}));
Swal.fire({
theme:"dark",
title: "😬 Ops!",
text: errorData.message || `Erro HTTP: ${response.status}`,
icon: "error"
});
throw new Error(errorData.message || `Erro HTTP: ${response.status}`);
}
const result = await response.text();
table.innerHTML = result;
Swal.fire({
theme:"dark",
title: "Feito!",
text: productName+" foi removido da comanda",
icon: "success"
});
}
});
}