diff --git a/nextjs/src/app/admin/(dashboard)/players/PlayersAdminClient.tsx b/nextjs/src/app/admin/(dashboard)/players/PlayersAdminClient.tsx index 72475a9..6b47b99 100644 --- a/nextjs/src/app/admin/(dashboard)/players/PlayersAdminClient.tsx +++ b/nextjs/src/app/admin/(dashboard)/players/PlayersAdminClient.tsx @@ -85,6 +85,37 @@ export function PlayersAdminClient() { await load(); } + function updateLocal(id: number, patch: Partial) { + setPlayers((prev) => prev.map((r) => (r.id === id ? { ...r, ...patch } : r))); + } + + async function save(row: PlayerRow) { + setError(''); + const cid = row.character_id != null && row.character_id !== '' ? String(row.character_id) : ''; + if (!cid) { + setError('Character is required'); + return; + } + const res = await fetch(`/api/admin/players/${row.id}`, { + method: 'PATCH', + headers: { 'Content-Type': 'application/json' }, + credentials: 'include', + body: JSON.stringify({ + player_key: row.player_key, + player_name: row.player_name, + description: row.description ?? '', + image: row.image === '' || row.image == null ? null : row.image, + character_id: cid, + }), + }); + const data = await res.json().catch(() => ({})); + if (!res.ok) { + setError((data as { error?: string }).error ?? 'Save failed'); + return; + } + await load(); + } + async function remove(id: number) { if (!window.confirm('Delete this player?')) return; setError(''); @@ -107,30 +138,73 @@ export function PlayersAdminClient() { {loading ?

Loading…

: null} {!loading && ( <> - - - - - - - - - - {players.map((p) => ( - - - - - - - ))} - -
KeyNameCharacter -
{p.player_key}{p.player_name}{p.name_jp ?? p.character_id} - -
+ {players.map((p) => ( +
+

+ id: {p.id} + {p.name_jp ? ` · ${p.name_jp}` : ''} +

+ + +