index.tsx 3.9 KB

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