header.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useContext } from 'use-context-selector'
  5. import cn from 'classnames'
  6. import { useTranslation } from 'react-i18next'
  7. import type { Collection } from '../types'
  8. import { CollectionType, LOC } from '../types'
  9. import { Settings01 } from '../../base/icons/src/vender/line/general'
  10. import I18n from '@/context/i18n'
  11. import { getModelRuntimeSupported } from '@/utils/language'
  12. type Props = {
  13. icon: JSX.Element
  14. collection: Collection
  15. loc: LOC
  16. onShowAuth: () => void
  17. onShowEditCustomCollection: () => void
  18. }
  19. const Header: FC<Props> = ({
  20. icon,
  21. collection,
  22. loc,
  23. onShowAuth,
  24. onShowEditCustomCollection,
  25. }) => {
  26. const { locale } = useContext(I18n)
  27. const language = getModelRuntimeSupported(locale)
  28. const { t } = useTranslation()
  29. const isInToolsPage = loc === LOC.tools
  30. const isInDebugPage = !isInToolsPage
  31. const needAuth = collection?.allow_delete
  32. // const isBuiltIn = collection.type === CollectionType.builtIn
  33. const isAuthed = collection.is_team_authorization
  34. return (
  35. <div className={cn(isInToolsPage ? 'py-4 px-6' : 'py-[11px] pl-4 pr-3', 'flex justify-between items-start border-b border-gray-200')}>
  36. <div className='flex items-start w-full'>
  37. {icon}
  38. <div className='ml-3 grow w-0'>
  39. <div className='flex items-center h-6 space-x-1'>
  40. <div className={cn(isInDebugPage && 'truncate', 'text-base font-semibold text-gray-900')}>{collection.label[language]}</div>
  41. <div className='text-xs font-normal text-gray-500'>·</div>
  42. <div className='text-xs font-normal text-gray-500'>{t('tools.author')}&nbsp;{collection.author}</div>
  43. </div>
  44. {collection.description && (
  45. <div className={cn('leading-[18px] text-[13px] font-normal text-gray-500')}>
  46. {collection.description[language]}
  47. </div>
  48. )}
  49. </div>
  50. </div>
  51. {collection.type === CollectionType.builtIn && needAuth && (
  52. <div
  53. className={cn('cursor-pointer', 'ml-1 shrink-0 flex items-center h-8 border border-gray-200 rounded-lg px-3 space-x-2 shadow-xs')}
  54. onClick={() => onShowAuth()}
  55. >
  56. <div className={cn(isAuthed ? 'border-[#12B76A] bg-[#32D583]' : 'border-gray-400 bg-gray-300', 'rounded h-2 w-2 border')}></div>
  57. <div className='leading-5 text-sm font-medium text-gray-700'>{t(`tools.auth.${isAuthed ? 'authorized' : 'unauthorized'}`)}</div>
  58. </div>
  59. )}
  60. {collection.type === CollectionType.custom && (
  61. <div
  62. className={cn('cursor-pointer', 'ml-1 shrink-0 flex items-center h-8 border border-gray-200 rounded-lg px-3 space-x-2 shadow-xs')}
  63. onClick={() => onShowEditCustomCollection()}
  64. >
  65. <Settings01 className='w-4 h-4 text-gray-700' />
  66. <div className='leading-5 text-sm font-medium text-gray-700'>{t('tools.createTool.editAction')}</div>
  67. </div>
  68. )}
  69. </div >
  70. )
  71. }
  72. export default React.memo(Header)