2021-07-01 06:48:30 +00:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
ButtonVariant,
|
|
|
|
Form,
|
|
|
|
FormGroup,
|
|
|
|
Modal,
|
|
|
|
ModalVariant,
|
|
|
|
ValidatedOptions,
|
|
|
|
} from "@patternfly/react-core";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { SubmitHandler, UseFormReturn } from "react-hook-form";
|
2021-07-01 06:48:30 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
2023-01-26 09:31:07 +00:00
|
|
|
import type { KeyValueType } from "../components/key-value-form/key-value-convert";
|
2022-04-21 15:03:26 +00:00
|
|
|
import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput";
|
|
|
|
|
2024-02-01 10:54:26 +00:00
|
|
|
type AddTranslationModalProps = {
|
2021-07-01 06:48:30 +00:00
|
|
|
id?: string;
|
2024-02-01 10:54:26 +00:00
|
|
|
form: UseFormReturn<TranslationForm>;
|
|
|
|
save: SubmitHandler<TranslationForm>;
|
2021-07-01 06:48:30 +00:00
|
|
|
handleModalToggle: () => void;
|
|
|
|
};
|
|
|
|
|
2024-02-01 10:54:26 +00:00
|
|
|
export type TranslationForm = {
|
2023-05-03 13:51:02 +00:00
|
|
|
key: string;
|
|
|
|
value: string;
|
2024-02-01 10:54:26 +00:00
|
|
|
translation: KeyValueType;
|
2021-07-01 06:48:30 +00:00
|
|
|
};
|
|
|
|
|
2024-02-01 10:54:26 +00:00
|
|
|
export const AddTranslationModal = ({
|
2021-07-01 06:48:30 +00:00
|
|
|
handleModalToggle,
|
|
|
|
save,
|
2023-01-26 09:31:07 +00:00
|
|
|
form: {
|
2022-04-08 12:37:31 +00:00
|
|
|
register,
|
|
|
|
handleSubmit,
|
|
|
|
formState: { errors },
|
2023-01-26 09:31:07 +00:00
|
|
|
},
|
2024-02-01 10:54:26 +00:00
|
|
|
}: AddTranslationModalProps) => {
|
2023-09-08 13:17:17 +00:00
|
|
|
const { t } = useTranslation();
|
2021-07-01 06:48:30 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
variant={ModalVariant.small}
|
2024-03-04 11:39:20 +00:00
|
|
|
title={t("addTranslation")}
|
2022-03-22 11:16:02 +00:00
|
|
|
isOpen
|
2021-07-01 06:48:30 +00:00
|
|
|
onClose={handleModalToggle}
|
|
|
|
actions={[
|
|
|
|
<Button
|
2024-02-01 10:54:26 +00:00
|
|
|
data-testid="add-translation-confirm-button"
|
2021-07-01 06:48:30 +00:00
|
|
|
key="confirm"
|
|
|
|
variant="primary"
|
|
|
|
type="submit"
|
2024-02-01 10:54:26 +00:00
|
|
|
form="translation-form"
|
2021-07-01 06:48:30 +00:00
|
|
|
>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("create")}
|
2021-07-01 06:48:30 +00:00
|
|
|
</Button>,
|
|
|
|
<Button
|
|
|
|
id="modal-cancel"
|
2022-02-02 11:44:52 +00:00
|
|
|
data-testid="cancel"
|
2021-07-01 06:48:30 +00:00
|
|
|
key="cancel"
|
|
|
|
variant={ButtonVariant.link}
|
|
|
|
onClick={() => {
|
|
|
|
handleModalToggle();
|
|
|
|
}}
|
|
|
|
>
|
2023-09-14 09:01:15 +00:00
|
|
|
{t("cancel")}
|
2021-07-01 06:48:30 +00:00
|
|
|
</Button>,
|
|
|
|
]}
|
|
|
|
>
|
2024-02-01 10:54:26 +00:00
|
|
|
<Form id="translation-form" isHorizontal onSubmit={handleSubmit(save)}>
|
2021-07-01 06:48:30 +00:00
|
|
|
<FormGroup
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("key")}
|
2021-07-01 06:48:30 +00:00
|
|
|
name="key"
|
2022-06-24 11:43:59 +00:00
|
|
|
fieldId="key-id"
|
2023-09-14 09:01:15 +00:00
|
|
|
helperTextInvalid={t("required")}
|
2021-07-01 06:48:30 +00:00
|
|
|
validated={
|
2022-03-22 11:16:02 +00:00
|
|
|
errors.key ? ValidatedOptions.error : ValidatedOptions.default
|
2021-07-01 06:48:30 +00:00
|
|
|
}
|
|
|
|
isRequired
|
|
|
|
>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-07-01 06:48:30 +00:00
|
|
|
data-testid="key-input"
|
|
|
|
autoFocus
|
2022-06-24 11:43:59 +00:00
|
|
|
id="key-id"
|
2021-07-01 06:48:30 +00:00
|
|
|
validated={
|
2022-03-22 11:16:02 +00:00
|
|
|
errors.key ? ValidatedOptions.error : ValidatedOptions.default
|
2021-07-01 06:48:30 +00:00
|
|
|
}
|
2023-01-26 09:31:07 +00:00
|
|
|
{...register("key", { required: true })}
|
2021-07-01 06:48:30 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
2023-09-14 09:01:15 +00:00
|
|
|
label={t("value")}
|
2021-07-01 06:48:30 +00:00
|
|
|
name="add-value"
|
|
|
|
fieldId="value-id"
|
2023-09-14 09:01:15 +00:00
|
|
|
helperTextInvalid={t("required")}
|
2021-07-01 06:48:30 +00:00
|
|
|
validated={
|
2022-03-22 11:16:02 +00:00
|
|
|
errors.value ? ValidatedOptions.error : ValidatedOptions.default
|
2021-07-01 06:48:30 +00:00
|
|
|
}
|
|
|
|
isRequired
|
|
|
|
>
|
2022-04-21 15:03:26 +00:00
|
|
|
<KeycloakTextInput
|
2021-07-01 06:48:30 +00:00
|
|
|
data-testid="value-input"
|
2022-06-24 11:43:59 +00:00
|
|
|
id="value-id"
|
2021-07-01 06:48:30 +00:00
|
|
|
validated={
|
2022-03-22 11:16:02 +00:00
|
|
|
errors.value ? ValidatedOptions.error : ValidatedOptions.default
|
2021-07-01 06:48:30 +00:00
|
|
|
}
|
2023-01-26 09:31:07 +00:00
|
|
|
{...register("value", { required: true })}
|
2021-07-01 06:48:30 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</Form>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
};
|