enhance UX alerts

This commit is contained in:
2026-07-20 16:45:00 +07:00
parent e04093ad3f
commit fbf84eb4cb
2 changed files with 49 additions and 14 deletions
@@ -815,7 +815,7 @@
let originalText = submitBtn.html(); let originalText = submitBtn.html();
submitBtn.prop('disabled', true).html('<i class="ti tabler-loader fa-spin me-2"></i> Menyimpan...'); submitBtn.prop('disabled', true).html('<i class="ti tabler-loader fa-spin me-2"></i> Menyimpan...');
$.ajax({ $.ajax({
url: $(form).attr('action'), url: $(form).attr('action'),
type: "POST", type: "POST",
data: formData, data: formData,
@@ -826,8 +826,15 @@
'Accept': 'application/json' 'Accept': 'application/json'
}, },
success: function(res) { success: function(res) {
alert('Data lahan berhasil ditambahkan!'); Swal.fire({
window.location.href = "{{ route('petani.index') }}"; icon: 'success',
title: 'Berhasil!',
text: 'Data lahan berhasil ditambahkan.',
showConfirmButton: false,
timer: 1500
}).then(() => {
window.location.href = "{{ route('petani.index') }}";
});
}, },
error: function(xhr) { error: function(xhr) {
submitBtn.prop('disabled', false).html(originalText); submitBtn.prop('disabled', false).html(originalText);
@@ -838,15 +845,26 @@
$.each(errors, function(key, val) { $.each(errors, function(key, val) {
errorMsg += val[0] + "\n"; errorMsg += val[0] + "\n";
}); });
alert("Penyimpanan Gagal:\n\n" + errorMsg);
Swal.fire({
icon: 'warning',
title: 'Penyimpanan Gagal',
text: errorMsg,
confirmButtonColor: '#dc3545'
});
} else { } else {
let errorDetail = xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText; let errorDetail = xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText;
alert("Error " + xhr.status + ": " + errorDetail);
Swal.fire({
icon: 'error',
title: 'Terjadi Kesalahan',
text: "Error " + xhr.status + ": " + errorDetail,
confirmButtonColor: '#dc3545'
});
console.error(xhr.responseText); console.error(xhr.responseText);
} }
} }
}); });
return false; return false;
} }
}); });
@@ -836,8 +836,6 @@
} }
}); });
// FORM VALIDATION & SUBMIT
$('#petani-lahan-tanaman').validate({ $('#petani-lahan-tanaman').validate({
rules: { rules: {
luas_lahan: { required: true }, luas_lahan: { required: true },
@@ -884,8 +882,8 @@
submitBtn.prop('disabled', true).html('<i class="ti tabler-loader fa-spin me-2"></i> Menyimpan...'); submitBtn.prop('disabled', true).html('<i class="ti tabler-loader fa-spin me-2"></i> Menyimpan...');
$.ajax({ $.ajax({
url: $(form).attr('action'), url: $(form).attr('action'),
type: "POST", type: "POST",
data: formData, data: formData,
processData: false, processData: false,
contentType: false, contentType: false,
@@ -894,8 +892,15 @@
'Accept': 'application/json' 'Accept': 'application/json'
}, },
success: function(res) { success: function(res) {
alert('Data lahan berhasil disimpan!'); Swal.fire({
window.location.href = "{{ route('petani.index') }}"; icon: 'success',
title: 'Berhasil!',
text: 'Data lahan berhasil disimpan.',
showConfirmButton: false,
timer: 1500
}).then(() => {
window.location.href = "{{ route('petani.index') }}";
});
}, },
error: function(xhr) { error: function(xhr) {
submitBtn.prop('disabled', false).html(originalText); submitBtn.prop('disabled', false).html(originalText);
@@ -906,10 +911,22 @@
$.each(errors, function(key, val) { $.each(errors, function(key, val) {
errorMsg += val[0] + "\n"; errorMsg += val[0] + "\n";
}); });
alert("Penyimpanan Gagal:\n\n" + errorMsg);
Swal.fire({
icon: 'warning',
title: 'Penyimpanan Gagal',
text: errorMsg,
confirmButtonColor: '#dc3545'
});
} else { } else {
let errorDetail = xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText; let errorDetail = xhr.responseJSON && xhr.responseJSON.message ? xhr.responseJSON.message : xhr.statusText;
alert("Error " + xhr.status + ": " + errorDetail);
Swal.fire({
icon: 'error',
title: 'Terjadi Kesalahan',
text: "Error " + xhr.status + ": " + errorDetail,
confirmButtonColor: '#dc3545'
});
console.error(xhr.responseText); console.error(xhr.responseText);
} }
} }