config-item.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. }
  28. const ConfigItem: FC<Props> = ({
  29. type,
  30. payload,
  31. onRemove,
  32. notionActions,
  33. }) => {
  34. const { t } = useTranslation()
  35. const isNotion = type === DataSourceType.notion
  36. const isWebsite = type === DataSourceType.website
  37. const onChangeAuthorizedPage = notionActions?.onChangeAuthorizedPage || function () { }
  38. return (
  39. <div className={cn(s['workspace-item'], 'flex items-center mb-1 py-1 pr-1 bg-white rounded-lg')} key={payload.id}>
  40. <payload.logo className='ml-3 mr-1.5' />
  41. <div className='grow py-[7px] leading-[18px] text-[13px] font-medium text-gray-700 truncate' title={payload.name}>{payload.name}</div>
  42. {
  43. payload.isActive
  44. ? <Indicator className='shrink-0 mr-[6px]' />
  45. : <Indicator className='shrink-0 mr-[6px]' color='yellow' />
  46. }
  47. <div className='shrink-0 mr-3 text-xs font-medium uppercase'>
  48. {
  49. payload.isActive
  50. ? t(isNotion ? 'common.dataSource.notion.connected' : 'common.dataSource.website.active')
  51. : t(isNotion ? 'common.dataSource.notion.disconnected' : 'common.dataSource.website.inactive')
  52. }
  53. </div>
  54. <div className='mr-2 w-[1px] h-3 bg-gray-100' />
  55. {isNotion && (
  56. <Operate payload={{
  57. id: payload.id,
  58. total: payload.notionConfig?.total || 0,
  59. }} onAuthAgain={onChangeAuthorizedPage}
  60. />
  61. )}
  62. {
  63. isWebsite && (
  64. <div className='p-2 text-gray-500 cursor-pointer rounded-md hover:bg-black/5' onClick={onRemove} >
  65. <Trash03 className='w-4 h-4 ' />
  66. </div>
  67. )
  68. }
  69. </div>
  70. )
  71. }
  72. export default React.memo(ConfigItem)