import React from "react"; import { useTranslation } from "react-i18next"; import { Controller, UseFormMethods } from "react-hook-form"; import { ActionGroup, Button, Divider, FormGroup, Switch, } from "@patternfly/react-core"; import { HelpItem } from "../../components/help-enabler/HelpItem"; import { TimeSelector } from "../../components/time-selector/TimeSelector"; import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog"; export type EventsType = "admin" | "user"; type EventConfigFormProps = { type: EventsType; form: UseFormMethods; 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 { onChange(value); } }} /> )} /> {eventsEnabled && ( <> {type === "admin" && ( } > ( )} /> )} {type === "user" && ( } > ( )} /> )} )} } > ); };