keycloak-scim/src/clients/authorization/DecisionStragegySelect.tsx
Erik Jan de Wit 109c255d90
Added the policy screens (#1884)
* initial policies tab

* added initial edit create screen

* removed switch in favour of mapping list

* added pickers

* added groups

* added regex

* added role select component

* added time

* added js type

* fixed create route

* fixed details

* added tests

* changed table header to required

* added user type

* added missing validation message
2022-01-21 15:10:36 +01:00

60 lines
1.7 KiB
TypeScript

import React from "react";
import { useTranslation } from "react-i18next";
import { Controller, useFormContext } from "react-hook-form";
import { FormGroup, Radio } from "@patternfly/react-core";
import { HelpItem } from "../../components/help-enabler/HelpItem";
const DECISION_STRATEGY = ["UNANIMOUS", "AFFIRMATIVE", "CONSENSUS"] as const;
type DecisionStrategySelectProps = {
helpLabel?: string;
isLimited?: boolean;
};
export const DecisionStrategySelect = ({
helpLabel,
isLimited = false,
}: DecisionStrategySelectProps) => {
const { t } = useTranslation("clients");
const { control } = useFormContext();
return (
<FormGroup
label={t("decisionStrategy")}
labelIcon={
<HelpItem
helpText={`clients-help:${helpLabel || "decisionStrategy"}`}
fieldLabelId="clients:decisionStrategy"
/>
}
fieldId="decisionStrategy"
hasNoPaddingTop
>
<Controller
name="decisionStrategy"
data-testid="decisionStrategy"
defaultValue={DECISION_STRATEGY[0]}
control={control}
render={({ onChange, value }) => (
<>
{(isLimited
? DECISION_STRATEGY.slice(0, 2)
: DECISION_STRATEGY
).map((strategy) => (
<Radio
id={strategy}
key={strategy}
data-testid={strategy}
isChecked={value === strategy}
name="decisionStrategy"
onChange={() => onChange(strategy)}
label={t(`decisionStrategies.${strategy}`)}
className="pf-u-mb-md"
/>
))}
</>
)}
/>
</FormGroup>
);
};