MIF_E31230356/resources/views/admin/profile/edit.blade.php

312 lines
9.6 KiB
PHP

@extends('admin.layouts.app')
@section('title', 'Edit Profil')
@push('styles')
<style>
.page-title { font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.page-subtitle { font-size: 14px; color: #64748b; margin-bottom: 28px; }
.profile-card {
background: white;
border-radius: 20px;
border: 2px solid #e5e5e5;
padding: 32px;
max-width: 560px;
}
.foto-wrap {
display: flex;
align-items: center;
gap: 24px;
margin-bottom: 32px;
padding-bottom: 28px;
border-bottom: 1px solid #f1f5f9;
}
.foto-preview {
width: 88px; height: 88px;
border-radius: 50%;
object-fit: cover;
border: 3px solid #e6f0ff;
flex-shrink: 0;
}
.foto-placeholder {
width: 88px; height: 88px;
border-radius: 50%;
background: #e6f0ff;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
border: 3px solid #e6f0ff;
}
.foto-placeholder svg { width: 40px; height: 40px; color: #2b8ef3; }
.foto-info p { font-size: 13px; color: #64748b; margin: 0 0 10px; }
.btn-upload {
display: inline-block;
background: #e6f0ff;
color: #2b8ef3;
font-size: 13px;
font-weight: 700;
padding: 8px 18px;
border-radius: 10px;
cursor: pointer;
transition: background 0.2s;
}
.btn-upload:hover { background: #dbeeff; }
.field-group { margin-bottom: 18px; }
.field-label {
display: block;
font-size: 12px;
font-weight: 700;
color: #475569;
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 6px;
}
.field-label span {
color: #94a3b8;
font-weight: 500;
text-transform: none;
letter-spacing: 0;
font-size: 11px;
margin-left: 4px;
}
.field-input {
width: 100%;
background: #f8fafc;
border: 1.5px solid #e2e8f0;
border-radius: 12px;
padding: 11px 14px;
font-size: 14px;
font-family: 'Poppins', sans-serif;
color: #1e293b;
outline: none;
transition: all 0.2s;
box-sizing: border-box;
}
.field-input:focus {
border-color: #2b8ef3;
background: white;
box-shadow: 0 0 0 3px rgba(43,142,243,0.1);
}
.field-input.is-error {
border-color: #f87171;
background: #fff5f5;
}
.field-hint {
font-size: 12px;
color: #ef4444;
margin-top: 5px;
display: none;
}
.field-hint.show { display: block; }
.divider { border: none; border-top: 1px solid #f1f5f9; margin: 24px 0; }
.btn-save {
background: #2b8ef3;
color: white;
border: none;
border-radius: 12px;
padding: 12px 28px;
font-size: 14px;
font-weight: 700;
font-family: 'Poppins', sans-serif;
cursor: pointer;
transition: all 0.2s;
box-shadow: 0 4px 14px rgba(43,142,243,0.3);
}
.btn-save:hover { background: #1a7ae0; transform: translateY(-1px); }
.alert-success {
background: #f0fdf4;
border: 1.5px solid #86efac;
color: #166534;
border-radius: 12px;
padding: 12px 16px;
font-size: 14px;
font-weight: 600;
margin-bottom: 20px;
max-width: 560px;
}
.alert-error {
background: #fef2f2;
border: 1.5px solid #fca5a5;
color: #991b1b;
border-radius: 12px;
padding: 12px 16px;
font-size: 13px;
margin-bottom: 20px;
max-width: 560px;
}
</style>
@endpush
@section('content')
@php $admin = Auth::guard('admin')->user(); @endphp
<h3 class="page-title">Edit Profil</h3>
<p class="page-subtitle">Perbarui username, foto profil, dan password akunmu.</p>
@if(session('success'))
<div class="alert-success"> {{ session('success') }}</div>
@endif
@if($errors->any())
<div class="alert-error">
<ul style="margin:0;padding-left:16px">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
{{-- Form TANPA novalidate agar browser validation tetap bisa dihandle JS --}}
<form id="profile-form" enctype="multipart/form-data">
@csrf
<div class="profile-card">
{{-- Foto Profil --}}
<div class="foto-wrap">
@if($admin->foto_profil)
<img src="/E31230356/storage/app/public/{{ $admin->foto_profil }}"
class="foto-preview" id="foto-preview" alt="Foto Profil">
@else
<div class="foto-placeholder" id="foto-placeholder">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<circle cx="12" cy="8" r="4"/>
<path d="M4 20c0-4 3.6-7 8-7s8 3 8 7"/>
</svg>
</div>
<img src="" class="foto-preview" id="foto-preview" alt="" style="display:none">
@endif
<div class="foto-info">
<p>Format: JPG, PNG, WEBP. Maks. 2MB.</p>
<label for="foto_profil" class="btn-upload">Pilih Foto</label>
<input type="file" name="foto_profil" id="foto_profil"
accept="image/jpeg,image/png,image/webp" style="display:none">
<div id="foto-error" class="field-hint"></div>
</div>
</div>
{{-- Username --}}
<div class="field-group">
<label class="field-label">Username</label>
<input type="text" name="username" id="username" class="field-input"
value="{{ old('username', $admin->username) }}" required>
</div>
<hr class="divider">
{{-- Password Baru --}}
<div class="field-group">
<label class="field-label">
Password Baru <span>(kosongkan jika tidak ingin mengubah)</span>
</label>
<input type="password" name="password" id="password" class="field-input"
placeholder="Masukkan password baru" autocomplete="new-password">
</div>
{{-- Konfirmasi Password --}}
<div class="field-group">
<label class="field-label">Konfirmasi Password Baru</label>
<input type="password" name="password_confirmation" id="password_confirmation"
class="field-input" placeholder="Ulangi password baru" autocomplete="new-password">
{{-- Pesan error inline --}}
<div id="confirm-error" class="field-hint"></div>
</div>
<div id="alert-success" style="display:none;background:#f0fdf4;border:1.5px solid #86efac;color:#166534;border-radius:12px;padding:12px 16px;font-size:14px;font-weight:600;margin-bottom:16px"></div>
<div id="alert-error" style="display:none;background:#fef2f2;border:1.5px solid #fca5a5;color:#991b1b;border-radius:12px;padding:12px 16px;font-size:13px;margin-bottom:16px"></div>
<div style="margin-top:8px">
<button type="submit" class="btn-save">Simpan Perubahan</button>
</div>
</div>
</form>
@endsection
@push('scripts')
<script>
document.getElementById('foto_profil').addEventListener('change', function () {
const file = this.files[0];
if (!file) return;
if (file.size > 2 * 1024 * 1024) {
document.getElementById('foto-error').textContent = 'Ukuran foto melebihi 2MB.';
document.getElementById('foto-error').classList.add('show');
this.value = '';
return;
}
document.getElementById('foto-error').classList.remove('show');
const preview = document.getElementById('foto-preview');
const placeholder = document.getElementById('foto-placeholder');
preview.src = URL.createObjectURL(file);
preview.style.display = 'block';
if (placeholder) placeholder.style.display = 'none';
});
document.getElementById('profile-form').addEventListener('submit', function (e) {
e.preventDefault();
const password = document.getElementById('password').value;
const confirmation = document.getElementById('password_confirmation').value;
const confirmError = document.getElementById('confirm-error');
if (password !== '' && password !== confirmation) {
confirmError.textContent = '⚠ Konfirmasi password tidak cocok.';
confirmError.classList.add('show');
return;
}
confirmError.classList.remove('show');
const formData = new FormData(this);
formData.append('_method', 'PUT');
fetch('{{ route('admin.profile.updateAjax') }}', {
method: 'POST',
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
body: formData,
})
.then(r => r.json())
.then(data => {
if (data.success) {
document.getElementById('alert-success').textContent = '✓ ' + data.message;
document.getElementById('alert-success').style.display = 'block';
document.getElementById('alert-error').style.display = 'none';
if (data.foto_url) {
document.getElementById('foto-preview').src = data.foto_url + '?t=' + Date.now();
document.getElementById('foto-preview').style.display = 'block';
const ph = document.getElementById('foto-placeholder');
if (ph) ph.style.display = 'none';
}
document.getElementById('password').value = '';
document.getElementById('password_confirmation').value = '';
} else {
const msgs = Object.values(data.errors || {}).flat().join('\n');
document.getElementById('alert-error').textContent = msgs || 'Terjadi kesalahan.';
document.getElementById('alert-error').style.display = 'block';
document.getElementById('alert-success').style.display = 'none';
}
})
.catch(() => {
document.getElementById('alert-error').textContent = 'Terjadi kesalahan, coba lagi.';
document.getElementById('alert-error').style.display = 'block';
});
});
</script>
@endpush