index.tsx 3.6 KB

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