Show and manage the linked partner in Settings

Settings never called GET /workspace/{id}/members -- confirmed by network
capture, not inference. There was no member list, no loading state and no
swallowed error; the code was simply absent. A workspace with a partner
therefore looked identical to a solo one, and nothing stopped a second
partner being added.

Settings now lists both members, marks the logged-in user, and offers
rename on either row and remove on the partner. The add-form appears only
when no partner exists. Removal asks for confirmation inline rather than
via window.confirm, which this codebase does not use anywhere and which
blocks the browser tooling used to verify it.

Own-name rename is offered too: the backend documents this route as the
only place a name can be corrected, so hiding it would leave that
capability dead.

Also fixes apiFetch's error parsing, which handled only string and array
detail bodies. A structured {message_key, data} object fell through and
was assigned to error.message, rendering as [object Object] or leaking
the raw key -- latent until this session's backend work started
returning exactly that shape.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RXMhc9nT6sNz1SL4j8dznL
This commit is contained in:
2026-09-14 18:54:43 +02:00
parent 68d982bb94
commit 8e14ac6576
5 changed files with 830 additions and 30 deletions
+52 -7
View File
@@ -509,16 +509,35 @@ async function apiFetch<T>(
}
try {
const body = (await response.json()) as {
detail?: string | Array<{ msg?: string }>
detail?: string | Array<{ msg?: string }> | { message_key: string; data?: Record<string, unknown> }
code?: string
message?: string
}
const detail = Array.isArray(body.detail)
? body.detail.map((e) => e.msg ?? JSON.stringify(e)).join('; ')
: body.detail
error = {
code: body.code ?? String(response.status),
message: detail ?? body.message ?? response.statusText,
if (
body.detail &&
typeof body.detail === 'object' &&
!Array.isArray(body.detail) &&
'message_key' in body.detail
) {
// Structured `{message_key, data}` error (see workspace.py's
// exception mapping) — kept out of `message` so callers never
// accidentally render the raw key; `details.messageKey`/`data` is
// the contract callers (e.g. Settings.tsx's `describePartnerError`)
// read instead.
const structured = body.detail
error = {
code: structured.message_key,
message: structured.message_key,
details: { messageKey: structured.message_key, data: structured.data ?? {} },
}
} else {
const detail = Array.isArray(body.detail)
? body.detail.map((e) => e.msg ?? JSON.stringify(e)).join('; ')
: body.detail
error = {
code: body.code ?? String(response.status),
message: detail ?? body.message ?? response.statusText,
}
}
} catch {
// response body wasn't JSON — use status text
@@ -873,6 +892,32 @@ export async function listWorkspaceMembers(workspaceId: string): Promise<Persona
return raw.map(toPersonalData)
}
/** Renames a workspace member (partner or the logged-in user themselves —
* the backend deliberately allows self-rename through this route). */
export async function renameWorkspaceParent(
workspaceId: string,
personalDataUuid: string,
displayName: string,
): Promise<PersonalData> {
const raw = (await apiFetch(`/workspace/${workspaceId}/parents/${personalDataUuid}`, {
method: 'PATCH',
body: JSON.stringify({ display_name: displayName }),
})) as RawPersonalData
return toPersonalData(raw)
}
/** Soft-deletes a workspace member. Refused (422) for the caller's own
* profile, a member with their own login, or one with dependent data —
* see `describePartnerError` in `Settings.tsx` for how those surface. */
export async function removeWorkspaceParent(
workspaceId: string,
personalDataUuid: string,
): Promise<void> {
return apiFetch(`/workspace/${workspaceId}/parents/${personalDataUuid}`, {
method: 'DELETE',
})
}
// ---------------------------------------------------------------------------
// Tips
// ---------------------------------------------------------------------------