index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 { FootLogo } from '@/app/components/share/chat/welcome/massive-component'
  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. className='shrink-0 px-2 py-0 h-6 bg-white text-xs font-medium text-primary-600 rounded-md'
  70. onClick={() => setCollapsed(false)}
  71. >
  72. <Edit02 className='mr-1 w-3 h-3' />
  73. {t('common.operation.edit')}
  74. </Button>
  75. </>
  76. )
  77. }
  78. {
  79. !showConfigPanelBeforeChat && !collapsed && (
  80. <>
  81. <Star06 className='mr-1 mt-1 w-4 h-4 text-indigo-600' />
  82. <div className='grow py-[3px] text-[13px] text-indigo-600 leading-[18px] font-medium'>
  83. {t('share.chat.privatePromptConfigTitle')}
  84. </div>
  85. </>
  86. )
  87. }
  88. </div>
  89. {
  90. !collapsed && !showConfigPanelBeforeChat && (
  91. <div className='p-6 rounded-b-xl'>
  92. <Form />
  93. <div className={cn('pl-[136px] flex items-center', isMobile && '!pl-0')}>
  94. <Button
  95. variant='primary'
  96. className='mr-2 text-sm font-medium'
  97. onClick={() => {
  98. setCollapsed(true)
  99. handleStartChat()
  100. }}
  101. >
  102. {t('common.operation.save')}
  103. </Button>
  104. <Button
  105. className='text-sm font-medium'
  106. onClick={() => setCollapsed(true)}
  107. >
  108. {t('common.operation.cancel')}
  109. </Button>
  110. </div>
  111. </div>
  112. )
  113. }
  114. {
  115. showConfigPanelBeforeChat && (
  116. <div className='p-6 rounded-b-xl'>
  117. <Form />
  118. <Button
  119. className={cn('px-4 py-0 h-9', inputsForms.length && !isMobile && 'ml-[136px]')}
  120. variant='primary'
  121. onClick={handleStartChat}
  122. >
  123. <MessageDotsCircle className='mr-2 w-4 h-4 text-white' />
  124. {t('share.chat.startChat')}
  125. </Button>
  126. </div>
  127. )
  128. }
  129. </div>
  130. {
  131. showConfigPanelBeforeChat && (site || customConfig) && (
  132. <div className='mt-4 flex flex-wrap justify-between items-center py-2 text-xs text-gray-400'>
  133. {site?.privacy_policy
  134. ? <div className={cn(isMobile && 'mb-2 w-full text-center')}>{t('share.chat.privacyPolicyLeft')}
  135. <a
  136. className='text-gray-500 px-1'
  137. href={site?.privacy_policy}
  138. target='_blank' rel='noopener noreferrer'>{t('share.chat.privacyPolicyMiddle')}</a>
  139. {t('share.chat.privacyPolicyRight')}
  140. </div>
  141. : <div>
  142. </div>}
  143. {
  144. customConfig?.remove_webapp_brand
  145. ? null
  146. : (
  147. <div className={cn('flex items-center justify-end', isMobile && 'w-full')}>
  148. <div className='flex items-center pr-3 space-x-3'>
  149. <span className='uppercase'>{t('share.chat.powerBy')}</span>
  150. {
  151. customConfig?.replace_webapp_logo
  152. ? <img src={customConfig?.replace_webapp_logo} alt='logo' className='block w-auto h-5' />
  153. : <FootLogo />
  154. }
  155. </div>
  156. </div>
  157. )
  158. }
  159. </div>
  160. )
  161. }
  162. </div>
  163. )
  164. }
  165. export default ConfigPanel