feat: CMS com limites de caracteres, traduções auto e painel de notificações
This commit is contained in:
@@ -3,23 +3,29 @@ import { useState, useEffect } from 'react';
|
||||
interface PageContentData {
|
||||
id: string;
|
||||
slug: string;
|
||||
locale: string;
|
||||
content: any;
|
||||
updatedAt: string;
|
||||
fallback?: boolean; // true se retornou versão PT por falta da traduzida
|
||||
}
|
||||
|
||||
export function usePageContent(slug: string) {
|
||||
export function usePageContent(slug: string, locale: string = 'pt') {
|
||||
const [content, setContent] = useState<any>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isFallback, setIsFallback] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchContent = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const response = await fetch(`/api/pages/${slug}`);
|
||||
// Busca com locale para pegar versão já traduzida do banco
|
||||
const response = await fetch(`/api/pages/${slug}?locale=${locale}`);
|
||||
|
||||
if (response.ok) {
|
||||
const data: PageContentData = await response.json();
|
||||
setContent(data.content);
|
||||
setIsFallback(data.fallback || false);
|
||||
} else if (response.status === 404) {
|
||||
// Página ainda não foi configurada no admin
|
||||
setContent(null);
|
||||
@@ -34,7 +40,7 @@ export function usePageContent(slug: string) {
|
||||
};
|
||||
|
||||
fetchContent();
|
||||
}, [slug]);
|
||||
}, [slug, locale]);
|
||||
|
||||
return { content, loading, error };
|
||||
return { content, loading, error, isFallback };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user