feat: merge Context page into Glossaries — single page for glossary + system prompt + presets
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 1m30s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 1m30s
- Add system prompt textarea and professional presets (HVAC, IT, Legal, etc.) to Glossaries page - Remove Context from sidebar navigation (constants.ts) - Make GlossarySelector always visible for Pro users (not just LLM mode) - Send system prompt from Zustand store to backend via custom_prompt - Add 24 new i18n keys across all 13 locales for glossaries page Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ export interface NavItem {
|
||||
export const baseNavItems: NavItem[] = [
|
||||
{ labelKey: 'dashboard.nav.translate', href: '/dashboard/translate', icon: FileText },
|
||||
{ labelKey: 'dashboard.nav.profile', href: '/dashboard/profile', icon: User },
|
||||
{ labelKey: 'dashboard.nav.context', href: '/dashboard/context', icon: Globe, proOnly: true },
|
||||
{ labelKey: 'dashboard.nav.glossaries', href: '/dashboard/glossaries', icon: BookText, proOnly: true },
|
||||
{ labelKey: 'dashboard.nav.apiKeys', href: '/dashboard/api-keys', icon: Key, proOnly: true },
|
||||
];
|
||||
|
||||
|
||||
@@ -1,18 +1,34 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { BookText, Plus, Library, Calendar, Hash } from 'lucide-react';
|
||||
import { useState, useEffect } from 'react';
|
||||
import {
|
||||
BookText, Plus, Library, Calendar, Hash,
|
||||
Zap, Save, Trash2, MessageSquare, Loader2,
|
||||
Wrench, HardHat, Monitor, Scale, Stethoscope, BarChart3,
|
||||
Megaphone, Car,
|
||||
} from 'lucide-react';
|
||||
import { useUser } from '@/app/dashboard/useUser';
|
||||
import { useI18n, formatDate } from '@/lib/i18n';
|
||||
import { useI18n } from '@/lib/i18n';
|
||||
import { useGlossaries, useGlossary } from './useGlossaries';
|
||||
import type { Glossary, GlossaryTermInput, GlossaryListItem } from './types';
|
||||
import { ProUpgradePrompt } from './ProUpgradePrompt';
|
||||
import { GlossaryCard } from './GlossaryCard';
|
||||
import { CreateGlossaryDialog } from './CreateGlossaryDialog';
|
||||
import { EditGlossaryDialog } from './EditGlossaryDialog';
|
||||
import { DeleteGlossaryDialog } from './DeleteGlossaryDialog';
|
||||
import { useToast } from '@/components/ui/toast';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { useTranslationStore } from '@/lib/store';
|
||||
import { API_BASE } from '@/lib/config';
|
||||
|
||||
const PRESETS = [
|
||||
{ key: 'hvac', title: 'HVAC / Génie climatique', desc: 'Thermique, ventilation, climatisation', icon: Wrench, templateId: 'hvac' },
|
||||
{ key: 'construction', title: 'BTP / Construction', desc: 'Gros œuvre, second œuvre, normes', icon: HardHat, templateId: 'construction' },
|
||||
{ key: 'it', title: 'IT / Logiciel', desc: 'Développement, infrastructure, DevOps', icon: Monitor, templateId: 'technology' },
|
||||
{ key: 'legal', title: 'Juridique / Contrats', desc: 'Droit des affaires, contentieux', icon: Scale, templateId: 'legal' },
|
||||
{ key: 'medical', title: 'Médical / Santé', desc: 'Pharmacologie, chirurgie, diagnostic', icon: Stethoscope, templateId: 'medical' },
|
||||
{ key: 'finance', title: 'Finance / Comptabilité', desc: 'IFRS, bilans, fiscalité', icon: BarChart3, templateId: 'finance' },
|
||||
{ key: 'marketing', title: 'Marketing / Publicité', desc: 'Digital, branding, analytics', icon: Megaphone, templateId: 'marketing' },
|
||||
{ key: 'automotive', title: 'Automobile', desc: 'Motorisation, ADAS, homologation', icon: Car, templateId: 'automotive' },
|
||||
];
|
||||
|
||||
export default function GlossariesPage() {
|
||||
const { t } = useI18n();
|
||||
@@ -31,6 +47,7 @@ export default function GlossariesPage() {
|
||||
importTemplate,
|
||||
} = useGlossaries();
|
||||
const { toast } = useToast();
|
||||
const { settings, updateSettings } = useTranslationStore();
|
||||
|
||||
const [createDialogOpen, setCreateDialogOpen] = useState(false);
|
||||
const [editDialogOpen, setEditDialogOpen] = useState(false);
|
||||
@@ -38,6 +55,9 @@ export default function GlossariesPage() {
|
||||
const [selectedGlossary, setSelectedGlossary] = useState<GlossaryListItem | null>(null);
|
||||
const [glossaryToEdit, setGlossaryToEdit] = useState<Glossary | null>(null);
|
||||
const [glossaryToDelete, setGlossaryToDelete] = useState<{ id: string; name: string } | null>(null);
|
||||
const [systemPrompt, setSystemPrompt] = useState(settings.systemPrompt);
|
||||
const [isSavingPrompt, setIsSavingPrompt] = useState(false);
|
||||
const [creatingPreset, setCreatingPreset] = useState<string | null>(null);
|
||||
|
||||
const { glossary: fullGlossary, isLoading: isLoadingGlossaryDetail } = useGlossary(
|
||||
selectedGlossary?.id || null
|
||||
@@ -46,6 +66,58 @@ export default function GlossariesPage() {
|
||||
const isPro = user?.tier === 'pro';
|
||||
const isLoading = isLoadingUser || isLoadingGlossaries;
|
||||
|
||||
useEffect(() => {
|
||||
setSystemPrompt(settings.systemPrompt);
|
||||
}, [settings]);
|
||||
|
||||
const handleSavePrompt = async () => {
|
||||
setIsSavingPrompt(true);
|
||||
try {
|
||||
updateSettings({ systemPrompt });
|
||||
await new Promise(resolve => setTimeout(resolve, 300));
|
||||
toast({ title: t('context.saved'), description: t('context.savedDesc') });
|
||||
} finally { setIsSavingPrompt(false); }
|
||||
};
|
||||
|
||||
const handleClearPrompt = () => {
|
||||
updateSettings({ systemPrompt: '' });
|
||||
setSystemPrompt('');
|
||||
};
|
||||
|
||||
const handleCreatePresetGlossary = async (preset: typeof PRESETS[0]) => {
|
||||
setCreatingPreset(preset.key);
|
||||
try {
|
||||
const token = localStorage.getItem('token');
|
||||
if (!token) return;
|
||||
const headers: Record<string, string> = {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`,
|
||||
};
|
||||
const params = new URLSearchParams({ template_id: preset.templateId });
|
||||
const res = await fetch(`${API_BASE}/api/v1/glossaries/import?${params.toString()}`, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
});
|
||||
if (res.ok) {
|
||||
const result = await res.json();
|
||||
const glossary = result.data;
|
||||
toast({
|
||||
title: t('context.presets.created'),
|
||||
description: t('context.presets.createdDesc', {
|
||||
name: glossary?.name ?? preset.title,
|
||||
count: String(glossary?.terms?.length ?? 0),
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
toast({ variant: 'destructive', title: t('glossaries.toast.error'), description: t('glossaries.toast.errorCreate') });
|
||||
}
|
||||
} catch {
|
||||
toast({ variant: 'destructive', title: t('glossaries.toast.error'), description: t('glossaries.toast.errorImport') });
|
||||
} finally {
|
||||
setCreatingPreset(null);
|
||||
}
|
||||
};
|
||||
|
||||
const handleEditClick = (id: string) => {
|
||||
const glossary = glossaries.find((g: GlossaryListItem) => g.id === id);
|
||||
if (glossary) {
|
||||
@@ -171,7 +243,81 @@ export default function GlossariesPage() {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* ── Glossary Grid ──────────────────────────────────────── */}
|
||||
<div className="space-y-12">
|
||||
{/* ── System Prompt ────────────────────────────────────── */}
|
||||
<section className="editorial-card p-10 lg:p-12 bg-white dark:bg-[#141414] border-none shadow-editorial">
|
||||
<div className="flex items-center gap-4 mb-8 text-brand-accent">
|
||||
<MessageSquare size={20} />
|
||||
<h3 className="text-[11px] font-black uppercase tracking-[0.3em] text-brand-dark dark:text-white">
|
||||
{t('context.instructions.title')}
|
||||
</h3>
|
||||
</div>
|
||||
<p className="text-sm text-brand-dark/40 dark:text-white/40 mb-10 font-medium">{t('context.instructions.desc')}</p>
|
||||
<textarea
|
||||
value={systemPrompt}
|
||||
onChange={e => setSystemPrompt(e.target.value)}
|
||||
placeholder={t('context.instructions.placeholder')}
|
||||
className="w-full h-48 p-8 bg-brand-muted dark:bg-white/5 rounded-[32px] border border-black/5 dark:border-white/10 text-sm focus:ring-2 focus:ring-brand-accent/20 focus:border-brand-accent/30 transition-all outline-none resize-y"
|
||||
/>
|
||||
<div className="flex justify-end mt-6 gap-4">
|
||||
<button
|
||||
onClick={handleClearPrompt}
|
||||
className="px-8 py-3 bg-brand-muted dark:bg-white/5 text-brand-dark/40 dark:text-white/40 rounded-xl text-[9px] font-black uppercase tracking-widest hover:text-brand-dark dark:hover:text-white transition-all"
|
||||
>
|
||||
<Trash2 size={12} className="inline mr-2" />{t('context.clearAll')}
|
||||
</button>
|
||||
<button
|
||||
onClick={handleSavePrompt}
|
||||
disabled={isSavingPrompt}
|
||||
className="premium-button px-10 py-3 text-[9px] uppercase tracking-widest !rounded-xl flex items-center gap-3 disabled:opacity-50"
|
||||
>
|
||||
{isSavingPrompt ? <Loader2 size={14} className="animate-spin" /> : <Save size={14} />}
|
||||
{isSavingPrompt ? t('context.saving') : t('context.save')}
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* ── Professional Presets ─────────────────────────────── */}
|
||||
<section className="editorial-card p-10 lg:p-12 bg-white dark:bg-[#141414] border-none shadow-editorial">
|
||||
<div className="flex items-center gap-4 mb-8 text-brand-accent">
|
||||
<Zap size={20} />
|
||||
<h3 className="text-[11px] font-black uppercase tracking-[0.3em] text-brand-dark dark:text-white">
|
||||
{t('context.presets.title')}
|
||||
</h3>
|
||||
</div>
|
||||
<p className="text-sm text-brand-dark/40 dark:text-white/40 mb-12 font-medium">{t('context.presets.desc')}</p>
|
||||
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-6">
|
||||
{PRESETS.map((p) => {
|
||||
const Icon = p.icon;
|
||||
const isCreating = creatingPreset === p.key;
|
||||
return (
|
||||
<button
|
||||
key={p.key}
|
||||
onClick={() => handleCreatePresetGlossary(p)}
|
||||
disabled={!!creatingPreset}
|
||||
className="p-6 bg-brand-muted dark:bg-white/5 hover:bg-brand-dark dark:hover:bg-brand-dark group transition-all rounded-[32px] text-center border border-black/5 dark:border-white/10 hover:shadow-2xl hover:-translate-y-1 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<div className="flex justify-center mb-4 text-brand-dark group-hover:text-brand-accent group-hover:scale-125 transition-all">
|
||||
{isCreating ? <Loader2 size={24} className="animate-spin" /> : <Icon size={24} />}
|
||||
</div>
|
||||
<h4 className="text-[11px] font-black uppercase tracking-tight text-brand-dark dark:text-white group-hover:text-white mb-2">
|
||||
{p.title}
|
||||
</h4>
|
||||
<p className="text-[8px] text-brand-dark/30 dark:text-white/30 group-hover:text-white/40 font-bold uppercase tracking-widest leading-relaxed">
|
||||
{p.desc}
|
||||
</p>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<p className="mt-8 text-[9px] text-brand-dark/20 dark:text-white/20 font-black uppercase tracking-widest italic border-t border-black/5 dark:border-white/5 pt-6">
|
||||
{t('context.presets.hint')}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{/* ── Glossary Grid ──────────────────────────────────────── */}
|
||||
{glossaries.length === 0 ? (
|
||||
<div className="editorial-card p-16 bg-white dark:bg-[#141414] border-none shadow-editorial text-center">
|
||||
<div className="w-16 h-16 bg-brand-muted dark:bg-white/10 rounded-2xl flex items-center justify-center text-brand-accent mx-auto mb-6">
|
||||
@@ -224,7 +370,7 @@ export default function GlossariesPage() {
|
||||
)}
|
||||
|
||||
{/* ── About section ──────────────────────────────────────── */}
|
||||
<div className="editorial-card p-10 lg:p-12 bg-white dark:bg-[#141414] border-none shadow-editorial mt-12">
|
||||
<div className="editorial-card p-10 lg:p-12 bg-white dark:bg-[#141414] border-none shadow-editorial">
|
||||
<div className="flex items-center gap-4 text-brand-accent mb-8">
|
||||
<BookText size={20} />
|
||||
<span className="text-[11px] font-black uppercase tracking-[0.3em] text-brand-dark dark:text-white">
|
||||
@@ -236,6 +382,7 @@ export default function GlossariesPage() {
|
||||
{t('glossaries.aboutFormat')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Dialogs */}
|
||||
<CreateGlossaryDialog
|
||||
|
||||
@@ -402,7 +402,7 @@ export default function TranslatePage() {
|
||||
isPro={config.isPro}
|
||||
/>
|
||||
|
||||
{config.isPro && config.mode === 'llm' && (
|
||||
{config.isPro && (
|
||||
<GlossarySelector
|
||||
glossaryId={config.glossaryId}
|
||||
onChange={config.setGlossaryId}
|
||||
|
||||
@@ -147,6 +147,11 @@ export function useTranslationSubmit(): UseTranslationSubmitReturn {
|
||||
if (config.glossaryId) {
|
||||
formData.append('glossary_id', config.glossaryId);
|
||||
}
|
||||
// System prompt from Context page (Pro only)
|
||||
const { settings } = await import('@/lib/store').then(m => m.useTranslationStore.getState());
|
||||
if (settings.systemPrompt?.trim()) {
|
||||
formData.append('custom_prompt', settings.systemPrompt.trim());
|
||||
}
|
||||
|
||||
const token = localStorage.getItem('token');
|
||||
const headers: Record<string, string> = {};
|
||||
|
||||
Reference in New Issue
Block a user