keycloak-scim/src/client-scopes/add/components/ScriptComponent.tsx
Erik Jan de Wit 27dd8d7e13
deleted original screens, works like old console (#1187)
Co-authored-by: Jon Koops <jonkoops@gmail.com>
2021-09-20 17:31:05 +02:00

44 lines
1.2 KiB
TypeScript

import React from "react";
import { Controller, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { FormGroup } from "@patternfly/react-core";
import { CodeEditor, Language } from "@patternfly/react-code-editor";
import { HelpItem } from "../../../components/help-enabler/HelpItem";
import type { ComponentProps } from "./components";
export const ScriptComponent = ({
name,
label,
helpText,
defaultValue,
}: ComponentProps) => {
const { t } = useTranslation("client-scopes");
const { control } = useFormContext();
return (
<FormGroup
label={t(label!)}
labelIcon={
<HelpItem helpText={t(helpText!)} forLabel={t(label!)} forID={name!} />
}
fieldId={name!}
>
<Controller
name={`config.${name?.replaceAll(".", "-")}`}
defaultValue={defaultValue}
control={control}
render={({ onChange, value }) => (
<CodeEditor
id={name!}
type="text"
onChange={onChange}
code={value}
height="600px"
language={Language.javascript}
/>
)}
/>
</FormGroup>
);
};