index.tsx 6.0 KB

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