diff --git a/src/app/(dashboard)/page.tsx b/src/app/(dashboard)/page.tsx
index ae5c46c..d590cdc 100644
--- a/src/app/(dashboard)/page.tsx
+++ b/src/app/(dashboard)/page.tsx
@@ -23,6 +23,8 @@ interface LastSync {
interface DashboardStats {
products: ProductStats
lastSync: LastSync | null
+ sheetDrift: boolean
+ sheetModifiedAt: string | null
}
function StatCard({
@@ -134,6 +136,22 @@ export default function DashboardPage() {
+ {/* ── Alerte drift Sheets ───────────────────────────────── */}
+ {!statsLoading && stats?.sheetDrift && (
+
+
⚠️
+
+
Google Sheets modifié depuis la dernière sync
+
+ {stats.sheetModifiedAt
+ ? `Dernière modification : ${formatDate(stats.sheetModifiedAt)}`
+ : 'Des changements sont peut-être en attente de synchronisation'}
+
+
+
Lancer la sync →
+
+ )}
+
{/* ── KPIs ─────────────────────────────────────────────── */}
Vue d'ensemble
diff --git a/src/app/api/dashboard/stats/route.ts b/src/app/api/dashboard/stats/route.ts
index 1f583a1..10a1dd1 100644
--- a/src/app/api/dashboard/stats/route.ts
+++ b/src/app/api/dashboard/stats/route.ts
@@ -43,18 +43,36 @@ async function fetchProductsLight(status: 'active' | 'draft'): Promise {
+ const apiKey = process.env.GOOGLE_API_KEY
+ const sheetId = process.env.GOOGLE_SHEETS_ID
+ if (!apiKey || !sheetId) return null
+ try {
+ const res = await fetch(
+ `https://www.googleapis.com/drive/v3/files/${sheetId}?fields=modifiedTime&key=${apiKey}`,
+ { cache: 'no-store' },
+ )
+ if (!res.ok) return null
+ const data = await res.json()
+ return (data.modifiedTime as string) ?? null
+ } catch {
+ return null
+ }
+}
+
export async function GET() {
const session = await getServerSession(authOptions)
if (!session) return NextResponse.json({ error: 'Non authentifié' }, { status: 401 })
try {
- const [activeProducts, draftProducts, lastSyncRun] = await Promise.all([
+ const [activeProducts, draftProducts, lastSyncRun, sheetModifiedTime] = await Promise.all([
fetchProductsLight('active'),
fetchProductsLight('draft'),
prisma.syncRun.findFirst({
orderBy: { createdAt: 'desc' },
include: { user: { select: { name: true } } },
}),
+ fetchSheetModifiedTime(),
])
const allProducts = [...activeProducts, ...draftProducts]
@@ -72,6 +90,12 @@ export async function GET() {
}
: null
+ // Drift : Sheets modifié après la dernière sync réussie
+ const sheetDrift =
+ sheetModifiedTime !== null &&
+ lastSyncRun !== null &&
+ new Date(sheetModifiedTime) > lastSyncRun.createdAt
+
return NextResponse.json({
products: {
active: activeProducts.length,
@@ -80,6 +104,8 @@ export async function GET() {
withoutImages,
},
lastSync,
+ sheetDrift,
+ sheetModifiedAt: sheetModifiedTime,
})
} catch (err) {
const message = err instanceof Error ? err.message : 'Erreur inconnue'