header.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 { getLanguage } from '@/i18n/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 = getLanguage(locale)
  28. const { t } = useTranslation()
  29. const isInToolsPage = loc === LOC.tools
  30. const isInDebugPage = !isInToolsPage
  31. const needAuth = collection?.allow_delete || collection?.type === CollectionType.model
  32. const isAuthed = collection.is_team_authorization
  33. return (
  34. <div className={cn(isInToolsPage ? 'py-4 px-6' : 'py-[11px] pl-4 pr-3', 'flex justify-between items-start border-b border-gray-200')}>
  35. <div className='flex items-start w-full'>
  36. {icon}
  37. <div className='ml-3 grow w-0'>
  38. <div className='flex items-center h-6 space-x-1'>
  39. <div className={cn(isInDebugPage && 'truncate', 'text-base font-semibold text-gray-900')}>{collection.label[language]}</div>
  40. <div className='text-xs font-normal text-gray-500'>·</div>
  41. <div className='text-xs font-normal text-gray-500'>{t('tools.author')}&nbsp;{collection.author}</div>
  42. </div>
  43. {collection.description && (
  44. <div className={cn('leading-[18px] text-[13px] font-normal text-gray-500')}>
  45. {collection.description[language]}
  46. </div>
  47. )}
  48. </div>
  49. </div>
  50. {(collection.type === CollectionType.builtIn || collection.type === CollectionType.model) && needAuth && (
  51. <div
  52. 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')}
  53. onClick={() => {
  54. if (collection.type === CollectionType.builtIn || collection.type === CollectionType.model)
  55. onShowAuth()
  56. }}
  57. >
  58. <div className={cn(isAuthed ? 'border-[#12B76A] bg-[#32D583]' : 'border-gray-400 bg-gray-300', 'rounded h-2 w-2 border')}></div>
  59. <div className='leading-5 text-sm font-medium text-gray-700'>{t(`tools.auth.${isAuthed ? 'authorized' : 'unauthorized'}`)}</div>
  60. </div>
  61. )}
  62. {collection.type === CollectionType.custom && (
  63. <div
  64. 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')}
  65. onClick={() => onShowEditCustomCollection()}
  66. >
  67. <Settings01 className='w-4 h-4 text-gray-700' />
  68. <div className='leading-5 text-sm font-medium text-gray-700'>{t('tools.createTool.editAction')}</div>
  69. </div>
  70. )}
  71. </div >
  72. )
  73. }
  74. export default React.memo(Header)