122 lines
4.1 KiB
TypeScript
122 lines
4.1 KiB
TypeScript
import { AdminLayout } from "./AdminLayout.tsx";
|
|
|
|
export const AdminUsersPage = ({
|
|
users,
|
|
}: {
|
|
users: any[];
|
|
}) => {
|
|
return (
|
|
<AdminLayout title="Manage Users" currentPath="/admin/users">
|
|
<div
|
|
id="status-banner"
|
|
style="display: none; margin-bottom: 1rem; padding: 0.75rem 1rem; border-radius: 4px; font-size: 0.9rem;"
|
|
/>
|
|
|
|
<div class="card">
|
|
<h2>User Management</h2>
|
|
<p>Review and activate pending users.</p>
|
|
<div class="table-container">
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Username</th>
|
|
<th>Display Name</th>
|
|
<th>Status</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{users.map((user) => (
|
|
<tr key={user.id}>
|
|
<td>{user.username}</td>
|
|
<td>{user.display_name || "-"}</td>
|
|
<td>
|
|
<span class={`badge badge-${user.account_status}`}>
|
|
{user.account_status}
|
|
</span>
|
|
</td>
|
|
<td>
|
|
<a
|
|
href={`/admin/users/${user.id}`}
|
|
class="btn-action"
|
|
style="text-decoration: none;"
|
|
>
|
|
Manage
|
|
</a>
|
|
{user.account_status === "pending" && (
|
|
<button
|
|
type="button"
|
|
class="btn-action btn-success"
|
|
onclick={`updateStatus('${user.id}', 'active')`}
|
|
>
|
|
Activate
|
|
</button>
|
|
)}
|
|
{user.account_status === "active" && (
|
|
<button
|
|
type="button"
|
|
class="btn-action btn-warning"
|
|
onclick={`updateStatus('${user.id}', 'suspended')`}
|
|
>
|
|
Suspend
|
|
</button>
|
|
)}
|
|
{user.account_status === "suspended" && (
|
|
<button
|
|
type="button"
|
|
class="btn-action btn-success"
|
|
onclick={`updateStatus('${user.id}', 'active')`}
|
|
>
|
|
Re-Activate
|
|
</button>
|
|
)}
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<script
|
|
dangerouslySetInnerHTML={{
|
|
__html: `
|
|
function showNotice(msg, isError) {
|
|
const banner = document.getElementById('status-banner');
|
|
banner.textContent = msg;
|
|
banner.style.display = 'block';
|
|
banner.style.background = isError ? '#f8d7da' : '#d1e7dd';
|
|
banner.style.color = isError ? '#842029' : '#0f5132';
|
|
banner.style.border = isError ? '1px solid #f5c2c7' : '1px solid #badbcc';
|
|
setTimeout(() => { banner.style.display = 'none'; }, 6000);
|
|
}
|
|
|
|
async function updateStatus(userId, status) {
|
|
if (!confirm('Are you sure you want to set this user to ' + status + '?')) {
|
|
return;
|
|
}
|
|
try {
|
|
const res = await fetch('/api/admin/users/' + userId + '/status', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ status })
|
|
});
|
|
if (res.ok) {
|
|
showNotice('User status updated to ' + status, false);
|
|
setTimeout(() => window.location.reload(), 800);
|
|
} else {
|
|
const data = await res.json();
|
|
showNotice(data.error || 'Failed to update status', true);
|
|
}
|
|
} catch (err) {
|
|
showNotice('Network error', true);
|
|
}
|
|
}
|
|
`,
|
|
}}
|
|
>
|
|
</script>
|
|
</AdminLayout>
|
|
);
|
|
};
|