Skip to content

Commit

Permalink
fix: fix edit Silence durations fails with date math
Browse files Browse the repository at this point in the history
Fixes #2369
  • Loading branch information
mainawycliffe committed Oct 23, 2024
1 parent 31c2216 commit 20abfe1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/components/Forms/Formik/FormikDurationPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default function FormikDurationPicker({
value={value}
placeholder={placeholder}
onChange={(value) => {
console.log(value, "value");
if (value.type === "absolute") {
setFieldValue(from, value.from);
setFieldValue(to, value.to);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import FormikTextArea from "@flanksource-ui/components/Forms/Formik/FormikTextAr
import FormikNotificationResourceField from "@flanksource-ui/components/Notifications/SilenceNotificationForm/FormikNotificationField";
import { toastError } from "@flanksource-ui/components/Toast/toast";
import { Button } from "@flanksource-ui/ui/Buttons/Button";
import { parseDateMath } from "@flanksource-ui/ui/Dates/TimeRangePicker/parseDateMath";
import { useMutation } from "@tanstack/react-query";
import { AxiosError } from "axios";
import { Form, Formik } from "formik";
Expand Down Expand Up @@ -93,8 +94,21 @@ export default function NotificationSilenceForm({
<Formik<Partial<SilenceNotificationRequest>>
initialValues={initialValues}
onSubmit={(v) => {
// Before submitting, we need to parse the date math expressions, if
// any are present in the from and until fields.
const { from, until } = v;
const fromTime = from?.includes("now")
? parseDateMath(from, false)
: from;

const untilTime = until?.includes("now")
? parseDateMath(until, false)
: until;

return mutate({
...v
...v,
from: fromTime,
until: untilTime
} as SilenceNotificationRequest);
}}
>
Expand Down

0 comments on commit 20abfe1

Please sign in to comment.