2026-03-19 14:03:15 +01:00
|
|
|
import { A, useNavigate, useParams } from '@solidjs/router';
|
|
|
|
|
import { createMemo, createResource, createSignal, Show } from 'solid-js';
|
|
|
|
|
import AdminShell from '~/components/AdminShell';
|
|
|
|
|
|
|
|
|
|
const API = '/api/gateway';
|
|
|
|
|
|
|
|
|
|
type Role = {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type User = {
|
|
|
|
|
id: string;
|
|
|
|
|
name?: string;
|
|
|
|
|
full_name?: string;
|
|
|
|
|
email: string;
|
|
|
|
|
roleId?: string;
|
|
|
|
|
role_id?: string;
|
|
|
|
|
role?: Role;
|
|
|
|
|
status?: 'ACTIVE' | 'INACTIVE' | 'PENDING';
|
|
|
|
|
createdAt?: string;
|
|
|
|
|
created_at?: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async function fetchRoles(): Promise<Role[]> {
|
|
|
|
|
try {
|
|
|
|
|
const res = await fetch(`${API}/api/admin/roles?audience=INTERNAL`);
|
|
|
|
|
if (!res.ok) return [];
|
|
|
|
|
const data = await res.json();
|
|
|
|
|
const rows = Array.isArray(data) ? data : (data.roles || []);
|
|
|
|
|
return rows.map((r: any) => ({ id: r.id, name: r.name }));
|
|
|
|
|
} catch {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function fetchUser(id: string): Promise<User | null> {
|
|
|
|
|
try {
|
|
|
|
|
const adminRes = await fetch(`${API}/api/admin/users/${id}`);
|
|
|
|
|
if (adminRes.ok) return adminRes.json();
|
|
|
|
|
|
|
|
|
|
const fallback = await fetch(`${API}/api/users/${id}`);
|
|
|
|
|
if (!fallback.ok) return null;
|
|
|
|
|
return fallback.json();
|
|
|
|
|
} catch {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function EditUserPage() {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const params = useParams();
|
|
|
|
|
const [user] = createResource(() => params.id, fetchUser);
|
|
|
|
|
const [roles] = createResource(fetchRoles);
|
|
|
|
|
|
|
|
|
|
const [name, setName] = createSignal('');
|
|
|
|
|
const [email, setEmail] = createSignal('');
|
|
|
|
|
const [roleId, setRoleId] = createSignal('');
|
|
|
|
|
const [status, setStatus] = createSignal<'ACTIVE' | 'INACTIVE' | 'PENDING'>('ACTIVE');
|
|
|
|
|
const [submitting, setSubmitting] = createSignal(false);
|
|
|
|
|
const [error, setError] = createSignal('');
|
|
|
|
|
|
|
|
|
|
createMemo(() => {
|
|
|
|
|
const u = user();
|
|
|
|
|
if (!u) return null;
|
|
|
|
|
setName(u.name || u.full_name || '');
|
|
|
|
|
setEmail(u.email || '');
|
|
|
|
|
setRoleId(u.roleId || u.role_id || u.role?.id || '');
|
|
|
|
|
setStatus((u.status || 'ACTIVE').toUpperCase() as 'ACTIVE' | 'INACTIVE' | 'PENDING');
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const save = async () => {
|
|
|
|
|
if (!name().trim() || !email().trim() || !roleId()) {
|
|
|
|
|
setError('Please fill in name, email, and role.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
setSubmitting(true);
|
|
|
|
|
setError('');
|
|
|
|
|
const body = {
|
|
|
|
|
name: name().trim(),
|
|
|
|
|
email: email().trim(),
|
|
|
|
|
roleId: roleId(),
|
|
|
|
|
status: status().toLowerCase(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let res = await fetch(`${API}/api/admin/users/${params.id}`, {
|
|
|
|
|
method: 'PATCH',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
res = await fetch(`${API}/api/users/${params.id}`, {
|
|
|
|
|
method: 'PATCH',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify(body),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!res.ok) {
|
|
|
|
|
const payload = await res.json().catch(() => ({}));
|
|
|
|
|
throw new Error(payload.message || 'Failed to update user');
|
|
|
|
|
}
|
|
|
|
|
navigate('/admin/users');
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
setError(err.message || 'Failed to update user');
|
|
|
|
|
} finally {
|
|
|
|
|
setSubmitting(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<AdminShell>
|
feat(admin): Phase 0 — Tailwind v4 foundation, shell rewrite, modern dashboard
- Install Tailwind CSS v4 via @tailwindcss/vite; configure vite.config.ts
- Rewrite app.css: Tailwind base, Exo 2 font, brand tokens (orange #fd6216, navy #050026), scrollbar utility; fix @import order
- Rewrite AdminShell.tsx: fixed header, fixed inset body grid (sidebar + main), session check, sub-tab system, logout, admin avatar/name/role
- Rewrite AdminSidebar.tsx: collapsible w-64/w-20, orange active rail + badge/dot, CSS filter for SVG icon tinting, min-h-0 flex fix
- Replace 84 route stub CSS classes (page-title, card, btn, table-wrap, etc.) with Tailwind equivalents via safe class-attr-only regex script
- Rewrite admin dashboard: Lucide icons in colored chip backgrounds, 4-col KPI grid, Control Plane 6-module grid, hover lift animations
- Disable SSR (ssr: false) to fix Vinxi dev manifest error; clear stale .vinxi cache
- Add lucide-solid icon library
- Add scripts/cleanup-css.mjs for class migration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:00:21 +01:00
|
|
|
<div class="mb-6 flex items-start justify-between gap-4">
|
2026-03-19 14:03:15 +01:00
|
|
|
<div>
|
feat(admin): Phase 0 — Tailwind v4 foundation, shell rewrite, modern dashboard
- Install Tailwind CSS v4 via @tailwindcss/vite; configure vite.config.ts
- Rewrite app.css: Tailwind base, Exo 2 font, brand tokens (orange #fd6216, navy #050026), scrollbar utility; fix @import order
- Rewrite AdminShell.tsx: fixed header, fixed inset body grid (sidebar + main), session check, sub-tab system, logout, admin avatar/name/role
- Rewrite AdminSidebar.tsx: collapsible w-64/w-20, orange active rail + badge/dot, CSS filter for SVG icon tinting, min-h-0 flex fix
- Replace 84 route stub CSS classes (page-title, card, btn, table-wrap, etc.) with Tailwind equivalents via safe class-attr-only regex script
- Rewrite admin dashboard: Lucide icons in colored chip backgrounds, 4-col KPI grid, Control Plane 6-module grid, hover lift animations
- Disable SSR (ssr: false) to fix Vinxi dev manifest error; clear stale .vinxi cache
- Add lucide-solid icon library
- Add scripts/cleanup-css.mjs for class migration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:00:21 +01:00
|
|
|
<h1 class="text-2xl font-bold text-gray-900">Edit User</h1>
|
|
|
|
|
<p class="mt-1 text-sm text-gray-500">Update user profile, role assignment, and account status.</p>
|
2026-03-19 14:03:15 +01:00
|
|
|
</div>
|
feat(admin): Phase 0 — Tailwind v4 foundation, shell rewrite, modern dashboard
- Install Tailwind CSS v4 via @tailwindcss/vite; configure vite.config.ts
- Rewrite app.css: Tailwind base, Exo 2 font, brand tokens (orange #fd6216, navy #050026), scrollbar utility; fix @import order
- Rewrite AdminShell.tsx: fixed header, fixed inset body grid (sidebar + main), session check, sub-tab system, logout, admin avatar/name/role
- Rewrite AdminSidebar.tsx: collapsible w-64/w-20, orange active rail + badge/dot, CSS filter for SVG icon tinting, min-h-0 flex fix
- Replace 84 route stub CSS classes (page-title, card, btn, table-wrap, etc.) with Tailwind equivalents via safe class-attr-only regex script
- Rewrite admin dashboard: Lucide icons in colored chip backgrounds, 4-col KPI grid, Control Plane 6-module grid, hover lift animations
- Disable SSR (ssr: false) to fix Vinxi dev manifest error; clear stale .vinxi cache
- Add lucide-solid icon library
- Add scripts/cleanup-css.mjs for class migration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:00:21 +01:00
|
|
|
<div class="flex items-center gap-2">
|
|
|
|
|
<A class="inline-flex items-center rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 transition-colors" href={`/admin/users/details/${params.id}`}>View Details</A>
|
|
|
|
|
<A class="inline-flex items-center rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 transition-colors" href="/admin/users">Back to Users</A>
|
2026-03-19 14:03:15 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Show when={error()}>
|
feat(admin): Phase 0 — Tailwind v4 foundation, shell rewrite, modern dashboard
- Install Tailwind CSS v4 via @tailwindcss/vite; configure vite.config.ts
- Rewrite app.css: Tailwind base, Exo 2 font, brand tokens (orange #fd6216, navy #050026), scrollbar utility; fix @import order
- Rewrite AdminShell.tsx: fixed header, fixed inset body grid (sidebar + main), session check, sub-tab system, logout, admin avatar/name/role
- Rewrite AdminSidebar.tsx: collapsible w-64/w-20, orange active rail + badge/dot, CSS filter for SVG icon tinting, min-h-0 flex fix
- Replace 84 route stub CSS classes (page-title, card, btn, table-wrap, etc.) with Tailwind equivalents via safe class-attr-only regex script
- Rewrite admin dashboard: Lucide icons in colored chip backgrounds, 4-col KPI grid, Control Plane 6-module grid, hover lift animations
- Disable SSR (ssr: false) to fix Vinxi dev manifest error; clear stale .vinxi cache
- Add lucide-solid icon library
- Add scripts/cleanup-css.mjs for class migration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:00:21 +01:00
|
|
|
<div class="mb-4 rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">{error()}</div>
|
2026-03-19 14:03:15 +01:00
|
|
|
</Show>
|
|
|
|
|
|
|
|
|
|
<Show when={user.loading}>
|
feat(admin): Phase 0 — Tailwind v4 foundation, shell rewrite, modern dashboard
- Install Tailwind CSS v4 via @tailwindcss/vite; configure vite.config.ts
- Rewrite app.css: Tailwind base, Exo 2 font, brand tokens (orange #fd6216, navy #050026), scrollbar utility; fix @import order
- Rewrite AdminShell.tsx: fixed header, fixed inset body grid (sidebar + main), session check, sub-tab system, logout, admin avatar/name/role
- Rewrite AdminSidebar.tsx: collapsible w-64/w-20, orange active rail + badge/dot, CSS filter for SVG icon tinting, min-h-0 flex fix
- Replace 84 route stub CSS classes (page-title, card, btn, table-wrap, etc.) with Tailwind equivalents via safe class-attr-only regex script
- Rewrite admin dashboard: Lucide icons in colored chip backgrounds, 4-col KPI grid, Control Plane 6-module grid, hover lift animations
- Disable SSR (ssr: false) to fix Vinxi dev manifest error; clear stale .vinxi cache
- Add lucide-solid icon library
- Add scripts/cleanup-css.mjs for class migration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:00:21 +01:00
|
|
|
<div class="rounded-xl border border-gray-200 bg-white shadow-sm"><p class="notice">Loading user...</p></div>
|
2026-03-19 14:03:15 +01:00
|
|
|
</Show>
|
|
|
|
|
|
|
|
|
|
<Show when={!user.loading && !user()}>
|
feat(admin): Phase 0 — Tailwind v4 foundation, shell rewrite, modern dashboard
- Install Tailwind CSS v4 via @tailwindcss/vite; configure vite.config.ts
- Rewrite app.css: Tailwind base, Exo 2 font, brand tokens (orange #fd6216, navy #050026), scrollbar utility; fix @import order
- Rewrite AdminShell.tsx: fixed header, fixed inset body grid (sidebar + main), session check, sub-tab system, logout, admin avatar/name/role
- Rewrite AdminSidebar.tsx: collapsible w-64/w-20, orange active rail + badge/dot, CSS filter for SVG icon tinting, min-h-0 flex fix
- Replace 84 route stub CSS classes (page-title, card, btn, table-wrap, etc.) with Tailwind equivalents via safe class-attr-only regex script
- Rewrite admin dashboard: Lucide icons in colored chip backgrounds, 4-col KPI grid, Control Plane 6-module grid, hover lift animations
- Disable SSR (ssr: false) to fix Vinxi dev manifest error; clear stale .vinxi cache
- Add lucide-solid icon library
- Add scripts/cleanup-css.mjs for class migration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:00:21 +01:00
|
|
|
<div class="rounded-xl border border-gray-200 bg-white shadow-sm"><p class="notice">User not found.</p></div>
|
2026-03-19 14:03:15 +01:00
|
|
|
</Show>
|
|
|
|
|
|
|
|
|
|
<Show when={user()}>
|
feat(admin): Phase 0 — Tailwind v4 foundation, shell rewrite, modern dashboard
- Install Tailwind CSS v4 via @tailwindcss/vite; configure vite.config.ts
- Rewrite app.css: Tailwind base, Exo 2 font, brand tokens (orange #fd6216, navy #050026), scrollbar utility; fix @import order
- Rewrite AdminShell.tsx: fixed header, fixed inset body grid (sidebar + main), session check, sub-tab system, logout, admin avatar/name/role
- Rewrite AdminSidebar.tsx: collapsible w-64/w-20, orange active rail + badge/dot, CSS filter for SVG icon tinting, min-h-0 flex fix
- Replace 84 route stub CSS classes (page-title, card, btn, table-wrap, etc.) with Tailwind equivalents via safe class-attr-only regex script
- Rewrite admin dashboard: Lucide icons in colored chip backgrounds, 4-col KPI grid, Control Plane 6-module grid, hover lift animations
- Disable SSR (ssr: false) to fix Vinxi dev manifest error; clear stale .vinxi cache
- Add lucide-solid icon library
- Add scripts/cleanup-css.mjs for class migration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:00:21 +01:00
|
|
|
<section class="rounded-xl border border-gray-200 bg-white shadow-sm" style="max-width:900px">
|
|
|
|
|
<div class="mt-4 grid grid-cols-1 gap-4 sm:grid-cols-2">
|
2026-03-19 14:03:15 +01:00
|
|
|
<div class="field">
|
|
|
|
|
<label>Full Name</label>
|
|
|
|
|
<input value={name()} onInput={(e) => setName(e.currentTarget.value)} />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="field">
|
|
|
|
|
<label>Email</label>
|
|
|
|
|
<input type="email" value={email()} onInput={(e) => setEmail(e.currentTarget.value)} />
|
|
|
|
|
</div>
|
|
|
|
|
<div class="field">
|
|
|
|
|
<label>Role</label>
|
|
|
|
|
<select value={roleId()} onChange={(e) => setRoleId(e.currentTarget.value)}>
|
|
|
|
|
<option value="">Select role</option>
|
|
|
|
|
<Show when={!roles.loading}>
|
|
|
|
|
{roles()?.map((r) => (
|
|
|
|
|
<option value={r.id}>{r.name}</option>
|
|
|
|
|
))}
|
|
|
|
|
</Show>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="field">
|
|
|
|
|
<label>Status</label>
|
|
|
|
|
<select value={status()} onChange={(e) => setStatus(e.currentTarget.value as 'ACTIVE' | 'INACTIVE' | 'PENDING')}>
|
|
|
|
|
<option value="ACTIVE">Active</option>
|
|
|
|
|
<option value="PENDING">Pending</option>
|
|
|
|
|
<option value="INACTIVE">Inactive</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="actions" style="justify-content:flex-end">
|
feat(admin): Phase 0 — Tailwind v4 foundation, shell rewrite, modern dashboard
- Install Tailwind CSS v4 via @tailwindcss/vite; configure vite.config.ts
- Rewrite app.css: Tailwind base, Exo 2 font, brand tokens (orange #fd6216, navy #050026), scrollbar utility; fix @import order
- Rewrite AdminShell.tsx: fixed header, fixed inset body grid (sidebar + main), session check, sub-tab system, logout, admin avatar/name/role
- Rewrite AdminSidebar.tsx: collapsible w-64/w-20, orange active rail + badge/dot, CSS filter for SVG icon tinting, min-h-0 flex fix
- Replace 84 route stub CSS classes (page-title, card, btn, table-wrap, etc.) with Tailwind equivalents via safe class-attr-only regex script
- Rewrite admin dashboard: Lucide icons in colored chip backgrounds, 4-col KPI grid, Control Plane 6-module grid, hover lift animations
- Disable SSR (ssr: false) to fix Vinxi dev manifest error; clear stale .vinxi cache
- Add lucide-solid icon library
- Add scripts/cleanup-css.mjs for class migration
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-23 23:00:21 +01:00
|
|
|
<button class="inline-flex items-center rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm font-medium text-gray-700 hover:bg-gray-50 transition-colors" type="button" onClick={() => navigate('/admin/users')}>Cancel</button>
|
|
|
|
|
<button class="inline-flex items-center rounded-lg bg-[#fd6216] px-4 py-2 text-sm font-semibold text-white hover:bg-orange-600 transition-colors" type="button" onClick={save} disabled={submitting()}>
|
2026-03-19 14:03:15 +01:00
|
|
|
{submitting() ? 'Saving...' : 'Save Changes'}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
</Show>
|
|
|
|
|
</AdminShell>
|
|
|
|
|
);
|
|
|
|
|
}
|