diff --git a/src/components/navigation/NotFoundView/isNotFound.ts b/src/components/navigation/NotFoundView/isNotFound.ts new file mode 100644 index 0000000000000000000000000000000000000000..e946190ff227a454c98afb9e9e3bfe50fc3bb469 --- /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 057e7e09606efc456f17c249d31944656a987c0e..9cb7408987cd5584476dc6106554f788beff940a 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 ed65825268694ce950cf955a1320fd0fe8abc800..acaf7b3674344f850128ae0e2673af808f214504 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 981d45c457a240fcf7c6a62d9415aecdf2cbc7a6..dc763ad6721006f575ab1a60c38da9baa7c4db01 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 55a2f90110ed534fe2f218d0dfcfcdc321214918..87c902f0ecf0756bb2f319f19faf2ed3def11d8a 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 />; }