index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import Button from '@/app/components/base/button'
  7. import { LinkExternal02, XClose } from '@/app/components/base/icons/src/vender/line/general'
  8. import { IS_CE_EDITION } from '@/config'
  9. import { useProviderContext } from '@/context/provider-context'
  10. import { useModalContext } from '@/context/modal-context'
  11. const APIKeyInfoPanel: FC = () => {
  12. const isCloud = !IS_CE_EDITION
  13. const { hasSettedApiKey } = useProviderContext()
  14. const { setShowAccountSettingModal } = useModalContext()
  15. const { t } = useTranslation()
  16. const [isShow, setIsShow] = useState(true)
  17. if (hasSettedApiKey)
  18. return null
  19. if (!(isShow))
  20. return null
  21. return (
  22. <div className={cn('bg-[#EFF4FF] border-[#D1E0FF]', 'mb-6 relative rounded-2xl shadow-md border p-8 ')}>
  23. <div className={cn('text-[24px] text-gray-800 font-semibold', isCloud ? 'flex items-center h-8 space-x-1' : 'leading-8 mb-6')}>
  24. {isCloud && <em-emoji id={'😀'} />}
  25. {isCloud
  26. ? (
  27. <div>{t('appOverview.apiKeyInfo.cloud.trial.title', { providerName: 'OpenAI' })}</div>
  28. )
  29. : (
  30. <div>
  31. <div>{t('appOverview.apiKeyInfo.selfHost.title.row1')}</div>
  32. <div>{t('appOverview.apiKeyInfo.selfHost.title.row2')}</div>
  33. </div>
  34. )}
  35. </div>
  36. {isCloud && (
  37. <div className='mt-1 text-sm text-gray-600 font-normal'>{t(`appOverview.apiKeyInfo.cloud.${'trial'}.description`)}</div>
  38. )}
  39. <Button
  40. type='primary'
  41. className='space-x-2'
  42. onClick={() => setShowAccountSettingModal({ payload: 'provider' })}
  43. >
  44. <div className='text-sm font-medium'>{t('appOverview.apiKeyInfo.setAPIBtn')}</div>
  45. <LinkExternal02 className='w-4 h-4' />
  46. </Button>
  47. {!isCloud && (
  48. <a
  49. className='mt-2 flex items-center h-[26px] text-xs font-medium text-[#155EEF] p-1 space-x-1'
  50. href='https://cloud.dify.ai/apps'
  51. target='_blank' rel='noopener noreferrer'
  52. >
  53. <div>{t('appOverview.apiKeyInfo.tryCloud')}</div>
  54. <LinkExternal02 className='w-3 h-3' />
  55. </a>
  56. )}
  57. <div
  58. onClick={() => setIsShow(false)}
  59. className='absolute right-4 top-4 flex items-center justify-center w-8 h-8 cursor-pointer '>
  60. <XClose className='w-4 h-4 text-gray-500' />
  61. </div>
  62. </div>
  63. )
  64. }
  65. export default React.memo(APIKeyInfoPanel)