index.tsx 5.8 KB

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