🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Implement ErrorState component for improved error handling across various pages, replacing inline error messages with a consistent UI component for better user experience.
Bill Yang28b68ca97a69
diff --git a/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx b/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsxindex ed95706f6..67fc6ee53 100644--- a/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx+++ b/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx@@ -12,6 +12,7 @@ import { IS_CLOUD } from "../../../../../lib/const";import { Row } from "./Row";import { StandardSkeleton } from "./Skeleton";import { StandardSectionDialog } from "./StandardSectionDialog";+import { ErrorState } from "../../../../../components/ErrorState";const MAX_ITEMS_TO_DISPLAY = 10;@@ -82,23 +83,7 @@ export function StandardSection({{isLoading ? (<StandardSkeleton />) : error ? (- <div className="py-6 flex-1 flex flex-col items-center justify-center gap-3 transition-all">- <AlertCircle className="text-amber-400 w-8 h-8" />- <div className="text-center">- <div className="text-neutral-100 font-medium mb-1">Failed to load data</div>- <div className="text-sm text-neutral-400 max-w-md mx-auto mb-3">- {error.message || "An error occurred while fetching data"}- </div>- </div>- <Button- variant="outline"- size="sm"- className="bg-transparent hover:bg-neutral-800 border-neutral-700 text-neutral-300 hover:text-neutral-100"- onClick={() => refetch()}- >- <RefreshCcw className="w-3 h-3" /> Try Again- </Button>- </div>+ <ErrorState title="Failed to load data" message={error.message} refetch={refetch} />) : (<>{itemsForDisplay?.length ? (diff --git a/client/src/app/[site]/errors/components/ErrorDetails.tsx b/client/src/app/[site]/errors/components/ErrorDetails.tsxindex a7eb339dd..b204f6ee7 100644--- a/client/src/app/[site]/errors/components/ErrorDetails.tsx+++ b/client/src/app/[site]/errors/components/ErrorDetails.tsx@@ -16,6 +16,7 @@ import { Browser } from "../../components/shared/icons/Browser";import { CountryFlag } from "../../components/shared/icons/CountryFlag";import { OperatingSystem } from "../../components/shared/icons/OperatingSystem";import { useParams } from "next/navigation";+import { ErrorState } from "../../../../components/ErrorState";interface ErrorDetailsProps {errorMessage: string;@@ -282,13 +283,10 @@ export function ErrorDetails({ errorMessage }: ErrorDetailsProps) {if (isError) {return (- <div className="p-4 bg-neutral-900 border-t border-neutral-800">- <div className="text-center text-red-400">- <AlertTriangle className="w-6 h-6 mx-auto mb-2" />- <p>Error loading error details</p>- <p className="text-sm text-neutral-400">{error?.toString()}</p>- </div>- </div>+ <ErrorState+ title="Failed to load errors"+ message="There was a problem fetching the errors. Please try again later."+ />);}diff --git a/client/src/app/[site]/events/components/EventLog.tsx b/client/src/app/[site]/events/components/EventLog.tsxindex 863a56efa..171d16fb4 100644--- a/client/src/app/[site]/events/components/EventLog.tsx+++ b/client/src/app/[site]/events/components/EventLog.tsx@@ -5,6 +5,7 @@ import { useGetEventsInfinite } from "../../../../api/analytics/events/useGetEveimport { NothingFound } from "../../../../components/NothingFound";import { formatter } from "../../../../lib/utils";import { EventLogItem, EventLogItemSkeleton } from "./EventLogItem";+import { ErrorState } from "../../../../components/ErrorState";export function EventLog() {const containerRef = useRef<HTMLDivElement>(null);@@ -57,7 +58,12 @@ export function EventLog() {}if (isError) {- return <div className="text-center py-8 text-neutral-400">Error loading events. Please try again.</div>;+ return (+ <ErrorState+ title="Failed to load events"+ message="There was a problem fetching the events. Please try again later."+ />+ );}if (allEvents.length === 0) {diff --git a/client/src/app/[site]/funnels/page.tsx b/client/src/app/[site]/funnels/page.tsxindex f38c0fbdd..9b6912aef 100644--- a/client/src/app/[site]/funnels/page.tsx+++ b/client/src/app/[site]/funnels/page.tsx@@ -14,6 +14,7 @@ import { MobileSidebar } from "../components/Sidebar/MobileSidebar";import { SubHeader } from "../components/SubHeader/SubHeader";import { Input } from "@/components/ui/input";import { useMemo, useState } from "react";+import { ErrorState } from "../../../components/ErrorState";// Skeleton for the funnel row componentconst FunnelRowSkeleton = () => (@@ -110,9 +111,10 @@ export default function FunnelsPage() {))}</div>) : error ? (- <div className="p-4 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 rounded-lg">- Failed to load funnels: {error instanceof Error ? error.message : "Unknown error"}- </div>+ <ErrorState+ title="Failed to load funnels"+ message="There was a problem fetching the funnels. Please try again later."+ />) : filteredFunnels?.length ? (<div className="space-y-4">{filteredFunnels.map((funnel: SavedFunnel, index: number) => (diff --git a/client/src/app/[site]/retention/page.tsx b/client/src/app/[site]/retention/page.tsxindex f0c47e071..a2b3177c1 100644--- a/client/src/app/[site]/retention/page.tsx+++ b/client/src/app/[site]/retention/page.tsx@@ -13,6 +13,7 @@ import { Tabs, TabsList, TabsTrigger } from "../../../components/ui/tabs";import { useSetPageTitle } from "../../../hooks/useSetPageTitle";import { MobileSidebar } from "../components/Sidebar/MobileSidebar";import { RetentionChart } from "./RetentionChart";+import { ErrorState } from "../../../components/ErrorState";// Available time range options (in days)const RANGE_OPTIONS = [@@ -155,12 +156,10 @@ export default function RetentionPage() {<div className="pt-4"><Card><CardContent>- <div className="p-8 text-center">- <div className="text-red-500 mb-2 font-medium">Error loading retention data</div>- <p className="text-neutral-500 text-sm">- There was a problem fetching the retention data. Please try again later.- </p>- </div>+ <ErrorState+ title="Failed to load retention data"+ message="There was a problem fetching the retention data. Please try again later."+ /></CardContent></Card></div>diff --git a/client/src/app/[site]/users/page.tsx b/client/src/app/[site]/users/page.tsxindex 1fb11e4f9..85770576c 100644--- a/client/src/app/[site]/users/page.tsx+++ b/client/src/app/[site]/users/page.tsx@@ -29,6 +29,7 @@ import { Browser } from "../components/shared/icons/Browser";import { CountryFlag } from "../components/shared/icons/CountryFlag";import { OperatingSystem } from "../components/shared/icons/OperatingSystem";import { SubHeader } from "../components/SubHeader/SubHeader";+import { ErrorState } from "../../../components/ErrorState";// Set up column helperconst columnHelper = createColumnHelper<UsersResponse>();@@ -263,7 +264,12 @@ export default function UsersPage() {});if (isError) {- return <div className="p-8 text-center text-red-500">An error occurred while fetching users data.</div>;+ return (+ <ErrorState+ title="Failed to load users"+ message="There was a problem fetching the users. Please try again later."+ />+ );}return (diff --git a/client/src/components/ErrorState.tsx b/client/src/components/ErrorState.tsxnew file mode 100644index 000000000..ba7c083b8--- /dev/null+++ b/client/src/components/ErrorState.tsx@@ -0,0 +1,26 @@+import { AlertCircle, RefreshCcw } from "lucide-react";+import { Button } from "./ui/button";++export function ErrorState({ title, message, refetch }: { title: string; message: string; refetch?: () => void }) {+ return (+ <div className="py-6 flex-1 flex flex-col items-center justify-center gap-3 transition-all">+ <AlertCircle className="text-amber-400 w-8 h-8" />+ <div className="text-center">+ <div className="text-neutral-100 font-medium mb-1">{title || "Failed to load data"}</div>+ <div className="text-sm text-neutral-400 max-w-md mx-auto mb-3">+ {message || "An error occurred while fetching data"}+ </div>+ </div>+ {refetch && (+ <Button+ variant="outline"+ size="sm"+ className="bg-transparent hover:bg-neutral-800 border-neutral-700 text-neutral-300 hover:text-neutral-100"+ onClick={() => refetch()}+ >+ <RefreshCcw className="w-3 h-3" /> Try Again+ </Button>+ )}+ </div>+ );+}