您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

config-item.tsx 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. import { noop } from 'lodash-es'
  14. export type ConfigItemType = {
  15. id: string
  16. logo: any
  17. name: string
  18. isActive: boolean
  19. notionConfig?: {
  20. total: number
  21. }
  22. }
  23. type Props = {
  24. type: DataSourceType
  25. payload: ConfigItemType
  26. onRemove: () => void
  27. notionActions?: {
  28. onChangeAuthorizedPage: () => void
  29. }
  30. readOnly: boolean
  31. }
  32. const ConfigItem: FC<Props> = ({
  33. type,
  34. payload,
  35. onRemove,
  36. notionActions,
  37. readOnly,
  38. }) => {
  39. const { t } = useTranslation()
  40. const isNotion = type === DataSourceType.notion
  41. const isWebsite = type === DataSourceType.website
  42. const onChangeAuthorizedPage = notionActions?.onChangeAuthorizedPage || noop
  43. return (
  44. <div className={cn(s['workspace-item'], 'mb-1 flex items-center rounded-lg bg-components-panel-on-panel-item-bg py-1 pr-1')} key={payload.id}>
  45. <payload.logo className='ml-3 mr-1.5' />
  46. <div className='system-sm-medium grow truncate py-[7px] text-text-secondary' title={payload.name}>{payload.name}</div>
  47. {
  48. payload.isActive
  49. ? <Indicator className='mr-[6px] shrink-0' color='green' />
  50. : <Indicator className='mr-[6px] shrink-0' color='yellow' />
  51. }
  52. <div className={`system-xs-semibold-uppercase mr-3 shrink-0 ${payload.isActive ? 'text-util-colors-green-green-600' : 'text-util-colors-warning-warning-600'}`}>
  53. {
  54. payload.isActive
  55. ? t(isNotion ? 'common.dataSource.notion.connected' : 'common.dataSource.website.active')
  56. : t(isNotion ? 'common.dataSource.notion.disconnected' : 'common.dataSource.website.inactive')
  57. }
  58. </div>
  59. <div className='mr-2 h-3 w-[1px] bg-divider-regular' />
  60. {isNotion && (
  61. <Operate payload={{
  62. id: payload.id,
  63. total: payload.notionConfig?.total || 0,
  64. }} onAuthAgain={onChangeAuthorizedPage}
  65. />
  66. )}
  67. {
  68. isWebsite && !readOnly && (
  69. <div className='cursor-pointer rounded-md p-2 text-text-tertiary hover:bg-state-base-hover' onClick={onRemove} >
  70. <RiDeleteBinLine className='h-4 w-4' />
  71. </div>
  72. )
  73. }
  74. </div>
  75. )
  76. }
  77. export default React.memo(ConfigItem)