|
1 | 1 | import React from 'react'; |
2 | | -import { Controller, UseControllerProps } from 'react-hook-form'; |
| 2 | +import { useController, UseControllerProps } from 'react-hook-form'; |
3 | 3 | import { |
4 | 4 | OdsFormField, |
5 | 5 | OdsRadio, |
@@ -28,54 +28,50 @@ export const SecretCasRequiredFormField = <T extends FormFieldInput>({ |
28 | 28 | isCasRequiredSetOnOkms, |
29 | 29 | }: SecretCasRequiredFormFieldProps<T>) => { |
30 | 30 | const { t } = useTranslation(['secret-manager', NAMESPACES.STATUS]); |
| 31 | + const { field, fieldState } = useController({ name, control }); |
| 32 | + |
31 | 33 | return ( |
32 | | - <Controller |
33 | | - name={name} |
34 | | - control={control} |
35 | | - render={({ field, fieldState }) => ( |
36 | | - <OdsFormField error={fieldState.error?.message}> |
37 | | - <label slot="label" className="flex items-center gap-2 relative mb-1"> |
38 | | - <span>{t('cas_with_description')}</span> |
39 | | - <HelpIconWithTooltip label={t('cas_with_description_tooltip')} /> |
| 34 | + <OdsFormField error={fieldState.error?.message}> |
| 35 | + <label slot="label" className="flex items-center gap-2 relative mb-1"> |
| 36 | + <span>{t('cas_with_description')}</span> |
| 37 | + <HelpIconWithTooltip label={t('cas_with_description_tooltip')} /> |
| 38 | + </label> |
| 39 | + <div className="flex gap-4"> |
| 40 | + <div className="flex items-center gap-2"> |
| 41 | + <OdsRadio |
| 42 | + inputId={`${field.name}-active`} |
| 43 | + name={field.name} |
| 44 | + value="active" |
| 45 | + isChecked={field.value === 'active'} |
| 46 | + onOdsChange={field.onChange} |
| 47 | + data-testid={SECRET_FORM_FIELD_TEST_IDS.CAS_REQUIRED_ACTIVE} |
| 48 | + /> |
| 49 | + <label htmlFor={`${field.name}-active`}> |
| 50 | + <OdsText preset="paragraph">{t('activated')}</OdsText> |
40 | 51 | </label> |
41 | | - <div className="flex gap-4"> |
42 | | - <div className="flex items-center gap-2"> |
43 | | - <OdsRadio |
44 | | - inputId={`${field.name}-active`} |
45 | | - name={field.name} |
46 | | - value="active" |
47 | | - isChecked={field.value === 'active'} |
48 | | - onOdsChange={field.onChange} |
49 | | - data-testid={SECRET_FORM_FIELD_TEST_IDS.CAS_REQUIRED_ACTIVE} |
50 | | - /> |
51 | | - <label htmlFor={`${field.name}-active`}> |
52 | | - <OdsText preset="paragraph">{t('activated')}</OdsText> |
53 | | - </label> |
54 | | - </div> |
55 | | - <div className="flex items-center gap-2"> |
56 | | - <OdsRadio |
57 | | - inputId={`${field.name}-inactive`} |
58 | | - name={field.name} |
59 | | - value="inactive" |
60 | | - isChecked={field.value === 'inactive'} |
61 | | - onOdsChange={field.onChange} |
62 | | - data-testid={SECRET_FORM_FIELD_TEST_IDS.CAS_REQUIRED_INACTIVE} |
63 | | - /> |
64 | | - <label htmlFor={`${field.name}-inactive`}> |
65 | | - <OdsText preset="paragraph"> |
66 | | - {t('disabled', { ns: NAMESPACES.STATUS })} |
67 | | - </OdsText> |
68 | | - </label> |
69 | | - </div> |
70 | | - </div> |
71 | | - {isCasRequiredSetOnOkms && ( |
72 | | - <OdsText slot="helper" preset="caption"> |
73 | | - {t('form_helper_cas_required_okms')} |
| 52 | + </div> |
| 53 | + <div className="flex items-center gap-2"> |
| 54 | + <OdsRadio |
| 55 | + inputId={`${field.name}-inactive`} |
| 56 | + name={field.name} |
| 57 | + value="inactive" |
| 58 | + isChecked={field.value === 'inactive'} |
| 59 | + onOdsChange={field.onChange} |
| 60 | + data-testid={SECRET_FORM_FIELD_TEST_IDS.CAS_REQUIRED_INACTIVE} |
| 61 | + /> |
| 62 | + <label htmlFor={`${field.name}-inactive`}> |
| 63 | + <OdsText preset="paragraph"> |
| 64 | + {t('disabled', { ns: NAMESPACES.STATUS })} |
74 | 65 | </OdsText> |
75 | | - )} |
76 | | - </OdsFormField> |
| 66 | + </label> |
| 67 | + </div> |
| 68 | + </div> |
| 69 | + {isCasRequiredSetOnOkms && ( |
| 70 | + <OdsText slot="helper" preset="caption"> |
| 71 | + {t('form_helper_cas_required_okms')} |
| 72 | + </OdsText> |
77 | 73 | )} |
78 | | - /> |
| 74 | + </OdsFormField> |
79 | 75 | ); |
80 | 76 | }; |
81 | 77 |
|
|
0 commit comments