moderation-content.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import type { FC } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import Switch from '@/app/components/base/switch'
  4. import type { ModerationContentConfig } from '@/models/debug'
  5. type ModerationContentProps = {
  6. title: string
  7. info?: string
  8. showPreset?: boolean
  9. config: ModerationContentConfig
  10. onConfigChange: (config: ModerationContentConfig) => void
  11. }
  12. const ModerationContent: FC<ModerationContentProps> = ({
  13. title,
  14. info,
  15. showPreset = true,
  16. config,
  17. onConfigChange,
  18. }) => {
  19. const { t } = useTranslation()
  20. const handleConfigChange = (field: string, value: boolean | string) => {
  21. if (field === 'preset_response' && typeof value === 'string')
  22. value = value.slice(0, 100)
  23. onConfigChange({ ...config, [field]: value })
  24. }
  25. return (
  26. <div className='py-2'>
  27. <div className='rounded-lg bg-gray-50 border border-gray-200'>
  28. <div className='flex items-center justify-between px-3 h-10 rounded-lg'>
  29. <div className='shrink-0 text-sm font-medium text-gray-900'>{title}</div>
  30. <div className='grow flex items-center justify-end'>
  31. {
  32. info && (
  33. <div className='mr-2 text-xs text-gray-500 truncate' title={info}>{info}</div>
  34. )
  35. }
  36. <Switch
  37. size='l'
  38. defaultValue={config.enabled}
  39. onChange={v => handleConfigChange('enabled', v)}
  40. />
  41. </div>
  42. </div>
  43. {
  44. config.enabled && showPreset && (
  45. <div className='px-3 pt-1 pb-3 bg-white rounded-lg'>
  46. <div className='flex items-center justify-between h-8 text-[13px] font-medium text-gray-700'>
  47. {t('appDebug.feature.moderation.modal.content.preset')}
  48. <span className='text-xs font-normal text-gray-500'>{t('appDebug.feature.moderation.modal.content.supportMarkdown')}</span>
  49. </div>
  50. <div className='relative px-3 py-2 h-20 rounded-lg bg-gray-100'>
  51. <textarea
  52. value={config.preset_response || ''}
  53. className='block w-full h-full bg-transparent text-sm outline-none appearance-none resize-none'
  54. placeholder={t('appDebug.feature.moderation.modal.content.placeholder') || ''}
  55. onChange={e => handleConfigChange('preset_response', e.target.value)}
  56. />
  57. <div className='absolute bottom-2 right-2 flex items-center px-1 h-5 rounded-md bg-gray-50 text-xs font-medium text-gray-300'>
  58. <span>{(config.preset_response || '').length}</span>/<span className='text-gray-500'>100</span>
  59. </div>
  60. </div>
  61. </div>
  62. )
  63. }
  64. </div>
  65. </div>
  66. )
  67. }
  68. export default ModerationContent