diff --git a/src/components/form-slice/FormPartSecret.tsx b/src/components/form-slice/FormPartSecret.tsx index 33aca159f..9492b96ab 100644 --- a/src/components/form-slice/FormPartSecret.tsx +++ b/src/components/form-slice/FormPartSecret.tsx @@ -14,21 +14,56 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { Divider, InputWrapper } from '@mantine/core'; -import { useFormContext } from 'react-hook-form'; +import { ActionIcon, Divider, InputWrapper } from '@mantine/core'; +import { useState } from 'react'; +import { type Control, type FieldPath, useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { FormItemSelect } from '@/components/form/Select'; import { FormItemSwitch } from '@/components/form/Switch'; import { FormItemTextInput } from '@/components/form/TextInput'; import { APISIX, type APISIXType } from '@/types/schema/apisix'; +import IconEye from '~icons/material-symbols/visibility'; +import IconEyeOff from '~icons/material-symbols/visibility-off'; import { FormItemTagsInput } from '../form/TagInput'; import { FormSection } from './FormSection'; +const SensitiveInput = ({ + name, + label, + control, + disabled +}: { + name: FieldPath; + label: string; + control: Control; + disabled?: boolean; +}) => { + const [showPassword, setShowPassword] = useState(false); + + return ( + setShowPassword((v) => !v)} + variant="subtle" + color="gray" + > + {showPassword ? : } + ) + } + /> + ); +}; + const VaultSecretForm = () => { const { t } = useTranslation(); - const { control } = useFormContext(); + const { control, formState } = useFormContext(); return ( <> @@ -42,10 +77,11 @@ const VaultSecretForm = () => { name="prefix" label={t('form.secrets.vault.prefix')} /> - { const AWSSecretForm = () => { const { t } = useTranslation(); - const { control } = useFormContext(); + const { control, formState } = useFormContext(); return ( <> @@ -67,15 +103,17 @@ const AWSSecretForm = () => { name="access_key_id" label={t('form.secrets.aws.access_key_id')} /> - - { const GCPSecretForm = () => { const { t } = useTranslation(); - const { control } = useFormContext(); + const { control, formState } = useFormContext(); return ( <> @@ -114,10 +152,11 @@ const GCPSecretForm = () => { name="auth_config.client_email" label={t('form.secrets.gcp.client_email')} /> - { const { t } = useTranslation(); const [adminKey, setAdminKey] = useAtom(adminKeyAtom); + const [visible, setVisible] = useState(false); return ( { setAdminKey(e.currentTarget.value); @@ -38,6 +43,15 @@ const AdminKey = () => { }); }} required + rightSection={ + setVisible((v) => !v)} + variant="subtle" + color='gray' + > + {visible ? : } + + } /> ); };