Implement timezone in incident table in details page

This commit is contained in:
Alex Holliday committed 2024-09-12 11:38:45 +08:00
1 parent 30cb62a93b
commit e8bb31b007
2 files changed
+20 -18

No files matched your search

@@ -18,10 +18,13 @@ import { StatusLabel } from "../../../../Components/Label";
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded"; import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded"; import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded";
import { logger } from "../../../../Utils/Logger"; import { logger } from "../../../../Utils/Logger";
import { useTheme } from "@emotion/react"; import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";
dayjs.extend(utc);
dayjs.extend(timezone);
const PaginationTable = ({ monitorId, dateRange }) => { const PaginationTable = ({ monitorId, dateRange }) => {
const theme = useTheme();
const { authToken } = useSelector((state) => state.auth); const { authToken } = useSelector((state) => state.auth);
const [checks, setChecks] = useState([]); const [checks, setChecks] = useState([]);
const [checksCount, setChecksCount] = useState(0); const [checksCount, setChecksCount] = useState(0);
@@ -29,6 +32,7 @@ const PaginationTable = ({ monitorId, dateRange }) => {
page: 0, page: 0,
rowsPerPage: 5, rowsPerPage: 5,
}); });
const uiTimezone = useSelector((state) => state.ui.timezone);
useEffect(() => { useEffect(() => {
setPaginationController((prevPaginationController) => ({ setPaginationController((prevPaginationController) => ({
@@ -119,7 +123,9 @@ const PaginationTable = ({ monitorId, dateRange }) => {
/> />
</TableCell> </TableCell>
<TableCell> <TableCell>
{new Date(check.createdAt).toLocaleString()} {dayjs(check.createdAt)
.tz(uiTimezone)
.format("ddd, MMMM D, YYYY, HH:mm A")}
</TableCell> </TableCell>
<TableCell> <TableCell>
{check.statusCode ? check.statusCode : "N/A"} {check.statusCode ? check.statusCode : "N/A"}
+11 -15
View File
@@ -14,14 +14,18 @@ import {
} from "../../Features/UptimeMonitors/uptimeMonitorsSlice"; } from "../../Features/UptimeMonitors/uptimeMonitorsSlice";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import LoadingButton from "@mui/lab/LoadingButton"; import LoadingButton from "@mui/lab/LoadingButton";
import { setTimezone } from "../../Features/UI/uiSlice";
import timezones from "../../Utils/timezones.json";
const Settings = ({ isAdmin }) => { const Settings = ({ isAdmin }) => {
const theme = useTheme(); const theme = useTheme();
const { user, authToken } = useSelector((state) => state.auth); const { user, authToken } = useSelector((state) => state.auth);
const { isLoading } = useSelector((state) => state.uptimeMonitors); const { isLoading } = useSelector((state) => state.uptimeMonitors);
const { timezone } = useSelector((state) => state.ui);
const dispatch = useDispatch(); const dispatch = useDispatch();
// TODO Handle saving // TODO Handle saving
const handleSave = async () => {};
const handleClearStats = async () => { const handleClearStats = async () => {
try { try {
@@ -115,25 +119,16 @@ const Settings = ({ isAdmin }) => {
<Typography component="span">Display timezone</Typography>- The <Typography component="span">Display timezone</Typography>- The
timezone of the dashboard you publicly display. timezone of the dashboard you publicly display.
</Typography> </Typography>
<Typography>
<Typography component="span">Server timezone</Typography>- The
timezone of your server.
</Typography>
</Box> </Box>
<Stack gap={theme.spacing(20)}> <Stack gap={theme.spacing(20)}>
<Select <Select
id="display-timezone" id="display-timezone"
label="Display timezone" label="Display timezone"
value="est" value={timezone}
onChange={() => logger.warn("disabled")} onChange={(e) => {
items={[{ _id: "est", name: "America / Toronto" }]} dispatch(setTimezone({ timezone: e.target.value }));
/> }}
<Select items={timezones}
id="server-timezone"
label="Server timezone"
value="est"
onChange={() => logger.warn("disabled")}
items={[{ _id: "est", name: "America / Toronto" }]}
/> />
</Stack> </Stack>
</ConfigBox> </ConfigBox>
@@ -232,6 +227,7 @@ const Settings = ({ isAdmin }) => {
variant="contained" variant="contained"
color="primary" color="primary"
sx={{ px: theme.spacing(12), mt: theme.spacing(20) }} sx={{ px: theme.spacing(12), mt: theme.spacing(20) }}
onClick={handleSave}
> >
Save Save
</LoadingButton> </LoadingButton>