You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { RiResetLeftLine } from '@remixicon/react'
  4. import { useTranslation } from 'react-i18next'
  5. import type { Theme } from '../theme/theme-context'
  6. import { CssTransform } from '../theme/utils'
  7. import {
  8. useEmbeddedChatbotContext,
  9. } from '../context'
  10. import Tooltip from '@/app/components/base/tooltip'
  11. import ActionButton from '@/app/components/base/action-button'
  12. import Divider from '@/app/components/base/divider'
  13. import ViewFormDropdown from '@/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown'
  14. import LogoSite from '@/app/components/base/logo/logo-site'
  15. import cn from '@/utils/classnames'
  16. export type IHeaderProps = {
  17. isMobile?: boolean
  18. allowResetChat?: boolean
  19. customerIcon?: React.ReactNode
  20. title: string
  21. theme?: Theme
  22. onCreateNewChat?: () => void
  23. }
  24. const Header: FC<IHeaderProps> = ({
  25. isMobile,
  26. allowResetChat,
  27. customerIcon,
  28. title,
  29. theme,
  30. onCreateNewChat,
  31. }) => {
  32. const { t } = useTranslation()
  33. const {
  34. appData,
  35. currentConversationId,
  36. inputsForms,
  37. } = useEmbeddedChatbotContext()
  38. if (!isMobile) {
  39. return (
  40. <div className='flex h-14 shrink-0 items-center justify-end p-3'>
  41. <div className='flex items-center gap-1'>
  42. {/* powered by */}
  43. <div className='shrink-0'>
  44. {!appData?.custom_config?.remove_webapp_brand && (
  45. <div className={cn(
  46. 'flex shrink-0 items-center gap-1.5 px-2',
  47. )}>
  48. <div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
  49. {appData?.custom_config?.replace_webapp_logo && (
  50. <img src={appData?.custom_config?.replace_webapp_logo} alt='logo' className='block h-5 w-auto' />
  51. )}
  52. {!appData?.custom_config?.replace_webapp_logo && (
  53. <LogoSite className='!h-5' />
  54. )}
  55. </div>
  56. )}
  57. </div>
  58. {currentConversationId && (
  59. <Divider type='vertical' className='h-3.5' />
  60. )}
  61. {currentConversationId && allowResetChat && (
  62. <Tooltip
  63. popupContent={t('share.chat.resetChat')}
  64. >
  65. <ActionButton size='l' onClick={onCreateNewChat}>
  66. <RiResetLeftLine className='h-[18px] w-[18px]' />
  67. </ActionButton>
  68. </Tooltip>
  69. )}
  70. {currentConversationId && inputsForms.length > 0 && (
  71. <ViewFormDropdown />
  72. )}
  73. </div>
  74. </div>
  75. )
  76. }
  77. return (
  78. <div
  79. className={cn('flex h-14 shrink-0 items-center justify-between rounded-t-2xl px-3')}
  80. style={Object.assign({}, CssTransform(theme?.backgroundHeaderColorStyle ?? ''), CssTransform(theme?.headerBorderBottomStyle ?? '')) }
  81. >
  82. <div className="flex grow items-center space-x-3">
  83. {customerIcon}
  84. <div
  85. className='system-md-semibold truncate'
  86. style={CssTransform(theme?.colorFontOnHeaderStyle ?? '')}
  87. >
  88. {title}
  89. </div>
  90. </div>
  91. <div className='flex items-center gap-1'>
  92. {currentConversationId && allowResetChat && (
  93. <Tooltip
  94. popupContent={t('share.chat.resetChat')}
  95. >
  96. <ActionButton size='l' onClick={onCreateNewChat}>
  97. <RiResetLeftLine className={cn('h-[18px] w-[18px]', theme?.colorPathOnHeader)} />
  98. </ActionButton>
  99. </Tooltip>
  100. )}
  101. {currentConversationId && inputsForms.length > 0 && (
  102. <ViewFormDropdown iconColor={theme?.colorPathOnHeader} />
  103. )}
  104. </div>
  105. </div>
  106. )
  107. }
  108. export default React.memo(Header)