From db0dec01e022954dd820b2ed906ec48eb2a99035 Mon Sep 17 00:00:00 2001 From: Max Frederiksen <maxfrederiksen@Maxs-MacBook-Air.local> Date: Thu, 16 Jan 2025 16:18:35 +0100 Subject: [PATCH] isNotFound --- src/components/navigation/NotFoundView/isNotFound.ts | 2 ++ src/views/IOC/IOCDetailsContainer.tsx | 6 +++++- src/views/host/details/HostDetailsContainer.tsx | 3 ++- src/views/jobs/JobDetailsContainer.tsx | 3 ++- src/views/records/RecordDetailsView.tsx | 3 ++- 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 src/components/navigation/NotFoundView/isNotFound.ts diff --git a/src/components/navigation/NotFoundView/isNotFound.ts b/src/components/navigation/NotFoundView/isNotFound.ts new file mode 100644 index 00000000..e946190f --- /dev/null +++ b/src/components/navigation/NotFoundView/isNotFound.ts @@ -0,0 +1,2 @@ +export const isNotFound = (status: string | number | null | undefined) => + status === "404" || status === 404; diff --git a/src/views/IOC/IOCDetailsContainer.tsx b/src/views/IOC/IOCDetailsContainer.tsx index 057e7e09..9cb74089 100644 --- a/src/views/IOC/IOCDetailsContainer.tsx +++ b/src/views/IOC/IOCDetailsContainer.tsx @@ -5,6 +5,8 @@ import { IOCDetailsView } from "./IOCDetailsView"; import { NotFoundView } from "../../components/navigation/NotFoundView/NotFoundView"; import { useGetIocQuery } from "../../store/enhancedApi"; import { ApiAlertError } from "../../components/common/Alerts/ApiAlertError"; +import { getErrorState } from "../../components/common/Alerts/AlertsData"; +import { isNotFound } from "../../components/navigation/NotFoundView/isNotFound"; const IOC_POLL_INTERVAL = 5000; @@ -22,7 +24,9 @@ export function IOCDetailsContainer({ id }: IOCDetailsContainerProps) { { skip: !id, pollingInterval: IOC_POLL_INTERVAL } ); - if (error && "status" in error && error.status === 404) { + const { status } = getErrorState(error); + + if (isNotFound(status)) { return <NotFoundView />; } diff --git a/src/views/host/details/HostDetailsContainer.tsx b/src/views/host/details/HostDetailsContainer.tsx index ed658252..acaf7b36 100644 --- a/src/views/host/details/HostDetailsContainer.tsx +++ b/src/views/host/details/HostDetailsContainer.tsx @@ -7,6 +7,7 @@ import { useFindNetBoxHostByHostIdQuery } from "../../../store/deployApi"; import { getErrorState } from "../../../components/common/Alerts/AlertsData"; +import { isNotFound } from "../../../components/navigation/NotFoundView/isNotFound"; interface HostDetailsContainerProps { hostId?: string; @@ -28,7 +29,7 @@ export function HostDetailsContainer({ hostId }: HostDetailsContainerProps) { const { status, message } = getErrorState(fetchError || alertError); - if (status === "404" || status === 404) { + if (isNotFound(status)) { return ( <NotFoundView message={message} diff --git a/src/views/jobs/JobDetailsContainer.tsx b/src/views/jobs/JobDetailsContainer.tsx index 981d45c4..dc763ad6 100644 --- a/src/views/jobs/JobDetailsContainer.tsx +++ b/src/views/jobs/JobDetailsContainer.tsx @@ -5,6 +5,7 @@ import { JobDetailsView } from "./JobDetailsView"; import { NotFoundView } from "../../components/navigation/NotFoundView/NotFoundView"; import { useFetchJobQuery } from "../../store/deployApi"; import { getErrorState } from "../../components/common/Alerts/AlertsData"; +import { isNotFound } from "../../components/navigation/NotFoundView/isNotFound"; const POLL_DEPLOYMENT_INTERVAL = 5000; export function JobDetailsContainer({ id }: { id?: string }) { @@ -30,7 +31,7 @@ export function JobDetailsContainer({ id }: { id?: string }) { const { status, message } = getErrorState(jobError); - if (status === "404" || status === 404) { + if (isNotFound(status)) { return ( <NotFoundView message={message} diff --git a/src/views/records/RecordDetailsView.tsx b/src/views/records/RecordDetailsView.tsx index 55a2f901..87c902f0 100644 --- a/src/views/records/RecordDetailsView.tsx +++ b/src/views/records/RecordDetailsView.tsx @@ -18,6 +18,7 @@ import { NotFoundView } from "../../components/navigation/NotFoundView/NotFoundV import { RecordDetails, useGetRecordQuery } from "../../store/deployApi"; import { GlobalAppBarContext as GlobalAppBarContextType } from "../../types/common"; import { getErrorState } from "../../components/common/Alerts/AlertsData"; +import { isNotFound } from "../../components/navigation/NotFoundView/isNotFound"; const LAST_UPDATED = "Last updated"; const RECORD_TYPE = "Record type"; @@ -93,7 +94,7 @@ export function RecordDetailsView() { const { status } = getErrorState(fetchError); - if (decodedName.includes(";") || status === "404" || status === 404) { + if (decodedName.includes(";") || isNotFound(status)) { return <NotFoundView />; } -- GitLab