config-item.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import Indicator from '../../../indicator'
  7. import Operate from '../data-source-notion/operate'
  8. import { DataSourceType } from './types'
  9. import s from './style.module.css'
  10. import { Trash03 } from '@/app/components/base/icons/src/vender/line/general'
  11. export type ConfigItemType = {
  12. id: string
  13. logo: any
  14. name: string
  15. isActive: boolean
  16. notionConfig?: {
  17. total: number
  18. }
  19. }
  20. type Props = {
  21. type: DataSourceType
  22. payload: ConfigItemType
  23. onRemove: () => void
  24. notionActions?: {
  25. onChangeAuthorizedPage: () => void
  26. }
  27. readOnly: boolean
  28. }
  29. const ConfigItem: FC<Props> = ({
  30. type,
  31. payload,
  32. onRemove,
  33. notionActions,
  34. readOnly,
  35. }) => {
  36. const { t } = useTranslation()
  37. const isNotion = type === DataSourceType.notion
  38. const isWebsite = type === DataSourceType.website
  39. const onChangeAuthorizedPage = notionActions?.onChangeAuthorizedPage || function () { }
  40. return (
  41. <div className={cn(s['workspace-item'], 'flex items-center mb-1 py-1 pr-1 bg-white rounded-lg')} key={payload.id}>
  42. <payload.logo className='ml-3 mr-1.5' />
  43. <div className='grow py-[7px] leading-[18px] text-[13px] font-medium text-gray-700 truncate' title={payload.name}>{payload.name}</div>
  44. {
  45. payload.isActive
  46. ? <Indicator className='shrink-0 mr-[6px]' />
  47. : <Indicator className='shrink-0 mr-[6px]' color='yellow' />
  48. }
  49. <div className='shrink-0 mr-3 text-xs font-medium uppercase'>
  50. {
  51. payload.isActive
  52. ? t(isNotion ? 'common.dataSource.notion.connected' : 'common.dataSource.website.active')
  53. : t(isNotion ? 'common.dataSource.notion.disconnected' : 'common.dataSource.website.inactive')
  54. }
  55. </div>
  56. <div className='mr-2 w-[1px] h-3 bg-gray-100' />
  57. {isNotion && (
  58. <Operate payload={{
  59. id: payload.id,
  60. total: payload.notionConfig?.total || 0,
  61. }} onAuthAgain={onChangeAuthorizedPage}
  62. />
  63. )}
  64. {
  65. isWebsite && !readOnly && (
  66. <div className='p-2 text-gray-500 cursor-pointer rounded-md hover:bg-black/5' onClick={onRemove} >
  67. <Trash03 className='w-4 h-4 ' />
  68. </div>
  69. )
  70. }
  71. </div>
  72. )
  73. }
  74. export default React.memo(ConfigItem)