feat: 🚸 add double confirmation for the deletion of an existing tenant

This commit is contained in:
Alexis Gousseau 2025-05-28 15:21:25 +02:00
parent 56e9c03574
commit d51c40b17e
4 changed files with 69 additions and 2 deletions

View file

@ -0,0 +1,64 @@
import Swal from "sweetalert2";
import trans from "../../modules/trans";
const elements = document.getElementsByClassName("confirmDeleteTenantTS");
if (elements) {
for (const element of elements) {
element.addEventListener("submit", (e) => {
const self = e.target as HTMLFormElement;
e.preventDefault();
Swal.fire({
title: trans.methods.__("Confirmez"),
text: trans.methods.__("Voulez-vous vraiment supprimer cet élément ?"),
color: getComputedStyle(document.body).getPropertyValue("--bs-body-color"),
icon: "error",
showCancelButton: true,
confirmButtonText:trans.methods.__("Oui"),
cancelButtonText: trans.methods.__("Annuler"),
// * Bootstrap Styling
customClass: {
confirmButton: "btn btn-primary mx-1",
cancelButton: "btn btn-danger mx-1",
},
buttonsStyling: false,
background: getComputedStyle(document.body).getPropertyValue("--bs-body-bg"),
}).then((result) => {
if (result.isConfirmed) {
Swal.fire({
title: trans.methods.__("Attention au conséquences"),
html: "Attention cette action est irréversible, toutes les informations liées à ce tenant seront supprimées !",
color: getComputedStyle(document.body).getPropertyValue("--bs-body-color"),
icon: "warning",
showCancelButton: true,
confirmButtonText:trans.methods.__("Je comprends le danger et suis conscient que celà aura des conséquences"),
cancelButtonText: trans.methods.__("Annuler"),
// * Bootstrap Styling
customClass: {
confirmButton: "btn btn-primary mx-1",
cancelButton: "btn btn-danger mx-1 mt-1",
},
buttonsStyling: false,
background: getComputedStyle(document.body).getPropertyValue("--bs-body-bg"),
}).then((result) => {
if (result.isConfirmed) {
self?.submit();
}
});
} else if (
/* Read more about handling dismissals below */
result.dismiss === Swal.DismissReason.cancel
) {
Swal.fire({
title: trans.methods.__("L'opération n'as pas été effectuée"),
confirmButtonText: trans.methods.__("Ok"),
// * Bootstrap Styling
customClass: {
confirmButton: "btn btn-primary",
},
buttonsStyling: false,
});
}
});
});
}
}

View file

@ -9,3 +9,6 @@ import "./utilities/vue-bo";
// MODULES
import "./../modules/sweetalert";
// CUSTOM
import "./base/common";

View file

@ -18,7 +18,7 @@
</div>
<div class="mb-md-0 mb-2">
@can('delete', $tenantModel)
<form class="btn-group confirmDeleteTS" action="{{ route('bo.tenants.destroy', ['tenant' => $tenantModel]) }}"
<form class="btn-group confirmDeleteTenantTS" action="{{ route('bo.tenants.destroy', ['tenant' => $tenantModel]) }}"
method="POST" novalidate>
@endcan
<div class="btn-group">

View file

@ -19,7 +19,7 @@
<td class="text-end">
@can('delete', $tenantModel)
<form action="{{ route('bo.tenants.destroy', ['tenant' => $tenantModel]) }}"
method="POST" class="d-inline confirmDeleteTS">
method="POST" class="d-inline confirmDeleteTenantTS">
@endcan
@method('DELETE')
@csrf