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();
const {
control,
watch,
setValue,
formState: { isDirty },
} = form;
const eventKey = type === "admin" ? "adminEventsEnabled" : "eventsEnabled";
const eventsEnabled: boolean = watch(eventKey);
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
titleKey: "events-disable-title",
messageKey: "events-disable-confirm",
continueButtonLabel: "confirm",
onConfirm: () => setValue(eventKey, false, { shouldDirty: true }),
});
return (
<>
}
>
(
{
if (!value) {
toggleDisableDialog();
} else {
field.onChange(value);
}
}}
aria-label={t("saveEvents")}
/>
)}
/>
{eventsEnabled && (
<>
{type === "admin" && (
}
>
(
)}
/>
)}
}
>
(
)}
/>
>
)}
}
>
>
);
};