index.tsx 6.7 KB

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