index.tsx 6.5 KB

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