This commit is contained in:
NotII
2025-04-08 01:54:20 +01:00
parent c85af30518
commit 2011a33c4d
6 changed files with 121 additions and 72 deletions

View File

@@ -1,17 +1,11 @@
import { getPlatformStatsServer } from "@/lib/api"; import { getPlatformStatsServer } from "@/lib/server-api";
import { HomeNavbar } from "@/components/home-navbar"; import { HomeNavbar } from "@/components/home-navbar";
import { Suspense } from "react"; import { Suspense } from "react";
import { Shield, LineChart, Zap } from "lucide-react"; import { Shield, LineChart, Zap } from "lucide-react";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import Link from "next/link"; import Link from "next/link";
import HeroSection from "@/components/3d/HeroSection"; import HeroSection from "@/components/3d/HeroSection";
import dynamic from 'next/dynamic'; import { AnimatedStatsSection } from "@/components/animated-stats-section";
// Dynamically import the 3D stats component to avoid SSR issues
const StatsSection = dynamic(() => import('@/components/3d/StatsSection'), {
ssr: false,
loading: () => <div className="h-40 w-full bg-gray-900 animate-pulse rounded-lg"></div>
});
// Constants // Constants
const PY_20 = 20; const PY_20 = 20;
@@ -49,9 +43,7 @@ export default async function Home() {
<section className="py-16 px-6 md:px-10 bg-black"> <section className="py-16 px-6 md:px-10 bg-black">
<div className="max-w-6xl mx-auto"> <div className="max-w-6xl mx-auto">
<h2 className="text-3xl md:text-4xl font-bold text-center mb-10 text-white">Platform Statistics</h2> <h2 className="text-3xl md:text-4xl font-bold text-center mb-10 text-white">Platform Statistics</h2>
<Suspense fallback={<div className="h-40 w-full bg-gray-900 animate-pulse rounded-lg"></div>}> <AnimatedStatsSection stats={stats} />
<StatsSection stats={stats} />
</Suspense>
</div> </div>
</section> </section>

View File

@@ -0,0 +1,32 @@
"use client";
import { Suspense, useEffect } from 'react';
import dynamic from 'next/dynamic';
// Dynamically import the 3D stats component
const StatsSection = dynamic(() => import('./StatsSection'), {
ssr: false,
loading: () => <div className="h-40 w-full bg-gray-900 animate-pulse rounded-lg"></div>
});
export default function ClientStatsWrapper({ stats }: { stats: any }) {
// Debug the stats to see what's being passed
useEffect(() => {
console.log('Stats data received in client component:', stats);
}, [stats]);
// Apply defaults if stats is undefined
const safeStats = stats || {
totalProducts: 0,
totalVendors: 0,
totalOrders: 0,
totalCustomers: 0,
gmv: 0
};
return (
<Suspense fallback={<div className="h-40 w-full bg-gray-900 animate-pulse rounded-lg"></div>}>
<StatsSection stats={safeStats} />
</Suspense>
);
}

View File

@@ -1,6 +1,6 @@
"use client"; "use client";
import { useState, useRef, useEffect } from 'react'; import { useState, useRef } from 'react';
import { motion, useMotionValue, useSpring, useTransform } from 'framer-motion'; import { motion, useMotionValue, useSpring, useTransform } from 'framer-motion';
interface StatCardProps { interface StatCardProps {
@@ -11,8 +11,7 @@ interface StatCardProps {
export default function StatCard({ title, value, className = "" }: StatCardProps) { export default function StatCard({ title, value, className = "" }: StatCardProps) {
const cardRef = useRef<HTMLDivElement>(null); const cardRef = useRef<HTMLDivElement>(null);
const [rotateX, setRotateX] = useState(0); const [isHovered, setIsHovered] = useState(false);
const [rotateY, setRotateY] = useState(0);
const x = useMotionValue(0); const x = useMotionValue(0);
const y = useMotionValue(0); const y = useMotionValue(0);
@@ -22,8 +21,8 @@ export default function StatCard({ title, value, className = "" }: StatCardProps
const springY = useSpring(y, { stiffness: 150, damping: 20 }); const springY = useSpring(y, { stiffness: 150, damping: 20 });
// Transform mouse movement to rotation values // Transform mouse movement to rotation values
const rotateXOutput = useTransform(springY, [-0.5, 0.5], ["10deg", "-10deg"]); const rotateXOutput = useTransform(springY, [-0.5, 0.5], ["7deg", "-7deg"]);
const rotateYOutput = useTransform(springX, [-0.5, 0.5], ["-10deg", "10deg"]); const rotateYOutput = useTransform(springX, [-0.5, 0.5], ["-7deg", "7deg"]);
const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => { const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
if (!cardRef.current) return; if (!cardRef.current) return;
@@ -39,17 +38,23 @@ export default function StatCard({ title, value, className = "" }: StatCardProps
y.set(mouseY - 0.5); y.set(mouseY - 0.5);
}; };
const handleMouseEnter = () => {
setIsHovered(true);
};
const handleMouseLeave = () => { const handleMouseLeave = () => {
// Reset to neutral position when mouse leaves // Reset to neutral position when mouse leaves
x.set(0); x.set(0);
y.set(0); y.set(0);
setIsHovered(false);
}; };
return ( return (
<motion.div <motion.div
ref={cardRef} ref={cardRef}
className={`relative overflow-hidden rounded-xl p-8 bg-gradient-to-br from-gray-800 to-gray-900 backdrop-blur-sm border border-gray-700/50 shadow-xl flex flex-col justify-center ${className}`} className={`relative overflow-hidden rounded-xl p-6 sm:p-8 bg-gradient-to-br from-gray-800/90 to-gray-900/90 border border-gray-700/50 shadow-lg flex flex-col justify-center group ${className}`}
onMouseMove={handleMouseMove} onMouseMove={handleMouseMove}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
style={{ style={{
rotateX: rotateXOutput, rotateX: rotateXOutput,
@@ -60,16 +65,21 @@ export default function StatCard({ title, value, className = "" }: StatCardProps
transition={{ duration: 0.2 }} transition={{ duration: 0.2 }}
> >
{/* Ambient light reflection */} {/* Ambient light reflection */}
<div className="absolute inset-0 w-full h-full bg-gradient-to-tr from-pink-500/10 to-purple-500/5 opacity-0 group-hover:opacity-100 transition-opacity duration-300" /> <div
className={`absolute inset-0 w-full h-full bg-gradient-to-tr from-pink-500/10 to-purple-500/5 transition-opacity duration-300 ${isHovered ? 'opacity-100' : 'opacity-0'}`}
/>
{/* Main content with 3D effect */}
<div style={{ transform: "translateZ(20px)" }} className="relative z-10"> <div style={{ transform: "translateZ(20px)" }} className="relative z-10">
<p className="text-gray-400 text-sm mb-1 font-medium">{title}</p> <p className="text-gray-400 text-xs sm:text-sm mb-1 font-medium">{title}</p>
<p className="text-3xl md:text-4xl font-bold text-white">{value}</p> <p className="text-2xl sm:text-3xl md:text-4xl font-bold text-white">{value}</p>
</div> </div>
{/* Shiny edge */} {/* Shiny shimmer effect */}
<div className="absolute inset-0 rounded-xl overflow-hidden"> <div className="absolute inset-0 rounded-xl overflow-hidden">
<div className="absolute inset-0 bg-gradient-to-r from-transparent via-pink-500/10 to-transparent opacity-0 group-hover:opacity-100 animate-shimmer" /> <div
className={`absolute inset-0 w-[200%] bg-gradient-to-r from-transparent via-pink-500/20 to-transparent -translate-x-[100%] animate-shimmer transition-opacity duration-300 ${isHovered ? 'opacity-100' : 'opacity-0'}`}
/>
</div> </div>
</motion.div> </motion.div>
); );

View File

@@ -1,6 +1,6 @@
"use client"; "use client";
import React from 'react'; import React, { useEffect } from 'react';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import StatCard from './StatCard'; import StatCard from './StatCard';
@@ -27,7 +27,15 @@ function formatCurrencyValue(amount: number = 0): string {
} }
export default function StatsSection({ stats }: StatsProps) { export default function StatsSection({ stats }: StatsProps) {
const { totalProducts = 0, totalVendors = 0, totalOrders = 0, totalCustomers = 0, gmv = 0 } = stats; useEffect(() => {
console.log('StatsSection rendering with data:', stats);
}, [stats]);
const totalProducts = stats?.totalProducts ?? 243;
const totalVendors = stats?.totalVendors ?? 15;
const totalOrders = stats?.totalOrders ?? 1289;
const totalCustomers = stats?.totalCustomers ?? 756;
const gmv = stats?.gmv ?? 38450;
// Container animation variants // Container animation variants
const containerVariants = { const containerVariants = {
@@ -63,20 +71,36 @@ export default function StatsSection({ stats }: StatsProps) {
animate="visible" animate="visible"
style={{ perspective: "1000px" }} style={{ perspective: "1000px" }}
> >
<motion.div variants={itemVariants}> <motion.div variants={itemVariants} className="group">
<StatCard title="Total Products" value={formatNumberValue(totalProducts)} className="h-32" /> <StatCard
title="Total Products"
value={formatNumberValue(totalProducts)}
className="h-32 group-hover:shadow-[0_0_30px_rgba(213,63,140,0.3)] transition-all duration-300"
/>
</motion.div> </motion.div>
<motion.div variants={itemVariants}> <motion.div variants={itemVariants} className="group">
<StatCard title="Total Vendors" value={formatNumberValue(totalVendors)} className="h-32" /> <StatCard
title="Total Vendors"
value={formatNumberValue(totalVendors)}
className="h-32 group-hover:shadow-[0_0_30px_rgba(213,63,140,0.3)] transition-all duration-300"
/>
</motion.div> </motion.div>
<motion.div variants={itemVariants}> <motion.div variants={itemVariants} className="group">
<StatCard title="Total Orders" value={formatNumberValue(totalOrders)} className="h-32" /> <StatCard
title="Total Orders"
value={formatNumberValue(totalOrders)}
className="h-32 group-hover:shadow-[0_0_30px_rgba(213,63,140,0.3)] transition-all duration-300"
/>
</motion.div> </motion.div>
<motion.div variants={itemVariants} className="sm:col-span-2 lg:col-span-1"> <motion.div variants={itemVariants} className="sm:col-span-2 lg:col-span-1 group">
<StatCard title="Revenue" value={formatCurrencyValue(gmv)} className="h-32 bg-gradient-to-br from-pink-900/40 to-gray-900 border-pink-800/30" /> <StatCard
title="Revenue"
value={formatCurrencyValue(gmv)}
className="h-32 bg-gradient-to-br from-pink-900/40 to-gray-900 border-pink-800/30 group-hover:shadow-[0_0_30px_rgba(213,63,140,0.4)] transition-all duration-300"
/>
</motion.div> </motion.div>
</motion.div> </motion.div>
</div> </div>

View File

@@ -54,6 +54,14 @@ export {
type PlatformStats, type PlatformStats,
} from './services/stats-service'; } from './services/stats-service';
// Re-export server API functions
export {
fetchServer,
getCustomersServer,
getCustomerDetailsServer,
getPlatformStatsServer
} from './server-api';
// Get clientFetch first so we can use it in the compatibility functions // Get clientFetch first so we can use it in the compatibility functions
import { clientFetch } from './api-client'; import { clientFetch } from './api-client';
import { getProductDetails, updateProduct } from './services/product-service'; import { getProductDetails, updateProduct } from './services/product-service';
@@ -97,40 +105,3 @@ export const fetchPlatformStats = async () => {
console.warn('fetchPlatformStats is deprecated, use getPlatformStats instead'); console.warn('fetchPlatformStats is deprecated, use getPlatformStats instead');
return getPlatformStats(); return getPlatformStats();
}; };
// Server API functions are conditionally exported
// They are only usable in Server Components in the app/ directory
// Dynamically check if we can use server components
let canUseServerComponents = false;
try {
// Check if next/headers is available
require('next/headers');
canUseServerComponents = true;
} catch (e) {
// We're not in a Server Component context
// This is normal in Client Components and pages/ directory
}
// Handle server API functions
// Define function types first for TypeScript
type ServerFetchFn = <T>(url: string, options?: RequestInit) => Promise<T>;
type CustomerServerFn = (options?: any) => Promise<any>;
type CustomerDetailServerFn = (id: string, options?: any) => Promise<any>;
type PlatformStatsServerFn = () => Promise<any>;
// Export the functions for use in server components
export const fetchServer: ServerFetchFn = canUseServerComponents
? require('./server-api').fetchServer
: (() => { throw new Error('fetchServer can only be used in Server Components'); }) as any;
export const getCustomersServer: CustomerServerFn = canUseServerComponents
? require('./server-api').getCustomersServer
: (() => { throw new Error('getCustomersServer can only be used in Server Components'); }) as any;
export const getCustomerDetailsServer: CustomerDetailServerFn = canUseServerComponents
? require('./server-api').getCustomerDetailsServer
: (() => { throw new Error('getCustomerDetailsServer can only be used in Server Components'); }) as any;
export const getPlatformStatsServer: PlatformStatsServerFn = canUseServerComponents
? require('./server-api').getPlatformStatsServer
: (() => { throw new Error('getPlatformStatsServer can only be used in Server Components'); }) as any;

View File

@@ -49,7 +49,7 @@ export async function fetchServer<T = unknown>(
} }
// Get auth token from cookies // Get auth token from cookies
const cookieStore = await cookiesModule.cookies(); const cookieStore = await cookiesModule.cookies();
const authToken = cookieStore.get('Authorization')?.value; const authToken = cookieStore.get('Authorization')?.value;
// Redirect to login if not authenticated // Redirect to login if not authenticated
@@ -116,7 +116,27 @@ export const getCustomerDetailsServer = async (userId: string): Promise<Customer
// Server-side platform stats function // Server-side platform stats function
export async function getPlatformStatsServer(): Promise<any> { export async function getPlatformStatsServer(): Promise<any> {
try { try {
return fetchServer('/stats/platform'); // Try to fetch from server first
const serverData = await fetchServer('/stats/platform')
.catch(e => {
console.warn('Could not fetch real stats from API:', e);
return null;
});
// If we have real data, use it
if (serverData && Object.keys(serverData).length > 0) {
return serverData;
}
// If API call failed or returned empty data, use sample data
console.info('Using sample stats data for demo');
return {
totalProducts: 243,
totalVendors: 15,
totalOrders: 1289,
totalCustomers: 756,
gmv: 38450
};
} catch (error) { } catch (error) {
console.error('Error fetching platform stats (server):', error); console.error('Error fetching platform stats (server):', error);
// Return default stats to prevent UI breakage // Return default stats to prevent UI breakage