2021-06-08 05:29:56 +00:00
|
|
|
import {
|
|
|
|
ActionGroup,
|
|
|
|
Button,
|
|
|
|
Divider,
|
|
|
|
FormGroup,
|
|
|
|
Switch,
|
|
|
|
} from "@patternfly/react-core";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { Controller, UseFormReturn } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2021-06-08 05:29:56 +00:00
|
|
|
|
2023-01-26 09:31:07 +00:00
|
|
|
import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog";
|
2023-03-07 09:29:40 +00:00
|
|
|
import { HelpItem } from "ui-shared";
|
2021-06-08 05:29:56 +00:00
|
|
|
import { TimeSelector } from "../../components/time-selector/TimeSelector";
|
|
|
|
|
|
|
|
export type EventsType = "admin" | "user";
|
|
|
|
|
|
|
|
type EventConfigFormProps = {
|
|
|
|
type: EventsType;
|
2023-01-26 09:31:07 +00:00
|
|
|
form: UseFormReturn;
|
2021-06-08 05:29:56 +00:00
|
|
|
reset: () => void;
|
|
|
|
clear: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const EventConfigForm = ({
|
|
|
|
type,
|
|
|
|
form,
|
|
|
|
reset,
|
|
|
|
clear,
|
|
|
|
}: EventConfigFormProps) => {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2021-06-08 05:29:56 +00:00
|
|
|
const {
|
|
|
|
control,
|
|
|
|
watch,
|
|
|
|
setValue,
|
|
|
|
formState: { isDirty },
|
|
|
|
} = form;
|
|
|
|
const eventKey = type === "admin" ? "adminEventsEnabled" : "eventsEnabled";
|
|
|
|
const eventsEnabled: boolean = watch(eventKey);
|
|
|
|
|
|
|
|
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
|
2023-09-25 07:06:56 +00:00
|
|
|
titleKey: "events-disable-title",
|
|
|
|
messageKey: "events-disable-confirm",
|
|
|
|
continueButtonLabel: "confirm",
|
2023-05-30 12:08:37 +00:00
|
|
|
onConfirm: () => setValue(eventKey, false, { shouldDirty: true }),
|
2021-06-08 05:29:56 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DisableConfirm />
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("saveEvents")}
|
|
|
|
fieldId={eventKey}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t(`save-${type}-eventsHelp`)}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="saveEvents"
|
2021-06-08 05:29:56 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name={eventKey}
|
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-06-08 05:29:56 +00:00
|
|
|
<Switch
|
|
|
|
data-testid={eventKey}
|
2021-07-12 14:09:14 +00:00
|
|
|
id={`${eventKey}-switch`}
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("on")}
|
|
|
|
labelOff={t("off")}
|
2023-01-26 09:31:07 +00:00
|
|
|
isChecked={field.value}
|
2021-06-08 05:29:56 +00:00
|
|
|
onChange={(value) => {
|
|
|
|
if (!value) {
|
|
|
|
toggleDisableDialog();
|
|
|
|
} else {
|
2023-01-26 09:31:07 +00:00
|
|
|
field.onChange(value);
|
2021-06-08 05:29:56 +00:00
|
|
|
}
|
|
|
|
}}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("saveEvents")}
|
2021-06-08 05:29:56 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
{eventsEnabled && (
|
|
|
|
<>
|
|
|
|
{type === "admin" && (
|
|
|
|
<FormGroup
|
|
|
|
hasNoPaddingTop
|
|
|
|
label={t("includeRepresentation")}
|
|
|
|
fieldId="includeRepresentation"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("includeRepresentationHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="includeRepresentation"
|
2021-06-08 05:29:56 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="adminEventsDetailsEnabled"
|
|
|
|
defaultValue={false}
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2021-06-08 05:29:56 +00:00
|
|
|
<Switch
|
|
|
|
data-testid="includeRepresentation"
|
|
|
|
id="includeRepresentation"
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("on")}
|
|
|
|
labelOff={t("off")}
|
2023-01-26 09:31:07 +00:00
|
|
|
isChecked={field.value}
|
|
|
|
onChange={field.onChange}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("includeRepresentation")}
|
2021-06-08 05:29:56 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
)}
|
2022-09-08 18:31:24 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("expiration")}
|
|
|
|
fieldId="expiration"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-08 13:17:17 +00:00
|
|
|
helpText={t("expirationHelp")}
|
2023-09-25 07:06:56 +00:00
|
|
|
fieldLabelId="expiration"
|
2021-06-08 05:29:56 +00:00
|
|
|
/>
|
2022-09-08 18:31:24 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name={
|
|
|
|
type === "user" ? "eventsExpiration" : "adminEventsExpiration"
|
|
|
|
}
|
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
2023-01-26 09:31:07 +00:00
|
|
|
render={({ field }) => (
|
2022-09-08 18:31:24 +00:00
|
|
|
<TimeSelector
|
2023-01-26 09:31:07 +00:00
|
|
|
value={field.value}
|
|
|
|
onChange={field.onChange}
|
2022-09-08 18:31:24 +00:00
|
|
|
units={["minute", "hour", "day"]}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2021-06-08 05:29:56 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<ActionGroup>
|
|
|
|
<Button
|
|
|
|
variant="primary"
|
|
|
|
type="submit"
|
|
|
|
id={`save-${type}`}
|
|
|
|
data-testid={`save-${type}`}
|
|
|
|
isDisabled={!isDirty}
|
|
|
|
>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("save")}
|
2021-06-08 05:29:56 +00:00
|
|
|
</Button>
|
|
|
|
<Button variant="link" onClick={reset}>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("revert")}
|
2021-06-08 05:29:56 +00:00
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
|
|
|
<Divider />
|
|
|
|
<FormGroup
|
2021-08-27 19:18:23 +00:00
|
|
|
label={type === "user" ? t("clearUserEvents") : t("clearAdminEvents")}
|
2021-06-08 05:29:56 +00:00
|
|
|
fieldId={`clear-${type}-events`}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
2023-09-20 08:52:43 +00:00
|
|
|
helpText={t(`${type}-clearEventsHelp`)}
|
2023-11-02 16:03:47 +00:00
|
|
|
fieldLabelId={`clear-${type}-events`}
|
2021-06-08 05:29:56 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Button
|
|
|
|
variant="danger"
|
|
|
|
id={`clear-${type}-events`}
|
|
|
|
data-testid={`clear-${type}-events`}
|
|
|
|
onClick={() => clear()}
|
|
|
|
>
|
2021-08-27 19:18:23 +00:00
|
|
|
{type === "user" ? t("clearUserEvents") : t("clearAdminEvents")}
|
2021-06-08 05:29:56 +00:00
|
|
|
</Button>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|