import { ActionGroup, Button, Divider, FormGroup, Switch, } from "@patternfly/react-core"; import { Controller, UseFormReturn } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog"; import { HelpItem } from "ui-shared"; import { TimeSelector } from "../../components/time-selector/TimeSelector"; export type EventsType = "admin" | "user"; type EventConfigFormProps = { type: EventsType; form: UseFormReturn; reset: () => void; clear: () => void; }; export const EventConfigForm = ({ type, form, reset, clear, }: EventConfigFormProps) => { const { t } = useTranslation("realm-settings"); const { control, watch, setValue, formState: { isDirty }, } = form; const eventKey = type === "admin" ? "adminEventsEnabled" : "eventsEnabled"; const eventsEnabled: boolean = watch(eventKey); const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({ titleKey: "realm-settings:events-disable-title", messageKey: "realm-settings:events-disable-confirm", continueButtonLabel: "realm-settings:confirm", onConfirm: () => setValue(eventKey, false), }); return ( <> } > ( { if (!value) { toggleDisableDialog(); } else { field.onChange(value); } }} aria-label={t("saveEvents")} /> )} /> {eventsEnabled && ( <> {type === "admin" && ( } > ( )} /> )} } > ( )} /> )} } > ); };