Skip to content

Commit e509ad6

Browse files
committed
fix: performance tabs and timezone error handling / zod
1 parent d0ffed4 commit e509ad6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

apps/api/src/query/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const QuerySchema = z.object({
1717
groupBy: z.array(z.string()).optional(),
1818
orderBy: z.string().optional(),
1919
limit: z.number().min(1).max(1000).optional(),
20-
offset: z.number().min(0).optional()
20+
offset: z.number().min(0).optional(),
21+
timezone: z.string().optional()
2122
});
2223

2324
export const executeQuery = async (request: QueryRequest, websiteDomain?: string | null, timezone?: string) => {

apps/dashboard/app/(main)/websites/[id]/_components/tabs/performance-tab.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import type { FullTabProps } from "../utils/types";
2121
import { getCountryCode, getCountryName } from "@databuddy/shared";
2222

2323
const getPerformanceRating = (score: number): { rating: string; className: string } => {
24+
if (typeof score !== "number" || Number.isNaN(score)) {
25+
return { rating: "Unknown", className: "text-muted-foreground" };
26+
}
2427
if (score >= 90) return { rating: "Excellent", className: "text-green-500" };
2528
if (score >= 70) return { rating: "Good", className: "text-green-500" };
2629
if (score >= 50) return { rating: "Moderate", className: "text-yellow-500" };
@@ -337,14 +340,23 @@ export function WebsitePerformanceTab({
337340
};
338341

339342
const getRegionCountryIcon = (name: string) => {
343+
if (typeof name !== "string" || !name.includes(",")) {
344+
return <CountryFlag country={""} size={16} />;
345+
}
340346
const countryPart = name.split(",")[1]?.trim();
341347
const code = getCountryCode(countryPart || "");
342348
return <CountryFlag country={code} size={16} />;
343349
};
344350

345351
const formatRegionName = (name: string) => {
352+
if (typeof name !== "string" || !name.includes(",")) {
353+
return name || "Unknown region";
354+
}
346355
const [region, countryPart] = name.split(",").map(s => s.trim());
347-
const code = getCountryCode(countryPart || "");
356+
if (!region || !countryPart) {
357+
return name || "Unknown region";
358+
}
359+
const code = getCountryCode(countryPart);
348360
const countryName = getCountryName(code);
349361
if (countryName && region && countryName.toLowerCase() === region.toLowerCase()) {
350362
return countryName;

0 commit comments

Comments
 (0)