Phase 4: Páginas Dashboard
- Layout completo com Brand Descomplicar: * Header: logo dourado, sticky, shadow-sm * Footer: copyright Descomplicar® * Fonts: Inter (body), Montserrat (display) * Metadata PT-PT - DashboardView component (client): * Fetch sites via /api/sites * Site selector dropdown * Fetch metrics via /api/metrics/[siteId]?period=30d * 4 KPI cards: visitors, sessions, engagement, pageViews * Chart área: tráfego diário (30d) * Chart pie: fontes de tráfego (top 10) * Tabela: Top 20 queries GSC (clicks, impressions, CTR, position) * Loading states em todos componentes * Error handling com mensagens PT-PT * Responsive: mobile/tablet/desktop - Home page: render DashboardView Features: - Auto-select primeiro site na lista - Comparação período anterior (% change) - Formatação PT-PT (números, datas, percentagens) - Brand colors (#cc8d00, #27a50e) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,34 +1,67 @@
|
||||
import type { Metadata } from "next";
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
import type { Metadata } from 'next'
|
||||
import { Inter, Montserrat } from 'next/font/google'
|
||||
import './globals.css'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
const inter = Inter({
|
||||
subsets: ['latin'],
|
||||
variable: '--font-sans',
|
||||
display: 'swap',
|
||||
})
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
const montserrat = Montserrat({
|
||||
subsets: ['latin'],
|
||||
variable: '--font-display',
|
||||
display: 'swap',
|
||||
})
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create Next App",
|
||||
description: "Generated by create next app",
|
||||
};
|
||||
title: 'BI Descomplicar® | Painéis de Métricas',
|
||||
description: 'Dashboards de performance digital para clientes Descomplicar - Agência de Aceleração Digital',
|
||||
icons: {
|
||||
icon: '/favicon.ico',
|
||||
},
|
||||
}
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
children: React.ReactNode
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body
|
||||
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
|
||||
>
|
||||
<html lang="pt">
|
||||
<body className={cn(
|
||||
inter.variable,
|
||||
montserrat.variable,
|
||||
'font-sans antialiased bg-gray-50'
|
||||
)}>
|
||||
<div className="min-h-screen flex flex-col">
|
||||
<header className="bg-white border-b border-gray-200 sticky top-0 z-50 shadow-sm">
|
||||
<div className="container mx-auto px-md py-md">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<h1 className="text-2xl font-display font-bold text-brand-dourado">
|
||||
BI Descomplicar®
|
||||
</h1>
|
||||
<p className="text-sm text-gray-600 mt-0.5">
|
||||
Painéis de Performance Digital
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main className="flex-1">
|
||||
{children}
|
||||
</main>
|
||||
|
||||
<footer className="bg-white border-t border-gray-200 py-sm">
|
||||
<div className="container mx-auto px-md text-center text-sm text-gray-500">
|
||||
© {new Date().getFullYear()} Descomplicar® - Agência de Aceleração Digital
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,65 +1,5 @@
|
||||
import Image from "next/image";
|
||||
import { DashboardView } from '@/components/dashboard/dashboard-view'
|
||||
|
||||
export default function Home() {
|
||||
return (
|
||||
<div className="flex min-h-screen items-center justify-center bg-zinc-50 font-sans dark:bg-black">
|
||||
<main className="flex min-h-screen w-full max-w-3xl flex-col items-center justify-between py-32 px-16 bg-white dark:bg-black sm:items-start">
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/next.svg"
|
||||
alt="Next.js logo"
|
||||
width={100}
|
||||
height={20}
|
||||
priority
|
||||
/>
|
||||
<div className="flex flex-col items-center gap-6 text-center sm:items-start sm:text-left">
|
||||
<h1 className="max-w-xs text-3xl font-semibold leading-10 tracking-tight text-black dark:text-zinc-50">
|
||||
To get started, edit the page.tsx file.
|
||||
</h1>
|
||||
<p className="max-w-md text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
||||
Looking for a starting point or more instructions? Head over to{" "}
|
||||
<a
|
||||
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Templates
|
||||
</a>{" "}
|
||||
or the{" "}
|
||||
<a
|
||||
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
className="font-medium text-zinc-950 dark:text-zinc-50"
|
||||
>
|
||||
Learning
|
||||
</a>{" "}
|
||||
center.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-4 text-base font-medium sm:flex-row">
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-foreground px-5 text-background transition-colors hover:bg-[#383838] dark:hover:bg-[#ccc] md:w-[158px]"
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
<Image
|
||||
className="dark:invert"
|
||||
src="/vercel.svg"
|
||||
alt="Vercel logomark"
|
||||
width={16}
|
||||
height={16}
|
||||
/>
|
||||
Deploy Now
|
||||
</a>
|
||||
<a
|
||||
className="flex h-12 w-full items-center justify-center rounded-full border border-solid border-black/[.08] px-5 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-[158px]"
|
||||
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Documentation
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
return <DashboardView />
|
||||
}
|
||||
|
||||
279
src/components/dashboard/dashboard-view.tsx
Normal file
279
src/components/dashboard/dashboard-view.tsx
Normal file
@@ -0,0 +1,279 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { MetricCard } from './metric-card'
|
||||
import { ChartCard } from './chart-card'
|
||||
import { SiteSelector } from './site-selector'
|
||||
import { Users, MousePointerClick, TrendingUp, Eye } from 'lucide-react'
|
||||
import { formatNumber, formatPercent } from '@/lib/utils'
|
||||
|
||||
interface Site {
|
||||
id: number
|
||||
siteName: string
|
||||
}
|
||||
|
||||
interface Metrics {
|
||||
visitors: number
|
||||
visitorsChange: number
|
||||
sessions: number
|
||||
sessionsChange: number
|
||||
pageViews: number
|
||||
pageViewsChange: number
|
||||
newUsers: number
|
||||
newUsersChange: number
|
||||
engagement: number
|
||||
}
|
||||
|
||||
interface Charts {
|
||||
dailyTraffic: Array<{
|
||||
date: string
|
||||
visitors: number
|
||||
sessions: number
|
||||
}>
|
||||
trafficSources: Array<{
|
||||
source: string
|
||||
medium: string
|
||||
sessions: number
|
||||
}>
|
||||
topQueries: Array<{
|
||||
query: string
|
||||
clicks: number
|
||||
impressions: number
|
||||
ctr: number
|
||||
position: number
|
||||
}>
|
||||
}
|
||||
|
||||
interface MetricsData {
|
||||
success: boolean
|
||||
site: {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
metrics: Metrics
|
||||
charts: Charts
|
||||
}
|
||||
|
||||
export function DashboardView() {
|
||||
const [sites, setSites] = useState<Site[]>([])
|
||||
const [selectedSite, setSelectedSite] = useState<number | null>(null)
|
||||
const [metricsData, setMetricsData] = useState<MetricsData | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
// Fetch sites on mount
|
||||
useEffect(() => {
|
||||
const fetchSites = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/sites')
|
||||
const data = await response.json()
|
||||
|
||||
if (data.success && data.sites.length > 0) {
|
||||
setSites(data.sites)
|
||||
setSelectedSite(data.sites[0].id)
|
||||
} else {
|
||||
setError('Nenhum site disponível')
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Erro ao carregar sites')
|
||||
console.error('Error fetching sites:', err)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
fetchSites()
|
||||
}, [])
|
||||
|
||||
// Fetch metrics when site changes
|
||||
useEffect(() => {
|
||||
if (!selectedSite) return
|
||||
|
||||
const fetchMetrics = async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const response = await fetch(`/api/metrics/${selectedSite}?period=30d`)
|
||||
const data = await response.json()
|
||||
|
||||
if (data.success) {
|
||||
setMetricsData(data)
|
||||
setError(null)
|
||||
} else {
|
||||
setError(data.error || 'Erro ao carregar métricas')
|
||||
}
|
||||
} catch (err) {
|
||||
setError('Erro ao carregar métricas')
|
||||
console.error('Error fetching metrics:', err)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
fetchMetrics()
|
||||
}, [selectedSite])
|
||||
|
||||
if (error && !selectedSite) {
|
||||
return (
|
||||
<div className="container mx-auto px-md py-lg">
|
||||
<div className="bg-red-50 border border-red-200 rounded-lg p-lg text-center">
|
||||
<p className="text-red-600 font-medium">{error}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="container mx-auto px-md py-lg">
|
||||
<div className="space-y-lg">
|
||||
{/* Header with Site Selector */}
|
||||
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-md">
|
||||
<div>
|
||||
<h2 className="text-xl font-semibold text-gray-900">
|
||||
Desempenho Digital
|
||||
</h2>
|
||||
<p className="text-sm text-gray-500 mt-1">
|
||||
Últimos 30 dias
|
||||
</p>
|
||||
</div>
|
||||
<SiteSelector
|
||||
sites={sites}
|
||||
selectedSite={selectedSite}
|
||||
onSiteChange={setSelectedSite}
|
||||
loading={loading && sites.length === 0}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{error && selectedSite && (
|
||||
<div className="bg-yellow-50 border border-yellow-200 rounded-lg p-md">
|
||||
<p className="text-yellow-800 text-sm">{error}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* KPIs Grid */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-md">
|
||||
<MetricCard
|
||||
title="Visitantes Únicos"
|
||||
value={metricsData?.metrics.visitors || 0}
|
||||
change={metricsData?.metrics.visitorsChange}
|
||||
icon={Users}
|
||||
loading={loading}
|
||||
/>
|
||||
<MetricCard
|
||||
title="Sessões Totais"
|
||||
value={metricsData?.metrics.sessions || 0}
|
||||
change={metricsData?.metrics.sessionsChange}
|
||||
icon={MousePointerClick}
|
||||
loading={loading}
|
||||
/>
|
||||
<MetricCard
|
||||
title="Taxa Engagement"
|
||||
value={formatPercent(metricsData?.metrics.engagement || 0)}
|
||||
icon={TrendingUp}
|
||||
loading={loading}
|
||||
/>
|
||||
<MetricCard
|
||||
title="Page Views"
|
||||
value={metricsData?.metrics.pageViews || 0}
|
||||
change={metricsData?.metrics.pageViewsChange}
|
||||
icon={Eye}
|
||||
loading={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Charts Grid */}
|
||||
<div className="grid grid-cols-1 lg:grid-cols-3 gap-md">
|
||||
<div className="lg:col-span-2">
|
||||
<ChartCard
|
||||
title="Tráfego Diário"
|
||||
description="Visitantes e sessões nos últimos 30 dias"
|
||||
data={metricsData?.charts.dailyTraffic.map(d => ({
|
||||
name: new Date(d.date).toLocaleDateString('pt-PT', {
|
||||
day: '2-digit',
|
||||
month: 'short'
|
||||
}),
|
||||
Visitantes: d.visitors,
|
||||
Sessões: d.sessions,
|
||||
})) || []}
|
||||
type="area"
|
||||
dataKey="Visitantes"
|
||||
xAxisKey="name"
|
||||
loading={loading}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<ChartCard
|
||||
title="Fontes de Tráfego"
|
||||
description="Top 10 fontes por sessões"
|
||||
data={metricsData?.charts.trafficSources.map(s => ({
|
||||
name: `${s.source} / ${s.medium}`,
|
||||
value: s.sessions,
|
||||
})) || []}
|
||||
type="pie"
|
||||
dataKey="value"
|
||||
loading={loading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Top Queries Table */}
|
||||
{metricsData?.charts.topQueries && metricsData.charts.topQueries.length > 0 && (
|
||||
<div className="bg-white rounded-lg border border-gray-200 shadow-sm overflow-hidden">
|
||||
<div className="px-lg py-md border-b border-gray-200">
|
||||
<h3 className="text-lg font-semibold text-gray-900">
|
||||
Top Queries de Pesquisa
|
||||
</h3>
|
||||
<p className="text-sm text-gray-500 mt-1">
|
||||
Dados Google Search Console
|
||||
</p>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full">
|
||||
<thead className="bg-gray-50">
|
||||
<tr>
|
||||
<th className="px-lg py-sm text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Query
|
||||
</th>
|
||||
<th className="px-lg py-sm text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Clicks
|
||||
</th>
|
||||
<th className="px-lg py-sm text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Impressões
|
||||
</th>
|
||||
<th className="px-lg py-sm text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
CTR
|
||||
</th>
|
||||
<th className="px-lg py-sm text-right text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Posição
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="bg-white divide-y divide-gray-200">
|
||||
{metricsData.charts.topQueries.slice(0, 10).map((query, index) => (
|
||||
<tr key={index} className="hover:bg-gray-50">
|
||||
<td className="px-lg py-sm text-sm text-gray-900">
|
||||
{query.query}
|
||||
</td>
|
||||
<td className="px-lg py-sm text-sm text-gray-900 text-right">
|
||||
{formatNumber(query.clicks)}
|
||||
</td>
|
||||
<td className="px-lg py-sm text-sm text-gray-900 text-right">
|
||||
{formatNumber(query.impressions)}
|
||||
</td>
|
||||
<td className="px-lg py-sm text-sm text-gray-900 text-right">
|
||||
{formatPercent(query.ctr)}
|
||||
</td>
|
||||
<td className="px-lg py-sm text-sm text-gray-900 text-right">
|
||||
{query.position.toFixed(1)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user