Skip to content

Commit

Permalink
fix: minor problem with dismiss (#1660)
Browse files Browse the repository at this point in the history
Co-authored-by: Tal <[email protected]>
  • Loading branch information
shahargl and talboren authored Aug 20, 2024
1 parent 95a2bed commit 09dc301
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions keep-ui/app/alerts/alert-dismiss-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useState } from "react";
import { useState, useEffect } from "react";
import { Button, Title, Subtitle, Card, Tab, TabGroup, TabList, TabPanel, TabPanels } from "@tremor/react";
import Modal from "@/components/ui/Modal";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import "react-quill/dist/quill.snow.css";
import { AlertDto } from "./models";
import { format, set } from "date-fns";
import { format, set, isSameDay, isAfter, addMinutes } from "date-fns";
import { getApiURL } from "utils/apiUrl";
import { useSession } from "next-auth/react";
import { usePresets } from "utils/hooks/usePresets";
Expand Down Expand Up @@ -37,6 +37,15 @@ export default function AlertDismissModal({
const { mutate: alertsMutator } = usePresetAlerts(presetName, { revalidateOnMount: false });

const { data: session } = useSession();

// Ensuring that the useEffect hook is called consistently
useEffect(() => {
const now = new Date();
const roundedMinutes = Math.ceil(now.getMinutes() / 15) * 15;
const defaultTime = set(now, { minutes: roundedMinutes, seconds: 0, milliseconds: 0 });
setSelectedDateTime(defaultTime);
}, []);

if (!alerts) return null;

const isOpen = !!alerts;
Expand Down Expand Up @@ -103,6 +112,17 @@ export default function AlertDismissModal({
handleClose();
};

const filterPassedTime = (time: Date) => {
const currentDate = new Date();
const selectedDate = new Date(time);

if (isSameDay(currentDate, selectedDate)) {
return isAfter(selectedDate, currentDate);
}

return true;
};

return (
<Modal onClose={clearAndClose} isOpen={isOpen} className="overflow-visible">
{alerts && alerts.length == 1 && alerts[0].dismissed ? (
Expand Down Expand Up @@ -158,8 +178,10 @@ export default function AlertDismissModal({
minutes: 59,
seconds: 59,
})}
filterTime={filterPassedTime}
inline
calendarClassName="custom-datepicker"

/>
{showError && <div className="text-red-500 mt-2">Must choose a date</div>}
</div>
Expand Down

0 comments on commit 09dc301

Please sign in to comment.