201 lines
7.5 KiB
TypeScript
201 lines
7.5 KiB
TypeScript
import React, { useState, useEffect } from 'react';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogFooter,
|
|
} from "@/components/ui/dialog"
|
|
import {
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from "@/components/ui/select"
|
|
import { CheckCircle2, Cpu, Globe, Link as LinkIcon } from 'lucide-react';
|
|
|
|
export default function SettingsModal({ onClose }: { onClose: () => void }) {
|
|
const [formData, setFormData] = useState({
|
|
notionToken: '',
|
|
notionDbId: '',
|
|
ollamaUrl: '',
|
|
ollamaModel: '',
|
|
searxngUrl: '',
|
|
aiLanguage: 'Français'
|
|
});
|
|
const [saved, setSaved] = useState(false);
|
|
|
|
useEffect(() => {
|
|
fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/settings`, {
|
|
credentials: 'include'
|
|
})
|
|
.then(res => res.json())
|
|
.then(data => {
|
|
if (data) {
|
|
setFormData({
|
|
notionToken: data.notionToken || '',
|
|
notionDbId: data.notionDbId || '',
|
|
ollamaUrl: data.ollamaUrl || '',
|
|
ollamaModel: data.ollamaModel || '',
|
|
searxngUrl: data.searxngUrl || '',
|
|
aiLanguage: data.aiLanguage || 'Français'
|
|
});
|
|
}
|
|
})
|
|
.catch(console.error);
|
|
}, []);
|
|
|
|
const handleSubmit = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
try {
|
|
await fetch(`${import.meta.env.VITE_API_URL || 'http://localhost:3001'}/api/settings`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
credentials: 'include',
|
|
body: JSON.stringify(formData)
|
|
});
|
|
setSaved(true);
|
|
setTimeout(() => setSaved(false), 3000);
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog open={true} onOpenChange={onClose}>
|
|
<DialogContent className="sm:max-w-[600px] max-h-[90vh] overflow-hidden flex flex-col p-0">
|
|
<DialogHeader className="p-6 pb-2 border-b">
|
|
<DialogTitle className="text-2xl font-bold tracking-tight">Paramètres Globaux</DialogTitle>
|
|
<DialogDescription>
|
|
Configurez vos intégrations Notion, Ollama et SearXNG pour personnaliser votre expérience LogAI.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<div className="flex-1 overflow-y-auto p-6 pt-2 space-y-8 scrollbar-thin">
|
|
{/* Notion Integration */}
|
|
<section className="space-y-4">
|
|
<div className="flex items-center gap-2 text-primary font-semibold">
|
|
<LinkIcon size={18} />
|
|
<h4>Intégration Notion</h4>
|
|
</div>
|
|
<div className="grid gap-4 bg-muted/30 p-4 rounded-xl border">
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="notionToken">Token d'intégration (Internal App)</Label>
|
|
<Input
|
|
id="notionToken"
|
|
type="password"
|
|
value={formData.notionToken}
|
|
onChange={e => setFormData({...formData, notionToken: e.target.value})}
|
|
placeholder="secret_..."
|
|
/>
|
|
</div>
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="notionDbId">ID de la base de données</Label>
|
|
<Input
|
|
id="notionDbId"
|
|
type="text"
|
|
value={formData.notionDbId}
|
|
onChange={e => setFormData({...formData, notionDbId: e.target.value})}
|
|
placeholder="ex: a1b2c3d4e5f6..."
|
|
/>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
{/* AI Integration */}
|
|
<section className="space-y-4">
|
|
<div className="flex items-center gap-2 text-secondary font-semibold">
|
|
<Cpu size={18} />
|
|
<h4>Intégration IA (Ollama Local)</h4>
|
|
</div>
|
|
<div className="grid gap-4 bg-secondary/5 p-4 rounded-xl border border-secondary/20">
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="ollamaUrl">URL de l'API Ollama</Label>
|
|
<Input
|
|
id="ollamaUrl"
|
|
type="text"
|
|
value={formData.ollamaUrl}
|
|
onChange={e => setFormData({...formData, ollamaUrl: e.target.value})}
|
|
placeholder="ex: http://localhost:11434"
|
|
/>
|
|
</div>
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="ollamaModel">Nom du modèle</Label>
|
|
<Input
|
|
id="ollamaModel"
|
|
type="text"
|
|
value={formData.ollamaModel}
|
|
onChange={e => setFormData({...formData, ollamaModel: e.target.value})}
|
|
placeholder="ex: qwen:7b, llama3"
|
|
/>
|
|
</div>
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="language">Langue de sortie</Label>
|
|
<Select
|
|
value={formData.aiLanguage}
|
|
onValueChange={(val) => setFormData({...formData, aiLanguage: val})}
|
|
>
|
|
<SelectTrigger id="language">
|
|
<SelectValue placeholder="Choisir une langue" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
<SelectItem value="Français">Français</SelectItem>
|
|
<SelectItem value="English">English</SelectItem>
|
|
<SelectItem value="Español">Español</SelectItem>
|
|
<SelectItem value="Deutsch">Deutsch</SelectItem>
|
|
<SelectItem value="Italiano">Italiano</SelectItem>
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
{/* Search Integration */}
|
|
<section className="space-y-4">
|
|
<div className="flex items-center gap-2 text-amber-500 font-semibold">
|
|
<Globe size={18} />
|
|
<h4>Recherche Web (SearXNG)</h4>
|
|
</div>
|
|
<div className="grid gap-4 bg-amber-500/5 p-4 rounded-xl border border-amber-500/20">
|
|
<div className="grid gap-2">
|
|
<Label htmlFor="searxngUrl">URL de SearXNG (enrichissement IA)</Label>
|
|
<Input
|
|
id="searxngUrl"
|
|
type="text"
|
|
value={formData.searxngUrl}
|
|
onChange={e => setFormData({...formData, searxngUrl: e.target.value})}
|
|
placeholder="ex: http://localhost:8080"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
|
|
<DialogFooter className="p-6 border-t bg-muted/10">
|
|
<div className="flex items-center justify-between w-full">
|
|
<div className="flex items-center gap-2">
|
|
{saved && (
|
|
<div className="flex items-center gap-1.5 text-green-500 animate-in fade-in slide-in-from-left-1">
|
|
<CheckCircle2 size={16} />
|
|
<span className="text-sm font-medium">Sauvegardé avec succès</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
<div className="flex gap-2">
|
|
<Button variant="ghost" onClick={onClose}>Fermer</Button>
|
|
<Button onClick={handleSubmit}>Enregistrer les modifications</Button>
|
|
</div>
|
|
</div>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|