Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fixed _root stats page bug

Steven Teycd184b6c2f62
diff --git a/components/stats/toggle.tsx b/components/stats/toggle.tsx
index c93c8fb8ec..090959dfaa 100644
--- a/components/stats/toggle.tsx
+++ b/components/stats/toggle.tsx
@@ -58,7 +58,9 @@ export default function Toggle({
<ExpandingArrow className="h-5 w-5" />
</a>
<div className="flex items-center">
- {pageType !== "stats" && <SharePopover domain={domain} />}
+ {pageType !== "stats" && key !== "_root" && (
+ <SharePopover domain={domain} />
+ )}
<Popover
content={
<div className="w-full p-2 md:w-48">
@@ -130,10 +132,9 @@ const SharePopover = ({ domain }: { domain: string }) => {
}
}, [slug]);
- const { data: { publicStats } = {} } = useSWR<{ publicStats: boolean }>(
- endpoint,
- fetcher,
- );
+ const {
+ data: { publicStats },
+ } = useSWR<{ publicStats: boolean }>(endpoint, fetcher);
const handleChange = async () => {
toast.promise(
diff --git a/lib/stats.ts b/lib/stats.ts
index 2a613d80df..7435e3c9e7 100644
--- a/lib/stats.ts
+++ b/lib/stats.ts
@@ -128,10 +128,10 @@ export const getStats = async ({
// get all-time clicks count if:
// 1. endpoint is /clicks
- // 2. interval is not defined
- // 3. there's a connection to MySQL
-
- if (endpoint === "clicks" && !interval && conn) {
+ // 2. key is not _root
+ // 3. interval is not defined
+ // 4. there's a connection to MySQL
+ if (endpoint === "clicks" && key !== "_root" && !interval && conn) {
const response = await conn.execute(
"SELECT clicks FROM Link WHERE domain = ? AND `key` = ?",
[domain, key],
diff --git a/pages/api/projects/[slug]/domains/[domain]/root/clicks.ts b/pages/api/projects/[slug]/domains/[domain]/root/clicks.ts
index 59f4a2705e..147a3f5717 100644
--- a/pages/api/projects/[slug]/domains/[domain]/root/clicks.ts
+++ b/pages/api/projects/[slug]/domains/[domain]/root/clicks.ts
@@ -15,13 +15,7 @@ export default withProjectAuth(
endpoint: "clicks",
});
- let clicks = 0;
- try {
- clicks = response[0]["count()"];
- } catch (e) {
- console.log(e);
- }
- return res.status(200).json(clicks);
+ return res.status(200).json(response);
} else {
res.setHeader("Allow", ["GET"]);
return res