2022-01-21 14:10:36 +00:00
|
|
|
import { FormGroup, Radio } from "@patternfly/react-core";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
2022-01-21 14:10:36 +00:00
|
|
|
|
|
|
|
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();
|
2022-05-04 17:51:17 +00:00
|
|
|
|
2022-01-21 14:10:36 +00:00
|
|
|
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}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={(field) => (
|
2022-01-21 14:10:36 +00:00
|
|
|
<>
|
|
|
|
{(isLimited
|
|
|
|
? DECISION_STRATEGY.slice(0, 2)
|
|
|
|
: DECISION_STRATEGY
|
|
|
|
).map((strategy) => (
|
|
|
|
<Radio
|
|
|
|
id={strategy}
|
|
|
|
key={strategy}
|
|
|
|
data-testid={strategy}
|
2022-12-02 14:54:30 +00:00
|
|
|
isChecked={field.value === strategy}
|
2022-01-21 14:10:36 +00:00
|
|
|
name="decisionStrategy"
|
2022-12-02 14:54:30 +00:00
|
|
|
onChange={() => field.onChange(strategy)}
|
2022-01-21 14:10:36 +00:00
|
|
|
label={t(`decisionStrategies.${strategy}`)}
|
|
|
|
className="pf-u-mb-md"
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
);
|
|
|
|
};
|