Skip to content

Commit 0f22db2

Browse files
committed
refactor(dashboard): route users pages through formatCountryName
1 parent d9c34f0 commit 0f22db2

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

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

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

33
import {
4+
formatCountryName,
45
getCountryCode,
5-
getCountryName,
66
} from "@databuddy/shared/country-codes";
77
import type { ProfileSession, Session } from "@/types/sessions";
88
import { notFound, useParams, useRouter } from "next/navigation";
@@ -443,7 +443,7 @@ function Header({
443443
const countryCode = userProfile
444444
? getCountryCode(userProfile.country || "")
445445
: "";
446-
const countryName = getCountryName(countryCode) || userProfile?.country || "";
446+
const countryName = formatCountryName(userProfile?.country);
447447
const isReturning = (userProfile?.total_sessions ?? 0) > 1;
448448

449449
return (
@@ -594,10 +594,7 @@ export default function UserDetailPage() {
594594
userProfile.region && userProfile.region !== "Unknown"
595595
? userProfile.region
596596
: undefined;
597-
const countryName =
598-
getCountryName(getCountryCode(userProfile.country || "")) ||
599-
userProfile.country ||
600-
"Unknown";
597+
const countryName = formatCountryName(userProfile.country) || "Unknown";
601598
const metrics = [
602599
{ label: "Sessions", value: totalSessions },
603600
{ label: "Pageviews", value: userProfile.total_pageviews ?? 0 },

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import { getDeviceIcon } from "@/components/device-icon";
1616
import { dynamicQueryFiltersAtom } from "@/stores/jotai/filterAtoms";
1717
import type { DynamicQueryFilter } from "@/stores/jotai/filterAtoms";
1818
import {
19+
formatCountryName,
1920
getCountryCode,
20-
getCountryName,
2121
} from "@databuddy/shared/country-codes";
2222
import type { ProfileData } from "@/types/analytics";
2323
import {
@@ -363,9 +363,8 @@ export default function UsersPage() {
363363
id: "location",
364364
header: "Location",
365365
cell: ({ row }) => {
366-
const country = row.original.country || "";
367-
const countryCode = getCountryCode(country);
368-
const countryName = getCountryName(countryCode);
366+
const countryCode = getCountryCode(row.original.country || "");
367+
const countryName = formatCountryName(row.original.country);
369368
const isUnknown = !countryCode || countryCode === "Unknown";
370369

371370
return (
@@ -376,7 +375,7 @@ export default function UsersPage() {
376375
<CountryFlag country={countryCode} size="sm" />
377376
)}
378377
<span className="truncate text-sm">
379-
{isUnknown ? "Unknown" : countryName || countryCode}
378+
{countryName || "Unknown"}
380379
</span>
381380
</div>
382381
);

0 commit comments

Comments
 (0)