feat: Implement QR code analytics dashboard with summary, charts, and geo-mapping, alongside new signup, marketing, and QR creation pages.

This commit is contained in:
Timo 2026-01-07 15:34:21 +01:00
parent b2d83a0cd6
commit 509e5a51a7
16 changed files with 13289 additions and 13289 deletions

19612
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,86 +1,86 @@
{ {
"name": "qr-master", "name": "qr-master",
"version": "1.0.0", "version": "1.0.0",
"description": "Create custom QR codes in seconds", "description": "Create custom QR codes in seconds",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 3050", "dev": "next dev -p 3050",
"build": "prisma generate && next build", "build": "prisma generate && next build",
"start": "next start", "start": "next start",
"lint": "next lint", "lint": "next lint",
"db:generate": "prisma generate", "db:generate": "prisma generate",
"db:migrate": "prisma migrate dev", "db:migrate": "prisma migrate dev",
"db:deploy": "prisma migrate deploy", "db:deploy": "prisma migrate deploy",
"db:seed": "tsx prisma/seed.ts", "db:seed": "tsx prisma/seed.ts",
"db:studio": "prisma studio", "db:studio": "prisma studio",
"postinstall": "prisma generate", "postinstall": "prisma generate",
"docker:dev": "docker compose -f docker-compose.dev.yml up -d", "docker:dev": "docker compose -f docker-compose.dev.yml up -d",
"docker:dev:stop": "docker compose -f docker-compose.dev.yml down", "docker:dev:stop": "docker compose -f docker-compose.dev.yml down",
"docker:dev:clean": "docker compose -f docker-compose.dev.yml down --remove-orphans && docker container prune -f", "docker:dev:clean": "docker compose -f docker-compose.dev.yml down --remove-orphans && docker container prune -f",
"docker:prod": "docker compose up -d --build", "docker:prod": "docker compose up -d --build",
"docker:stop": "docker compose down", "docker:stop": "docker compose down",
"docker:logs": "docker compose logs -f", "docker:logs": "docker compose logs -f",
"docker:db": "docker compose exec db psql -U postgres -d qrmaster", "docker:db": "docker compose exec db psql -U postgres -d qrmaster",
"docker:redis": "docker compose exec redis redis-cli", "docker:redis": "docker compose exec redis redis-cli",
"docker:backup": "docker compose exec db pg_dump -U postgres qrmaster > backup_$(date +%Y%m%d).sql" "docker:backup": "docker compose exec db pg_dump -U postgres qrmaster > backup_$(date +%Y%m%d).sql"
}, },
"dependencies": { "dependencies": {
"@auth/prisma-adapter": "^2.11.1", "@auth/prisma-adapter": "^2.11.1",
"@edge-runtime/cookies": "^6.0.0", "@edge-runtime/cookies": "^6.0.0",
"@prisma/client": "^5.7.0", "@prisma/client": "^5.7.0",
"@stripe/stripe-js": "^8.0.0", "@stripe/stripe-js": "^8.0.0",
"@types/d3-scale": "^4.0.9", "@types/d3-scale": "^4.0.9",
"bcryptjs": "^2.4.3", "bcryptjs": "^2.4.3",
"chart.js": "^4.4.0", "chart.js": "^4.4.0",
"clsx": "^2.0.0", "clsx": "^2.0.0",
"d3-scale": "^4.0.2", "d3-scale": "^4.0.2",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"exceljs": "^4.4.0", "exceljs": "^4.4.0",
"file-saver": "^2.0.5", "file-saver": "^2.0.5",
"i18next": "^23.7.6", "i18next": "^23.7.6",
"ioredis": "^5.3.2", "ioredis": "^5.3.2",
"jszip": "^3.10.1", "jszip": "^3.10.1",
"lucide-react": "^0.562.0", "lucide-react": "^0.562.0",
"next": "^14.2.35", "next": "^14.2.35",
"next-auth": "^4.24.5", "next-auth": "^4.24.5",
"papaparse": "^5.4.1", "papaparse": "^5.4.1",
"posthog-js": "^1.276.0", "posthog-js": "^1.276.0",
"qr-code-styling": "^1.9.2", "qr-code-styling": "^1.9.2",
"qrcode": "^1.5.3", "qrcode": "^1.5.3",
"qrcode.react": "^3.1.0", "qrcode.react": "^3.1.0",
"react": "^18.2.0", "react": "^18.2.0",
"react-chartjs-2": "^5.2.0", "react-chartjs-2": "^5.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-dropzone": "^14.2.3", "react-dropzone": "^14.2.3",
"react-i18next": "^13.5.0", "react-i18next": "^13.5.0",
"react-simple-maps": "^3.0.0", "react-simple-maps": "^3.0.0",
"resend": "^6.4.2", "resend": "^6.4.2",
"sharp": "^0.33.1", "sharp": "^0.33.1",
"stripe": "^19.1.0", "stripe": "^19.1.0",
"tailwind-merge": "^2.2.0", "tailwind-merge": "^2.2.0",
"uuid": "^13.0.0", "uuid": "^13.0.0",
"zod": "^3.25.76" "zod": "^3.25.76"
}, },
"devDependencies": { "devDependencies": {
"@types/bcryptjs": "^2.4.6", "@types/bcryptjs": "^2.4.6",
"@types/file-saver": "^2.0.7", "@types/file-saver": "^2.0.7",
"@types/node": "^20.10.5", "@types/node": "^20.10.5",
"@types/papaparse": "^5.3.14", "@types/papaparse": "^5.3.14",
"@types/qrcode": "^1.5.5", "@types/qrcode": "^1.5.5",
"@types/react": "^18.2.45", "@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18", "@types/react-dom": "^18.2.18",
"autoprefixer": "^10.4.16", "autoprefixer": "^10.4.16",
"eslint": "^8.56.0", "eslint": "^8.56.0",
"eslint-config-next": "^16.1.1", "eslint-config-next": "^16.1.1",
"next-sitemap": "^4.2.3", "next-sitemap": "^4.2.3",
"postcss": "^8.4.32", "postcss": "^8.4.32",
"prettier": "^3.1.1", "prettier": "^3.1.1",
"prisma": "^5.7.0", "prisma": "^5.7.0",
"tailwindcss": "^3.3.6", "tailwindcss": "^3.3.6",
"tsx": "^4.7.0", "tsx": "^4.7.0",
"typescript": "^5.3.3" "typescript": "^5.3.3"
}, },
"engines": { "engines": {
"node": ">=18.0.0" "node": ">=18.0.0"
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,254 +1,254 @@
'use client'; 'use client';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import Link from 'next/link'; import Link from 'next/link';
import { usePathname, useRouter } from 'next/navigation'; import { usePathname, useRouter } from 'next/navigation';
import { Button } from '@/components/ui/Button'; import { Button } from '@/components/ui/Button';
import { Dropdown, DropdownItem } from '@/components/ui/Dropdown'; import { Dropdown, DropdownItem } from '@/components/ui/Dropdown';
import { Footer } from '@/components/ui/Footer'; import { Footer } from '@/components/ui/Footer';
import { useTranslation } from '@/hooks/useTranslation'; import { useTranslation } from '@/hooks/useTranslation';
interface User { interface User {
id: string; id: string;
name: string | null; name: string | null;
email: string; email: string;
plan: string | null; plan: string | null;
} }
export default function AppLayout({ export default function AppLayout({
children, children,
}: { }: {
children: React.ReactNode; children: React.ReactNode;
}) { }) {
const pathname = usePathname(); const pathname = usePathname();
const router = useRouter(); const router = useRouter();
const { t } = useTranslation(); const { t } = useTranslation();
const [sidebarOpen, setSidebarOpen] = useState(false); const [sidebarOpen, setSidebarOpen] = useState(false);
const [user, setUser] = useState<User | null>(null); const [user, setUser] = useState<User | null>(null);
// Fetch user data on mount // Fetch user data on mount
useEffect(() => { useEffect(() => {
const fetchUser = async () => { const fetchUser = async () => {
try { try {
const response = await fetch('/api/user'); const response = await fetch('/api/user');
if (response.ok) { if (response.ok) {
const userData = await response.json(); const userData = await response.json();
setUser(userData); setUser(userData);
} }
} catch (error) { } catch (error) {
console.error('Error fetching user:', error); console.error('Error fetching user:', error);
} }
}; };
fetchUser(); fetchUser();
}, []); }, []);
const handleSignOut = async () => { const handleSignOut = async () => {
// Track logout event before clearing data // Track logout event before clearing data
try { try {
const { trackEvent, resetUser } = await import('@/components/PostHogProvider'); const { trackEvent, resetUser } = await import('@/components/PostHogProvider');
trackEvent('user_logout'); trackEvent('user_logout');
resetUser(); // Reset PostHog user session resetUser(); // Reset PostHog user session
} catch (error) { } catch (error) {
console.error('PostHog tracking error:', error); console.error('PostHog tracking error:', error);
} }
// Clear all cookies // Clear all cookies
document.cookie.split(";").forEach(c => { document.cookie.split(";").forEach(c => {
document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/");
}); });
// Clear localStorage // Clear localStorage
localStorage.clear(); localStorage.clear();
// Redirect to home // Redirect to home
router.push('/'); router.push('/');
}; };
// Get user initials for avatar (e.g., "Timo Schmidt" -> "TS") // Get user initials for avatar (e.g., "Timo Schmidt" -> "TS")
const getUserInitials = () => { const getUserInitials = () => {
if (!user) return 'U'; if (!user) return 'U';
if (user.name) { if (user.name) {
const names = user.name.trim().split(' '); const names = user.name.trim().split(' ');
if (names.length >= 2) { if (names.length >= 2) {
return (names[0][0] + names[names.length - 1][0]).toUpperCase(); return (names[0][0] + names[names.length - 1][0]).toUpperCase();
} }
return user.name.substring(0, 2).toUpperCase(); return user.name.substring(0, 2).toUpperCase();
} }
// Fallback to email // Fallback to email
return user.email.substring(0, 1).toUpperCase(); return user.email.substring(0, 1).toUpperCase();
}; };
// Get display name (first name or full name) // Get display name (first name or full name)
const getDisplayName = () => { const getDisplayName = () => {
if (!user) return 'User'; if (!user) return 'User';
if (user.name) { if (user.name) {
return user.name; return user.name;
} }
// Fallback to email without domain // Fallback to email without domain
return user.email.split('@')[0]; return user.email.split('@')[0];
}; };
const navigation = [ const navigation = [
{ {
name: t('nav.dashboard'), name: t('nav.dashboard'),
href: '/dashboard', href: '/dashboard',
icon: ( icon: (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
</svg> </svg>
), ),
}, },
{ {
name: t('nav.create_qr'), name: t('nav.create_qr'),
href: '/create', href: '/create',
icon: ( icon: (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" />
</svg> </svg>
), ),
}, },
{ {
name: t('nav.bulk_creation'), name: t('nav.bulk_creation'),
href: '/bulk-creation', href: '/bulk-creation',
icon: ( icon: (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
</svg> </svg>
), ),
}, },
{ {
name: t('nav.analytics'), name: t('nav.analytics'),
href: '/analytics', href: '/analytics',
icon: ( icon: (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z" />
</svg> </svg>
), ),
}, },
{ {
name: t('nav.pricing'), name: t('nav.pricing'),
href: '/pricing', href: '/pricing',
icon: ( icon: (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg> </svg>
), ),
}, },
{ {
name: t('nav.settings'), name: t('nav.settings'),
href: '/settings', href: '/settings',
icon: ( icon: (
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" />
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
</svg> </svg>
), ),
}, },
]; ];
return ( return (
<div className="min-h-screen bg-gray-50"> <div className="min-h-screen bg-gray-50">
{/* Mobile sidebar backdrop */} {/* Mobile sidebar backdrop */}
{sidebarOpen && ( {sidebarOpen && (
<div <div
className="fixed inset-0 bg-black bg-opacity-50 z-40 lg:hidden" className="fixed inset-0 bg-black bg-opacity-50 z-40 lg:hidden"
onClick={() => setSidebarOpen(false)} onClick={() => setSidebarOpen(false)}
/> />
)} )}
{/* Sidebar */} {/* Sidebar */}
<aside <aside
className={`fixed top-0 left-0 z-50 h-full w-64 bg-white border-r border-gray-200 transform transition-transform lg:translate-x-0 ${sidebarOpen ? 'translate-x-0' : '-translate-x-full' className={`fixed top-0 left-0 z-50 h-full w-64 bg-white border-r border-gray-200 transform transition-transform lg:translate-x-0 ${sidebarOpen ? 'translate-x-0' : '-translate-x-full'
}`} }`}
> >
<div className="flex items-center justify-between p-4 border-b border-gray-200"> <div className="flex items-center justify-between p-4 border-b border-gray-200">
<Link href="/" className="flex items-center space-x-2"> <Link href="/" className="flex items-center space-x-2">
<img src="/logo.svg" alt="QR Master" className="w-8 h-8" /> <img src="/logo.svg" alt="QR Master" className="w-8 h-8" />
<span className="text-xl font-bold text-gray-900">QR Master</span> <span className="text-xl font-bold text-gray-900">QR Master</span>
</Link> </Link>
<button <button
className="lg:hidden" className="lg:hidden"
onClick={() => setSidebarOpen(false)} onClick={() => setSidebarOpen(false)}
> >
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg> </svg>
</button> </button>
</div> </div>
<nav className="p-4 space-y-1"> <nav className="p-4 space-y-1">
{navigation.map((item) => { {navigation.map((item) => {
const isActive = pathname === item.href; const isActive = pathname === item.href;
return ( return (
<Link <Link
key={item.name} key={item.name}
href={item.href} href={item.href}
className={`flex items-center space-x-3 px-3 py-2 rounded-lg transition-colors ${isActive className={`flex items-center space-x-3 px-3 py-2 rounded-lg transition-colors ${isActive
? 'bg-primary-50 text-primary-600' ? 'bg-primary-50 text-primary-600'
: 'text-gray-700 hover:bg-gray-100' : 'text-gray-700 hover:bg-gray-100'
}`} }`}
> >
{item.icon} {item.icon}
<span className="font-medium">{item.name}</span> <span className="font-medium">{item.name}</span>
</Link> </Link>
); );
})} })}
</nav> </nav>
</aside> </aside>
{/* Main content */} {/* Main content */}
<div className="lg:ml-64"> <div className="lg:ml-64">
{/* Top bar */} {/* Top bar */}
<header className="bg-white border-b border-gray-200"> <header className="bg-white border-b border-gray-200">
<div className="flex items-center justify-between px-4 py-3"> <div className="flex items-center justify-between px-4 py-3">
<button <button
className="lg:hidden" className="lg:hidden"
onClick={() => setSidebarOpen(true)} onClick={() => setSidebarOpen(true)}
> >
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" />
</svg> </svg>
</button> </button>
<div className="flex items-center space-x-4 ml-auto"> <div className="flex items-center space-x-4 ml-auto">
{/* User Menu */} {/* User Menu */}
<Dropdown <Dropdown
align="right" align="right"
trigger={ trigger={
<button className="flex items-center space-x-2 text-gray-700 hover:text-gray-900"> <button className="flex items-center space-x-2 text-gray-700 hover:text-gray-900">
<div className="w-8 h-8 bg-primary-100 rounded-full flex items-center justify-center"> <div className="w-8 h-8 bg-primary-100 rounded-full flex items-center justify-center">
<span className="text-sm font-medium text-primary-600"> <span className="text-sm font-medium text-primary-600">
{getUserInitials()} {getUserInitials()}
</span> </span>
</div> </div>
<span className="hidden md:block font-medium"> <span className="hidden md:block font-medium">
{getDisplayName()} {getDisplayName()}
</span> </span>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
</svg> </svg>
</button> </button>
} }
> >
<DropdownItem onClick={handleSignOut}> <DropdownItem onClick={handleSignOut}>
Sign Out Sign Out
</DropdownItem> </DropdownItem>
</Dropdown> </Dropdown>
</div> </div>
</div> </div>
</header> </header>
{/* Page content */} {/* Page content */}
<main className="p-6"> <main className="p-6">
{children} {children}
</main> </main>
{/* Footer */} {/* Footer */}
<Footer variant="dashboard" /> <Footer variant="dashboard" />
</div> </div>
</div> </div>
); );
} }

View File

@ -1,164 +1,164 @@
'use client'; 'use client';
import React, { useState } from 'react'; import React, { useState } from 'react';
import Link from 'next/link'; import Link from 'next/link';
import { Button } from '@/components/ui/Button'; import { Button } from '@/components/ui/Button';
import en from '@/i18n/en.json'; import en from '@/i18n/en.json';
export default function MarketingLayout({ export default function MarketingLayout({
children, children,
}: { }: {
children: React.ReactNode; children: React.ReactNode;
}) { }) {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
// Always use English for marketing pages // Always use English for marketing pages
const t = en; const t = en;
const navigation = [ const navigation = [
{ name: t.nav.features, href: '/#features' }, { name: t.nav.features, href: '/#features' },
{ name: t.nav.pricing, href: '/#pricing' }, { name: t.nav.pricing, href: '/#pricing' },
{ name: t.nav.faq, href: '/#faq' }, { name: t.nav.faq, href: '/#faq' },
{ name: t.nav.blog, href: '/blog' }, { name: t.nav.blog, href: '/blog' },
]; ];
return ( return (
<div className="min-h-screen bg-white"> <div className="min-h-screen bg-white">
{/* Header */} {/* Header */}
<header className="sticky top-0 z-50 bg-white border-b border-gray-200"> <header className="sticky top-0 z-50 bg-white border-b border-gray-200">
<nav className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl py-4"> <nav className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl py-4">
<div className="flex items-center justify-between"> <div className="flex items-center justify-between">
{/* Logo */} {/* Logo */}
<Link href="/" className="flex items-center space-x-2"> <Link href="/" className="flex items-center space-x-2">
<img src="/favicon.svg" alt="QR Master" className="w-8 h-8" /> <img src="/favicon.svg" alt="QR Master" className="w-8 h-8" />
<span className="text-xl font-bold text-gray-900">QR Master</span> <span className="text-xl font-bold text-gray-900">QR Master</span>
</Link> </Link>
{/* Desktop Navigation */} {/* Desktop Navigation */}
<div className="hidden md:flex items-center space-x-8"> <div className="hidden md:flex items-center space-x-8">
{navigation.map((item) => ( {navigation.map((item) => (
<Link <Link
key={item.name} key={item.name}
href={item.href} href={item.href}
className="text-gray-600 hover:text-gray-900 font-medium transition-colors" className="text-gray-600 hover:text-gray-900 font-medium transition-colors"
> >
{item.name} {item.name}
</Link> </Link>
))} ))}
</div> </div>
{/* Right Actions */} {/* Right Actions */}
<div className="hidden md:flex items-center space-x-4"> <div className="hidden md:flex items-center space-x-4">
<Link href="/login"> <Link href="/login">
<Button variant="outline">{t.nav.login}</Button> <Button variant="outline">{t.nav.login}</Button>
</Link> </Link>
<Link href="/signup"> <Link href="/signup">
<Button>Get Started Free</Button> <Button>Get Started Free</Button>
</Link> </Link>
</div> </div>
{/* Mobile Menu Button */} {/* Mobile Menu Button */}
<button <button
className="md:hidden text-gray-900" className="md:hidden text-gray-900"
onClick={() => setMobileMenuOpen(!mobileMenuOpen)} onClick={() => setMobileMenuOpen(!mobileMenuOpen)}
aria-label={mobileMenuOpen ? 'Close menu' : 'Open menu'} aria-label={mobileMenuOpen ? 'Close menu' : 'Open menu'}
aria-expanded={mobileMenuOpen} aria-expanded={mobileMenuOpen}
> >
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"> <svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
{mobileMenuOpen ? ( {mobileMenuOpen ? (
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
) : ( ) : (
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" />
)} )}
</svg> </svg>
</button> </button>
</div> </div>
{/* Mobile Menu */} {/* Mobile Menu */}
{mobileMenuOpen && ( {mobileMenuOpen && (
<div className="md:hidden mt-4 pb-4 border-t border-gray-200 pt-4"> <div className="md:hidden mt-4 pb-4 border-t border-gray-200 pt-4">
<div className="flex flex-col space-y-4"> <div className="flex flex-col space-y-4">
{navigation.map((item) => ( {navigation.map((item) => (
<Link <Link
key={item.name} key={item.name}
href={item.href} href={item.href}
className="text-gray-600 hover:text-gray-900 font-medium" className="text-gray-600 hover:text-gray-900 font-medium"
onClick={() => setMobileMenuOpen(false)} onClick={() => setMobileMenuOpen(false)}
> >
{item.name} {item.name}
</Link> </Link>
))} ))}
<Link href="/login" onClick={() => setMobileMenuOpen(false)}> <Link href="/login" onClick={() => setMobileMenuOpen(false)}>
<Button variant="outline" className="w-full">{t.nav.login}</Button> <Button variant="outline" className="w-full">{t.nav.login}</Button>
</Link> </Link>
<Link href="/signup" onClick={() => setMobileMenuOpen(false)}> <Link href="/signup" onClick={() => setMobileMenuOpen(false)}>
<Button className="w-full">Get Started Free</Button> <Button className="w-full">Get Started Free</Button>
</Link> </Link>
</div> </div>
</div> </div>
)} )}
</nav> </nav>
</header> </header>
{/* Main Content */} {/* Main Content */}
<main>{children}</main> <main>{children}</main>
{/* Footer */} {/* Footer */}
<footer className="bg-gray-900 text-white py-12 mt-20"> <footer className="bg-gray-900 text-white py-12 mt-20">
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl"> <div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl">
<div className="grid md:grid-cols-4 gap-8"> <div className="grid md:grid-cols-4 gap-8">
<div> <div>
<Link href="/" className="flex items-center space-x-2 mb-4 hover:opacity-80 transition-opacity"> <Link href="/" className="flex items-center space-x-2 mb-4 hover:opacity-80 transition-opacity">
<img src="/logo.svg" alt="QR Master" className="w-10 h-10" /> <img src="/logo.svg" alt="QR Master" className="w-10 h-10" />
<span className="text-xl font-bold">QR Master</span> <span className="text-xl font-bold">QR Master</span>
</Link> </Link>
<p className="text-gray-400"> <p className="text-gray-400">
Create custom QR codes in seconds with advanced tracking and analytics. Create custom QR codes in seconds with advanced tracking and analytics.
</p> </p>
</div> </div>
<div> <div>
<h3 className="font-semibold mb-4">Product</h3> <h3 className="font-semibold mb-4">Product</h3>
<ul className="space-y-2 text-gray-400"> <ul className="space-y-2 text-gray-400">
<li><Link href="/#features" className="hover:text-white">Features</Link></li> <li><Link href="/#features" className="hover:text-white">Features</Link></li>
<li><Link href="/#pricing" className="hover:text-white">Pricing</Link></li> <li><Link href="/#pricing" className="hover:text-white">Pricing</Link></li>
<li><Link href="/#faq" className="hover:text-white">FAQ</Link></li> <li><Link href="/#faq" className="hover:text-white">FAQ</Link></li>
<li><Link href="/blog" className="hover:text-white">Blog</Link></li> <li><Link href="/blog" className="hover:text-white">Blog</Link></li>
</ul> </ul>
</div> </div>
<div> <div>
<h3 className="font-semibold mb-4">Resources</h3> <h3 className="font-semibold mb-4">Resources</h3>
<ul className="space-y-2 text-gray-400"> <ul className="space-y-2 text-gray-400">
<li><Link href="/#pricing" className="hover:text-white">Full Pricing</Link></li> <li><Link href="/#pricing" className="hover:text-white">Full Pricing</Link></li>
<li><Link href="/faq" className="hover:text-white">All Questions</Link></li> <li><Link href="/faq" className="hover:text-white">All Questions</Link></li>
<li><Link href="/blog" className="hover:text-white">Blog</Link></li> <li><Link href="/blog" className="hover:text-white">Blog</Link></li>
<li><Link href="/signup" className="hover:text-white">Get Started</Link></li> <li><Link href="/signup" className="hover:text-white">Get Started</Link></li>
</ul> </ul>
</div> </div>
<div> <div>
<h3 className="font-semibold mb-4">Legal</h3> <h3 className="font-semibold mb-4">Legal</h3>
<ul className="space-y-2 text-gray-400"> <ul className="space-y-2 text-gray-400">
<li><Link href="/privacy" className="hover:text-white">Privacy Policy</Link></li> <li><Link href="/privacy" className="hover:text-white">Privacy Policy</Link></li>
</ul> </ul>
</div> </div>
</div> </div>
<div className="border-t border-gray-800 mt-8 pt-8 flex items-center justify-between text-gray-400"> <div className="border-t border-gray-800 mt-8 pt-8 flex items-center justify-between text-gray-400">
<Link <Link
href="/newsletter" href="/newsletter"
className="text-[6px] text-gray-700 opacity-[0.25] hover:opacity-100 hover:text-white transition-opacity duration-300" className="text-[6px] text-gray-700 opacity-[0.25] hover:opacity-100 hover:text-white transition-opacity duration-300"
> >
</Link> </Link>
<p>&copy; 2025 QR Master. All rights reserved.</p> <p>&copy; 2025 QR Master. All rights reserved.</p>
<div className="w-12"></div> <div className="w-12"></div>
</div> </div>
</div> </div>
</footer> </footer>
</div> </div>
); );
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,216 +1,216 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { cookies } from 'next/headers'; import { cookies } from 'next/headers';
import { db } from '@/lib/db'; import { db } from '@/lib/db';
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
try { try {
// Check newsletter-admin cookie authentication // Check newsletter-admin cookie authentication
const cookieStore = cookies(); const cookieStore = cookies();
const adminCookie = cookieStore.get('newsletter-admin'); const adminCookie = cookieStore.get('newsletter-admin');
if (!adminCookie || adminCookie.value !== 'authenticated') { if (!adminCookie || adminCookie.value !== 'authenticated') {
return NextResponse.json( return NextResponse.json(
{ error: 'Unauthorized - Admin login required' }, { error: 'Unauthorized - Admin login required' },
{ status: 401 } { status: 401 }
); );
} }
// Get 30 days ago date // Get 30 days ago date
const thirtyDaysAgo = new Date(); const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30); thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
// Get 7 days ago date // Get 7 days ago date
const sevenDaysAgo = new Date(); const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7); sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7);
// Get start of current month // Get start of current month
const startOfMonth = new Date(); const startOfMonth = new Date();
startOfMonth.setDate(1); startOfMonth.setDate(1);
startOfMonth.setHours(0, 0, 0, 0); startOfMonth.setHours(0, 0, 0, 0);
// Fetch all statistics in parallel // Fetch all statistics in parallel
const [ const [
totalUsers, totalUsers,
premiumUsers, premiumUsers,
newUsersThisWeek, newUsersThisWeek,
newUsersThisMonth, newUsersThisMonth,
totalQRCodes, totalQRCodes,
dynamicQRCodes, dynamicQRCodes,
staticQRCodes, staticQRCodes,
totalScans, totalScans,
dynamicQRCodesWithScans, dynamicQRCodesWithScans,
activeQRCodes, activeQRCodes,
newsletterSubscribers, newsletterSubscribers,
] = await Promise.all([ ] = await Promise.all([
// Total users // Total users
db.user.count(), db.user.count(),
// Premium users (PRO or BUSINESS) // Premium users (PRO or BUSINESS)
db.user.count({ db.user.count({
where: { where: {
plan: { plan: {
in: ['PRO', 'BUSINESS'], in: ['PRO', 'BUSINESS'],
}, },
}, },
}), }),
// New users this week // New users this week
db.user.count({ db.user.count({
where: { where: {
createdAt: { createdAt: {
gte: sevenDaysAgo, gte: sevenDaysAgo,
}, },
}, },
}), }),
// New users this month // New users this month
db.user.count({ db.user.count({
where: { where: {
createdAt: { createdAt: {
gte: startOfMonth, gte: startOfMonth,
}, },
}, },
}), }),
// Total QR codes // Total QR codes
db.qRCode.count(), db.qRCode.count(),
// Dynamic QR codes // Dynamic QR codes
db.qRCode.count({ db.qRCode.count({
where: { where: {
type: 'DYNAMIC', type: 'DYNAMIC',
}, },
}), }),
// Static QR codes // Static QR codes
db.qRCode.count({ db.qRCode.count({
where: { where: {
type: 'STATIC', type: 'STATIC',
}, },
}), }),
// Total scans // Total scans
db.qRScan.count(), db.qRScan.count(),
// Get all dynamic QR codes with their scan counts // Get all dynamic QR codes with their scan counts
db.qRCode.findMany({ db.qRCode.findMany({
where: { where: {
type: 'DYNAMIC', type: 'DYNAMIC',
}, },
include: { include: {
_count: { _count: {
select: { select: {
scans: true, scans: true,
}, },
}, },
}, },
}), }),
// Active QR codes (scanned in last 30 days) // Active QR codes (scanned in last 30 days)
db.qRCode.findMany({ db.qRCode.findMany({
where: { where: {
scans: { scans: {
some: { some: {
ts: { ts: {
gte: thirtyDaysAgo, gte: thirtyDaysAgo,
}, },
}, },
}, },
}, },
distinct: ['id'], distinct: ['id'],
}), }),
// Newsletter subscribers // Newsletter subscribers
db.newsletterSubscription.count({ db.newsletterSubscription.count({
where: { where: {
status: 'subscribed', status: 'subscribed',
}, },
}), }),
]); ]);
// Calculate dynamic QR scans // Calculate dynamic QR scans
const dynamicQRScans = dynamicQRCodesWithScans.reduce( const dynamicQRScans = dynamicQRCodesWithScans.reduce(
(total, qr) => total + qr._count.scans, (total, qr) => total + qr._count.scans,
0 0
); );
// Calculate average scans per dynamic QR // Calculate average scans per dynamic QR
const avgScansPerDynamicQR = const avgScansPerDynamicQR =
dynamicQRCodes > 0 ? (dynamicQRScans / dynamicQRCodes).toFixed(1) : '0'; dynamicQRCodes > 0 ? (dynamicQRScans / dynamicQRCodes).toFixed(1) : '0';
// Get top 5 most scanned QR codes // Get top 5 most scanned QR codes
const topQRCodes = await db.qRCode.findMany({ const topQRCodes = await db.qRCode.findMany({
take: 5, take: 5,
include: { include: {
_count: { _count: {
select: { select: {
scans: true, scans: true,
}, },
}, },
user: { user: {
select: { select: {
email: true, email: true,
name: true, name: true,
}, },
}, },
}, },
orderBy: { orderBy: {
scans: { scans: {
_count: 'desc', _count: 'desc',
}, },
}, },
}); });
// Get recent users // Get recent users
const recentUsers = await db.user.findMany({ const recentUsers = await db.user.findMany({
take: 5, take: 5,
orderBy: { orderBy: {
createdAt: 'desc', createdAt: 'desc',
}, },
select: { select: {
email: true, email: true,
name: true, name: true,
plan: true, plan: true,
createdAt: true, createdAt: true,
}, },
}); });
return NextResponse.json({ return NextResponse.json({
users: { users: {
total: totalUsers, total: totalUsers,
premium: premiumUsers, premium: premiumUsers,
newThisWeek: newUsersThisWeek, newThisWeek: newUsersThisWeek,
newThisMonth: newUsersThisMonth, newThisMonth: newUsersThisMonth,
recent: recentUsers, recent: recentUsers,
}, },
qrCodes: { qrCodes: {
total: totalQRCodes, total: totalQRCodes,
dynamic: dynamicQRCodes, dynamic: dynamicQRCodes,
static: staticQRCodes, static: staticQRCodes,
active: activeQRCodes.length, active: activeQRCodes.length,
}, },
scans: { scans: {
total: totalScans, total: totalScans,
dynamicOnly: dynamicQRScans, dynamicOnly: dynamicQRScans,
avgPerDynamicQR: avgScansPerDynamicQR, avgPerDynamicQR: avgScansPerDynamicQR,
}, },
newsletter: { newsletter: {
subscribers: newsletterSubscribers, subscribers: newsletterSubscribers,
}, },
topQRCodes: topQRCodes.map((qr) => ({ topQRCodes: topQRCodes.map((qr) => ({
id: qr.id, id: qr.id,
title: qr.title, title: qr.title,
type: qr.type, type: qr.type,
scans: qr._count.scans, scans: qr._count.scans,
owner: qr.user.name || qr.user.email, owner: qr.user.name || qr.user.email,
createdAt: qr.createdAt, createdAt: qr.createdAt,
})), })),
}); });
} catch (error) { } catch (error) {
console.error('Error fetching admin stats:', error); console.error('Error fetching admin stats:', error);
return NextResponse.json( return NextResponse.json(
{ error: 'Failed to fetch statistics' }, { error: 'Failed to fetch statistics' },
{ status: 500 } { status: 500 }
); );
} }
} }

View File

@ -1,288 +1,288 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import { cookies } from 'next/headers'; import { cookies } from 'next/headers';
import { db } from '@/lib/db'; import { db } from '@/lib/db';
import { rateLimit, getClientIdentifier, RateLimits } from '@/lib/rateLimit'; import { rateLimit, getClientIdentifier, RateLimits } from '@/lib/rateLimit';
import { TrendData } from '@/types/analytics'; import { TrendData } from '@/types/analytics';
export const dynamic = 'force-dynamic'; export const dynamic = 'force-dynamic';
// Helper function to calculate trend with proper edge case handling // Helper function to calculate trend with proper edge case handling
function calculateTrend(current: number, previous: number): TrendData { function calculateTrend(current: number, previous: number): TrendData {
// Handle edge case: no data in either period // Handle edge case: no data in either period
if (previous === 0 && current === 0) { if (previous === 0 && current === 0) {
return { trend: 'flat', percentage: 0 }; return { trend: 'flat', percentage: 0 };
} }
// Handle new growth from zero - mark as "new" to distinguish from actual 100% growth // Handle new growth from zero - mark as "new" to distinguish from actual 100% growth
if (previous === 0 && current > 0) { if (previous === 0 && current > 0) {
return { trend: 'up', percentage: 100, isNew: true }; return { trend: 'up', percentage: 100, isNew: true };
} }
// Calculate actual percentage change // Calculate actual percentage change
const change = ((current - previous) / previous) * 100; const change = ((current - previous) / previous) * 100;
const roundedChange = Math.round(change); const roundedChange = Math.round(change);
// Determine trend direction (use threshold of 5% to filter noise) // Determine trend direction (use threshold of 5% to filter noise)
let trend: 'up' | 'down' | 'flat'; let trend: 'up' | 'down' | 'flat';
if (roundedChange > 5) { if (roundedChange > 5) {
trend = 'up'; trend = 'up';
} else if (roundedChange < -5) { } else if (roundedChange < -5) {
trend = 'down'; trend = 'down';
} else { } else {
trend = 'flat'; trend = 'flat';
} }
return { return {
trend, trend,
percentage: Math.abs(roundedChange), percentage: Math.abs(roundedChange),
isNegative: roundedChange < 0 isNegative: roundedChange < 0
}; };
} }
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
try { try {
const userId = cookies().get('userId')?.value; const userId = cookies().get('userId')?.value;
// Rate Limiting (user-based) // Rate Limiting (user-based)
const clientId = userId || getClientIdentifier(request); const clientId = userId || getClientIdentifier(request);
const rateLimitResult = rateLimit(clientId, RateLimits.ANALYTICS); const rateLimitResult = rateLimit(clientId, RateLimits.ANALYTICS);
if (!rateLimitResult.success) { if (!rateLimitResult.success) {
return NextResponse.json( return NextResponse.json(
{ {
error: 'Too many requests. Please try again later.', error: 'Too many requests. Please try again later.',
retryAfter: Math.ceil((rateLimitResult.reset - Date.now()) / 1000) retryAfter: Math.ceil((rateLimitResult.reset - Date.now()) / 1000)
}, },
{ {
status: 429, status: 429,
headers: { headers: {
'X-RateLimit-Limit': rateLimitResult.limit.toString(), 'X-RateLimit-Limit': rateLimitResult.limit.toString(),
'X-RateLimit-Remaining': rateLimitResult.remaining.toString(), 'X-RateLimit-Remaining': rateLimitResult.remaining.toString(),
'X-RateLimit-Reset': rateLimitResult.reset.toString(), 'X-RateLimit-Reset': rateLimitResult.reset.toString(),
} }
} }
); );
} }
if (!userId) { if (!userId) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
} }
// Get date range from query params (default: last 30 days) // Get date range from query params (default: last 30 days)
const { searchParams } = request.nextUrl; const { searchParams } = request.nextUrl;
const range = searchParams.get('range') || '30'; const range = searchParams.get('range') || '30';
const daysInRange = parseInt(range, 10); const daysInRange = parseInt(range, 10);
// Standardize to week (7 days) or month (30 days) for clear comparison labels // Standardize to week (7 days) or month (30 days) for clear comparison labels
const comparisonDays = daysInRange <= 7 ? 7 : 30; const comparisonDays = daysInRange <= 7 ? 7 : 30;
const comparisonPeriod: 'week' | 'month' = comparisonDays === 7 ? 'week' : 'month'; const comparisonPeriod: 'week' | 'month' = comparisonDays === 7 ? 'week' : 'month';
// Calculate current and previous period dates // Calculate current and previous period dates
const now = new Date(); const now = new Date();
const currentPeriodStart = new Date(); const currentPeriodStart = new Date();
currentPeriodStart.setDate(now.getDate() - comparisonDays); currentPeriodStart.setDate(now.getDate() - comparisonDays);
const previousPeriodEnd = new Date(currentPeriodStart); const previousPeriodEnd = new Date(currentPeriodStart);
const previousPeriodStart = new Date(previousPeriodEnd); const previousPeriodStart = new Date(previousPeriodEnd);
previousPeriodStart.setDate(previousPeriodEnd.getDate() - comparisonDays); previousPeriodStart.setDate(previousPeriodEnd.getDate() - comparisonDays);
// Get user's QR codes with scans filtered by period // Get user's QR codes with scans filtered by period
const qrCodes = await db.qRCode.findMany({ const qrCodes = await db.qRCode.findMany({
where: { userId }, where: { userId },
include: { include: {
scans: { scans: {
where: { where: {
ts: { ts: {
gte: currentPeriodStart, gte: currentPeriodStart,
}, },
}, },
}, },
}, },
}); });
// Get previous period scans for comparison // Get previous period scans for comparison
const qrCodesWithPreviousScans = await db.qRCode.findMany({ const qrCodesWithPreviousScans = await db.qRCode.findMany({
where: { userId }, where: { userId },
include: { include: {
scans: { scans: {
where: { where: {
ts: { ts: {
gte: previousPeriodStart, gte: previousPeriodStart,
lt: previousPeriodEnd, lt: previousPeriodEnd,
}, },
}, },
}, },
}, },
}); });
// Calculate current period stats // Calculate current period stats
const totalScans = qrCodes.reduce((sum, qr) => sum + qr.scans.length, 0); const totalScans = qrCodes.reduce((sum, qr) => sum + qr.scans.length, 0);
const uniqueScans = qrCodes.reduce((sum, qr) => const uniqueScans = qrCodes.reduce((sum, qr) =>
sum + qr.scans.filter(s => s.isUnique).length, 0 sum + qr.scans.filter(s => s.isUnique).length, 0
); );
// Calculate previous period stats for comparison // Calculate previous period stats for comparison
const previousTotalScans = qrCodesWithPreviousScans.reduce((sum, qr) => sum + qr.scans.length, 0); const previousTotalScans = qrCodesWithPreviousScans.reduce((sum, qr) => sum + qr.scans.length, 0);
const previousUniqueScans = qrCodesWithPreviousScans.reduce((sum, qr) => const previousUniqueScans = qrCodesWithPreviousScans.reduce((sum, qr) =>
sum + qr.scans.filter(s => s.isUnique).length, 0 sum + qr.scans.filter(s => s.isUnique).length, 0
); );
// Calculate average scans per QR code (only count QR codes with scans) // Calculate average scans per QR code (only count QR codes with scans)
const qrCodesWithScans = qrCodes.filter(qr => qr.scans.length > 0).length; const qrCodesWithScans = qrCodes.filter(qr => qr.scans.length > 0).length;
const avgScansPerQR = qrCodesWithScans > 0 const avgScansPerQR = qrCodesWithScans > 0
? Math.round(totalScans / qrCodesWithScans) ? Math.round(totalScans / qrCodesWithScans)
: 0; : 0;
// Calculate previous period average scans per QR // Calculate previous period average scans per QR
const previousQrCodesWithScans = qrCodesWithPreviousScans.filter(qr => qr.scans.length > 0).length; const previousQrCodesWithScans = qrCodesWithPreviousScans.filter(qr => qr.scans.length > 0).length;
const previousAvgScansPerQR = previousQrCodesWithScans > 0 const previousAvgScansPerQR = previousQrCodesWithScans > 0
? Math.round(previousTotalScans / previousQrCodesWithScans) ? Math.round(previousTotalScans / previousQrCodesWithScans)
: 0; : 0;
// Calculate trends // Calculate trends
const scansTrend = calculateTrend(totalScans, previousTotalScans); const scansTrend = calculateTrend(totalScans, previousTotalScans);
// New Conversion Rate Logic: (Unique Scans / Total Scans) * 100 // New Conversion Rate Logic: (Unique Scans / Total Scans) * 100
// This represents "Engagement Efficiency" - how many scans are from fresh users // This represents "Engagement Efficiency" - how many scans are from fresh users
const currentConversion = totalScans > 0 ? Math.round((uniqueScans / totalScans) * 100) : 0; const currentConversion = totalScans > 0 ? Math.round((uniqueScans / totalScans) * 100) : 0;
const previousConversion = previousTotalScans > 0 const previousConversion = previousTotalScans > 0
? Math.round((previousUniqueScans / previousTotalScans) * 100) ? Math.round((previousUniqueScans / previousTotalScans) * 100)
: 0; : 0;
const avgScansTrend = calculateTrend(currentConversion, previousConversion); const avgScansTrend = calculateTrend(currentConversion, previousConversion);
// Device stats // Device stats
const deviceStats = qrCodes.flatMap(qr => qr.scans) const deviceStats = qrCodes.flatMap(qr => qr.scans)
.reduce((acc, scan) => { .reduce((acc, scan) => {
const device = scan.device || 'unknown'; const device = scan.device || 'unknown';
acc[device] = (acc[device] || 0) + 1; acc[device] = (acc[device] || 0) + 1;
return acc; return acc;
}, {} as Record<string, number>); }, {} as Record<string, number>);
const mobileScans = (deviceStats.mobile || 0) + (deviceStats.tablet || 0); const mobileScans = (deviceStats.mobile || 0) + (deviceStats.tablet || 0);
const mobilePercentage = totalScans > 0 const mobilePercentage = totalScans > 0
? Math.round((mobileScans / totalScans) * 100) ? Math.round((mobileScans / totalScans) * 100)
: 0; : 0;
// Country stats (current period) // Country stats (current period)
const countryStats = qrCodes.flatMap(qr => qr.scans) const countryStats = qrCodes.flatMap(qr => qr.scans)
.reduce((acc, scan) => { .reduce((acc, scan) => {
const country = scan.country ?? 'Unknown Location'; const country = scan.country ?? 'Unknown Location';
acc[country] = (acc[country] || 0) + 1; acc[country] = (acc[country] || 0) + 1;
return acc; return acc;
}, {} as Record<string, number>); }, {} as Record<string, number>);
// Country stats (previous period) // Country stats (previous period)
const previousCountryStats = qrCodesWithPreviousScans.flatMap(qr => qr.scans) const previousCountryStats = qrCodesWithPreviousScans.flatMap(qr => qr.scans)
.reduce((acc, scan) => { .reduce((acc, scan) => {
const country = scan.country ?? 'Unknown Location'; const country = scan.country ?? 'Unknown Location';
acc[country] = (acc[country] || 0) + 1; acc[country] = (acc[country] || 0) + 1;
return acc; return acc;
}, {} as Record<string, number>); }, {} as Record<string, number>);
const topCountry = Object.entries(countryStats) const topCountry = Object.entries(countryStats)
.sort(([, a], [, b]) => b - a)[0]; .sort(([, a], [, b]) => b - a)[0];
// Daily scan counts for chart (current period) // Daily scan counts for chart (current period)
const dailyScans = qrCodes.flatMap(qr => qr.scans).reduce((acc, scan) => { const dailyScans = qrCodes.flatMap(qr => qr.scans).reduce((acc, scan) => {
const date = new Date(scan.ts).toISOString().split('T')[0]; const date = new Date(scan.ts).toISOString().split('T')[0];
acc[date] = (acc[date] || 0) + 1; acc[date] = (acc[date] || 0) + 1;
return acc; return acc;
}, {} as Record<string, number>); }, {} as Record<string, number>);
// Generate last 7 days for sparkline // Generate last 7 days for sparkline
const last7Days = Array.from({ length: 7 }, (_, i) => { const last7Days = Array.from({ length: 7 }, (_, i) => {
const date = new Date(); const date = new Date();
date.setDate(date.getDate() - (6 - i)); date.setDate(date.getDate() - (6 - i));
return date.toISOString().split('T')[0]; return date.toISOString().split('T')[0];
}); });
// QR performance (only show DYNAMIC QR codes since STATIC don't track scans) // QR performance (only show DYNAMIC QR codes since STATIC don't track scans)
const qrPerformance = qrCodes const qrPerformance = qrCodes
.filter(qr => qr.type === 'DYNAMIC') .filter(qr => qr.type === 'DYNAMIC')
.map(qr => { .map(qr => {
const currentTotal = qr.scans.length; const currentTotal = qr.scans.length;
const currentUnique = qr.scans.filter(s => s.isUnique).length; const currentUnique = qr.scans.filter(s => s.isUnique).length;
// Find previous period data for this QR code // Find previous period data for this QR code
const previousQR = qrCodesWithPreviousScans.find(prev => prev.id === qr.id); const previousQR = qrCodesWithPreviousScans.find(prev => prev.id === qr.id);
const previousTotal = previousQR ? previousQR.scans.length : 0; const previousTotal = previousQR ? previousQR.scans.length : 0;
// Calculate trend // Calculate trend
const trendData = calculateTrend(currentTotal, previousTotal); const trendData = calculateTrend(currentTotal, previousTotal);
// Calculate sparkline data (scans per day for last 7 days) // Calculate sparkline data (scans per day for last 7 days)
const sparklineData = last7Days.map(date => { const sparklineData = last7Days.map(date => {
return qr.scans.filter(s => return qr.scans.filter(s =>
new Date(s.ts).toISOString().split('T')[0] === date new Date(s.ts).toISOString().split('T')[0] === date
).length; ).length;
}); });
// Find last scanned date // Find last scanned date
const lastScanned = qr.scans.length > 0 const lastScanned = qr.scans.length > 0
? new Date(Math.max(...qr.scans.map(s => new Date(s.ts).getTime()))) ? new Date(Math.max(...qr.scans.map(s => new Date(s.ts).getTime())))
: null; : null;
return { return {
id: qr.id, id: qr.id,
title: qr.title, title: qr.title,
type: qr.type, type: qr.type,
totalScans: currentTotal, totalScans: currentTotal,
uniqueScans: currentUnique, uniqueScans: currentUnique,
conversion: currentTotal > 0 conversion: currentTotal > 0
? Math.round((currentUnique / currentTotal) * 100) ? Math.round((currentUnique / currentTotal) * 100)
: 0, : 0,
trend: trendData.trend, trend: trendData.trend,
trendPercentage: trendData.percentage, trendPercentage: trendData.percentage,
sparkline: sparklineData, sparkline: sparklineData,
lastScanned: lastScanned?.toISOString() || null, lastScanned: lastScanned?.toISOString() || null,
...(trendData.isNew && { isNew: true }), ...(trendData.isNew && { isNew: true }),
}; };
}) })
.sort((a, b) => b.totalScans - a.totalScans); .sort((a, b) => b.totalScans - a.totalScans);
return NextResponse.json({ return NextResponse.json({
summary: { summary: {
totalScans, totalScans,
uniqueScans, uniqueScans,
avgScansPerQR: currentConversion, // Now sending Unique Rate instead of Avg per QR avgScansPerQR: currentConversion, // Now sending Unique Rate instead of Avg per QR
mobilePercentage, mobilePercentage,
topCountry: topCountry ? topCountry[0] : 'N/A', topCountry: topCountry ? topCountry[0] : 'N/A',
topCountryPercentage: topCountry && totalScans > 0 topCountryPercentage: topCountry && totalScans > 0
? Math.round((topCountry[1] / totalScans) * 100) ? Math.round((topCountry[1] / totalScans) * 100)
: 0, : 0,
scansTrend, scansTrend,
avgScansTrend, avgScansTrend,
comparisonPeriod, comparisonPeriod,
comparisonDays, comparisonDays,
}, },
deviceStats, deviceStats,
countryStats: Object.entries(countryStats) countryStats: Object.entries(countryStats)
.sort(([, a], [, b]) => b - a) .sort(([, a], [, b]) => b - a)
.slice(0, 10) .slice(0, 10)
.map(([country, count]) => { .map(([country, count]) => {
const previousCount = previousCountryStats[country] || 0; const previousCount = previousCountryStats[country] || 0;
const trendData = calculateTrend(count, previousCount); const trendData = calculateTrend(count, previousCount);
return { return {
country, country,
count, count,
percentage: totalScans > 0 percentage: totalScans > 0
? Math.round((count / totalScans) * 100) ? Math.round((count / totalScans) * 100)
: 0, : 0,
trend: trendData.trend, trend: trendData.trend,
trendPercentage: trendData.percentage, trendPercentage: trendData.percentage,
...(trendData.isNew && { isNew: true }), ...(trendData.isNew && { isNew: true }),
}; };
}), }),
dailyScans, dailyScans,
qrPerformance: qrPerformance.slice(0, 10), qrPerformance: qrPerformance.slice(0, 10),
}); });
} catch (error) { } catch (error) {
console.error('Error fetching analytics:', error); console.error('Error fetching analytics:', error);
return NextResponse.json( return NextResponse.json(
{ error: 'Internal server error' }, { error: 'Internal server error' },
{ status: 500 } { status: 500 }
); );
} }
} }

View File

@ -1,106 +1,106 @@
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
import bcrypt from 'bcryptjs'; import bcrypt from 'bcryptjs';
import { cookies } from 'next/headers'; import { cookies } from 'next/headers';
import { db } from '@/lib/db'; import { db } from '@/lib/db';
import { z } from 'zod'; import { z } from 'zod';
import { csrfProtection } from '@/lib/csrf'; import { csrfProtection } from '@/lib/csrf';
import { rateLimit, getClientIdentifier, RateLimits } from '@/lib/rateLimit'; import { rateLimit, getClientIdentifier, RateLimits } from '@/lib/rateLimit';
import { getAuthCookieOptions } from '@/lib/cookieConfig'; import { getAuthCookieOptions } from '@/lib/cookieConfig';
import { signupSchema, validateRequest } from '@/lib/validationSchemas'; import { signupSchema, validateRequest } from '@/lib/validationSchemas';
export async function POST(request: NextRequest) { export async function POST(request: NextRequest) {
try { try {
// CSRF Protection // CSRF Protection
const csrfCheck = csrfProtection(request); const csrfCheck = csrfProtection(request);
if (!csrfCheck.valid) { if (!csrfCheck.valid) {
return NextResponse.json( return NextResponse.json(
{ error: csrfCheck.error }, { error: csrfCheck.error },
{ status: 403 } { status: 403 }
); );
} }
// Rate Limiting // Rate Limiting
const clientId = getClientIdentifier(request); const clientId = getClientIdentifier(request);
const rateLimitResult = rateLimit(clientId, RateLimits.SIGNUP); const rateLimitResult = rateLimit(clientId, RateLimits.SIGNUP);
if (!rateLimitResult.success) { if (!rateLimitResult.success) {
return NextResponse.json( return NextResponse.json(
{ {
error: 'Too many signup attempts. Please try again later.', error: 'Too many signup attempts. Please try again later.',
retryAfter: Math.ceil((rateLimitResult.reset - Date.now()) / 1000) retryAfter: Math.ceil((rateLimitResult.reset - Date.now()) / 1000)
}, },
{ {
status: 429, status: 429,
headers: { headers: {
'X-RateLimit-Limit': rateLimitResult.limit.toString(), 'X-RateLimit-Limit': rateLimitResult.limit.toString(),
'X-RateLimit-Remaining': rateLimitResult.remaining.toString(), 'X-RateLimit-Remaining': rateLimitResult.remaining.toString(),
'X-RateLimit-Reset': rateLimitResult.reset.toString(), 'X-RateLimit-Reset': rateLimitResult.reset.toString(),
} }
} }
); );
} }
const body = await request.json(); const body = await request.json();
// Validate request body // Validate request body
const validation = await validateRequest(signupSchema, body); const validation = await validateRequest(signupSchema, body);
if (!validation.success) { if (!validation.success) {
return NextResponse.json(validation.error, { status: 400 }); return NextResponse.json(validation.error, { status: 400 });
} }
const { name, email, password } = validation.data; const { name, email, password } = validation.data;
// Check if user already exists // Check if user already exists
const existingUser = await db.user.findUnique({ const existingUser = await db.user.findUnique({
where: { email }, where: { email },
}); });
if (existingUser) { if (existingUser) {
return NextResponse.json( return NextResponse.json(
{ error: 'User already exists' }, { error: 'User already exists' },
{ status: 400 } { status: 400 }
); );
} }
// Hash password // Hash password
const hashedPassword = await bcrypt.hash(password, 12); const hashedPassword = await bcrypt.hash(password, 12);
// Create user // Create user
const user = await db.user.create({ const user = await db.user.create({
data: { data: {
name, name,
email, email,
password: hashedPassword, password: hashedPassword,
}, },
}); });
// Create response // Create response
const response = NextResponse.json({ const response = NextResponse.json({
success: true, success: true,
user: { user: {
id: user.id, id: user.id,
name: user.name, name: user.name,
email: user.email, email: user.email,
plan: 'FREE', plan: 'FREE',
}, },
}); });
// Set cookie for auto-login after signup // Set cookie for auto-login after signup
response.cookies.set('userId', user.id, getAuthCookieOptions()); response.cookies.set('userId', user.id, getAuthCookieOptions());
return response; return response;
} catch (error) { } catch (error) {
if (error instanceof z.ZodError) { if (error instanceof z.ZodError) {
return NextResponse.json( return NextResponse.json(
{ error: 'Invalid input', details: error.errors }, { error: 'Invalid input', details: error.errors },
{ status: 400 } { status: 400 }
); );
} }
console.error('Signup error:', error); console.error('Signup error:', error);
return NextResponse.json( return NextResponse.json(
{ error: 'Internal server error' }, { error: 'Internal server error' },
{ status: 500 } { status: 500 }
); );
} }
} }

View File

@ -1,192 +1,192 @@
'use client'; 'use client';
import React, { memo } from 'react'; import React, { memo } from 'react';
import { import {
ComposableMap, ComposableMap,
Geographies, Geographies,
Geography, Geography,
ZoomableGroup, ZoomableGroup,
} from 'react-simple-maps'; } from 'react-simple-maps';
import { scaleLinear } from 'd3-scale'; import { scaleLinear } from 'd3-scale';
// TopoJSON world map // TopoJSON world map
const geoUrl = 'https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json'; const geoUrl = 'https://cdn.jsdelivr.net/npm/world-atlas@2/countries-110m.json';
// ISO Alpha-2 to country name mapping for common countries // ISO Alpha-2 to country name mapping for common countries
const countryNameToCode: Record<string, string> = { const countryNameToCode: Record<string, string> = {
'United States': 'US', 'United States': 'US',
'USA': 'US', 'USA': 'US',
'US': 'US', 'US': 'US',
'Germany': 'DE', 'Germany': 'DE',
'DE': 'DE', 'DE': 'DE',
'United Kingdom': 'GB', 'United Kingdom': 'GB',
'UK': 'GB', 'UK': 'GB',
'GB': 'GB', 'GB': 'GB',
'France': 'FR', 'France': 'FR',
'FR': 'FR', 'FR': 'FR',
'Canada': 'CA', 'Canada': 'CA',
'CA': 'CA', 'CA': 'CA',
'Australia': 'AU', 'Australia': 'AU',
'AU': 'AU', 'AU': 'AU',
'Japan': 'JP', 'Japan': 'JP',
'JP': 'JP', 'JP': 'JP',
'China': 'CN', 'China': 'CN',
'CN': 'CN', 'CN': 'CN',
'India': 'IN', 'India': 'IN',
'IN': 'IN', 'IN': 'IN',
'Brazil': 'BR', 'Brazil': 'BR',
'BR': 'BR', 'BR': 'BR',
'Spain': 'ES', 'Spain': 'ES',
'ES': 'ES', 'ES': 'ES',
'Italy': 'IT', 'Italy': 'IT',
'IT': 'IT', 'IT': 'IT',
'Netherlands': 'NL', 'Netherlands': 'NL',
'NL': 'NL', 'NL': 'NL',
'Switzerland': 'CH', 'Switzerland': 'CH',
'CH': 'CH', 'CH': 'CH',
'Austria': 'AT', 'Austria': 'AT',
'AT': 'AT', 'AT': 'AT',
'Poland': 'PL', 'Poland': 'PL',
'PL': 'PL', 'PL': 'PL',
'Sweden': 'SE', 'Sweden': 'SE',
'SE': 'SE', 'SE': 'SE',
'Norway': 'NO', 'Norway': 'NO',
'NO': 'NO', 'NO': 'NO',
'Denmark': 'DK', 'Denmark': 'DK',
'DK': 'DK', 'DK': 'DK',
'Finland': 'FI', 'Finland': 'FI',
'FI': 'FI', 'FI': 'FI',
'Belgium': 'BE', 'Belgium': 'BE',
'BE': 'BE', 'BE': 'BE',
'Portugal': 'PT', 'Portugal': 'PT',
'PT': 'PT', 'PT': 'PT',
'Ireland': 'IE', 'Ireland': 'IE',
'IE': 'IE', 'IE': 'IE',
'Mexico': 'MX', 'Mexico': 'MX',
'MX': 'MX', 'MX': 'MX',
'Argentina': 'AR', 'Argentina': 'AR',
'AR': 'AR', 'AR': 'AR',
'South Korea': 'KR', 'South Korea': 'KR',
'KR': 'KR', 'KR': 'KR',
'Singapore': 'SG', 'Singapore': 'SG',
'SG': 'SG', 'SG': 'SG',
'New Zealand': 'NZ', 'New Zealand': 'NZ',
'NZ': 'NZ', 'NZ': 'NZ',
'Russia': 'RU', 'Russia': 'RU',
'RU': 'RU', 'RU': 'RU',
'South Africa': 'ZA', 'South Africa': 'ZA',
'ZA': 'ZA', 'ZA': 'ZA',
'Unknown Location': 'UNKNOWN', 'Unknown Location': 'UNKNOWN',
'unknown': 'UNKNOWN', 'unknown': 'UNKNOWN',
}; };
// ISO Alpha-2 to ISO Alpha-3 mapping (for matching with TopoJSON) // ISO Alpha-2 to ISO Alpha-3 mapping (for matching with TopoJSON)
const alpha2ToAlpha3: Record<string, string> = { const alpha2ToAlpha3: Record<string, string> = {
'US': 'USA', 'US': 'USA',
'DE': 'DEU', 'DE': 'DEU',
'GB': 'GBR', 'GB': 'GBR',
'FR': 'FRA', 'FR': 'FRA',
'CA': 'CAN', 'CA': 'CAN',
'AU': 'AUS', 'AU': 'AUS',
'JP': 'JPN', 'JP': 'JPN',
'CN': 'CHN', 'CN': 'CHN',
'IN': 'IND', 'IN': 'IND',
'BR': 'BRA', 'BR': 'BRA',
'ES': 'ESP', 'ES': 'ESP',
'IT': 'ITA', 'IT': 'ITA',
'NL': 'NLD', 'NL': 'NLD',
'CH': 'CHE', 'CH': 'CHE',
'AT': 'AUT', 'AT': 'AUT',
'PL': 'POL', 'PL': 'POL',
'SE': 'SWE', 'SE': 'SWE',
'NO': 'NOR', 'NO': 'NOR',
'DK': 'DNK', 'DK': 'DNK',
'FI': 'FIN', 'FI': 'FIN',
'BE': 'BEL', 'BE': 'BEL',
'PT': 'PRT', 'PT': 'PRT',
'IE': 'IRL', 'IE': 'IRL',
'MX': 'MEX', 'MX': 'MEX',
'AR': 'ARG', 'AR': 'ARG',
'KR': 'KOR', 'KR': 'KOR',
'SG': 'SGP', 'SG': 'SGP',
'NZ': 'NZL', 'NZ': 'NZL',
'RU': 'RUS', 'RU': 'RUS',
'ZA': 'ZAF', 'ZA': 'ZAF',
}; };
interface CountryStat { interface CountryStat {
country: string; country: string;
count: number; count: number;
percentage: number; percentage: number;
} }
interface GeoMapProps { interface GeoMapProps {
countryStats: CountryStat[]; countryStats: CountryStat[];
totalScans: number; totalScans: number;
} }
const GeoMap: React.FC<GeoMapProps> = ({ countryStats, totalScans }) => { const GeoMap: React.FC<GeoMapProps> = ({ countryStats, totalScans }) => {
// Build a map of ISO Alpha-3 codes to scan counts // Build a map of ISO Alpha-3 codes to scan counts
const countryData: Record<string, number> = {}; const countryData: Record<string, number> = {};
let maxCount = 0; let maxCount = 0;
countryStats.forEach((stat) => { countryStats.forEach((stat) => {
const alpha2 = countryNameToCode[stat.country] || stat.country; const alpha2 = countryNameToCode[stat.country] || stat.country;
const alpha3 = alpha2ToAlpha3[alpha2]; const alpha3 = alpha2ToAlpha3[alpha2];
if (alpha3) { if (alpha3) {
countryData[alpha3] = stat.count; countryData[alpha3] = stat.count;
if (stat.count > maxCount) maxCount = stat.count; if (stat.count > maxCount) maxCount = stat.count;
} }
}); });
// Color scale: light blue to dark blue based on scan count // Color scale: light blue to dark blue based on scan count
const colorScale = scaleLinear<string>() const colorScale = scaleLinear<string>()
.domain([0, maxCount || 1]) .domain([0, maxCount || 1])
.range(['#E0F2FE', '#1E40AF']); .range(['#E0F2FE', '#1E40AF']);
return ( return (
<div className="w-full h-full"> <div className="w-full h-full">
<ComposableMap <ComposableMap
projection="geoMercator" projection="geoMercator"
projectionConfig={{ projectionConfig={{
scale: 120, scale: 120,
center: [0, 30], center: [0, 30],
}} }}
style={{ width: '100%', height: '100%' }} style={{ width: '100%', height: '100%' }}
> >
<ZoomableGroup center={[0, 30]} zoom={1}> <ZoomableGroup center={[0, 30]} zoom={1}>
<Geographies geography={geoUrl}> <Geographies geography={geoUrl}>
{({ geographies }) => {({ geographies }) =>
geographies.map((geo) => { geographies.map((geo) => {
const isoCode = geo.properties.ISO_A3 || geo.id; const isoCode = geo.properties.ISO_A3 || geo.id;
const scanCount = countryData[isoCode] || 0; const scanCount = countryData[isoCode] || 0;
const fillColor = scanCount > 0 ? colorScale(scanCount) : '#F1F5F9'; const fillColor = scanCount > 0 ? colorScale(scanCount) : '#F1F5F9';
return ( return (
<Geography <Geography
key={geo.rsmKey} key={geo.rsmKey}
geography={geo} geography={geo}
fill={fillColor} fill={fillColor}
stroke="#CBD5E1" stroke="#CBD5E1"
strokeWidth={0.5} strokeWidth={0.5}
style={{ style={{
default: { outline: 'none' }, default: { outline: 'none' },
hover: { hover: {
fill: scanCount > 0 ? '#3B82F6' : '#E2E8F0', fill: scanCount > 0 ? '#3B82F6' : '#E2E8F0',
outline: 'none', outline: 'none',
cursor: 'pointer', cursor: 'pointer',
}, },
pressed: { outline: 'none' }, pressed: { outline: 'none' },
}} }}
/> />
); );
}) })
} }
</Geographies> </Geographies>
</ZoomableGroup> </ZoomableGroup>
</ComposableMap> </ComposableMap>
</div> </div>
); );
}; };
export default memo(GeoMap); export default memo(GeoMap);

View File

@ -1,86 +1,86 @@
'use client'; 'use client';
import React from 'react'; import React from 'react';
import { Line } from 'react-chartjs-2'; import { Line } from 'react-chartjs-2';
import { import {
Chart as ChartJS, Chart as ChartJS,
CategoryScale, CategoryScale,
LinearScale, LinearScale,
PointElement, PointElement,
LineElement, LineElement,
Filler, Filler,
} from 'chart.js'; } from 'chart.js';
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Filler); ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Filler);
interface SparklineProps { interface SparklineProps {
data: number[]; data: number[];
color?: 'blue' | 'green' | 'red'; color?: 'blue' | 'green' | 'red';
width?: number; width?: number;
height?: number; height?: number;
} }
const colorMap = { const colorMap = {
blue: { blue: {
border: 'rgb(59, 130, 246)', border: 'rgb(59, 130, 246)',
background: 'rgba(59, 130, 246, 0.1)', background: 'rgba(59, 130, 246, 0.1)',
}, },
green: { green: {
border: 'rgb(34, 197, 94)', border: 'rgb(34, 197, 94)',
background: 'rgba(34, 197, 94, 0.1)', background: 'rgba(34, 197, 94, 0.1)',
}, },
red: { red: {
border: 'rgb(239, 68, 68)', border: 'rgb(239, 68, 68)',
background: 'rgba(239, 68, 68, 0.1)', background: 'rgba(239, 68, 68, 0.1)',
}, },
}; };
const Sparkline: React.FC<SparklineProps> = ({ const Sparkline: React.FC<SparklineProps> = ({
data, data,
color = 'blue', color = 'blue',
width = 100, width = 100,
height = 30, height = 30,
}) => { }) => {
const colors = colorMap[color]; const colors = colorMap[color];
const chartData = { const chartData = {
labels: data.map((_, i) => i.toString()), labels: data.map((_, i) => i.toString()),
datasets: [ datasets: [
{ {
data, data,
borderColor: colors.border, borderColor: colors.border,
backgroundColor: colors.background, backgroundColor: colors.background,
borderWidth: 1.5, borderWidth: 1.5,
pointRadius: 0, pointRadius: 0,
tension: 0.4, tension: 0.4,
fill: true, fill: true,
}, },
], ],
}; };
const options = { const options = {
responsive: false, responsive: false,
maintainAspectRatio: false, maintainAspectRatio: false,
plugins: { plugins: {
legend: { display: false }, legend: { display: false },
tooltip: { enabled: false }, tooltip: { enabled: false },
}, },
scales: { scales: {
x: { display: false }, x: { display: false },
y: { display: false }, y: { display: false },
}, },
elements: { elements: {
line: { line: {
borderJoinStyle: 'round' as const, borderJoinStyle: 'round' as const,
}, },
}, },
}; };
return ( return (
<div style={{ width, height }}> <div style={{ width, height }}>
<Line data={chartData} options={options} width={width} height={height} /> <Line data={chartData} options={options} width={width} height={height} />
</div> </div>
); );
}; };
export default Sparkline; export default Sparkline;

View File

@ -1,103 +1,103 @@
'use client'; 'use client';
import React from 'react'; import React from 'react';
import { TrendingUp, TrendingDown, Minus } from 'lucide-react'; import { TrendingUp, TrendingDown, Minus } from 'lucide-react';
interface StatCardProps { interface StatCardProps {
title: string; title: string;
value: string | number; value: string | number;
subtitle?: string; subtitle?: string;
trend?: { trend?: {
direction: 'up' | 'down' | 'flat'; direction: 'up' | 'down' | 'flat';
percentage: number; percentage: number;
isNew?: boolean; isNew?: boolean;
period?: string; period?: string;
}; };
icon?: React.ReactNode; icon?: React.ReactNode;
variant?: 'default' | 'highlight'; variant?: 'default' | 'highlight';
} }
const StatCard: React.FC<StatCardProps> = ({ const StatCard: React.FC<StatCardProps> = ({
title, title,
value, value,
subtitle, subtitle,
trend, trend,
icon, icon,
variant = 'default', variant = 'default',
}) => { }) => {
const getTrendColor = () => { const getTrendColor = () => {
if (!trend) return 'text-gray-500'; if (!trend) return 'text-gray-500';
if (trend.direction === 'up') return 'text-emerald-600'; if (trend.direction === 'up') return 'text-emerald-600';
if (trend.direction === 'down') return 'text-red-500'; if (trend.direction === 'down') return 'text-red-500';
return 'text-gray-500'; return 'text-gray-500';
}; };
const getTrendIcon = () => { const getTrendIcon = () => {
if (!trend) return null; if (!trend) return null;
if (trend.direction === 'up') return <TrendingUp className="w-4 h-4" />; if (trend.direction === 'up') return <TrendingUp className="w-4 h-4" />;
if (trend.direction === 'down') return <TrendingDown className="w-4 h-4" />; if (trend.direction === 'down') return <TrendingDown className="w-4 h-4" />;
return <Minus className="w-4 h-4" />; return <Minus className="w-4 h-4" />;
}; };
return ( return (
<div <div
className={`rounded-xl p-6 transition-all duration-200 ${variant === 'highlight' className={`rounded-xl p-6 transition-all duration-200 ${variant === 'highlight'
? 'bg-gradient-to-br from-primary-500 to-primary-600 text-white shadow-lg shadow-primary-500/25' ? 'bg-gradient-to-br from-primary-500 to-primary-600 text-white shadow-lg shadow-primary-500/25'
: 'bg-white border border-gray-200 hover:shadow-md' : 'bg-white border border-gray-200 hover:shadow-md'
}`} }`}
> >
<div className="flex items-start justify-between"> <div className="flex items-start justify-between">
<div className="flex-1"> <div className="flex-1">
<p <p
className={`text-sm font-medium ${variant === 'highlight' ? 'text-primary-100' : 'text-gray-500' className={`text-sm font-medium ${variant === 'highlight' ? 'text-primary-100' : 'text-gray-500'
}`} }`}
> >
{title} {title}
</p> </p>
<p <p
className={`text-3xl font-bold mt-2 ${variant === 'highlight' ? 'text-white' : 'text-gray-900' className={`text-3xl font-bold mt-2 ${variant === 'highlight' ? 'text-white' : 'text-gray-900'
}`} }`}
> >
{typeof value === 'number' ? value.toLocaleString() : value} {typeof value === 'number' ? value.toLocaleString() : value}
</p> </p>
{trend && ( {trend && (
<div className={`flex items-center gap-1 mt-3 ${getTrendColor()}`}> <div className={`flex items-center gap-1 mt-3 ${getTrendColor()}`}>
{getTrendIcon()} {getTrendIcon()}
<span className="text-sm font-medium"> <span className="text-sm font-medium">
{trend.direction === 'up' ? '+' : trend.direction === 'down' ? '-' : ''} {trend.direction === 'up' ? '+' : trend.direction === 'down' ? '-' : ''}
{trend.percentage}% {trend.percentage}%
{trend.isNew && ' (new)'} {trend.isNew && ' (new)'}
</span> </span>
{trend.period && ( {trend.period && (
<span <span
className={`text-sm ${variant === 'highlight' ? 'text-primary-200' : 'text-gray-400' className={`text-sm ${variant === 'highlight' ? 'text-primary-200' : 'text-gray-400'
}`} }`}
> >
vs last {trend.period} vs last {trend.period}
</span> </span>
)} )}
</div> </div>
)} )}
{subtitle && !trend && ( {subtitle && !trend && (
<p <p
className={`text-sm mt-2 ${variant === 'highlight' ? 'text-primary-200' : 'text-gray-500' className={`text-sm mt-2 ${variant === 'highlight' ? 'text-primary-200' : 'text-gray-500'
}`} }`}
> >
{subtitle} {subtitle}
</p> </p>
)} )}
</div> </div>
{icon && ( {icon && (
<div <div
className={`p-3 rounded-lg ${variant === 'highlight' ? 'bg-white/20' : 'bg-gray-100' className={`p-3 rounded-lg ${variant === 'highlight' ? 'bg-white/20' : 'bg-gray-100'
}`} }`}
> >
{icon} {icon}
</div> </div>
)} )}
</div> </div>
</div> </div>
); );
}; };
export default StatCard; export default StatCard;

View File

@ -1,3 +1,3 @@
export { default as GeoMap } from './GeoMap'; export { default as GeoMap } from './GeoMap';
export { default as Sparkline } from './Sparkline'; export { default as Sparkline } from './Sparkline';
export { default as StatCard } from './StatCard'; export { default as StatCard } from './StatCard';

View File

@ -1,70 +1,70 @@
import Link from 'next/link'; import Link from 'next/link';
interface FooterProps { interface FooterProps {
variant?: 'marketing' | 'dashboard'; variant?: 'marketing' | 'dashboard';
} }
export function Footer({ variant = 'marketing' }: FooterProps) { export function Footer({ variant = 'marketing' }: FooterProps) {
const isDashboard = variant === 'dashboard'; const isDashboard = variant === 'dashboard';
return ( return (
<footer className={`${isDashboard ? 'bg-gray-50 text-gray-600 border-t border-gray-200 mt-12' : 'bg-gray-900 text-white mt-20'} py-12`}> <footer className={`${isDashboard ? 'bg-gray-50 text-gray-600 border-t border-gray-200 mt-12' : 'bg-gray-900 text-white mt-20'} py-12`}>
<div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl"> <div className="container mx-auto px-4 sm:px-6 lg:px-8 max-w-7xl">
<div className="grid md:grid-cols-4 gap-8"> <div className="grid md:grid-cols-4 gap-8">
<div> <div>
<Link href="/" className="flex items-center space-x-2 mb-4 hover:opacity-80 transition-opacity"> <Link href="/" className="flex items-center space-x-2 mb-4 hover:opacity-80 transition-opacity">
<img src="/logo.svg" alt="QR Master" className="w-10 h-10" /> <img src="/logo.svg" alt="QR Master" className="w-10 h-10" />
<span className={`text-xl font-bold ${isDashboard ? 'text-gray-900' : ''}`}>QR Master</span> <span className={`text-xl font-bold ${isDashboard ? 'text-gray-900' : ''}`}>QR Master</span>
</Link> </Link>
<p className={isDashboard ? 'text-gray-500' : 'text-gray-400'}> <p className={isDashboard ? 'text-gray-500' : 'text-gray-400'}>
Create custom QR codes in seconds with advanced tracking and analytics. Create custom QR codes in seconds with advanced tracking and analytics.
</p> </p>
</div> </div>
<div> <div>
<h3 className={`font-semibold mb-4 ${isDashboard ? 'text-gray-900' : ''}`}>Product</h3> <h3 className={`font-semibold mb-4 ${isDashboard ? 'text-gray-900' : ''}`}>Product</h3>
<ul className={`space-y-2 ${isDashboard ? 'text-gray-500' : 'text-gray-400'}`}> <ul className={`space-y-2 ${isDashboard ? 'text-gray-500' : 'text-gray-400'}`}>
<li><Link href="/#features" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Features</Link></li> <li><Link href="/#features" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Features</Link></li>
<li><Link href="/#pricing" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Pricing</Link></li> <li><Link href="/#pricing" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Pricing</Link></li>
<li><Link href="/#faq" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>FAQ</Link></li> <li><Link href="/#faq" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>FAQ</Link></li>
<li><Link href="/blog" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Blog</Link></li> <li><Link href="/blog" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Blog</Link></li>
</ul> </ul>
</div> </div>
<div> <div>
<h3 className={`font-semibold mb-4 ${isDashboard ? 'text-gray-900' : ''}`}>Resources</h3> <h3 className={`font-semibold mb-4 ${isDashboard ? 'text-gray-900' : ''}`}>Resources</h3>
<ul className={`space-y-2 ${isDashboard ? 'text-gray-500' : 'text-gray-400'}`}> <ul className={`space-y-2 ${isDashboard ? 'text-gray-500' : 'text-gray-400'}`}>
<li><Link href="/pricing" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Full Pricing</Link></li> <li><Link href="/pricing" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Full Pricing</Link></li>
<li><Link href="/faq" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>All Questions</Link></li> <li><Link href="/faq" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>All Questions</Link></li>
<li><Link href="/blog" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Blog</Link></li> <li><Link href="/blog" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Blog</Link></li>
<li><Link href="/signup" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Get Started</Link></li> <li><Link href="/signup" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Get Started</Link></li>
</ul> </ul>
</div> </div>
<div> <div>
<h3 className={`font-semibold mb-4 ${isDashboard ? 'text-gray-900' : ''}`}>Legal</h3> <h3 className={`font-semibold mb-4 ${isDashboard ? 'text-gray-900' : ''}`}>Legal</h3>
<ul className={`space-y-2 ${isDashboard ? 'text-gray-500' : 'text-gray-400'}`}> <ul className={`space-y-2 ${isDashboard ? 'text-gray-500' : 'text-gray-400'}`}>
<li><Link href="/privacy" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Privacy Policy</Link></li> <li><Link href="/privacy" className={isDashboard ? 'hover:text-primary-600' : 'hover:text-white'}>Privacy Policy</Link></li>
</ul> </ul>
</div> </div>
</div> </div>
<div className={`border-t mt-8 pt-8 flex items-center justify-between ${isDashboard ? 'border-gray-200 text-gray-500' : 'border-gray-800 text-gray-400'}`}> <div className={`border-t mt-8 pt-8 flex items-center justify-between ${isDashboard ? 'border-gray-200 text-gray-500' : 'border-gray-800 text-gray-400'}`}>
{!isDashboard ? ( {!isDashboard ? (
<Link <Link
href="/newsletter" href="/newsletter"
className="text-[6px] text-gray-700 opacity-[0.03] hover:opacity-100 hover:text-white transition-opacity duration-300" className="text-[6px] text-gray-700 opacity-[0.03] hover:opacity-100 hover:text-white transition-opacity duration-300"
> >
</Link> </Link>
) : ( ) : (
<div></div> <div></div>
)} )}
<p>&copy; 2025 QR Master. All rights reserved.</p> <p>&copy; 2025 QR Master. All rights reserved.</p>
<div className="w-12"></div> <div className="w-12"></div>
</div> </div>
</div> </div>
</footer> </footer>
); );
} }

View File

@ -1,58 +1,58 @@
declare module 'react-simple-maps' { declare module 'react-simple-maps' {
import { ComponentType, ReactNode, CSSProperties } from 'react'; import { ComponentType, ReactNode, CSSProperties } from 'react';
export interface ComposableMapProps { export interface ComposableMapProps {
projection?: string; projection?: string;
projectionConfig?: { projectionConfig?: {
scale?: number; scale?: number;
center?: [number, number]; center?: [number, number];
rotate?: [number, number, number]; rotate?: [number, number, number];
}; };
width?: number; width?: number;
height?: number; height?: number;
style?: CSSProperties; style?: CSSProperties;
children?: ReactNode; children?: ReactNode;
} }
export interface GeographiesProps { export interface GeographiesProps {
geography: string | object; geography: string | object;
children: (data: { geographies: any[] }) => ReactNode; children: (data: { geographies: any[] }) => ReactNode;
} }
export interface GeographyProps { export interface GeographyProps {
geography: any; geography: any;
style?: { style?: {
default?: CSSProperties; default?: CSSProperties;
hover?: CSSProperties; hover?: CSSProperties;
pressed?: CSSProperties; pressed?: CSSProperties;
}; };
fill?: string; fill?: string;
stroke?: string; stroke?: string;
strokeWidth?: number; strokeWidth?: number;
onClick?: (event: React.MouseEvent) => void; onClick?: (event: React.MouseEvent) => void;
onMouseEnter?: (event: React.MouseEvent) => void; onMouseEnter?: (event: React.MouseEvent) => void;
onMouseLeave?: (event: React.MouseEvent) => void; onMouseLeave?: (event: React.MouseEvent) => void;
} }
export interface ZoomableGroupProps { export interface ZoomableGroupProps {
center?: [number, number]; center?: [number, number];
zoom?: number; zoom?: number;
minZoom?: number; minZoom?: number;
maxZoom?: number; maxZoom?: number;
translateExtent?: [[number, number], [number, number]]; translateExtent?: [[number, number], [number, number]];
onMoveStart?: (event: any) => void; onMoveStart?: (event: any) => void;
onMove?: (event: any) => void; onMove?: (event: any) => void;
onMoveEnd?: (event: any) => void; onMoveEnd?: (event: any) => void;
children?: ReactNode; children?: ReactNode;
} }
export const ComposableMap: ComponentType<ComposableMapProps>; export const ComposableMap: ComponentType<ComposableMapProps>;
export const Geographies: ComponentType<GeographiesProps>; export const Geographies: ComponentType<GeographiesProps>;
export const Geography: ComponentType<GeographyProps>; export const Geography: ComponentType<GeographyProps>;
export const ZoomableGroup: ComponentType<ZoomableGroupProps>; export const ZoomableGroup: ComponentType<ZoomableGroupProps>;
export const Marker: ComponentType<any>; export const Marker: ComponentType<any>;
export const Line: ComponentType<any>; export const Line: ComponentType<any>;
export const Annotation: ComponentType<any>; export const Annotation: ComponentType<any>;
export const Graticule: ComponentType<any>; export const Graticule: ComponentType<any>;
export const Sphere: ComponentType<any>; export const Sphere: ComponentType<any>;
} }