feat: add admin statistics API endpoint and GeoMap component for scan visualization.
This commit is contained in:
parent
509e5a51a7
commit
57d6e3a449
|
|
@ -2,6 +2,8 @@ import { NextRequest, NextResponse } from 'next/server';
|
|||
import { cookies } from 'next/headers';
|
||||
import { db } from '@/lib/db';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
// Check newsletter-admin cookie authentication
|
||||
|
|
|
|||
|
|
@ -81,37 +81,37 @@ const countryNameToCode: Record<string, string> = {
|
|||
};
|
||||
|
||||
// ISO Alpha-2 to ISO Alpha-3 mapping (for matching with TopoJSON)
|
||||
const alpha2ToAlpha3: Record<string, string> = {
|
||||
'US': 'USA',
|
||||
'DE': 'DEU',
|
||||
'GB': 'GBR',
|
||||
'FR': 'FRA',
|
||||
'CA': 'CAN',
|
||||
'AU': 'AUS',
|
||||
'JP': 'JPN',
|
||||
'CN': 'CHN',
|
||||
'IN': 'IND',
|
||||
'BR': 'BRA',
|
||||
'ES': 'ESP',
|
||||
'IT': 'ITA',
|
||||
'NL': 'NLD',
|
||||
'CH': 'CHE',
|
||||
'AT': 'AUT',
|
||||
'PL': 'POL',
|
||||
'SE': 'SWE',
|
||||
'NO': 'NOR',
|
||||
'DK': 'DNK',
|
||||
'FI': 'FIN',
|
||||
'BE': 'BEL',
|
||||
'PT': 'PRT',
|
||||
'IE': 'IRL',
|
||||
'MX': 'MEX',
|
||||
'AR': 'ARG',
|
||||
'KR': 'KOR',
|
||||
'SG': 'SGP',
|
||||
'NZ': 'NZL',
|
||||
'RU': 'RUS',
|
||||
'ZA': 'ZAF',
|
||||
const alpha2ToNumeric: Record<string, string> = {
|
||||
'US': '840',
|
||||
'DE': '276',
|
||||
'GB': '826',
|
||||
'FR': '250',
|
||||
'CA': '124',
|
||||
'AU': '036',
|
||||
'JP': '392',
|
||||
'CN': '156',
|
||||
'IN': '356',
|
||||
'BR': '076',
|
||||
'ES': '724',
|
||||
'IT': '380',
|
||||
'NL': '528',
|
||||
'CH': '756',
|
||||
'AT': '040',
|
||||
'PL': '616',
|
||||
'SE': '752',
|
||||
'NO': '578',
|
||||
'DK': '208',
|
||||
'FI': '246',
|
||||
'BE': '056',
|
||||
'PT': '620',
|
||||
'IE': '372',
|
||||
'MX': '484',
|
||||
'AR': '032',
|
||||
'KR': '410',
|
||||
'SG': '702',
|
||||
'NZ': '554',
|
||||
'RU': '643',
|
||||
'ZA': '710',
|
||||
};
|
||||
|
||||
interface CountryStat {
|
||||
|
|
@ -132,9 +132,9 @@ const GeoMap: React.FC<GeoMapProps> = ({ countryStats, totalScans }) => {
|
|||
|
||||
countryStats.forEach((stat) => {
|
||||
const alpha2 = countryNameToCode[stat.country] || stat.country;
|
||||
const alpha3 = alpha2ToAlpha3[alpha2];
|
||||
if (alpha3) {
|
||||
countryData[alpha3] = stat.count;
|
||||
const numericCode = alpha2ToNumeric[alpha2];
|
||||
if (numericCode) {
|
||||
countryData[numericCode] = stat.count;
|
||||
if (stat.count > maxCount) maxCount = stat.count;
|
||||
}
|
||||
});
|
||||
|
|
@ -158,8 +158,9 @@ const GeoMap: React.FC<GeoMapProps> = ({ countryStats, totalScans }) => {
|
|||
<Geographies geography={geoUrl}>
|
||||
{({ geographies }) =>
|
||||
geographies.map((geo) => {
|
||||
const isoCode = geo.properties.ISO_A3 || geo.id;
|
||||
const scanCount = countryData[isoCode] || 0;
|
||||
// geo.id is the numeric ISO code as a string (e.g., "840" for US)
|
||||
const geoId = geo.id;
|
||||
const scanCount = countryData[geoId] || 0;
|
||||
const fillColor = scanCount > 0 ? colorScale(scanCount) : '#F1F5F9';
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in New Issue