Skip to content

Commit 147d32d

Browse files
committed
Merge branch 'staging'
2 parents 6510c70 + 2b16faa commit 147d32d

File tree

6 files changed

+23
-50
lines changed

6 files changed

+23
-50
lines changed

apps/api/src/query/builders/geo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { SimpleQueryConfig } from "../types";
22
import { Analytics } from "../../types/tables";
33

4-
export const GeoBuilders: Record<string, SimpleQueryConfig<typeof Analytics.events>> = {
4+
export const GeoBuilders: Record<string, SimpleQueryConfig> = {
55
country: {
66
table: Analytics.events,
77
fields: [

apps/better-admin

apps/dashboard/app/(main)/websites/[id]/map/page.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { AlertCircle, Globe, HelpCircle, MapPin } from "lucide-react";
3+
import { GlobeIcon, MapPinIcon, QuestionIcon } from "@phosphor-icons/react";
44
import dynamic from "next/dynamic";
55
import { useParams } from "next/navigation";
66
import { Suspense, useState } from "react";
@@ -11,6 +11,7 @@ import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
1111
import { useMapLocationData } from "@/hooks/use-dynamic-query";
1212
import { cn } from "@/lib/utils";
1313
import { WebsitePageHeader } from "../_components/website-page-header";
14+
import { CountryFlag } from "@/components/analytics/icons/CountryFlag";
1415

1516
interface CountryData {
1617
country: string;
@@ -50,24 +51,24 @@ function WebsiteMapPage() {
5051
const { id } = useParams<{ id: string }>();
5152
const [mode, setMode] = useState<"total" | "perCapita">("total");
5253

53-
if (!id) {
54-
return <div>No website ID</div>;
55-
}
56-
57-
const { results, isLoading, getDataForQuery } = useMapLocationData(id, {
54+
const { isLoading, getDataForQuery } = useMapLocationData(id, {
5855
start_date: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
5956
end_date: new Date().toISOString().split('T')[0],
6057
granularity: 'daily'
6158
});
6259

60+
if (!id) {
61+
return <div>No website ID</div>;
62+
}
63+
6364
const locationData: LocationData = {
64-
countries: (getDataForQuery("map-countries", "countries") || []).map((item: { name: string; visitors: number; pageviews: number; country_code?: string; country_name?: string }) => ({
65+
countries: (getDataForQuery("map-countries", "country") || []).map((item: { name: string; visitors: number; pageviews: number; country_code?: string; country_name?: string }) => ({
6566
country: item.country_name || item.name,
6667
country_code: item.country_code || item.name,
6768
visitors: item.visitors,
6869
pageviews: item.pageviews,
6970
})),
70-
regions: (getDataForQuery("map-regions", "regions") || []).map((item: { name: string; visitors: number; pageviews: number }) => ({
71+
regions: (getDataForQuery("map-regions", "region") || []).map((item: { name: string; visitors: number; pageviews: number }) => ({
7172
country: item.name,
7273
visitors: item.visitors,
7374
pageviews: item.pageviews,
@@ -86,7 +87,7 @@ function WebsiteMapPage() {
8687
<div className="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
8788
<WebsitePageHeader
8889
title="Geographic Data"
89-
icon={<Globe className="h-5 w-5 text-primary" />}
90+
icon={<GlobeIcon className="h-5 w-5 text-primary" weight="duotone" aria-label="Globe" />}
9091
websiteId={id}
9192
variant="minimal"
9293
subtitle={!isLoading && totalVisitors > 0 ? `${totalVisitors.toLocaleString()} visitors across ${topCountries.length} countries` : undefined}
@@ -124,7 +125,7 @@ function WebsiteMapPage() {
124125
<CardHeader className="flex-shrink-0 pb-3">
125126
<CardTitle className="flex items-center justify-between">
126127
<span className="flex items-center gap-2">
127-
<MapPin className="h-4 w-4" />
128+
<MapPinIcon className="h-4 w-4" weight="duotone" aria-label="World Map" />
128129
World Map
129130
</span>
130131
<Badge className="text-xs" variant="secondary">
@@ -145,7 +146,7 @@ function WebsiteMapPage() {
145146
<Card className="flex min-h-0 flex-1 flex-col overflow-hidden rounded md:w-72 md:flex-none">
146147
<CardHeader className="flex-shrink-0 pb-3">
147148
<CardTitle className="flex items-center gap-2">
148-
<Globe className="h-4 w-4" />
149+
<GlobeIcon className="h-4 w-4" weight="duotone" aria-label="Top Countries" />
149150
Top Countries
150151
</CardTitle>
151152
</CardHeader>
@@ -220,7 +221,7 @@ function WebsiteMapPage() {
220221
<div className="flex items-center justify-between p-3">
221222
<div className="flex min-w-0 flex-1 items-center gap-3">
222223
<div className="flex h-4 w-6 flex-shrink-0 items-center justify-center rounded bg-muted">
223-
<HelpCircle className="h-3 w-3 text-muted-foreground" />
224+
<QuestionIcon className="h-3 w-3 text-muted-foreground" weight="duotone" aria-label="Unknown" />
224225
</div>
225226
<div className="min-w-0 flex-1">
226227
<div className="font-medium text-sm">Unknown</div>
@@ -244,7 +245,7 @@ function WebsiteMapPage() {
244245
<div className="flex flex-col items-center justify-center py-16 text-center">
245246
<div className="mb-4">
246247
<div className="mx-auto mb-3 flex h-16 w-16 items-center justify-center rounded-2xl bg-muted/20">
247-
<Globe className="h-7 w-7 text-muted-foreground/50" />
248+
<GlobeIcon className="h-7 w-7 text-muted-foreground/50" weight="duotone" aria-label="No Data" />
248249
</div>
249250
</div>
250251
<h4 className="mb-2 font-medium text-base text-foreground">

apps/dashboard/components/analytics/data-table.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ import {
1616
Search,
1717
X,
1818
} from "lucide-react";
19-
import React, { Fragment, useCallback, useMemo, useRef, useState, useEffect } from "react";
19+
import React, { Fragment, useCallback, useRef, useState, useEffect } from "react";
2020
import ReactDOM from "react-dom";
21-
import { Card, CardContent, CardHeader } from "@/components/ui/card";
2221
import { Input } from "@/components/ui/input";
2322
import { Skeleton } from "@/components/ui/skeleton";
2423
import {

apps/dashboard/components/analytics/map-component.tsx

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import "leaflet/dist/leaflet.css";
77
import { useEffect, useMemo, useRef, useState } from "react";
88
import { GeoJSON, MapContainer } from "react-leaflet";
99
import { getCountryPopulation } from "@/lib/data";
10-
import { useCountries, useSubdivisions } from "@/lib/geo";
10+
import { useCountries } from "@/lib/geo";
1111
import { CountryFlag } from "./icons/CountryFlag";
1212

1313
interface TooltipContent {
@@ -58,39 +58,13 @@ export function MapComponent({
5858
};
5959
}, [locationsData?.countries]);
6060

61-
const subdivisionData = useMemo(() => {
62-
if (!locationsData?.cities) return null;
63-
64-
const regions: Record<string, { visitors: number; pageviews: number }> = {};
65-
66-
for (const city of locationsData.cities) {
67-
const regionKey = `${city.country}-${city.region}`;
68-
if (!regions[regionKey]) {
69-
regions[regionKey] = { visitors: 0, pageviews: 0 };
70-
}
71-
regions[regionKey].visitors += city.visitors;
72-
regions[regionKey].pageviews += city.pageviews;
73-
}
74-
75-
return {
76-
data: Object.entries(regions).map(([key, data]) => ({
77-
value: key,
78-
count: data.visitors,
79-
percentage:
80-
(data.visitors /
81-
(locationsData.cities.reduce((sum: number, c: any) => sum + c.visitors, 0) || 1)) *
82-
100,
83-
})),
84-
};
85-
}, [locationsData?.cities]);
86-
8761
const [dataVersion, setDataVersion] = useState<number>(0);
8862

8963
useEffect(() => {
90-
if (countryData || subdivisionData) {
64+
if (countryData) {
9165
setDataVersion((prev) => prev + 1);
9266
}
93-
}, [countryData, subdivisionData]);
67+
}, [countryData]);
9468

9569
const [tooltipContent, setTooltipContent] = useState<TooltipContent | null>(null);
9670
const [tooltipPosition, setTooltipPosition] = useState<TooltipPosition>({
@@ -144,7 +118,6 @@ export function MapComponent({
144118
};
145119
}, [processedCountryData, mode]);
146120

147-
const { data: subdivisionsGeoData } = useSubdivisions();
148121
const { data: countriesGeoData } = useCountries();
149122

150123
const handleStyle = (feature: Feature<any>) => {
@@ -252,7 +225,7 @@ export function MapComponent({
252225
</div>
253226
)}
254227

255-
{(countriesGeoData || subdivisionsGeoData) && (
228+
{(countriesGeoData) && (
256229
<MapContainer
257230
attributionControl={false}
258231
center={[40, 3]}

apps/dashboard/hooks/use-dynamic-query.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,12 @@ export function useMapLocationData(
608608
const queries: DynamicQueryRequest[] = [
609609
{
610610
id: "map-countries",
611-
parameters: ["countries"],
611+
parameters: ["country"],
612612
limit: 100,
613613
},
614614
{
615615
id: "map-regions",
616-
parameters: ["regions"],
616+
parameters: ["region"],
617617
limit: 100,
618618
},
619619
];

0 commit comments

Comments
 (0)