import { useState, useEffect } from "react"; import { Settings as SettingsIcon, Bell, Key, Shield, Cloud, Brain } from "lucide-react"; import { useQuery, useMutation } from "@tanstack/react-query"; import Sidebar from "@/components/sidebar"; import TopBar from "@/components/topbar"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Button } from "@/components/ui/button"; import { useToast } from "@/hooks/use-toast"; import { apiRequest, queryClient } from "@/lib/queryClient"; import { ModelCombobox } from "@/components/model-combobox"; export default function Settings() { const [sidebarOpen, setSidebarOpen] = useState(false); const [notifications, setNotifications] = useState(true); const [autoPublish, setAutoPublish] = useState(true); const [cloudName, setCloudName] = useState(""); const [apiKey, setApiKey] = useState(""); const [apiSecret, setApiSecret] = useState(""); const [openrouterApiKey, setOpenrouterApiKey] = useState(""); const [openrouterModel, setOpenrouterModel] = useState("anthropic/claude-3.5-sonnet"); const [openrouterSystemPrompt, setOpenrouterSystemPrompt] = useState("Tu es un expert en marketing des réseaux sociaux. Génère 3 variations de textes engageants pour des publications Facebook et Instagram à partir des informations produit fournies. Chaque variation doit être unique, captivante et optimisée pour l'engagement."); const { toast } = useToast(); const { data: cloudinaryConfig } = useQuery({ queryKey: ['/api/cloudinary/config'], }); const { data: openrouterConfig } = useQuery({ queryKey: ['/api/openrouter/config'], }); const { data: openrouterModels, isLoading: modelsLoading } = useQuery({ queryKey: ['/api/openrouter/models'], }); useEffect(() => { if (cloudinaryConfig) { setCloudName((cloudinaryConfig as any).cloudName || ""); setApiKey((cloudinaryConfig as any).apiKey || ""); } }, [cloudinaryConfig]); useEffect(() => { if (openrouterConfig) { setOpenrouterModel((openrouterConfig as any).model || "anthropic/claude-3.5-sonnet"); setOpenrouterSystemPrompt((openrouterConfig as any).systemPrompt || "Tu es un expert en marketing des réseaux sociaux. Génère 3 variations de textes engageants pour des publications Facebook et Instagram à partir des informations produit fournies. Chaque variation doit être unique, captivante et optimisée pour l'engagement."); } }, [openrouterConfig]); // Vérifier si une config OpenRouter existe déjà const hasExistingConfig = !!openrouterConfig; const saveCloudinaryMutation = useMutation({ mutationFn: () => { const payload: any = { cloudName, }; // N'inclure apiKey et apiSecret que s'ils ne sont pas vides if (apiKey && apiKey.trim() !== "") { payload.apiKey = apiKey; } if (apiSecret && apiSecret.trim() !== "") { payload.apiSecret = apiSecret; } return apiRequest('POST', '/api/cloudinary/config', payload); }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['/api/cloudinary/config'] }); toast({ title: "Configuration sauvegardée", description: "Vos paramètres Cloudinary ont été enregistrés", }); setApiKey(""); // Clear the API key after saving setApiSecret(""); // Clear the secret after saving }, onError: () => { toast({ title: "Erreur", description: "Impossible de sauvegarder la configuration", variant: "destructive", }); }, }); const saveOpenrouterMutation = useMutation({ mutationFn: () => { const payload: any = { model: openrouterModel, systemPrompt: openrouterSystemPrompt, }; // N'inclure apiKey que s'il n'est pas vide if (openrouterApiKey && openrouterApiKey.trim() !== "") { payload.apiKey = openrouterApiKey; } return apiRequest('POST', '/api/openrouter/config', payload); }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['/api/openrouter/config'] }); toast({ title: "Configuration sauvegardée", description: "Vos paramètres OpenRouter ont été enregistrés", }); setOpenrouterApiKey(""); // Clear the API key after saving }, onError: () => { toast({ title: "Erreur", description: "Impossible de sauvegarder la configuration OpenRouter", variant: "destructive", }); }, }); return (
{sidebarOpen && (
setSidebarOpen(false)} /> )}
setSidebarOpen(false)} />
setSidebarOpen(!sidebarOpen)} />

Paramètres

Configurez votre application

Notifications Gérez vos préférences de notification

Recevez des notifications pour les publications

Publier automatiquement à l'heure programmée

Configuration OpenRouter (IA) Configurez OpenRouter pour la génération de texte avec l'IA
setOpenrouterApiKey(e.target.value)} placeholder={hasExistingConfig ? "••••••••••••••••" : "sk-or-v1-..."} data-testid="input-openrouter-api-key" />

{hasExistingConfig ? ( <> ✓ Clé API configurée - Laissez vide pour garder la clé actuelle ) : ( <> Obtenez votre clé API sur{" "} openrouter.ai )}

Choisissez le modèle d'IA pour générer vos publications