From d0bbcca839d396974af4bd6dbd389c46d58116c2 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Fri, 15 Dec 2023 12:21:20 +0000 Subject: [PATCH] Redirect to project dashboard when project access is revoked (#16270) GitOrigin-RevId: 4e90789fee440feec5360660305d414ea8193704 --- .../ide-react/hooks/use-socket-listeners.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/web/frontend/js/features/ide-react/hooks/use-socket-listeners.ts b/services/web/frontend/js/features/ide-react/hooks/use-socket-listeners.ts index 713f39e183..71207f75fa 100644 --- a/services/web/frontend/js/features/ide-react/hooks/use-socket-listeners.ts +++ b/services/web/frontend/js/features/ide-react/hooks/use-socket-listeners.ts @@ -11,6 +11,7 @@ import { useModalsContext } from '@/features/ide-react/context/modals-context' import { debugConsole } from '@/utils/debugging' import { useCallback } from 'react' import { PublicAccessLevel } from '../../../../../types/public-access-level' +import { useLocation } from '@/shared/hooks/use-location' function useSocketListeners() { const { t } = useTranslation() @@ -20,6 +21,7 @@ function useSocketListeners() { const [, setPublicAccessLevel] = useScopeValue('project.publicAccesLevel') const [, setProjectMembers] = useScopeValue('project.members') const [, setProjectInvites] = useScopeValue('project.invites') + const location = useLocation() useSocketListener( socket, @@ -31,7 +33,16 @@ function useSocketListeners() { 'you_have_been_removed_from_this_project_and_will_be_redirected_to_project_dashboard' ) ) - }, [showGenericMessageModal, t]) + + // redirect to project page before reconnect timer runs out and reloads the page + const timer = window.setTimeout(() => { + location.assign('/project') + }, 5000) + + return () => { + window.clearTimeout(timer) + } + }, [showGenericMessageModal, t, location]) ) useSocketListener(