index.tsx 6.2 KB

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