mirror of
https://github.com/langgenius/dify.git
synced 2025-07-30 04:45:43 +00:00
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import {
|
|
memo,
|
|
useState,
|
|
} from 'react'
|
|
import Button from '@/app/components/base/button'
|
|
import type { ButtonProps } from '@/app/components/base/button'
|
|
import ApiKeyModal from './api-key-modal'
|
|
import type { PluginPayload } from '../types'
|
|
import type { FormSchema } from '@/app/components/base/form/types'
|
|
|
|
export type AddApiKeyButtonProps = {
|
|
pluginPayload: PluginPayload
|
|
buttonVariant?: ButtonProps['variant']
|
|
buttonText?: string
|
|
disabled?: boolean
|
|
onUpdate?: () => void
|
|
formSchemas?: FormSchema[]
|
|
}
|
|
const AddApiKeyButton = ({
|
|
pluginPayload,
|
|
buttonVariant = 'secondary-accent',
|
|
buttonText = 'Use Api Key',
|
|
disabled,
|
|
onUpdate,
|
|
formSchemas = [],
|
|
}: AddApiKeyButtonProps) => {
|
|
const [isApiKeyModalOpen, setIsApiKeyModalOpen] = useState(false)
|
|
|
|
return (
|
|
<>
|
|
<Button
|
|
className='w-full'
|
|
variant={buttonVariant}
|
|
onClick={() => setIsApiKeyModalOpen(true)}
|
|
disabled={disabled}
|
|
>
|
|
{buttonText}
|
|
</Button>
|
|
{
|
|
isApiKeyModalOpen && (
|
|
<ApiKeyModal
|
|
pluginPayload={pluginPayload}
|
|
onClose={() => setIsApiKeyModalOpen(false)}
|
|
onUpdate={onUpdate}
|
|
formSchemas={formSchemas}
|
|
/>
|
|
)
|
|
}
|
|
</>
|
|
|
|
)
|
|
}
|
|
|
|
export default memo(AddApiKeyButton)
|