diff --git a/app/sites/[id]/page.tsx b/app/sites/[id]/page.tsx index 3b7a8c0..0feb961 100644 --- a/app/sites/[id]/page.tsx +++ b/app/sites/[id]/page.tsx @@ -12,8 +12,6 @@ import RealtimeVisitors from '@/components/dashboard/RealtimeVisitors' import TopPages from '@/components/dashboard/TopPages' import TopReferrers from '@/components/dashboard/TopReferrers' import Countries from '@/components/dashboard/Countries' -import Cities from '@/components/dashboard/Cities' -import Regions from '@/components/dashboard/Regions' import Chart from '@/components/dashboard/Chart' export default function SiteDashboardPage() { @@ -141,12 +139,7 @@ export default function SiteDashboardPage() {
- -
- -
- - +
) diff --git a/components/dashboard/Cities.tsx b/components/dashboard/Cities.tsx deleted file mode 100644 index de277ea..0000000 --- a/components/dashboard/Cities.tsx +++ /dev/null @@ -1,48 +0,0 @@ -'use client' - -import { formatNumber } from '@/lib/utils/format' -import * as Flags from 'country-flag-icons/react/3x2' - -interface CitiesProps { - cities: Array<{ city: string; country: string; pageviews: number }> -} - -export default function Cities({ cities }: CitiesProps) { - if (!cities || cities.length === 0) { - return ( -
-

- Cities -

-

No data available

-
- ) - } - - const getFlagComponent = (countryCode: string) => { - if (!countryCode || countryCode === 'Unknown') return null - const FlagComponent = (Flags as any)[countryCode] - return FlagComponent ? : null - } - - return ( -
-

- Cities -

-
- {cities.map((city, index) => ( -
-
- {getFlagComponent(city.country)} - {city.city === 'Unknown' ? 'Unknown' : city.city} -
-
- {formatNumber(city.pageviews)} -
-
- ))} -
-
- ) -} diff --git a/components/dashboard/Countries.tsx b/components/dashboard/Countries.tsx index ba03ec9..d649778 100644 --- a/components/dashboard/Countries.tsx +++ b/components/dashboard/Countries.tsx @@ -1,23 +1,19 @@ 'use client' +import { useState } from 'react' import { formatNumber } from '@/lib/utils/format' import * as Flags from 'country-flag-icons/react/3x2' -interface CountriesProps { +interface LocationProps { countries: Array<{ country: string; pageviews: number }> + cities: Array<{ city: string; country: string; pageviews: number }> + regions: Array<{ region: string; country: string; pageviews: number }> } -export default function Countries({ countries }: CountriesProps) { - if (!countries || countries.length === 0) { - return ( -
-

- Countries -

-

No data available

-
- ) - } +type Tab = 'countries' | 'regions' | 'cities' + +export default function Locations({ countries, cities, regions }: LocationProps) { + const [activeTab, setActiveTab] = useState('countries') const getFlagComponent = (countryCode: string) => { if (!countryCode || countryCode === 'Unknown') return null @@ -37,24 +33,111 @@ export default function Countries({ countries }: CountriesProps) { } } + const renderContent = () => { + if (activeTab === 'countries') { + if (!countries || countries.length === 0) { + return

No data available

+ } + return ( +
+ {countries.map((country, index) => ( +
+
+ {getFlagComponent(country.country)} + {getCountryName(country.country)} +
+
+ {formatNumber(country.pageviews)} +
+
+ ))} +
+ ) + } + + if (activeTab === 'regions') { + if (!regions || regions.length === 0) { + return

No data available

+ } + return ( +
+ {regions.map((region, index) => ( +
+
+ {getFlagComponent(region.country)} + {region.region === 'Unknown' ? 'Unknown' : region.region} +
+
+ {formatNumber(region.pageviews)} +
+
+ ))} +
+ ) + } + + if (activeTab === 'cities') { + if (!cities || cities.length === 0) { + return

No data available

+ } + return ( +
+ {cities.map((city, index) => ( +
+
+ {getFlagComponent(city.country)} + {city.city === 'Unknown' ? 'Unknown' : city.city} +
+
+ {formatNumber(city.pageviews)} +
+
+ ))} +
+ ) + } + } + return ( -
-

- Countries -

-
- {countries.map((country, index) => ( -
-
- {getFlagComponent(country.country)} - {getCountryName(country.country)} -
-
- {formatNumber(country.pageviews)} -
-
- ))} +
+
+

+ Locations +

+
+ + + +
+ {renderContent()}
) } diff --git a/components/dashboard/Regions.tsx b/components/dashboard/Regions.tsx deleted file mode 100644 index 3cf7dc4..0000000 --- a/components/dashboard/Regions.tsx +++ /dev/null @@ -1,48 +0,0 @@ -'use client' - -import { formatNumber } from '@/lib/utils/format' -import * as Flags from 'country-flag-icons/react/3x2' - -interface RegionsProps { - regions: Array<{ region: string; country: string; pageviews: number }> -} - -export default function Regions({ regions }: RegionsProps) { - if (!regions || regions.length === 0) { - return ( -
-

- Regions -

-

No data available

-
- ) - } - - const getFlagComponent = (countryCode: string) => { - if (!countryCode || countryCode === 'Unknown') return null - const FlagComponent = (Flags as any)[countryCode] - return FlagComponent ? : null - } - - return ( -
-

- Regions -

-
- {regions.map((region, index) => ( -
-
- {getFlagComponent(region.country)} - {region.region === 'Unknown' ? 'Unknown' : region.region} -
-
- {formatNumber(region.pageviews)} -
-
- ))} -
-
- ) -}