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.

Add new paywall state

Tim Wilsond24527f2e60e
diff --git a/apps/web/ui/analytics/events/events-table.tsx b/apps/web/ui/analytics/events/events-table.tsx
index 95498f3374..613d3a291b 100644
--- a/apps/web/ui/analytics/events/events-table.tsx
+++ b/apps/web/ui/analytics/events/events-table.tsx
@@ -29,6 +29,7 @@ import z from "zod";
import { AnalyticsContext } from "../analytics-provider";
import DeviceIcon from "../device-icon";
import EditColumnsButton from "./edit-columns-button";
+import { exampleData } from "./example-data";
import ExportButton from "./export-button";
import usePagination from "./use-pagination";
@@ -417,7 +418,7 @@ export default function EventsTable() {
const needsHigherPlan = Boolean(error?.message?.includes("Need higher plan"));
const { table, ...tableProps } = useTable({
- data: data ?? defaultData,
+ data: data ?? (needsHigherPlan ? exampleData[tab] : defaultData),
loading: isLoading,
error: error && !needsHigherPlan ? "Failed to fetch events." : undefined,
columns,
@@ -444,15 +445,7 @@ export default function EventsTable() {
</>
);
},
- emptyState: needsHigherPlan ? (
- <EmptyState
- icon={Menu3}
- title="Real-time Events Stream"
- description={`Want more data on your ${tab === "clicks" ? "link clicks & QR code scans" : tab}? Upgrade to our Business Plan to get a detailed, real-time stream of events in your workspace.`}
- buttonText="Upgrade to Business"
- buttonLink={`/${workspaceId}/settings/billing?upgrade=business`}
- />
- ) : (
+ emptyState: (
<EmptyState
icon={Magnifier}
title="No events recorded"
@@ -489,7 +482,22 @@ export default function EventsTable() {
</div>
</div>
<div className="mt-3">
- <Table {...tableProps} table={table} />
+ <Table {...tableProps} table={table}>
+ {needsHigherPlan && (
+ <>
+ <div className="absolute inset-0 flex touch-pan-y items-center justify-center bg-gradient-to-t from-[#fff_70%] to-[#fff6]">
+ <EmptyState
+ icon={Menu3}
+ title="Real-time Events Stream"
+ description={`Want more data on your ${tab === "clicks" ? "link clicks & QR code scans" : tab}? Upgrade to our Business Plan to get a detailed, real-time stream of events in your workspace.`}
+ buttonText="Upgrade to Business"
+ buttonLink={`/${workspaceId}/settings/billing?upgrade=business`}
+ />
+ </div>
+ <div className="h-[400px]" />
+ </>
+ )}
+ </Table>
</div>
</div>
);
diff --git a/apps/web/ui/analytics/events/example-data.ts b/apps/web/ui/analytics/events/example-data.ts
new file mode 100644
index 0000000000..dceaa9921e
--- /dev/null
+++ b/apps/web/ui/analytics/events/example-data.ts
@@ -0,0 +1,209 @@
+export const exampleData = {
+ clicks: [
+ {
+ timestamp: "2024-06-09T16:12:02.556Z",
+ click_id: "1",
+ country: "US",
+ city: "San Francisco",
+ device: "Desktop",
+ browser: "Chrome",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ link: {
+ id: "1",
+ domain: "dub.link",
+ key: "uxUrVCz",
+ url: "https://dub.co/",
+ },
+ },
+ {
+ timestamp: "2024-06-09T15:52:02.556Z",
+ click_id: "2",
+ country: "US",
+ city: "San Francisco",
+ device: "Desktop",
+ browser: "Chrome",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ link: {
+ id: "2",
+ domain: "dub.link",
+ key: "cHT2sg4",
+ url: "https://google.com",
+ },
+ },
+ {
+ timestamp: "2024-06-08T13:32:02.556Z",
+ click_id: "3",
+ country: "US",
+ city: "New York",
+ device: "Desktop",
+ browser: "Firefox",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ link: {
+ id: "3",
+ domain: "git.new",
+ key: "9XyzIho",
+ url: "https://github.com/dubinc/dub",
+ },
+ },
+ ],
+ leads: [
+ {
+ timestamp: "2024-06-11T17:03:56.000Z",
+ event_id: "YbL8RwLTRRCxQz5H",
+ event_name: "Sign up",
+ country: "US",
+ city: "San Francisco",
+ device: "Desktop",
+ browser: "Chrome",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ ip: "",
+ link: {
+ id: "1",
+ domain: "dub.link",
+ key: "uxUrVCz",
+ url: "https://dub.co/",
+ },
+ customer: {
+ name: "Steven",
+ email: "",
+ avatar: "https://avatar.vercel.sh/s.png?text=S",
+ },
+ },
+ {
+ timestamp: "2024-06-10T16:07:56.000Z",
+ event_id: "YbL8RwLTRRCxQz5H",
+ event_name: "Sign up",
+ country: "IN",
+ city: "Kerala",
+ device: "Desktop",
+ browser: "Chrome",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ ip: "",
+ link: {
+ id: "1",
+ domain: "dub.link",
+ key: "uxUrVCz",
+ url: "https://dub.co/",
+ },
+ customer: {
+ name: "Kiran",
+ email: "",
+ avatar: "https://avatar.vercel.sh/k.png?text=K",
+ },
+ },
+ {
+ timestamp: "2024-06-10T16:07:56.000Z",
+ event_id: "YbL8RwLTRRCxQz5H",
+ event_name: "Sign up",
+ country: "US",
+ city: "Pittsburgh",
+ device: "Desktop",
+ browser: "Chrome",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ ip: "",
+ link: {
+ id: "1",
+ domain: "dub.link",
+ key: "uxUrVCz",
+ url: "https://dub.co/",
+ },
+ customer: {
+ name: "Tim",
+ email: "",
+ avatar: "https://avatar.vercel.sh/t.png?text=T",
+ },
+ },
+ ],
+ sales: [
+ {
+ timestamp: "2024-06-14T18:36:01.000Z",
+ event_id: "Nffk2cwShKu5lQ7E",
+ event_name: "Purchase",
+ payment_processor: "stripe",
+ invoice_id: "123456",
+ amount: 900,
+ country: "US",
+ city: "San Francisco",
+ device: "Desktop",
+ browser: "Chrome",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ link: {
+ id: "clx97xeyl00017deqwbuvqmq7",
+ domain: "dub.localhost",
+ key: "0SHZh1V",
+ url: "https://dub.co/",
+ },
+ customer: {
+ name: "Steven",
+ email: "",
+ avatar: "https://avatar.vercel.sh/s.png?text=S",
+ },
+ },
+ {
+ timestamp: "2024-06-13T20:36:06.000Z",
+ event_id: "Nffk2cwShKu5lQ7E",
+ event_name: "Purchase",
+ payment_processor: "stripe",
+ invoice_id: "123456",
+ amount: 700,
+ country: "US",
+ city: "Pittsburgh",
+ device: "Desktop",
+ browser: "Chrome",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ link: {
+ id: "clx97xeyl00017deqwbuvqmq7",
+ domain: "dub.localhost",
+ key: "0SHZh1V",
+ url: "https://dub.co/",
+ },
+ customer: {
+ name: "Tim",
+ email: "",
+ avatar: "https://avatar.vercel.sh/t.png?text=T",
+ },
+ },
+ {
+ timestamp: "2024-06-13T22:02:06.000Z",
+ event_id: "Nffk2cwShKu5lQ7E",
+ event_name: "Purchase",
+ payment_processor: "stripe",
+ invoice_id: "123456",
+ amount: 1000,
+ country: "IN",
+ city: "Kerala",
+ device: "Desktop",
+ browser: "Chrome",
+ os: "Mac OS",
+ referer: "(direct)",
+ qr: 0,
+ link: {
+ id: "clx97xeyl00017deqwbuvqmq7",
+ domain: "dub.localhost",
+ key: "0SHZh1V",
+ url: "https://dub.co/",
+ },
+ customer: {
+ name: "Kiran",
+ email: "",
+ avatar: "https://avatar.vercel.sh/k.png?text=K",
+ },
+ },
+ ],
+};
diff --git a/packages/ui/src/table/table.tsx b/packages/ui/src/table/table.tsx
index b4ccccdbff..d54ac95a60 100644
--- a/packages/ui/src/table/table.tsx
+++ b/packages/ui/src/table/table.tsx
@@ -12,6 +12,7 @@ import {
import { AnimatePresence, motion } from "framer-motion";
import {
Dispatch,
+ PropsWithChildren,
ReactNode,
SetStateAction,
useEffect,
@@ -57,9 +58,10 @@ type UseTableProps<T> = {
| { pagination?: never; onPaginationChange?: never; rowCount?: never }
);
-type TableProps<T> = UseTableProps<T> & {
- table: TableType<T>;
-};
+type TableProps<T> = UseTableProps<T> &
+ PropsWithChildren<{
+ table: TableType<T>;
+ }>;
export function useTable<T extends any>(
props: UseTableProps<T>,
@@ -133,6 +135,8 @@ export function Table<T>({
table,
pagination,
resourceName,
+ rowCount,
+ children,
}: TableProps<T>) {
// Memoize column sizes to pass to table as CSS variables
const columnSizeVars = useMemo(() => {
@@ -154,7 +158,7 @@ export function Table<T>({
return (
<div className="relative border border-gray-200 bg-white sm:rounded-xl">
{(!error && !!data?.length) || loading ? (
- <div className="min-h-[400px] overflow-x-auto rounded-[inherit]">
+ <div className="relative min-h-[400px] overflow-x-auto rounded-[inherit]">
<table
className={cn(
[
@@ -270,6 +274,7 @@ export function Table<T>({
))}
</tbody>
</table>
+ {children}
</div>
) : (
<div className="flex h-96 w-full items-center justify-center text-sm text-gray-500">
@@ -278,7 +283,7 @@ export function Table<T>({
`No ${resourceName?.(true) || "items"} found.`}
</div>
)}
- {pagination && !error && !!data?.length && (
+ {pagination && !error && !!data?.length && !!rowCount && (
<div className="sticky bottom-0 mx-auto -mt-px flex w-full max-w-full items-center justify-between rounded-b-[inherit] border-t border-gray-200 bg-white px-4 py-3.5 text-sm leading-6 text-gray-600">
<div>
<span className="hidden sm:inline-block">Viewing</span>{" "}