import { useState } from 'react' import { Outlet, NavLink } from 'react-router-dom' import { useAuth } from '../core/auth/AuthContext' import { apiClient } from '../core/api/api-client' const PasswordChangeForm = ({ onDone }) => { const [current, setCurrent] = useState('') const [next, setNext] = useState('') const [saving, setSaving] = useState(false) const [error, setError] = useState('') const [success, setSuccess] = useState(false) const submit = async (e) => { e.preventDefault() setError('') setSaving(true) try { await apiClient.patch('/internal/control-center-users/me/password', { current_password: current, new_password: next, }) setSuccess(true) setCurrent('') setNext('') } catch (err) { const code = err?.response?.data?.error?.code const msg = err?.response?.data?.error?.message if (code === 'INVALID_CREDENTIALS') setError('Password saat ini salah.') else if (code?.startsWith('PASSWORD_')) setError(msg || 'Password tidak memenuhi syarat.') else setError('Gagal mengubah password.') } finally { setSaving(false) } } return (
setCurrent(e.target.value)} required style={{ display: 'block', width: '100%', marginBottom: 6 }} /> setNext(e.target.value)} required minLength={8} style={{ display: 'block', width: '100%', marginBottom: 6 }} /> {error &&

{error}

} {success &&

Password berhasil diubah.

}
) } export default function Layout() { const { user, logout } = useAuth() const [showPwForm, setShowPwForm] = useState(false) return (
) }