index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { PlusIcon } from '@heroicons/react/24/solid'
  6. import type { ConfigItemType } from './config-item'
  7. import ConfigItem from './config-item'
  8. import s from './style.module.css'
  9. import { DataSourceType } from './types'
  10. import cn from '@/utils/classnames'
  11. type Props = {
  12. type: DataSourceType
  13. isConfigured: boolean
  14. onConfigure: () => void
  15. readOnly: boolean
  16. isSupportList?: boolean
  17. configuredList: ConfigItemType[]
  18. onRemove: () => void
  19. notionActions?: {
  20. onChangeAuthorizedPage: () => void
  21. }
  22. }
  23. const Panel: FC<Props> = ({
  24. type,
  25. isConfigured,
  26. onConfigure,
  27. readOnly,
  28. configuredList,
  29. isSupportList,
  30. onRemove,
  31. notionActions,
  32. }) => {
  33. const { t } = useTranslation()
  34. const isNotion = type === DataSourceType.notion
  35. const isWebsite = type === DataSourceType.website
  36. return (
  37. <div className='mb-2 border-[0.5px] border-gray-200 bg-gray-50 rounded-xl'>
  38. <div className='flex items-center px-3 py-[9px]'>
  39. <div className={cn(s[`${type}-icon`], 'w-8 h-8 mr-3 border border-gray-100 rounded-lg')} />
  40. <div className='grow'>
  41. <div className='flex items-center h-5'>
  42. <div className='text-sm font-medium text-gray-800'>{t(`common.dataSource.${type}.title`)}</div>
  43. {isWebsite && (
  44. <div className='ml-1 leading-[18px] px-1.5 rounded-md bg-white border border-gray-100 text-xs font-medium text-gray-700'>
  45. <span className='text-gray-500'>{t('common.dataSource.website.with')}</span> 🔥 Firecrawl
  46. </div>
  47. )}
  48. </div>
  49. {
  50. !isConfigured && (
  51. <div className='leading-5 text-xs text-gray-500'>
  52. {t(`common.dataSource.${type}.description`)}
  53. </div>
  54. )
  55. }
  56. </div>
  57. {isNotion && (
  58. <>
  59. {
  60. isConfigured
  61. ? (
  62. <div
  63. className={
  64. `flex items-center ml-3 px-3 h-7 bg-white border border-gray-200
  65. rounded-md text-xs font-medium text-gray-700
  66. ${!readOnly ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
  67. }
  68. onClick={onConfigure}
  69. >
  70. {t('common.dataSource.configure')}
  71. </div>
  72. )
  73. : (
  74. <>
  75. {isSupportList && <div
  76. className={
  77. `flex items-center px-3 py-1 min-h-7 bg-white border-[0.5px] border-gray-200 text-xs font-medium text-primary-600 rounded-md
  78. ${!readOnly ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
  79. }
  80. onClick={onConfigure}
  81. >
  82. <PlusIcon className='w-[14px] h-[14px] mr-[5px]' />
  83. {t('common.dataSource.notion.addWorkspace')}
  84. </div>}
  85. </>
  86. )
  87. }
  88. </>
  89. )}
  90. {isWebsite && !isConfigured && (
  91. <div
  92. className={
  93. `flex items-center ml-3 px-3 h-7 bg-white border border-gray-200
  94. rounded-md text-xs font-medium text-gray-700
  95. ${!readOnly ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
  96. }
  97. onClick={!readOnly ? onConfigure : undefined}
  98. >
  99. {t('common.dataSource.configure')}
  100. </div>
  101. )}
  102. </div>
  103. {
  104. isConfigured && (
  105. <>
  106. <div className='flex items-center px-3 h-[18px]'>
  107. <div className='text-xs font-medium text-gray-500'>
  108. {isNotion ? t('common.dataSource.notion.connectedWorkspace') : t('common.dataSource.website.configuredCrawlers')}
  109. </div>
  110. <div className='grow ml-3 border-t border-t-gray-100' />
  111. </div>
  112. <div className='px-3 pt-2 pb-3'>
  113. {
  114. configuredList.map(item => (
  115. <ConfigItem
  116. key={item.id}
  117. type={type}
  118. payload={item}
  119. onRemove={onRemove}
  120. notionActions={notionActions}
  121. readOnly={readOnly}
  122. />
  123. ))
  124. }
  125. </div>
  126. </>
  127. )
  128. }
  129. </div>
  130. )
  131. }
  132. export default React.memo(Panel)