'use client' import type { FC } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import Tooltip from '@/app/components/base/tooltip' import cn from '@/utils/classnames' import type { Credential } from '@/app/components/tools/types' import Drawer from '@/app/components/base/drawer-plus' import Button from '@/app/components/base/button' import Radio from '@/app/components/base/radio/ui' import { AuthHeaderPrefix, AuthType } from '@/app/components/tools/types' type Props = { positionCenter?: boolean credential: Credential onChange: (credential: Credential) => void onHide: () => void } const keyClassNames = 'py-2 leading-5 text-sm font-medium text-gray-900' type ItemProps = { text: string value: AuthType | AuthHeaderPrefix isChecked: boolean onClick: (value: AuthType | AuthHeaderPrefix) => void } const SelectItem: FC = ({ text, value, isChecked, onClick }) => { return (
onClick(value)} >
{text}
) } const ConfigCredential: FC = ({ positionCenter, credential, onChange, onHide, }) => { const { t } = useTranslation() const [tempCredential, setTempCredential] = React.useState(credential) return (
{t('tools.createTool.authMethod.type')}
setTempCredential({ ...tempCredential, auth_type: value as AuthType })} /> setTempCredential({ ...tempCredential, auth_type: value as AuthType, api_key_header: tempCredential.api_key_header || 'Authorization', api_key_value: tempCredential.api_key_value || '', api_key_header_prefix: tempCredential.api_key_header_prefix || AuthHeaderPrefix.custom, })} />
{tempCredential.auth_type === AuthType.apiKey && ( <>
{t('tools.createTool.authHeaderPrefix.title')}
setTempCredential({ ...tempCredential, api_key_header_prefix: value as AuthHeaderPrefix })} /> setTempCredential({ ...tempCredential, api_key_header_prefix: value as AuthHeaderPrefix })} /> setTempCredential({ ...tempCredential, api_key_header_prefix: value as AuthHeaderPrefix })} />
{t('tools.createTool.authMethod.key')} {t('tools.createTool.authMethod.keyTooltip')}
} triggerClassName='ml-0.5 w-4 h-4' />
setTempCredential({ ...tempCredential, api_key_header: e.target.value })} className='w-full h-10 px-3 text-sm font-normal bg-gray-100 rounded-lg grow' placeholder={t('tools.createTool.authMethod.types.apiKeyPlaceholder')!} />
{t('tools.createTool.authMethod.value')}
setTempCredential({ ...tempCredential, api_key_value: e.target.value })} className='w-full h-10 px-3 text-sm font-normal bg-gray-100 rounded-lg grow' placeholder={t('tools.createTool.authMethod.types.apiValuePlaceholder')!} />
)}
} /> ) } export default React.memo(ConfigCredential)