diff --git a/apps/admin-ui/src/app/scripts/ViaplayPanel.tsx b/apps/admin-ui/src/app/scripts/ViaplayPanel.tsx index 90bba9b..5b393ac 100644 --- a/apps/admin-ui/src/app/scripts/ViaplayPanel.tsx +++ b/apps/admin-ui/src/app/scripts/ViaplayPanel.tsx @@ -72,6 +72,11 @@ export function ViaplayPanel({ onChanged }: { onChanged?: (o: ViaplayOverview) = const [newAccessToken, setNewAccessToken] = useState(""); const [newProfileId, setNewProfileId] = useState(""); + const [tokenEditId, setTokenEditId] = useState(null); + const [editSession, setEditSession] = useState(""); + const [editAccessToken, setEditAccessToken] = useState(""); + const [editProfileId, setEditProfileId] = useState(""); + const applySettings = useCallback( (d: ViaplaySettings) => { setSettings(d); @@ -186,6 +191,55 @@ export function ViaplayPanel({ onChanged }: { onChanged?: (o: ViaplayOverview) = } } + function openTokenEdit(account: ViaplayAccount) { + setTokenEditId((id) => (id === account.id ? null : account.id)); + setEditSession(""); + setEditAccessToken(""); + setEditProfileId(""); + setErr(null); + setMsg(null); + } + + async function saveAccountTokens(account: ViaplayAccount) { + if (!editSession.trim() && !editAccessToken.trim() && !editProfileId.trim()) { + setErr("Plak minstens session, accessToken of profileId"); + return; + } + setBusy(true); + setErr(null); + setMsg(null); + try { + const body: Record = {}; + if (editSession.trim()) body.session = editSession.trim(); + if (editAccessToken.trim()) body.accessToken = editAccessToken.trim(); + if (editProfileId.trim()) body.profileId = editProfileId.trim(); + const r = await fetch(`/api/v1/admin/scripts/viaplay/accounts/${account.id}`, { + method: "PATCH", + credentials: "include", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(body), + }); + const d = await r.json(); + if (!r.ok) throw new Error(d.error?.message ?? "Tokens bijwerken mislukt"); + applySettings(d); + setTokenEditId(null); + setEditSession(""); + setEditAccessToken(""); + setEditProfileId(""); + const updated = (d.accounts as ViaplayAccount[] | undefined)?.find((a) => a.id === account.id); + const sub = updated?.subscriptionSummary; + setMsg( + sub + ? `Tokens bijgewerkt · abonnement: ${sub}` + : "Tokens bijgewerkt — druk Check als abonnement nog ontbreekt" + ); + } catch (e) { + setErr(String((e as Error).message ?? e)); + } finally { + setBusy(false); + } + } + async function removeAccount(account: ViaplayAccount) { if (!confirm(`Account “${account.label || account.email}” verwijderen?`)) return; setBusy(true); @@ -378,68 +432,133 @@ export function ViaplayPanel({ onChanged }: { onChanged?: (o: ViaplayOverview) =
  • -
    -
    - {a.label || a.email} - {healthBadge(a)} - - {a.email} - {a.eventCount ? ` · ${a.eventCount} events` : ""} - +
    +
    +
    + {a.label || a.email} + {healthBadge(a)} + + {a.email} + {a.eventCount ? ` · ${a.eventCount} events` : ""} + +
    +
    +
    + Abonnement: + {a.subscriptionSummary ? ( + {a.subscriptionSummary} + ) : ( + + {a.healthError?.includes("pakket") + ? "niet opgehaald (zie melding hieronder)" + : "nog niet opgehaald — druk Check"} + + )} +
    + {a.partnerName && + a.subscriptionSummary && + !a.subscriptionSummary.includes(a.partnerName) ? ( +
    + Partner: {a.partnerName} +
    + ) : null} + {a.healthError ? ( +
    + {a.healthError} +
    + ) : null} +
    +
    + + + + +
    +
    + {tokenEditId === a.id ? (
    -
    - Abonnement: - {a.subscriptionSummary ? ( - {a.subscriptionSummary} - ) : ( - - {a.healthError?.includes("pakket") - ? "niet opgehaald (zie melding hieronder)" - : "nog niet opgehaald — druk Check"} - - )} -
    - {a.partnerName && a.subscriptionSummary && !a.subscriptionSummary.includes(a.partnerName) ? ( -
    - Partner: {a.partnerName} -
    - ) : null} - {a.healthError ? ( -
    - {a.healthError} -
    - ) : null} +

    + Plak verse waarden uit de browser. Lege velden blijven ongewijzigd. +

    +