-
-
Notifications
You must be signed in to change notification settings - Fork 729
Expand file tree
/
Copy pathindex.tsx
More file actions
61 lines (55 loc) · 1.9 KB
/
index.tsx
File metadata and controls
61 lines (55 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { BasePageWithStates } from "@/Components/v2/design-elements";
import { HeaderCreate } from "@/Components/v2/common";
import { useTranslation } from "react-i18next";
import { useGet } from "@/Hooks/UseApi";
import { MaintenanceWindowTable } from "./MaintenanceWindowTable";
import { useState } from "react";
import { useSelector } from "react-redux";
import type { RootState } from "@/Types/state";
import type { MaintenanceWindow } from "@/Types/MaintenanceWindow";
import { useIsAdmin } from "@/Hooks/useIsAdmin";
interface MaintenanceWindowsResponse {
maintenanceWindows: MaintenanceWindow[];
maintenanceWindowCount: number;
}
const MaintenanceWindowPage = () => {
const { t } = useTranslation();
const isAdmin = useIsAdmin();
const [page, setPage] = useState(0);
const rowsPerPage = useSelector(
(state: RootState) => state?.ui?.maintenance?.rowsPerPage ?? 5
);
const { data, isLoading, isValidating, error, refetch } =
useGet<MaintenanceWindowsResponse>(
`/maintenance-window/team?page=${page}&rowsPerPage=${rowsPerPage}`
);
const maintenanceWindows = data?.maintenanceWindows ?? [];
const maintenanceWindowCount = data?.maintenanceWindowCount ?? 0;
return (
<BasePageWithStates
page={t("pages.maintenanceWindow.fallback.title")}
totalCount={maintenanceWindowCount}
bullets={
t("pages.maintenanceWindow.fallback.checks", { returnObjects: true }) as string[]
}
loading={isLoading}
error={!!error}
actionButtonText={t("pages.maintenanceWindow.fallback.actionButton")}
actionLink="/maintenance/create"
>
<HeaderCreate
path="/maintenance/create"
isLoading={isLoading || isValidating}
isAdmin={isAdmin}
/>
<MaintenanceWindowTable
maintenanceWindows={maintenanceWindows}
maintenanceWindowCount={maintenanceWindowCount}
page={page}
setPage={setPage}
refetch={refetch}
/>
</BasePageWithStates>
);
};
export default MaintenanceWindowPage;