diff --git a/src/components/Forms/Formik/FormikNotificationsTemplateField.tsx b/src/components/Forms/Formik/FormikNotificationsTemplateField.tsx index 6cb8dcc3e..ff3016acd 100644 --- a/src/components/Forms/Formik/FormikNotificationsTemplateField.tsx +++ b/src/components/Forms/Formik/FormikNotificationsTemplateField.tsx @@ -1,3 +1,6 @@ +import { Switch } from "@flanksource-ui/ui/FormControls/Switch"; +import { useField } from "formik"; +import { useState } from "react"; import { FormikCodeEditor } from "./FormikCodeEditor"; type Props = { @@ -5,14 +8,46 @@ type Props = { }; export default function FormikNotificationsTemplateField({ name }: Props) { + const [field] = useField({ + name + }); + + const value = field.value; + + const [templateOption, setTemplateOption] = useState< + "Default" | "Custom Template" + >(() => { + return value ? "Custom Template" : "Default"; + }); + return (
- - + +
+ { + setTemplateOption(v); + // Clear the field if the user selects the default option + if (v === "Default") { + field.onChange({ + target: { value: null, name: field.name } + }); + } + }} + /> +
+ {templateOption === "Custom Template" && ( + + )}
); }