feat(F-096): completed feature

This commit is contained in:
chattie
2026-08-20 22:12:01 +02:00
parent 4b60db026b
commit 5561776627
14 changed files with 298 additions and 67 deletions

View File

@@ -8,6 +8,7 @@ const TABS = [
{ id: 'general', label: 'General', icon: '⚙️' },
{ id: 'social', label: 'Redes sociales', icon: '🌐' },
{ id: 'footer', label: 'Footer', icon: '📄' },
{ id: 'ai', label: 'IA para SEO', icon: '✨' },
] as const;
type TabId = (typeof TABS)[number]['id'];
@@ -31,7 +32,8 @@ export default function SettingsPage() {
if (!form) return;
setSaving(true); setErr(''); setMsg('');
try {
const updated = await settingsApi.update(form);
const { aiApiKey, ...settingsWithoutKey } = form;
const updated = await settingsApi.update(aiApiKey ? form : settingsWithoutKey);
setData(updated); setForm(updated);
setMsg('Cambios guardados correctamente');
setTimeout(() => setMsg(''), 4000);
@@ -42,7 +44,7 @@ export default function SettingsPage() {
}
};
const field = (key: keyof FormData, label: string, opts?: { type?: string; placeholder?: string; rows?: number; hint?: string }) => (
const field = (key: Exclude<keyof FormData, 'aiApiKeyConfigured'>, label: string, opts?: { type?: string; placeholder?: string; rows?: number; hint?: string }) => (
<div key={key}>
<label className="block text-sm font-medium text-gray-700 mb-1">{label}</label>
{opts?.rows ? (
@@ -129,6 +131,23 @@ export default function SettingsPage() {
</>
)}
{tab === 'ai' && (
<>
<div className="px-6 py-4 bg-gray-50 border-b border-gray-200">
<h2 className="text-base font-semibold text-gray-800">Modelo de IA para SEO</h2>
<p className="text-xs text-gray-400 mt-0.5">Se usa solo para completar campos SEO que estén vacíos.</p>
</div>
<div className="p-6 space-y-5">
{field('aiProvider', 'Proveedor', { placeholder: 'OpenAI compatible' })}
{field('aiBaseUrl', 'URL base de la API', { type: 'url', placeholder: 'https://api.openai.com/v1' })}
{field('aiModel', 'Modelo', { placeholder: 'gpt-4o-mini' })}
{field('aiApiKey', 'API key', { type: 'password', placeholder: form?.aiApiKeyConfigured ? 'API key configurada (escribe para reemplazar)' : 'sk-...' })}
{field('aiSeoTitlePrompt', 'Prompt para Título SEO', { rows: 4, hint: 'Usa {{name}}, {{description}} y {{brand}} como variables.' })}
{field('aiSeoDescriptionPrompt', 'Prompt para Descripción SEO (Google)', { rows: 5, hint: 'Usa {{name}}, {{description}} y {{brand}} como variables.' })}
</div>
</>
)}
{tab === 'footer' && (
<>
<div className="px-6 py-4 bg-gray-50 border-b border-gray-200">

View File

@@ -152,13 +152,22 @@ export function ProductEditor({ productId }: ProductEditorProps) {
featured,
attributes,
state,
seoTitle: seoTitle || undefined,
seoDescription: seoDesc || undefined,
seoTitle: seoTitle.trim() || null,
seoDescription: seoDesc.trim() || null,
expirationDate: expirationDate || undefined,
};
let saved: Product;
if (isCreate) saved = await productsApi.create(payload);
else saved = await productsApi.update(productId, payload);
if (!seoTitle.trim() || !seoDesc.trim()) {
try {
saved = await productsApi.generateSeo(saved.id);
setSeoTitle(saved.seoTitle ?? '');
setSeoDesc(saved.seoDescription ?? '');
} catch (generationError) {
setError(generationError instanceof Error ? generationError.message : 'No se pudieron generar los campos SEO');
}
}
snapRef.current = getSnap();
dirtyRef.current = false;
setSuccess(isCreate ? '¡Producto creado!' : 'Cambios guardados');

View File

@@ -80,6 +80,8 @@ export const productsApi = {
create: (data: unknown) => api.post<import('@/types').Product>('/api/products', data),
update: (id: string, data: unknown) =>
api.patch<import('@/types').Product>(`/api/products/${id}`, data),
generateSeo: (id: string) =>
api.post<import('@/types').Product>(`/api/products/${id}/generate-seo`),
setState: (id: string, state: 'active' | 'archived') =>
api.patch(`/api/products/${id}/state`, { state }),
delete: (id: string) => api.delete(`/api/products/${id}`),
@@ -325,6 +327,13 @@ export interface StoreSettings {
footerText: string;
facebookUrl: string;
instagramUrl: string;
aiProvider: string;
aiBaseUrl: string;
aiModel: string;
aiApiKey: string;
aiApiKeyConfigured?: boolean;
aiSeoTitlePrompt: string;
aiSeoDescriptionPrompt: string;
}
export const settingsApi = {