From 6f30eac7233cd08990e6147e7f78a7683a8f7a4b Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Wed, 8 Jul 2026 00:22:09 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(frontend)=20add=20client=20for=20the?= =?UTF-8?q?=20update=20participant=20role=20endpoint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add the frontend client that calls the update participant role endpoint. Straightforward API call, no special handling. --- .../src/features/rooms/api/ApiRoom.ts | 1 + .../rooms/api/updateParticipantRole.ts | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/frontend/src/features/rooms/api/updateParticipantRole.ts diff --git a/src/frontend/src/features/rooms/api/ApiRoom.ts b/src/frontend/src/features/rooms/api/ApiRoom.ts index 4e00bc3b..7c8fde65 100644 --- a/src/frontend/src/features/rooms/api/ApiRoom.ts +++ b/src/frontend/src/features/rooms/api/ApiRoom.ts @@ -30,3 +30,4 @@ export type ApiRoom = { } export type ParticipantRole = 'member' | 'administrator' | 'owner' +export type AssignableParticipantRole = Exclude diff --git a/src/frontend/src/features/rooms/api/updateParticipantRole.ts b/src/frontend/src/features/rooms/api/updateParticipantRole.ts new file mode 100644 index 00000000..11e37ff4 --- /dev/null +++ b/src/frontend/src/features/rooms/api/updateParticipantRole.ts @@ -0,0 +1,32 @@ +import type { Participant } from 'livekit-client' +import { fetchApi } from '@/api/fetchApi' +import { useRoomData } from '@/features/rooms/livekit/hooks/useRoomData' +import { AssignableParticipantRole } from '@/features/rooms/api/ApiRoom' + +export const useParticipantRole = () => { + const data = useRoomData() + + const updateParticipantRole = async ( + participant: Participant, + role: AssignableParticipantRole + ) => { + if (!data?.id) { + throw new Error('Room id is not available') + } + + try { + return fetchApi(`rooms/${data.id}/update-participant-role/`, { + method: 'POST', + body: JSON.stringify({ + participant_identity: participant.identity, + role: role, + }), + }) + } catch (error) { + console.error( + `Failed to update participant's role ${participant.identity}: ${error instanceof Error ? error.message : 'Unknown error'}` + ) + } + } + return { updateParticipantRole } +}