index.tsx 6.0 KB

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