(frontend) close admin side panel when the user is demoted

Listen to role changes in the admin panel and close the side panel
if the current user is demoted while it is open. Without this,
unprivileged users could still see the admin side panel until they
closed it manually.

I checked the other features that could be affected by hot role
changes; this was the only one still exposing admin-only UI after a
demotion. Everything else already handles live permission updates
correctly.
This commit is contained in:
lebaudantoine
2026-07-28 11:23:47 +02:00
parent 14b23d9e7b
commit 1306c13f28
@@ -11,6 +11,9 @@ import { useQuery } from '@tanstack/react-query'
import { useParams } from 'wouter'
import { usePublishSourcesManager } from '../hooks/usePublishSourcesManager'
import { usePermissionsManager } from '../hooks/usePermissionsManager'
import { useEffect } from 'react'
import { closeSidePanel } from '@/stores/layout'
import { useIsAdminOrOwner } from '../hooks/useIsAdminOrOwner'
export const Admin = () => {
const { t } = useTranslation('rooms', { keyPrefix: 'admin' })
@@ -23,6 +26,14 @@ export const Admin = () => {
const { mutateAsync: patchRoom } = usePatchRoom()
const isAdminOrOwner = useIsAdminOrOwner()
useEffect(() => {
if (!isAdminOrOwner) {
closeSidePanel()
}
}, [isAdminOrOwner])
const { data: readOnlyData } = useQuery({
queryKey: [keys.room, roomId],
queryFn: () => fetchRoom({ roomId }),