import { useEffect, useReducer, useState } from "react";
import { Alert, AlertIcon, Heading, HStack } from "@chakra-ui/react";
import {
HelpDrawer,
PrettyButton,
SpinnerPage,
tableEventReducer,
} from "components";
import { useNginxTemplates } from "hooks";
import { intl } from "locale";
import { NginxTemplatesTable } from "./NginxTemplatesTable";
const initialState = {
offset: 0,
limit: 10,
sortBy: [
{
id: "name",
desc: false,
},
],
filters: [],
};
function NginxTemplates() {
const [{ offset, limit, sortBy, filters }, dispatch] = useReducer(
tableEventReducer,
initialState,
);
const [tableData, setTableData] = useState(null);
const { isFetching, isLoading, error, data } = useNginxTemplates(
offset,
limit,
sortBy,
filters,
);
useEffect(() => {
setTableData(data as any);
}, [data]);
if (error || (!tableData && !isFetching && !isLoading)) {
return (
{error?.message || "Unknown error"}
);
}
if (isFetching || isLoading || !tableData) {
return ;
}
const pagination = {
offset: data?.offset || initialState.offset,
limit: data?.limit || initialState.limit,
total: data?.total || 0,
};
return (
<>
{intl.formatMessage({ id: "nginx-templates.title" })}
{intl.formatMessage({ id: "create-nginx-template" })}
>
);
}
export default NginxTemplates;