Skip to content

Commit

Permalink
fix: page titles update in useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
nishantharcot committed Dec 24, 2024
1 parent 86a74a6 commit f418a88
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions frontend/src/pages/AlertDetails/AlertDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import RouteTab from 'components/RouteTab';
import Spinner from 'components/Spinner';
import ROUTES from 'constants/routes';
import history from 'lib/history';
import { useMemo } from 'react';
import { useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';

Expand Down Expand Up @@ -80,8 +80,10 @@ function AlertDetails(): JSX.Element {
alertDetailsResponse,
} = useGetAlertRuleDetails();

const alertTitle = alertDetailsResponse?.payload?.data.alert;
document.title = alertTitle || document.title;
useEffect(() => {
const alertTitle = alertDetailsResponse?.payload?.data.alert;
document.title = alertTitle || document.title;
}, [alertDetailsResponse?.payload?.data.alert, isRefetching]);

if (
isError ||
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/pages/NewDashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import NotFound from 'components/NotFound';
import Spinner from 'components/Spinner';
import NewDashboard from 'container/NewDashboard';
import { useDashboard } from 'providers/Dashboard/Dashboard';
import { useEffect } from 'react';
import { ErrorType } from 'types/common';

function DashboardPage(): JSX.Element {
Expand All @@ -17,8 +18,10 @@ function DashboardPage(): JSX.Element {
(dashboardResponse?.error as AxiosError)?.response?.data?.errorType
: 'Something went wrong';

const dashboardTitle = dashboardResponse.data?.data.title;
document.title = dashboardTitle || document.title;
useEffect(() => {
const dashboardTitle = dashboardResponse.data?.data.title;
document.title = dashboardTitle || document.title;
}, [dashboardResponse.data?.data.title, isFetching]);

if (isError && !isFetching && errorMessage === ErrorType.NotFound) {
return <NotFound />;
Expand Down

0 comments on commit f418a88

Please sign in to comment.