refinement registrasi-verifikasi role & rbac
This commit is contained in:
@@ -178,20 +178,30 @@
|
||||
<span class="badge bg-label-success">Verified</span>
|
||||
@else
|
||||
<span class="badge bg-label-warning">Pending</span>
|
||||
<form action="{{ route('users.verify', $user->id) }}" method="POST" class="d-inline">
|
||||
@csrf
|
||||
@method('PATCH')
|
||||
<button type="button" class="btn btn-xs btn-outline-success ms-2 btn-verify">Verify</button>
|
||||
</form>
|
||||
</form>
|
||||
|
||||
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center">
|
||||
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill edit-record" title="Edit" data-id="{{ $user->id }}"><i class="ti tabler-edit ti-md"></i></a>
|
||||
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill delete-record" data-id="{{ $user->id }}" data-name="{{ $user->name }}" title="Delete"><i class="ti tabler-trash ti-md"></i></a>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center">
|
||||
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill edit-record" title="Edit" data-id="{{ $user->id }}">
|
||||
<i class="ti tabler-edit ti-md"></i>
|
||||
</a>
|
||||
|
||||
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill delete-record" data-id="{{ $user->id }}" data-name="{{ $user->name }}" title="Delete">
|
||||
<i class="ti tabler-trash ti-md"></i>
|
||||
</a>
|
||||
|
||||
@if(!$user->email_verified_at)
|
||||
<button type="button"
|
||||
class="btn btn-primary px-9 d-flex align-items-center btn-verify shadow-sm waves-effect waves-light"
|
||||
style="margin-left: 60px;"
|
||||
data-url="{{ route('users.verify', $user->id) }}">
|
||||
<i class="ti tabler-user-check me-2"></i> Verify
|
||||
</button>
|
||||
@endif
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="5" class="text-center py-4">No users found.</td></tr>
|
||||
@@ -216,34 +226,54 @@
|
||||
$(document).ready(function () {
|
||||
$(document).on('click', '.btn-verify', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const form = $(this).closest('form');
|
||||
const url = form.attr('action');
|
||||
const formData = new FormData(form[0]);
|
||||
const url = $(this).data('url');
|
||||
|
||||
Swal.fire({
|
||||
title: 'Verifikasi User?',
|
||||
text: "User ini akan diaktifkan dan dapat login ke dalam sistem.",
|
||||
icon: 'question',
|
||||
title: 'Verifikasi Akun',
|
||||
icon: 'info',
|
||||
iconColor: '#696cff',
|
||||
width: '28em',
|
||||
html: `
|
||||
<p class="text-muted mb-4" style="font-size: 0.95rem;">Tentukan role akses untuk pengguna ini agar dapat masuk ke dalam sistem AgroMonev.</p>
|
||||
|
||||
<div class="px-2 px-md-4 mb-2">
|
||||
<select id="role-select" class="form-select form-select-md text-start shadow-none" style="cursor: pointer; border-radius: 8px; border-color: #d9dee3;">
|
||||
<option value="" selected disabled>-- Pilih Role Akses --</option>
|
||||
<option value="super_admin">🟣 Super Admin</option>
|
||||
<option value="admin">🟣 Admin</option>
|
||||
<option value="fasilitator">🟣 Fasilitator</option>
|
||||
<option value="offtaker">🟣 Offtaker</option>
|
||||
</select>
|
||||
</div>
|
||||
`,
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Ya, Verifikasi!',
|
||||
confirmButtonText: '<i class="ti tabler-check me-1"></i> Simpan',
|
||||
cancelButtonText: 'Batal',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-success me-3',
|
||||
cancelButton: 'btn btn-label-secondary'
|
||||
popup: 'rounded-4',
|
||||
confirmButton: 'btn btn-primary me-3 waves-effect waves-light',
|
||||
cancelButton: 'btn btn-label-secondary waves-effect'
|
||||
},
|
||||
buttonsStyling: false
|
||||
buttonsStyling: false,
|
||||
preConfirm: () => {
|
||||
const role = Swal.getPopup().querySelector('#role-select').value;
|
||||
if (!role) {
|
||||
Swal.showValidationMessage('Silakan pilih role terlebih dahulu!');
|
||||
}
|
||||
return { role: role };
|
||||
}
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
if (result.isConfirmed) {
|
||||
const payload = {
|
||||
_token: csrfToken,
|
||||
_method: 'PUT',
|
||||
role: result.value.role
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
},
|
||||
type: 'POST',
|
||||
data: payload,
|
||||
success: function (res) {
|
||||
if (res.status === 'success') {
|
||||
Swal.fire({
|
||||
@@ -251,17 +281,18 @@
|
||||
title: 'Berhasil!',
|
||||
text: res.message,
|
||||
showConfirmButton: false,
|
||||
timer: 1500
|
||||
timer: 1500,
|
||||
customClass: { popup: 'rounded-4' }
|
||||
}).then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
} else {
|
||||
Swal.fire({ icon: 'error', title: 'Gagal!', text: res.message });
|
||||
Swal.fire({ icon: 'error', title: 'Gagal!', text: res.message, customClass: { popup: 'rounded-4' } });
|
||||
}
|
||||
},
|
||||
error: function (xhr) {
|
||||
let errorMsg = xhr.responseJSON ? xhr.responseJSON.message : 'Terjadi kesalahan pada server.';
|
||||
Swal.fire({ icon: 'error', title: 'Error!', text: errorMsg });
|
||||
Swal.fire({ icon: 'error', title: 'Error!', text: errorMsg, customClass: { popup: 'rounded-4' } });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -276,10 +307,7 @@
|
||||
|
||||
$(document).on('click', '.edit-record', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
const id = $(this).data('id');
|
||||
const offcanvasEditEl = document.getElementById('offcanvasEdit');
|
||||
|
||||
if (!id) return;
|
||||
|
||||
$(this).html('<span class="spinner-border spinner-border-sm" role="status"></span>');
|
||||
@@ -290,10 +318,8 @@
|
||||
type: 'GET',
|
||||
success: function (res) {
|
||||
btn.html('<i class="ti tabler-edit ti-md"></i>');
|
||||
|
||||
if (res.status === 'success') {
|
||||
const user = res.data;
|
||||
|
||||
$('#editUserName').text(user.name);
|
||||
$('#editEmail').text(user.email);
|
||||
$('#formEdit').attr('action', `/users/${user.id}`);
|
||||
@@ -355,7 +381,7 @@
|
||||
}).then(function (result) {
|
||||
if (result.value) {
|
||||
$.ajax({
|
||||
url: `/users/${id}`, // Sesuaikan dengan route destroy kamu
|
||||
url: `/users/${id}`,
|
||||
type: 'DELETE',
|
||||
headers: { 'X-CSRF-TOKEN': csrfToken },
|
||||
success: function (res) {
|
||||
@@ -369,4 +395,4 @@
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@endpush
|
||||
Reference in New Issue
Block a user