citation.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React, { useCallback } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import produce from 'immer'
  4. import { Citations } from '@/app/components/base/icons/src/vender/features'
  5. import FeatureCard from '@/app/components/base/features/new-feature-panel/feature-card'
  6. import { useFeatures, useFeaturesStore } from '@/app/components/base/features/hooks'
  7. import type { OnFeaturesChange } from '@/app/components/base/features/types'
  8. import { FeatureEnum } from '@/app/components/base/features/types'
  9. type Props = {
  10. disabled?: boolean
  11. onChange?: OnFeaturesChange
  12. }
  13. const Citation = ({
  14. disabled,
  15. onChange,
  16. }: Props) => {
  17. const { t } = useTranslation()
  18. const features = useFeatures(s => s.features)
  19. const featuresStore = useFeaturesStore()
  20. const handleChange = useCallback((type: FeatureEnum, enabled: boolean) => {
  21. const {
  22. features,
  23. setFeatures,
  24. } = featuresStore!.getState()
  25. const newFeatures = produce(features, (draft) => {
  26. draft[type] = {
  27. ...draft[type],
  28. enabled,
  29. }
  30. })
  31. setFeatures(newFeatures)
  32. if (onChange)
  33. onChange(newFeatures)
  34. }, [featuresStore, onChange])
  35. return (
  36. <FeatureCard
  37. icon={
  38. <div className='shrink-0 p-1 rounded-lg border-[0.5px] border-divider-subtle shadow-xs bg-util-colors-warning-warning-500'>
  39. <Citations className='w-4 h-4 text-text-primary-on-surface' />
  40. </div>
  41. }
  42. title={t('appDebug.feature.citation.title')}
  43. value={!!features.citation?.enabled}
  44. description={t('appDebug.feature.citation.description')!}
  45. onChange={state => handleChange(FeatureEnum.citation, state)}
  46. disabled={disabled}
  47. />
  48. )
  49. }
  50. export default Citation