index.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { useTranslation } from 'react-i18next'
  2. import Link from 'next/link'
  3. import { PlusIcon } from '@heroicons/react/24/solid'
  4. import cn from 'classnames'
  5. import Indicator from '../../../indicator'
  6. import Operate from './operate'
  7. import s from './style.module.css'
  8. import NotionIcon from '@/app/components/base/notion-icon'
  9. import { apiPrefix } from '@/config'
  10. import type { DataSourceNotion as TDataSourceNotion } from '@/models/common'
  11. import { useAppContext } from '@/context/app-context'
  12. type DataSourceNotionProps = {
  13. workspaces: TDataSourceNotion[]
  14. }
  15. const DataSourceNotion = ({
  16. workspaces,
  17. }: DataSourceNotionProps) => {
  18. const { t } = useTranslation()
  19. const { isCurrentWorkspaceManager } = useAppContext()
  20. const connected = !!workspaces.length
  21. return (
  22. <div className='mb-2 border-[0.5px] border-gray-200 bg-gray-50 rounded-xl'>
  23. <div className='flex items-center px-3 py-[9px]'>
  24. <div className={cn(s['notion-icon'], 'w-8 h-8 mr-3 border border-gray-100 rounded-lg')} />
  25. <div className='grow'>
  26. <div className='leading-5 text-sm font-medium text-gray-800'>
  27. {t('common.dataSource.notion.title')}
  28. </div>
  29. {
  30. !connected && (
  31. <div className='leading-5 text-xs text-gray-500'>
  32. {t('common.dataSource.notion.description')}
  33. </div>
  34. )
  35. }
  36. </div>
  37. {
  38. connected
  39. ? (
  40. <Link
  41. className={
  42. `flex items-center ml-3 px-3 h-7 bg-white border border-gray-200
  43. rounded-md text-xs font-medium text-gray-700
  44. ${isCurrentWorkspaceManager ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
  45. }
  46. href={isCurrentWorkspaceManager ? `${apiPrefix}/oauth/data-source/notion` : '/'}>
  47. {t('common.dataSource.connect')}
  48. </Link>
  49. )
  50. : (
  51. <Link
  52. href={isCurrentWorkspaceManager ? `${apiPrefix}/oauth/data-source/notion` : '/' }
  53. className={
  54. `flex items-center px-3 h-7 bg-white border-[0.5px] border-gray-200 text-xs font-medium text-primary-600 rounded-md
  55. ${isCurrentWorkspaceManager ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
  56. }>
  57. <PlusIcon className='w-[14px] h-[14px] mr-[5px]' />
  58. {t('common.dataSource.notion.addWorkspace')}
  59. </Link>
  60. )
  61. }
  62. </div>
  63. {
  64. connected && (
  65. <div className='flex items-center px-3 h-[18px]'>
  66. <div className='text-xs font-medium text-gray-500'>
  67. {t('common.dataSource.notion.connectedWorkspace')}
  68. </div>
  69. <div className='grow ml-3 border-t border-t-gray-100' />
  70. </div>
  71. )
  72. }
  73. {
  74. connected && (
  75. <div className='px-3 pt-2 pb-3'>
  76. {
  77. workspaces.map(workspace => (
  78. <div className={cn(s['workspace-item'], 'flex items-center mb-1 py-1 pr-1 bg-white rounded-lg')} key={workspace.id}>
  79. <NotionIcon
  80. className='ml-3 mr-[6px]'
  81. src={workspace.source_info.workspace_icon}
  82. name={workspace.source_info.workspace_name}
  83. />
  84. <div className='grow py-[7px] leading-[18px] text-[13px] font-medium text-gray-700 truncate' title={workspace.source_info.workspace_name}>{workspace.source_info.workspace_name}</div>
  85. {
  86. workspace.is_bound
  87. ? <Indicator className='shrink-0 mr-[6px]' />
  88. : <Indicator className='shrink-0 mr-[6px]' color='yellow' />
  89. }
  90. <div className='shrink-0 mr-3 text-xs font-medium'>
  91. {
  92. workspace.is_bound
  93. ? t('common.dataSource.notion.connected')
  94. : t('common.dataSource.notion.disconnected')
  95. }
  96. </div>
  97. <div className='mr-2 w-[1px] h-3 bg-gray-100' />
  98. <Operate workspace={workspace} />
  99. </div>
  100. ))
  101. }
  102. </div>
  103. )
  104. }
  105. </div>
  106. )
  107. }
  108. export default DataSourceNotion