Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Enhance UI components and streamline functionality

Bill Yang6638ea32e4ec
diff --git a/client/src/app/[site]/components/Header/UsageBanners.tsx b/client/src/app/[site]/components/Header/UsageBanners.tsx
index 874bb8fce..f9cdda201 100644
--- a/client/src/app/[site]/components/Header/UsageBanners.tsx
+++ b/client/src/app/[site]/components/Header/UsageBanners.tsx
@@ -39,7 +39,7 @@ export function UsageBanners() {
site.monthlyEventCount > site.eventLimit
) {
return (
- <Alert variant="destructive" className="mb-3 p-4">
+ <Alert variant="destructive" className="p-4">
<div className="flex items-start space-x-3">
<AlertTriangle className="h-5 w-5 mt-0.5" />
<div className="flex-1">
@@ -78,7 +78,7 @@ export function UsageBanners() {
// If approaching limit (>90%), show warning banner
if (isNearLimit) {
return (
- <Alert className="mb-3 p-4 bg-amber-50 border-amber-200 dark:bg-amber-900/20 dark:border-amber-800">
+ <Alert className="p-4 bg-amber-50 border-amber-200 dark:bg-amber-900/20 dark:border-amber-800">
<div className="flex items-start space-x-3">
<AlertTriangle className="h-5 w-5 mt-0.5 text-amber-500" />
<div className="flex-1">
diff --git a/client/src/app/layout.tsx b/client/src/app/layout.tsx
index 1f68d9e0e..3a155fa7b 100644
--- a/client/src/app/layout.tsx
+++ b/client/src/app/layout.tsx
@@ -84,12 +84,12 @@ export default function RootLayout({
return (
<html lang="en" className="dark">
- <Toaster />
<TooltipProvider>
<body
className={`${inter.className} bg-background text-foreground h-full`}
>
<QueryProvider>{children}</QueryProvider>
+ <Toaster />
</body>
</TooltipProvider>
</html>
diff --git a/client/src/app/login/page.tsx b/client/src/app/login/page.tsx
index ee8824fec..282131906 100644
--- a/client/src/app/login/page.tsx
+++ b/client/src/app/login/page.tsx
@@ -12,7 +12,6 @@ import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert";
import { authClient } from "../../lib/auth";
import { IS_CLOUD } from "../../lib/const";
import { userStore } from "../../lib/userStore";
-import { StandardPage } from "../../components/StandardPage";
import { GithubLogo, GoogleLogo } from "@phosphor-icons/react/dist/ssr";
export default function Page() {
diff --git a/client/src/app/settings/layout.tsx b/client/src/app/settings/layout.tsx
index 068b49942..716062eee 100644
--- a/client/src/app/settings/layout.tsx
+++ b/client/src/app/settings/layout.tsx
@@ -5,6 +5,7 @@ import { Button } from "../../components/ui/button";
import { CreditCard, User, Users } from "lucide-react";
import { usePathname, useRouter } from "next/navigation";
import { StandardPage } from "../../components/StandardPage";
+import { IS_CLOUD } from "../../lib/const";
export default function SettingsLayout({
children,
@@ -50,17 +51,19 @@ export default function SettingsLayout({
<Users size={16} />
Organizations
</Button>
- <Button
- variant={selectedTab === "subscription" ? "default" : "ghost"}
- onClick={() => {
- setSelectedTab("subscription");
- router.push("/settings/subscription");
- }}
- className="justify-start"
- >
- <CreditCard size={16} />
- Subscription
- </Button>
+ {IS_CLOUD && (
+ <Button
+ variant={selectedTab === "subscription" ? "default" : "ghost"}
+ onClick={() => {
+ setSelectedTab("subscription");
+ router.push("/settings/subscription");
+ }}
+ className="justify-start"
+ >
+ <CreditCard size={16} />
+ Subscription
+ </Button>
+ )}
</div>
{children}
</div>
diff --git a/client/src/app/signup/page.tsx b/client/src/app/signup/page.tsx
index 7d3423165..f0225a406 100644
--- a/client/src/app/signup/page.tsx
+++ b/client/src/app/signup/page.tsx
@@ -24,7 +24,7 @@ import { addSite } from "../../api/admin/sites";
import { CodeSnippet } from "../../components/CodeSnippet";
import { Alert, AlertDescription, AlertTitle } from "../../components/ui/alert";
import { authClient } from "../../lib/auth";
-import { BACKEND_URL } from "../../lib/const";
+import { BACKEND_URL, IS_CLOUD } from "../../lib/const";
import { userStore } from "../../lib/userStore";
// Animation variants for step transitions
@@ -242,42 +242,45 @@ export default function SignupPage() {
<ArrowRight className="ml-2 h-4 w-4" />
</Button>
- <div className="relative flex justify-center text-xs uppercase">
- <span className="bg-background px-2 text-muted-foreground">
- Or continue with
- </span>
- </div>
-
- <div className="grid grid-cols-2 gap-2">
- <Button
- type="button"
- variant="outline"
- onClick={() => {
- authClient.signIn.social({
- provider: "google",
- callbackURL: "/",
- });
- }}
- className="transition-all duration-300 hover:bg-muted"
- >
- <GoogleLogo weight="bold" />
- Google
- </Button>
- <Button
- type="button"
- variant="outline"
- onClick={() => {
- authClient.signIn.social({
- provider: "github",
- callbackURL: "/",
- });
- }}
- className="transition-all duration-300 hover:bg-muted"
- >
- <GithubLogo weight="bold" />
- GitHub
- </Button>
- </div>
+ {IS_CLOUD && (
+ <>
+ <div className="relative flex justify-center text-xs uppercase">
+ <span className="bg-background px-2 text-muted-foreground">
+ Or continue with
+ </span>
+ </div>
+ <div className="grid grid-cols-2 gap-2">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => {
+ authClient.signIn.social({
+ provider: "google",
+ callbackURL: "/",
+ });
+ }}
+ className="transition-all duration-300 hover:bg-muted"
+ >
+ <GoogleLogo weight="bold" />
+ Google
+ </Button>
+ <Button
+ type="button"
+ variant="outline"
+ onClick={() => {
+ authClient.signIn.social({
+ provider: "github",
+ callbackURL: "/",
+ });
+ }}
+ className="transition-all duration-300 hover:bg-muted"
+ >
+ <GithubLogo weight="bold" />
+ GitHub
+ </Button>
+ </div>
+ </>
+ )}
<div className="text-center text-sm">
Already have an account?{" "}
<Link
diff --git a/client/src/app/subscribe/page.tsx b/client/src/app/subscribe/page.tsx
index 8ea8e6767..475ece389 100644
--- a/client/src/app/subscribe/page.tsx
+++ b/client/src/app/subscribe/page.tsx
@@ -15,7 +15,7 @@ import { authClient } from "@/lib/auth";
import { STRIPE_PRICES } from "@/lib/stripe";
import { cn } from "@/lib/utils";
import { Check } from "lucide-react";
-import { useEffect, useState } from "react";
+import { useState } from "react";
import { toast } from "sonner";
import { StandardPage } from "../../components/StandardPage";
import { BACKEND_URL } from "../../lib/const";
@@ -88,10 +88,6 @@ function findPriceForTier(
eventLimit: number,
interval: "month" | "year"
): StripePrice | null {
- console.log(
- `Finding price for tier: ${tier}, event limit: ${eventLimit}, interval: ${interval}`
- );
-
// Determine if we need to look for annual plans
const isAnnual = interval === "year";
const namePattern = isAnnual ? `${tier}-annual` : tier;
@@ -105,35 +101,10 @@ function findPriceForTier(
plan.interval === interval
);
- console.log(
- `Filtered plans for ${namePattern} with interval ${interval}:`,
- plans.map((p) => ({
- name: p.name,
- interval: p.interval,
- events: p.limits.events,
- price: p.price,
- }))
- );
-
- if (plans.length === 0) {
- console.warn(`No plans found for ${namePattern} with interval ${interval}`);
- return null;
- }
-
// Find a plan that matches or exceeds the event limit
const matchingPlan = plans.find((plan) => plan.limits.events >= eventLimit);
const selectedPlan = matchingPlan || plans[plans.length - 1] || null;
- if (selectedPlan) {
- console.log(
- `Selected plan: ${selectedPlan.name} (${selectedPlan.interval}) - $${selectedPlan.price} - ${selectedPlan.limits.events} events`
- );
- } else {
- console.log(
- `No plan selected for ${namePattern} with interval ${interval}`
- );
- }
-
// Return the matching plan or the highest tier available
return selectedPlan;
}
@@ -219,7 +190,6 @@ export default function Subscribe() {
throw new Error("Checkout URL not received.");
}
} catch (error: any) {
- console.error("Subscription Error:", error);
toast.error(`Subscription failed: ${error.message}`);
setIsLoading(false); // Stop loading on error
}
diff --git a/client/src/components/SiteCard.tsx b/client/src/components/SiteCard.tsx
index 0fbe5386d..af0fa04e1 100644
--- a/client/src/components/SiteCard.tsx
+++ b/client/src/components/SiteCard.tsx
@@ -30,10 +30,10 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
if (isLoading || isOverviewLoading) {
return (
<div
- className="flex flex-col rounded-lg bg-neutral-900/70 p-5 border border-neutral-800 shadow-lg transition-all duration-300"
+ className="flex flex-col rounded-lg bg-neutral-900/70 p-4 border border-neutral-800 shadow-lg transition-all duration-300"
key={siteId}
>
- <div className="flex justify-between items-center mb-4">
+ <div className="flex justify-between items-center">
<div className="flex gap-3 items-center">
<Skeleton className="w-6 h-6 rounded" />
<Skeleton className="h-6 w-40" />
@@ -45,13 +45,13 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
<Skeleton className="h-[110px] w-full rounded-md" />
</div>
- <div className="grid grid-cols-3 gap-2 mt-4">
- <div className="flex flex-col gap-1 items-center bg-neutral-800/30 rounded-md p-3">
+ <div className="grid grid-cols-3 gap-2 mt-2">
+ <div className="flex flex-col gap-1 items-center bg-neutral-800/50 rounded-md p-2">
<Skeleton className="h-3 w-16 rounded" />
<Skeleton className="h-6 w-10 rounded mt-1" />
</div>
- <div className="flex flex-col gap-1 items-center bg-neutral-800/30 rounded-md p-3">
+ <div className="flex flex-col gap-1 items-center bg-neutral-800/50 rounded-md p-2">
<Skeleton className="h-3 w-16 rounded" />
<Skeleton className="h-6 w-10 rounded mt-1" />
</div>
@@ -65,11 +65,11 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
}
return (
- <div className="flex flex-col rounded-lg bg-neutral-900/70 p-5 border border-neutral-800 shadow-lg hover:shadow-xl hover:border-neutral-700 transition-all duration-300 hover:translate-y-[-2px]">
- <div className="flex justify-between items-center mb-4">
+ <div className="flex flex-col rounded-lg bg-neutral-900/70 p-4 border border-neutral-800 shadow-lg hover:shadow-xl hover:border-neutral-700 transition-all duration-300 hover:translate-y-[-2px]">
+ <div className="flex justify-between items-center">
<Link
href={`/${siteId}`}
- className="group flex gap-3 items-center hover:text-blue-400 transition-colors duration-200"
+ className="group flex gap-3 items-center duration-200"
>
<img
className="w-6 h-6"
@@ -98,17 +98,17 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
)}
</div>
- <div className="grid grid-cols-3 gap-2 mt-4">
- <div className="flex flex-col gap-1 items-center bg-neutral-800/50 rounded-md p-3 hover:bg-neutral-800 transition-colors">
+ <div className="grid grid-cols-3 gap-2 mt-2">
+ <div className="flex flex-col gap-1 items-center bg-neutral-800/50 rounded-md p-2 hover:bg-neutral-800 transition-colors">
<div className="text-xs text-neutral-400">Sessions</div>
- <div className="font-semibold text-lg">
+ <div className="font-semibold">
{overviewData?.data?.sessions?.toLocaleString() || "0"}
</div>
</div>
- <div className="flex flex-col gap-1 items-center bg-neutral-800/50 rounded-md p-3 hover:bg-neutral-800 transition-colors">
+ <div className="flex flex-col gap-1 items-center bg-neutral-800/50 rounded-md p-2 hover:bg-neutral-800 transition-colors">
<div className="text-xs text-neutral-400">Users</div>
- <div className="font-semibold text-lg">
+ <div className="font-semibold">
{overviewData?.data?.users?.toLocaleString() || "0"}
</div>
</div>
@@ -119,7 +119,7 @@ export function SiteCard({ siteId, domain }: SiteCardProps) {
size="sm"
className="w-full h-full border-neutral-700 bg-neutral-800/50 hover:bg-neutral-800 hover:text-blue-400 transition-all"
>
- <span className="mr-1">Details</span>
+ <span className="mr-1">View</span>
<ArrowRight
size={14}
className="transition-transform group-hover:translate-x-0.5"
diff --git a/server/src/cron/index.ts b/server/src/cron/index.ts
index f0d682177..9b3650438 100644
--- a/server/src/cron/index.ts
+++ b/server/src/cron/index.ts
@@ -1,16 +1,17 @@
import * as cron from "node-cron";
import { updateUsersMonthlyUsage } from "./monthly-usage-checker.js";
+import { cleanupOldSessions } from "../db/postgres/session-cleanup.js";
+import { IS_CLOUD } from "../lib/const.js";
export function initializeCronJobs() {
console.log("Initializing cron jobs...");
- // Schedule the monthly usage checker to run every 5 minutes
- cron.schedule("*/5 * * * *", async () => {
- console.log("Running monthly usage checker cron job");
- await updateUsersMonthlyUsage();
- });
-
- updateUsersMonthlyUsage();
+ if (IS_CLOUD) {
+ // Schedule the monthly usage checker to run every 5 minutes
+ cron.schedule("*/5 * * * *", updateUsersMonthlyUsage);
+ updateUsersMonthlyUsage();
+ }
+ cron.schedule("*/60 * * * * *", cleanupOldSessions);
console.log("Cron jobs initialized successfully");
}
diff --git a/server/src/db/postgres/session-cleanup.ts b/server/src/db/postgres/session-cleanup.ts
index d27906216..3b92cfeee 100644
--- a/server/src/db/postgres/session-cleanup.ts
+++ b/server/src/db/postgres/session-cleanup.ts
@@ -41,16 +41,5 @@ export async function cleanupOldSessions() {
RETURNING *
`;
- // console.log(`Cleaned up ${deletedSessions.length} sessions`);
-
- // disabled for now dubvious if we need sessions in clikchouse
- // if (deletedSessions.length > 0) {
- // await insertSessions(
- // deletedSessions.map((e) => ({
- // ...e,
- // start_time: convertPostgresToClickhouse(e.start_time),
- // end_time: convertPostgresToClickhouse(e.end_time),
- // }))
- // );
- // }
+ // console.log(`Cleaned up ${deletedSessions.length} sessions`)
}
diff --git a/server/src/index.ts b/server/src/index.ts
index 0bfa45ac1..98a98d115 100644
--- a/server/src/index.ts
+++ b/server/src/index.ts
@@ -2,7 +2,6 @@ import cors from "@fastify/cors";
import fastifyStatic from "@fastify/static";
import { toNodeHandler } from "better-auth/node";
import Fastify from "fastify";
-import cron from "node-cron";
import { dirname, join } from "path";
import { Headers, HeadersInit } from "undici";
import { fileURLToPath } from "url";
@@ -20,6 +19,7 @@ import { getSession } from "./api/analytics/getSession.js";
import { getSessions } from "./api/analytics/getSessions.js";
import { getSingleCol } from "./api/analytics/getSingleCol.js";
import { getUserInfo } from "./api/analytics/getUserInfo.js";
+import { getUserSessionCount } from "./api/analytics/getUserSessionCount.js";
import { getUserSessions } from "./api/analytics/getUserSessions.js";
import { getUsers } from "./api/analytics/getUsers.js";
import { addSite } from "./api/sites/addSite.js";
@@ -28,6 +28,7 @@ import { changeSitePublic } from "./api/sites/changeSitePublic.js";
import { deleteSite } from "./api/sites/deleteSite.js";
import { getSite } from "./api/sites/getSite.js";
import { getSiteHasData } from "./api/sites/getSiteHasData.js";
+import { getSiteIsPublic } from "./api/sites/getSiteIsPublic.js";
import { getSites } from "./api/sites/getSites.js";
import { createAccount } from "./api/user/createAccount.js";
import { getUserOrganizations } from "./api/user/getUserOrganizations.js";
@@ -35,21 +36,19 @@ import { listOrganizationMembers } from "./api/user/listOrganizationMembers.js";
import { initializeCronJobs } from "./cron/index.js";
import { initializeClickhouse } from "./db/clickhouse/clickhouse.js";
import { initializePostgres } from "./db/postgres/postgres.js";
-import { cleanupOldSessions } from "./db/postgres/session-cleanup.js";
import { allowList, loadAllowedDomains } from "./lib/allowedDomains.js";
import { mapHeaders } from "./lib/auth-utils.js";
import { auth } from "./lib/auth.js";
+import { publicSites } from "./lib/publicSites.js";
import { trackEvent } from "./tracker/trackEvent.js";
import { extractSiteId, isSitePublic } from "./utils.js";
-import { publicSites } from "./lib/publicSites.js";
-import { getSiteIsPublic } from "./api/sites/getSiteIsPublic.js";
-import { getUserSessionCount } from "./api/analytics/getUserSessionCount.js";
// Import Stripe handlers
import { createCheckoutSession } from "./api/stripe/createCheckoutSession.js";
import { createPortalSession } from "./api/stripe/createPortalSession.js";
import { getSubscription } from "./api/stripe/getSubscription.js";
import { handleWebhook } from "./api/stripe/webhook.js";
+import { IS_CLOUD } from "./lib/const.js";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
@@ -217,15 +216,17 @@ server.get(
);
server.get("/user/organizations", getUserOrganizations);
-// Stripe Routes
-server.post("/stripe/create-checkout-session", createCheckoutSession);
-server.post("/stripe/create-portal-session", createPortalSession);
-server.get("/stripe/subscription", getSubscription);
-server.post(
- "/api/stripe/webhook",
- { config: { rawBody: true } },
- handleWebhook
-); // Use rawBody parser config for webhook
+if (IS_CLOUD) {
+ // Stripe Routes
+ server.post("/stripe/create-checkout-session", createCheckoutSession);
+ server.post("/stripe/create-portal-session", createPortalSession);
+ server.get("/stripe/subscription", getSubscription);
+ server.post(
+ "/api/stripe/webhook",
+ { config: { rawBody: true } },
+ handleWebhook
+ ); // Use rawBody parser config for webhook
+}
server.post("/track", trackEvent);
@@ -242,12 +243,6 @@ const start = async () => {
// Start the server
await server.listen({ port: 3001, host: "0.0.0.0" });
- // Start session cleanup cron job
- cron.schedule("*/60 * * * * *", () => {
- cleanupOldSessions();
- });
-
- // Initialize all cron jobs including monthly usage checker
initializeCronJobs();
} catch (err) {
server.log.error(err);