import { useEffect, useReducer, useState } from "react"; import { Alert, AlertIcon, Heading } from "@chakra-ui/react"; import { SpinnerPage, tableEventReducer } from "src/components"; import { useSettings } from "src/hooks"; import { intl } from "src/locale"; import { SettingsTable } from "./SettingsTable"; const initialState = { offset: 0, limit: 10, sortBy: [ { id: "name", desc: false, }, ], filters: [], }; function Settings() { const [{ offset, limit, sortBy, filters }, dispatch] = useReducer( tableEventReducer, initialState, ); const [tableData, setTableData] = useState(null); const { isFetching, isLoading, error, data } = useSettings( 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: "settings.title" })} ); } export default Settings;