index.tsx 6.1 KB

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