index.tsx 6.0 KB

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