header.tsx 2.9 KB

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