From 732d11b3558f99cbe26bc81f5f1141ab44a61fa5 Mon Sep 17 00:00:00 2001 From: Usman Baig Date: Fri, 16 Jan 2026 19:10:50 +0100 Subject: [PATCH] feat: add country flags to dashboard --- components/dashboard/Countries.tsx | 14 ++++++++++++-- package-lock.json | 8 ++++++++ package.json | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/dashboard/Countries.tsx b/components/dashboard/Countries.tsx index f57e5ce..d54b505 100644 --- a/components/dashboard/Countries.tsx +++ b/components/dashboard/Countries.tsx @@ -1,6 +1,7 @@ 'use client' import { formatNumber } from '@/lib/utils/format' +import * as Flags from 'country-flag-icons/react/3x2' interface CountriesProps { countries: Array<{ country: string; pageviews: number }> @@ -18,6 +19,14 @@ export default function Countries({ countries }: CountriesProps) { ) } + const getFlagComponent = (countryCode: string) => { + if (!countryCode || countryCode === 'Unknown') return null + // * The API returns 2-letter country codes (e.g. US, DE) + // * We cast it to the flag component name + const FlagComponent = (Flags as any)[countryCode] + return FlagComponent ? : null + } + return (

@@ -26,8 +35,9 @@ export default function Countries({ countries }: CountriesProps) {
{countries.map((country, index) => (
-
- {country.country} +
+ {getFlagComponent(country.country)} + {country.country === 'Unknown' ? 'Unknown' : country.country}
{formatNumber(country.pageviews)} diff --git a/package-lock.json b/package-lock.json index 5217edb..34c2917 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "@ciphera-net/ui": "^0.0.6", "@radix-ui/react-icons": "^1.3.2", "axios": "^1.13.2", + "country-flag-icons": "^1.6.4", "framer-motion": "^12.23.26", "next": "^16.1.1", "next-themes": "^0.4.6", @@ -2644,6 +2645,12 @@ "dev": true, "license": "MIT" }, + "node_modules/country-flag-icons": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/country-flag-icons/-/country-flag-icons-1.6.4.tgz", + "integrity": "sha512-Z3Zi419FI889tlElMsVhCIS5eRkiLDWixr576J5DPiTe5RGxpbRi+enMpHdYVp5iK5WFjr8P/RgyIFAGhFsiFg==", + "license": "MIT" + }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -3399,6 +3406,7 @@ "integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@rtsao/scc": "^1.1.0", "array-includes": "^3.1.9", diff --git a/package.json b/package.json index a8ea4ed..bcd7a28 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "@ciphera-net/ui": "^0.0.6", "@radix-ui/react-icons": "^1.3.2", "axios": "^1.13.2", + "country-flag-icons": "^1.6.4", "framer-motion": "^12.23.26", "next": "^16.1.1", "next-themes": "^0.4.6",