index.tsx 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { useState } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { useEmbeddedChatbotContext } from '../context'
  4. import { useThemeContext } from '../theme/theme-context'
  5. import { CssTransform } from '../theme/utils'
  6. import Form from './form'
  7. import cn from '@/utils/classnames'
  8. import Button from '@/app/components/base/button'
  9. import AppIcon from '@/app/components/base/app-icon'
  10. import { MessageDotsCircle } from '@/app/components/base/icons/src/vender/solid/communication'
  11. import { Edit02 } from '@/app/components/base/icons/src/vender/line/general'
  12. import { Star06 } from '@/app/components/base/icons/src/vender/solid/shapes'
  13. import LogoSite from '@/app/components/base/logo/logo-site'
  14. const ConfigPanel = () => {
  15. const { t } = useTranslation()
  16. const {
  17. appData,
  18. inputsForms,
  19. handleStartChat,
  20. showConfigPanelBeforeChat,
  21. isMobile,
  22. } = useEmbeddedChatbotContext()
  23. const [collapsed, setCollapsed] = useState(true)
  24. const customConfig = appData?.custom_config
  25. const site = appData?.site
  26. const themeBuilder = useThemeContext()
  27. return (
  28. <div className='flex flex-col max-h-[80%] w-full max-w-[720px]'>
  29. <div
  30. className={cn(
  31. 'grow rounded-xl overflow-y-auto',
  32. showConfigPanelBeforeChat && 'border-[0.5px] border-gray-100 shadow-lg',
  33. !showConfigPanelBeforeChat && collapsed && 'border border-indigo-100',
  34. !showConfigPanelBeforeChat && !collapsed && 'border-[0.5px] border-gray-100 shadow-lg',
  35. )}
  36. >
  37. <div
  38. style={CssTransform(themeBuilder.theme?.roundedBackgroundColorStyle ?? '')}
  39. className={`
  40. flex flex-wrap px-6 py-4 rounded-t-xl bg-indigo-25
  41. ${isMobile && '!px-4 !py-3'}
  42. `}
  43. >
  44. {
  45. showConfigPanelBeforeChat && (
  46. <>
  47. <div className='flex items-center h-8 text-2xl font-semibold text-gray-800'>
  48. <AppIcon
  49. iconType={appData?.site.icon_type}
  50. icon={appData?.site.icon}
  51. imageUrl={appData?.site.icon_url}
  52. background='transparent'
  53. size='small'
  54. className="mr-2"
  55. />
  56. {appData?.site.title}
  57. </div>
  58. {
  59. appData?.site.description && (
  60. <div className='mt-2 w-full text-sm text-gray-500'>
  61. {appData?.site.description}
  62. </div>
  63. )
  64. }
  65. </>
  66. )
  67. }
  68. {
  69. !showConfigPanelBeforeChat && collapsed && (
  70. <>
  71. <Star06 className='mr-1 mt-1 w-4 h-4 text-indigo-600' />
  72. <div className='grow py-[3px] text-[13px] text-indigo-600 leading-[18px] font-medium'>
  73. {t('share.chat.configStatusDes')}
  74. </div>
  75. <Button
  76. styleCss={CssTransform(themeBuilder.theme?.backgroundButtonDefaultColorStyle ?? '')}
  77. variant='secondary-accent'
  78. size='small'
  79. className='shrink-0'
  80. onClick={() => setCollapsed(false)}
  81. >
  82. <Edit02 className='mr-1 w-3 h-3' />
  83. {t('common.operation.edit')}
  84. </Button>
  85. </>
  86. )
  87. }
  88. {
  89. !showConfigPanelBeforeChat && !collapsed && (
  90. <>
  91. <Star06 className='mr-1 mt-1 w-4 h-4 text-indigo-600' />
  92. <div className='grow py-[3px] text-[13px] text-indigo-600 leading-[18px] font-medium'>
  93. {t('share.chat.privatePromptConfigTitle')}
  94. </div>
  95. </>
  96. )
  97. }
  98. </div>
  99. {
  100. !collapsed && !showConfigPanelBeforeChat && (
  101. <div className='p-6 rounded-b-xl'>
  102. <Form />
  103. <div className={cn('pl-[136px] flex items-center', isMobile && '!pl-0')}>
  104. <Button
  105. styleCss={CssTransform(themeBuilder.theme?.backgroundButtonDefaultColorStyle ?? '')}
  106. variant='primary'
  107. className='mr-2'
  108. onClick={() => {
  109. setCollapsed(true)
  110. handleStartChat()
  111. }}
  112. >
  113. {t('common.operation.save')}
  114. </Button>
  115. <Button
  116. onClick={() => setCollapsed(true)}
  117. >
  118. {t('common.operation.cancel')}
  119. </Button>
  120. </div>
  121. </div>
  122. )
  123. }
  124. {
  125. showConfigPanelBeforeChat && (
  126. <div className='p-6 rounded-b-xl'>
  127. <Form />
  128. <Button
  129. styleCss={CssTransform(themeBuilder.theme?.backgroundButtonDefaultColorStyle ?? '')}
  130. className={cn(inputsForms.length && !isMobile && 'ml-[136px]')}
  131. variant='primary'
  132. size='large'
  133. onClick={handleStartChat}
  134. >
  135. <MessageDotsCircle className='mr-2 w-4 h-4 text-white' />
  136. {t('share.chat.startChat')}
  137. </Button>
  138. </div>
  139. )
  140. }
  141. </div>
  142. {
  143. showConfigPanelBeforeChat && (site || customConfig) && (
  144. <div className='mt-4 flex flex-wrap justify-between items-center py-2 text-xs text-gray-400'>
  145. {site?.privacy_policy
  146. ? <div className={cn(isMobile && 'mb-2 w-full text-center')}>{t('share.chat.privacyPolicyLeft')}
  147. <a
  148. className='text-gray-500 px-1'
  149. href={site?.privacy_policy}
  150. target='_blank' rel='noopener noreferrer'>{t('share.chat.privacyPolicyMiddle')}</a>
  151. {t('share.chat.privacyPolicyRight')}
  152. </div>
  153. : <div>
  154. </div>}
  155. {
  156. customConfig?.remove_webapp_brand
  157. ? null
  158. : (
  159. <div className={cn('flex items-center justify-end', isMobile && 'w-full')}>
  160. <div className='flex items-center pr-3 space-x-3'>
  161. <span className='uppercase'>{t('share.chat.poweredBy')}</span>
  162. {
  163. customConfig?.replace_webapp_logo
  164. ? <img src={customConfig?.replace_webapp_logo} alt='logo' className='block w-auto h-5' />
  165. : <LogoSite className='!h-5' />
  166. }
  167. </div>
  168. </div>
  169. )
  170. }
  171. </div>
  172. )
  173. }
  174. </div>
  175. )
  176. }
  177. export default ConfigPanel