You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

add-api-key-button.tsx 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import {
  2. memo,
  3. useState,
  4. } from 'react'
  5. import Button from '@/app/components/base/button'
  6. import type { ButtonProps } from '@/app/components/base/button'
  7. import ApiKeyModal from './api-key-modal'
  8. import type { PluginPayload } from '../types'
  9. export type AddApiKeyButtonProps = {
  10. pluginPayload: PluginPayload
  11. buttonVariant?: ButtonProps['variant']
  12. buttonText?: string
  13. disabled?: boolean
  14. onUpdate?: () => void
  15. }
  16. const AddApiKeyButton = ({
  17. pluginPayload,
  18. buttonVariant = 'secondary-accent',
  19. buttonText = 'use api key',
  20. disabled,
  21. onUpdate,
  22. }: AddApiKeyButtonProps) => {
  23. const [isApiKeyModalOpen, setIsApiKeyModalOpen] = useState(false)
  24. return (
  25. <>
  26. <Button
  27. className='w-full'
  28. variant={buttonVariant}
  29. onClick={() => setIsApiKeyModalOpen(true)}
  30. disabled={disabled}
  31. >
  32. {buttonText}
  33. </Button>
  34. {
  35. isApiKeyModalOpen && (
  36. <ApiKeyModal
  37. pluginPayload={pluginPayload}
  38. onClose={() => setIsApiKeyModalOpen(false)}
  39. onUpdate={onUpdate}
  40. />
  41. )
  42. }
  43. </>
  44. )
  45. }
  46. export default memo(AddApiKeyButton)