config-item.tsx 2.3 KB

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