SettingsDrawer.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React from 'react';
  2. import ConfigPanel from './ConfigPanel';
  3. import { AppSettings, ModelConfig } from '../types';
  4. import { X } from 'lucide-react';
  5. import { useLanguage } from '../contexts/LanguageContext';
  6. interface SettingsDrawerProps {
  7. isOpen: boolean;
  8. onClose: () => void;
  9. settings: AppSettings;
  10. models: ModelConfig[];
  11. onSettingsChange: (newSettings: AppSettings) => void;
  12. onOpenSettings: () => void; // Keeps the "Full Settings" link working if needed, or we might redirect
  13. mode?: 'chat' | 'kb' | 'all';
  14. isAdmin?: boolean;
  15. }
  16. export const SettingsDrawer: React.FC<SettingsDrawerProps> = ({
  17. isOpen,
  18. onClose,
  19. settings,
  20. models,
  21. onSettingsChange,
  22. onOpenSettings,
  23. mode = 'all',
  24. isAdmin = false
  25. }) => {
  26. const { t } = useLanguage();
  27. const [localSettings, setLocalSettings] = React.useState<AppSettings>(settings);
  28. // Initial sync
  29. React.useEffect(() => {
  30. if (isOpen) {
  31. setLocalSettings(settings);
  32. }
  33. }, [isOpen, settings]);
  34. if (!isOpen) return null;
  35. const handleLocalChange = (newSettings: AppSettings) => {
  36. setLocalSettings(newSettings);
  37. };
  38. const handleConfirm = () => {
  39. onSettingsChange(localSettings);
  40. onClose();
  41. };
  42. return (
  43. <div className="fixed inset-0 z-50 overflow-hidden">
  44. <div className="absolute inset-0 bg-black bg-opacity-30 transition-opacity" onClick={onClose} />
  45. <div className="absolute inset-y-0 right-0 max-w-md w-full flex">
  46. <div className="flex-1 flex flex-col bg-white shadow-xl animate-in slide-in-from-right duration-300">
  47. <div className="flex items-center justify-between px-4 py-3 border-b border-gray-200">
  48. <h2 className="text-lg font-medium text-gray-900">{t('systemConfiguration')}</h2>
  49. <button
  50. onClick={onClose}
  51. className="text-gray-400 hover:text-gray-500 focus:outline-none"
  52. >
  53. <X size={24} />
  54. </button>
  55. </div>
  56. <div className="flex-1 overflow-y-auto">
  57. <ConfigPanel
  58. settings={localSettings}
  59. models={models}
  60. onSettingsChange={handleLocalChange}
  61. onOpenSettings={onOpenSettings}
  62. mode={mode}
  63. isAdmin={isAdmin}
  64. />
  65. </div>
  66. <div className="p-4 border-t border-gray-200 bg-gray-50">
  67. <button
  68. onClick={handleConfirm}
  69. className="w-full py-2.5 bg-blue-600 text-white font-medium rounded-xl hover:bg-blue-700 transition-colors shadow-sm"
  70. >
  71. {t('confirm')}
  72. </button>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. );
  78. };