import Stack from "@mui/material/Stack"; import { BasePage, ConfigBox } from "@/components/design-elements"; import { AutoComplete, Select, LanguageSelector } from "@/components/inputs"; import { RadioWithDescription } from "@/components/inputs/RadioInput"; import MenuItem from "@mui/material/MenuItem"; import Typography from "@mui/material/Typography"; import { SettingsForm } from "@/pages/settings/SettingsForm"; import { useTheme } from "@mui/material/styles"; import { useEffect, useMemo, useState } from "react"; import { setTimezone, setMode, setChartType } from "@/features/uiSlice"; import { useAppSelector, useAppDispatch } from "@/hooks/AppHooks"; import timezones from "@/utils/timezones.json"; import type { ITimeZone } from "@/types/timezone"; import type { SelectChangeEvent } from "@mui/material/Select"; import { useGet, usePatch, usePost } from "@/hooks/UseApi"; import type { ApiResponse } from "@/hooks/UseApi"; import { z } from "zod"; import { systemSettingsSchema } from "@/validation/zod"; import DummyChart from "./DummyChart"; const SettingsPage = () => { type FormValues = z.infer; const user = useAppSelector((state) => state.auth.user); const orgPermissions = user?.org?.permissions || []; const hasMaster = orgPermissions.includes("master"); const theme = useTheme(); const dispatch = useAppDispatch(); const timezone = useAppSelector((state) => state.ui.timezone); const mode = useAppSelector((state) => state.ui.mode); const chartType = useAppSelector((state) => state.ui.chartType); const [selectedTimezone, setSelectedTimezone] = useState( null ); useEffect(() => { const tz = timezones.find((tz) => tz._id === timezone); setSelectedTimezone(tz || null); }, [timezone]); const { post, loading: posting } = usePost, any>(); const { patch, loading: patching } = usePatch, any>(); const { response, loading } = useGet>( hasMaster ? "/settings" : null ); const settings = response?.data || {}; const initialSettings = useMemo(() => settings, [settings]); const onSubmit = async (data: Partial) => { await patch("/settings/email", data); }; const onTest = async (data: Partial) => { await post("/settings/test-transport", data); }; return ( Time zone option.name} onChange={(_, timezone: ITimeZone) => { dispatch(setTimezone(timezone._id)); }} /> UI Mode Language } /> } rightContent={ Chart Type dispatch(setChartType("heatmap"))} value="heatmap" label="Heatmap" description="Compact tiles; color shows response speed, top strip shows availability." name="chart-type" /> dispatch(setChartType("histogram"))} value="histogram" label="Histogram" description="One bar per check; height shows response time, color shows status." name="chart-type" /> } /> {hasMaster && ( )} ); }; export default SettingsPage;