diff --git a/resources/views/parents/index.blade.php b/resources/views/parents/index.blade.php index 9960dc9..ee51974 100644 --- a/resources/views/parents/index.blade.php +++ b/resources/views/parents/index.blade.php @@ -3,7 +3,7 @@ @section('title', 'Data Wali Murid') @section('content') -
+
{{-- Header premium --}}
@@ -275,7 +275,7 @@ title="Logout akun di semua perangkat"> Logout -
@endif
+ {{-- Modal Reset Password (premium) --}} + +
@push('scripts') @@ -351,43 +435,56 @@ function deleteWali(userId, userName) { }); } -function resetWaliPassword(userId, userName) { - Swal.fire({ - title: 'Reset Password — ' + userName, - html: '' + - '', - confirmButtonText: ' Simpan', - showCancelButton: true, - cancelButtonText: 'Batal', - preConfirm: () => { - const pwd = document.getElementById('new-password').value; - const confirm = document.getElementById('confirm-password').value; - if (!pwd || pwd.length < 6) { - Swal.showValidationMessage('Password minimal 6 karakter'); - return false; +function resetPasswordModal() { + return { + show: false, + loading: false, + id: null, + name: '', + password: '', + confirm: '', + showPwd: false, + error: '', + openReset(userId, userName) { + this.id = userId; + this.name = userName; + this.password = ''; + this.confirm = ''; + this.showPwd = false; + this.error = ''; + this.show = true; + }, + confirmReset() { + this.error = ''; + if (!this.password || this.password.length < 6) { + this.error = 'Password minimal 6 karakter.'; + return; } - if (pwd !== confirm) { - Swal.showValidationMessage('Password tidak cocok'); - return false; + if (this.password !== this.confirm) { + this.error = 'Konfirmasi password tidak cocok.'; + return; } - return pwd; - } - }).then((result) => { - if (result.isConfirmed) { - fetch('{{ url('users') }}/' + userId + '/reset-password', { + if (this.loading) return; + this.loading = true; + fetch('{{ url('users') }}/' + this.id + '/reset-password', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content, 'Accept': 'application/json', }, - body: JSON.stringify({ new_password: result.value }), - }).then(r => { + body: JSON.stringify({ new_password: this.password }), + }) + .then(r => { if (r.redirected) window.location.href = r.url; else location.reload(); + }) + .catch(() => { + this.loading = false; + this.error = 'Gagal menyimpan. Coba lagi.'; }); - } - }); + }, + }; } @endpush