feat(editor): show notification on permission revoke + redirect

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson
2026-05-13 21:57:01 +02:00
parent fb87cee9c2
commit 2d10b7cfff
2 changed files with 20 additions and 7 deletions
+4
View File
@@ -616,6 +616,10 @@
"noteDeleted": {
"title": "Note '{{noteTitle}}' deleted",
"text": "You were redirected to the explore page, because the note you just edited was deleted."
},
"notePermissionsRevoked": {
"title": "Access permission for note was revoked",
"text": "You were redirected to the explore page, because the permissions for the note you just edited were revoked."
}
},
"realtime": {
@@ -12,6 +12,7 @@ import { useEffect } from 'react'
import { Logger } from '../../../../../utils/logger'
import { DEFAULT_FALLBACK_URL } from '../../../../login-page/utils/use-get-post-login-redirect-url'
import { useRouter } from 'next/navigation'
import { ApiError } from '../../../../../api/common/api-error'
const logger = new Logger('useOnPermissionsUpdated')
@@ -21,18 +22,26 @@ const logger = new Logger('useOnPermissionsUpdated')
* @param websocketConnection The websocket connection that emits the permissions changed event
*/
export const useOnPermissionsUpdated = (websocketConnection: MessageTransporter): void => {
const { showErrorNotificationBuilder } = useUiNotifications()
const { showErrorNotificationBuilder, dispatchUiNotification } = useUiNotifications()
const router = useRouter()
useEffect(() => {
const listener = websocketConnection.on(
MessageType.PERMISSIONS_UPDATED,
() => {
updateNotePermissions().catch(() => {
logger.error(
`Got an error while updating note permissions after receiving ${MessageType.PERMISSIONS_UPDATED}. Returning the user to explore page`
)
router.replace(DEFAULT_FALLBACK_URL)
updateNotePermissions().catch((error: unknown) => {
if (error instanceof ApiError && error.statusCode === 403) {
logger.error(
`Got an error while updating note permissions after receiving ${MessageType.PERMISSIONS_UPDATED}. Returning the user to explore page`
)
dispatchUiNotification(
'notifications.notePermissionsRevoked.title',
'notifications.notePermissionsRevoked.text',
{}
)
return router.replace(DEFAULT_FALLBACK_URL)
}
showErrorNotificationBuilder('common.errorWhileLoading', { name: 'note permission update' })
})
},
{
@@ -42,5 +51,5 @@ export const useOnPermissionsUpdated = (websocketConnection: MessageTransporter)
return () => {
listener.off()
}
}, [showErrorNotificationBuilder, websocketConnection, router])
}, [showErrorNotificationBuilder, dispatchUiNotification, websocketConnection, router])
}