index.tsx 6.7 KB

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