Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

some refactoring and more ui updates

ameer246888c662d08a41
diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
index 01225b41c..de69b941e 100644
--- a/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
+++ b/apps/web/app/(org)/dashboard/_components/Navbar/Items.tsx
@@ -62,6 +62,7 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
{
name: "Analytics",
href: `/dashboard/analytics`,
+ ignoreParams: true,
icon: <ChartLineIcon />,
subNav: [],
},
@@ -84,7 +85,8 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
const [openAIDialog, setOpenAIDialog] = useState(false);
const router = useRouter();
- const isPathActive = (path: string) => pathname.includes(path);
+ const isPathActive = (path: string, ignoreParams: boolean = false) =>
+ ignoreParams ? pathname === path : pathname.includes(path);
const isDomainSetupVerified =
activeOrg?.organization.customDomain &&
activeOrg?.organization.domainVerified;
@@ -273,7 +275,7 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
key={item.name}
className="flex relative justify-center items-center mb-1.5 w-full"
>
- {isPathActive(item.href) && (
+ {isPathActive(item.href, item.ignoreParams) && (
<motion.div
animate={{
width: sidebarCollapsed ? 36 : "100%",
@@ -302,6 +304,7 @@ const AdminNavItems = ({ toggleMobileNav }: Props) => {
toggleMobileNav={toggleMobileNav}
isPathActive={isPathActive}
extraText={item.extraText}
+ ignoreParams={item.ignoreParams ?? false}
/>
</div>
))}
@@ -391,6 +394,7 @@ const NavItem = ({
sidebarCollapsed,
toggleMobileNav,
isPathActive,
+ ignoreParams,
extraText,
}: {
name: string;
@@ -402,8 +406,9 @@ const NavItem = ({
}>;
sidebarCollapsed: boolean;
toggleMobileNav?: () => void;
- isPathActive: (path: string) => boolean;
+ isPathActive: (path: string, ignoreParams: boolean) => boolean;
extraText: number | null | undefined;
+ ignoreParams: boolean;
}) => {
const iconRef = useRef<CogIconHandle>(null);
return (
@@ -424,7 +429,7 @@ const NavItem = ({
sidebarCollapsed
? "flex justify-center items-center px-0 w-full size-9"
: "px-3 py-2 w-full",
- isPathActive(href)
+ isPathActive(href, ignoreParams)
? "bg-transparent pointer-events-none"
: "hover:bg-gray-2",
"flex overflow-hidden justify-start items-center tracking-tight rounded-xl outline-none",
diff --git a/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx b/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
index 266689d28..6290a4cc5 100644
--- a/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
+++ b/apps/web/app/(org)/dashboard/_components/Navbar/Top.tsx
@@ -17,7 +17,7 @@ import clsx from "clsx";
import { AnimatePresence } from "framer-motion";
import { MoreVertical } from "lucide-react";
import Link from "next/link";
-import { usePathname } from "next/navigation";
+import { useParams, usePathname } from "next/navigation";
import { signOut } from "next-auth/react";
import {
cloneElement,
@@ -53,6 +53,7 @@ const Top = () => {
const queryClient = useQueryClient();
const pathname = usePathname();
+ const params = useParams();
const titles: Record<string, string> = {
"/dashboard/caps": "Caps",
@@ -63,6 +64,7 @@ const Top = () => {
"/dashboard/spaces": "Spaces",
"/dashboard/spaces/browse": "Browse Spaces",
"/dashboard/analytics": "Analytics",
+ [`/dashboard/analytics/s/${params.id}`]: "Analytics: cap name",
};
const title = activeSpace
diff --git a/apps/web/app/(org)/dashboard/analytics/components/ChartArea.tsx b/apps/web/app/(org)/dashboard/analytics/components/ChartArea.tsx
index 06ed45b23..732f481e5 100644
--- a/apps/web/app/(org)/dashboard/analytics/components/ChartArea.tsx
+++ b/apps/web/app/(org)/dashboard/analytics/components/ChartArea.tsx
@@ -13,18 +13,40 @@ export const description = "An area chart with gradient fill";
const chartData = Array.from({ length: 24 }, (_, i) => ({
hour: i + 1,
- desktop: Math.floor(Math.random() * 100).toFixed(0),
+ views: Math.floor(Math.random() * 100),
+ comments: Math.floor(Math.random() * 100),
+ reactions: Math.floor(Math.random() * 100),
+ caps: Math.floor(Math.random() * 100),
}));
const chartConfig = {
- desktop: {
- label: "Desktop",
+ views: {
+ label: "Views",
color: "var(--gray-12)",
},
+ comments: {
+ label: "Comments",
+ color: "#3b82f6",
+ },
+ reactions: {
+ label: "Reactions",
+ color: "#60a5fa",
+ },
+ caps: {
+ label: "Caps",
+ color: "#06b6d4",
+ },
} satisfies ChartConfig;
-function ChartArea() {
- const desktopGradientId = useId();
+interface ChartAreaProps {
+ selectedMetric: "caps" | "views" | "comments" | "reactions";
+}
+
+function ChartArea({ selectedMetric }: ChartAreaProps) {
+ const viewsGradientId = useId();
+ const commentsGradientId = useId();
+ const reactionsGradientId = useId();
+ const capsGradientId = useId();
const glowFilterId = useId();
return (
@@ -56,7 +78,6 @@ function ChartArea() {
<YAxis
axisLine={false}
tickMargin={8}
- domain={[0, 100]}
ticks={[0, 20, 40, 60, 80, 100]}
width={16}
allowDataOverflow={false}
@@ -70,20 +91,81 @@ function ChartArea() {
<feMergeNode in="SourceGraphic" />
</feMerge>
</filter>
- <linearGradient id={desktopGradientId} x1="0" y1="0" x2="0" y2="1">
- <stop offset="0%" stopColor="var(--gray-8)" stopOpacity={0.6} />
- <stop offset="95%" stopColor="var(--gray-8)" stopOpacity={0} />
- </linearGradient>
+ {selectedMetric === "views" && (
+ <linearGradient id={viewsGradientId} x1="0" y1="0" x2="0" y2="1">
+ <stop offset="5%" stopColor="var(--gray-8)" stopOpacity={0.5} />
+ <stop offset="95%" stopColor="var(--gray-8)" stopOpacity={0} />
+ </linearGradient>
+ )}
+ {selectedMetric === "comments" && (
+ <linearGradient id={commentsGradientId} x1="0" y1="0" x2="0" y2="1">
+ <stop offset="5%" stopColor="#3b82f6" stopOpacity={0.5} />
+ <stop offset="95%" stopColor="#3b82f6" stopOpacity={0} />
+ </linearGradient>
+ )}
+ {selectedMetric === "reactions" && (
+ <linearGradient
+ id={reactionsGradientId}
+ x1="0"
+ y1="0"
+ x2="0"
+ y2="1"
+ >
+ <stop offset="5%" stopColor="#60a5fa" stopOpacity={0.5} />
+ <stop offset="95%" stopColor="#60a5fa" stopOpacity={0} />
+ </linearGradient>
+ )}
+ {selectedMetric === "caps" && (
+ <linearGradient id={capsGradientId} x1="0" y1="0" x2="0" y2="1">
+ <stop offset="5%" stopColor="#06b6d4" stopOpacity={0.5} />
+ <stop offset="95%" stopColor="#06b6d4" stopOpacity={0} />
+ </linearGradient>
+ )}
</defs>
- <Area
- dataKey="desktop"
- type="natural"
- fill={`url(#${desktopGradientId})`}
- fillOpacity={1}
- stroke="var(--gray-12)"
- strokeWidth={1}
- filter={`url(#${glowFilterId})`}
- />
+ {selectedMetric === "views" && (
+ <Area
+ dataKey="views"
+ type="monotone"
+ fill={`url(#${viewsGradientId})`}
+ fillOpacity={0.4}
+ stroke="var(--gray-12)"
+ strokeWidth={1}
+ filter={`url(#${glowFilterId})`}
+ />
+ )}
+ {selectedMetric === "comments" && (
+ <Area
+ dataKey="comments"
+ type="monotone"
+ fill={`url(#${commentsGradientId})`}
+ fillOpacity={0.4}
+ stroke="#3b82f6"
+ strokeWidth={1}
+ filter={`url(#${glowFilterId})`}
+ />
+ )}
+ {selectedMetric === "reactions" && (
+ <Area
+ dataKey="reactions"
+ type="monotone"
+ fill={`url(#${reactionsGradientId})`}
+ fillOpacity={0.4}
+ stroke="#60a5fa"
+ strokeWidth={1}
+ filter={`url(#${glowFilterId})`}
+ />
+ )}
+ {selectedMetric === "caps" && (
+ <Area
+ dataKey="caps"
+ type="monotone"
+ fill={`url(#${capsGradientId})`}
+ fillOpacity={0.4}
+ stroke="#06b6d4"
+ strokeWidth={1}
+ filter={`url(#${glowFilterId})`}
+ />
+ )}
</AreaChart>
</ChartContainer>
);
diff --git a/apps/web/app/(org)/dashboard/analytics/components/OtherStatBox.tsx b/apps/web/app/(org)/dashboard/analytics/components/OtherStatBox.tsx
new file mode 100644
index 000000000..8a5f4f37f
--- /dev/null
+++ b/apps/web/app/(org)/dashboard/analytics/components/OtherStatBox.tsx
@@ -0,0 +1,32 @@
+import type { FontAwesomeIconProps } from "@fortawesome/react-fontawesome";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { clsx } from "clsx";
+
+interface OtherStatBoxProps {
+ title: string;
+ icon: FontAwesomeIconProps["icon"];
+ children: React.ReactNode;
+ className?: string;
+}
+
+export default function OtherStatBox({
+ title,
+ icon,
+ children,
+ className,
+}: OtherStatBoxProps) {
+ return (
+ <div
+ className={clsx(
+ className,
+ "p-6 space-y-6 w-full rounded-xl border bg-gray-1 border-gray-3 h-fit",
+ )}
+ >
+ <div className="flex gap-2 items-center">
+ <FontAwesomeIcon icon={icon} className="size-4 text-gray-10" />
+ <p className="text-xl font-medium text-gray-12">{title}</p>
+ </div>
+ {children}
+ </div>
+ );
+}
diff --git a/apps/web/app/(org)/dashboard/analytics/components/OtherStats.tsx b/apps/web/app/(org)/dashboard/analytics/components/OtherStats.tsx
index ff2508efb..d986c1c34 100644
--- a/apps/web/app/(org)/dashboard/analytics/components/OtherStats.tsx
+++ b/apps/web/app/(org)/dashboard/analytics/components/OtherStats.tsx
@@ -1,168 +1,57 @@
"use client";
import {
- Logo,
- LogoBadge,
- Table,
- TableBody,
- TableCell,
- TableHead,
- TableHeader,
- TableRow,
-} from "@cap/ui";
-import {
- faAppleWhole,
- faCamera,
faDesktop,
faGlobe,
faMobileScreen,
faRecordVinyl,
- faTablet,
- faUserGroup,
} from "@fortawesome/free-solid-svg-icons";
-import {
- FontAwesomeIcon,
- type FontAwesomeIconProps,
-} from "@fortawesome/react-fontawesome";
-import clsx from "clsx";
-import getUnicodeFlagIcon from "country-flag-icons/unicode";
-import Image from "next/image";
-import CapIcon from "../../_components/AnimatedIcons/Cap";
+import OtherStatBox from "./OtherStatBox";
+import type {
+ BrowserRowData,
+ CapRowData,
+ CityRowData,
+ CountryRowData,
+ DeviceRowData,
+ OSRowData,
+} from "./TableCard";
+import TableCard from "./TableCard";
-const countryCodeToIcon = (countryCode: string) => {
- return getUnicodeFlagIcon(countryCode.toUpperCase());
-};
+export interface OtherStatsData {
+ countries: CountryRowData[];
+ cities: CityRowData[];
+ browsers: BrowserRowData[];
+ operatingSystems: OSRowData[];
+ deviceTypes: DeviceRowData[];
+ topCaps: CapRowData[];
+}
-export default function OtherStats() {
+interface OtherStatsProps {
+ data: OtherStatsData;
+}
+
+export default function OtherStats({ data }: OtherStatsProps) {
return (
<div className="grid grid-cols-1 gap-8 w-full xl:grid-cols-4">
<OtherStatBox className="col-span-2" title="Geography" icon={faGlobe}>
<div className="flex flex-col flex-1 gap-5 justify-center w-full">
<TableCard
title="Countries"
- columns={["Country", "Views", "Percentage"]}
- rows={[
- {
- icon: countryCodeToIcon("US"),
- name: "United States",
- views: "8,452",
- percentage: "34.2%",
- },
- {
- icon: countryCodeToIcon("GB"),
- name: "United Kingdom",
- views: "3,891",
- percentage: "15.7%",
- },
- {
- icon: countryCodeToIcon("CA"),
- name: "Canada",
- views: "2,764",
- percentage: "11.2%",
- },
- {
- icon: countryCodeToIcon("DE"),
- name: "Germany",
- views: "2,143",
- percentage: "8.7%",
- },
- {
- icon: countryCodeToIcon("FR"),
- name: "France",
- views: "1,876",
- percentage: "7.6%",
- },
- {
- icon: countryCodeToIcon("AU"),
- name: "Australia",
- views: "1,542",
- percentage: "6.2%",
- },
- {
- icon: countryCodeToIcon("JP"),
- name: "Japan",
- views: "1,298",
- percentage: "5.2%",
- },
- {
- icon: countryCodeToIcon("BR"),
- name: "Brazil",
- views: "987",
- percentage: "4.0%",
- },
+ columns={[
+ "Country",
+ "Views",
+ "Comments",
+ "Reactions",
+ "Percentage",
]}
+ rows={data.countries}
+ type="country"
/>
<TableCard
title="Cities"
- columns={["City", "Views", "Percentage"]}
- rows={[
- {
- name: "New York",
- icon: countryCodeToIcon("US"),
- views: "3,421",
- percentage: "18.7%",
- },
- {
- name: "Los Angeles",
- icon: countryCodeToIcon("US"),
- views: "2,876",
- percentage: "15.7%",
- },
- {
- name: "London",
- icon: countryCodeToIcon("GB"),
- views: "2,145",
- percentage: "11.7%",
- },
- {
- name: "Toronto",
- icon: countryCodeToIcon("CA"),
- views: "1,892",
- percentage: "10.3%",
- },
- {
- name: "San Francisco",
- icon: countryCodeToIcon("US"),
- views: "1,654",
- percentage: "9.0%",
- },
- {
- name: "Chicago",
- icon: countryCodeToIcon("US"),
- views: "1,432",
- percentage: "7.8%",
- },
- {
- name: "Berlin",
- icon: countryCodeToIcon("DE"),
- views: "1,198",
- percentage: "6.5%",
- },
- {
- name: "Seattle",
- icon: countryCodeToIcon("US"),
- views: "987",
- percentage: "5.4%",
- },
- {
- name: "Sydney",
- icon: countryCodeToIcon("AU"),
- views: "876",
- percentage: "4.8%",
- },
- {
- name: "Paris",
- icon: countryCodeToIcon("FR"),
- views: "743",
- percentage: "4.1%",
- },
- {
- name: "Boston",
- icon: countryCodeToIcon("US"),
- views: "621",
- percentage: "3.4%",
- },
- ]}
+ columns={["City", "Views", "Comments", "Reactions", "Percentage"]}
+ rows={data.cities}
+ type="city"
/>
</div>
</OtherStatBox>
@@ -170,99 +59,27 @@ export default function OtherStats() {
<div className="flex flex-col flex-1 gap-5 justify-center w-full">
<TableCard
title="Browsers"
- columns={["Browser", "Views", "Percentage"]}
- rows={[
- {
- icon: <BrowserIcon browser="google-chrome" />,
- name: "Chrome",
- views: "12,456",
- percentage: "42.3%",
- },
- {
- icon: <BrowserIcon browser="safari" />,
- name: "Safari",
- views: "6,234",
- percentage: "21.2%",
- },
- {
- icon: <BrowserIcon browser="firefox" />,
- name: "Firefox",
- views: "4,187",
- percentage: "14.2%",
- },
- {
- icon: <BrowserIcon browser="explorer" />,
- name: "Edge",
- views: "3,542",
- percentage: "12.0%",
- },
- {
- icon: <BrowserIcon browser="brave" />,
- name: "Brave",
- views: "1,876",
- percentage: "6.4%",
- },
- {
- icon: <BrowserIcon browser="opera" />,
- name: "Opera",
- views: "654",
- percentage: "2.2%",
- },
- {
- icon: <BrowserIcon browser="vivaldi" />,
- name: "Vivaldi",
- views: "298",
- percentage: "1.0%",
- },
- {
- icon: <BrowserIcon browser="yandex" />,
- name: "Yandex",
- views: "143",
- percentage: "0.5%",
- },
- {
- icon: <BrowserIcon browser="duckduckgo" />,
- name: "DuckDuckGo",
- views: "67",
- percentage: "0.2%",
- },
+ columns={[
+ "Browser",
+ "Views",
+ "Comments",
+ "Reactions",
+ "Percentage",
]}
+ rows={data.browsers}
+ type="browser"
/>
<TableCard
title="Operating Systems"
- columns={["Operating System", "Views", "Percentage"]}
- rows={[
- {
- icon: <OperatingSystemIcon operatingSystem="windows" />,
- name: "Windows",
- views: "9,876",
- percentage: "38.7%",
- },
- {
- icon: <OperatingSystemIcon operatingSystem="ios" />,
- name: "macOS",
- views: "7,432",
- percentage: "29.1%",
- },
- {
- icon: <OperatingSystemIcon operatingSystem="linux" />,
- name: "Linux",
- views: "3,654",
- percentage: "14.3%",
- },
- {
- icon: <OperatingSystemIcon operatingSystem="ubuntu" />,
- name: "Ubuntu",
- views: "2,187",
- percentage: "8.6%",
- },
- {
- icon: <OperatingSystemIcon operatingSystem="fedora" />,
- name: "Fedora",
- views: "1,243",
- percentage: "4.9%",
- },
+ columns={[
+ "Operating System",
+ "Views",
+ "Comments",
+ "Reactions",
+ "Percentage",
]}
+ rows={data.operatingSystems}
+ type="os"
/>
</div>
</OtherStatBox>
@@ -274,36 +91,9 @@ export default function OtherStats() {
<div className="flex flex-col flex-1 gap-5 justify-center w-full">
<TableCard
title="Device Type"
- columns={["Device", "Views", "Percentage"]}
- rows={[
- {
- icon: (
- <FontAwesomeIcon icon={faDesktop} className="text-gray-12" />
- ),
- name: "Desktop",
- views: "2,456",
- percentage: "45.6%",
- },
- {
- icon: (
- <FontAwesomeIcon icon={faTablet} className="text-gray-12" />
- ),
- name: "Tablet",
- views: "1,234",
- percentage: "23.4%",
- },
- {
- icon: (
- <FontAwesomeIcon
- icon={faMobileScreen}
- className="text-gray-12"
- />
- ),
- name: "Mobile",
- views: "1,789",
- percentage: "30.9%",
- },
- ]}
+ columns={["Device", "Views", "Comments", "Reactions", "Percentage"]}
+ rows={data.deviceTypes}
+ type="device"
/>
</div>
</OtherStatBox>
@@ -315,215 +105,12 @@ export default function OtherStats() {
<div className="flex flex-col flex-1 gap-5 justify-center w-full">
<TableCard
title="Caps"
- columns={["Cap", "Views", "Percentage"]}
- rows={[
- {
- name: "Product Demo - Q4 2024",
- views: "5,842",
- icon: <LogoBadge className="size-4" />,
- percentage: "28.3%",
- },
- {
- name: "Tutorial: Getting Started",
- views: "4,156",
- icon: <LogoBadge className="size-4" />,
- percentage: "20.1%",
- },
- {
- name: "Team Meeting Highlights",
- views: "3,421",
- icon: <LogoBadge className="size-4" />,
- percentage: "16.6%",
- },
- {
- name: "Bug Fix Walkthrough",
- views: "2,789",
- icon: <LogoBadge className="size-4" />,
- percentage: "13.5%",
- },
- {
- name: "Feature Announcement",
- views: "1,923",
- icon: <LogoBadge className="size-4" />,
- percentage: "9.3%",
- },
- {
- name: "Customer Feedback Review",
- views: "1,245",
- icon: <LogoBadge className="size-4" />,
- percentage: "6.0%",
- },
- {
- name: "Sprint Retrospective",
- views: "876",
- icon: <LogoBadge className="size-4" />,
- percentage: "4.2%",
- },
- {
- name: "Design System Update",
- views: "543",
- icon: <LogoBadge className="size-4" />,
- percentage: "2.6%",
- },
- {
- name: "API Documentation Demo",
- views: "289",
- icon: <LogoBadge className="size-4" />,
- percentage: "1.4%",
- },
- ]}
+ columns={["Cap", "Views", "Comments", "Reactions", "Percentage"]}
+ rows={data.topCaps}
+ type="cap"
/>
</div>
</OtherStatBox>
</div>
);
}
-
-interface OtherStatBoxProps {
- title: string;
- icon: FontAwesomeIconProps["icon"];
- children: React.ReactNode;
- className?: string;
-}
-
-const OtherStatBox = ({
- title,
- icon,
- children,
- className,
-}: OtherStatBoxProps) => {
- return (
- <div
- className={clsx(
- className,
- "p-6 space-y-6 w-full rounded-xl border bg-gray-1 border-gray-3 h-fit",
- )}
- >
- <div className="flex gap-2 items-center">
- <FontAwesomeIcon icon={icon} className="size-4 text-gray-10" />
- <p className="text-xl font-medium text-gray-12">{title}</p>
- </div>
- {children}
- </div>
- );
-};
-
-interface TableCardProps {
- title: string;
- columns: string[];
- tableClassname?: string;
- rows: {
- icon?: string | React.ReactNode;
- name: string;
- views: string;
- comments?: string;
- reactions?: string;
- percentage?: string;
- }[];
-}
-
-const TableCard = ({
- title,
- columns,
- rows,
- tableClassname,
-}: TableCardProps) => {
- return (
- <div className="p-5 w-full rounded-xl border bg-gray-2 border-gray-4">
- <p className="text-lg font-medium text-gray-12">{title}</p>
- <Table
- className={clsx(
- "block pr-2 w-full border-separate border-spacing-y-2 h-[400px] custom-scroll",
- tableClassname,
- )}
- >
- <TableHeader>
- <TableRow>
- {columns.map((column) => (
- <TableHead
- key={column}
- className="sticky top-0 border-b text-nowrap border-gray-4 bg-gray-2 text-gray-10"
- >
- {column}
- </TableHead>
- ))}
- </TableRow>
- </TableHeader>
- <TableBody className="before:content-[''] before:block before:h-2 w-full">
- {rows.map((row) => (
- <TableRow className="cursor-pointer group" key={row.name}>
- <TableCell className="flex gap-2 items-center group-hover:bg-gray-6 group-hover:border-gray-8 transition-colors duration-200 w-full p-2.5 text-sm rounded-l-lg border-l border-y text-gray-11 bg-gray-3 border-gray-5">
- <span className="flex-shrink-0 fill-[var(--gray-12)]">
- {row.icon}
- </span>
- <span className="truncate text-nowrap max-w-[200px]">
- {row.name}
- </span>
- </TableCell>
-
- <TableCell className="p-2.5 text-sm w-full text-gray-11 bg-gray-3 border-y border-gray-5 group-hover:bg-gray-6 group-hover:border-gray-8 transition-colors duration-200">
- {row.views}
- </TableCell>
- <TableCell className="p-2.5 text-sm rounded-r-lg border-r w-full text-gray-11 bg-gray-3 border-y border-gray-5 group-hover:bg-gray-6 group-hover:border-gray-8 transition-colors duration-200">
- {row.percentage}
- </TableCell>
- </TableRow>
- ))}
- </TableBody>
- </Table>
- </div>
- );
-};
-
-type OperatingSystemIconProps = {
- operatingSystem: "windows" | "ios" | "linux" | "fedora" | "ubuntu";
-};
-
-const OperatingSystemIcon = ({ operatingSystem }: OperatingSystemIconProps) => {
- if (operatingSystem === "ios") {
- return <FontAwesomeIcon className="text-gray-12" icon={faAppleWhole} />;
- } else {
- return (
- <Image
- src={`/logos/os/${operatingSystem}.svg`}
- alt={operatingSystem}
- width={16}
- height={16}
- className="size-4"
- />
- );
- }
-};
-
-type BrowserIconProps = {
- browser:
- | "google-chrome"
- | "firefox"
- | "safari"
- | "explorer"
- | "opera"
- | "brave"
- | "vivaldi"
- | "yandex"
- | "duckduckgo"
- | "internet-explorer"
- | "samsung-internet"
- | "uc-browser"
- | "qq-browser"
- | "maxthon"
- | "arora"
- | "lunascape"
- | "lunascape";
-};
-
-const BrowserIcon = ({ browser }: BrowserIconProps) => {
- return (
- <Image
- src={`/logos/browsers/${browser}.svg`}
- alt={browser}
- width={16}
- height={16}
- className="size-4"
- />
- );
-};
diff --git a/apps/web/app/(org)/dashboard/analytics/components/StatsChart.tsx b/apps/web/app/(org)/dashboard/analytics/components/StatsChart.tsx
index d7a5a78da..974d494ca 100644
--- a/apps/web/app/(org)/dashboard/analytics/components/StatsChart.tsx
+++ b/apps/web/app/(org)/dashboard/analytics/components/StatsChart.tsx
@@ -17,64 +17,81 @@ import { classNames } from "@/utils/helpers";
import type { CapIconHandle } from "../../_components/AnimatedIcons/Cap";
import ChartArea from "./ChartArea";
-export default function StatsBox() {
- const [selectedBox, setSelectedBox] = useState<
- "caps" | "views" | "chats" | "reactions" | null
- >(null);
+type boxes = "caps" | "views" | "comments" | "reactions";
+interface StatsChartProps {
+ counts: {
+ caps?: string;
+ views?: string;
+ chats?: string;
+ reactions?: string;
+ };
+ defaultSelectedBox?: boxes;
+}
+
+export default function StatsBox({
+ counts,
+ defaultSelectedBox = "caps",
+}: StatsChartProps) {
+ const [selectedBox, setSelectedBox] = useState<boxes>(defaultSelectedBox);
const capsBoxRef = useRef<CapIconHandle | null>(null);
const viewsBoxRef = useRef<CapIconHandle | null>(null);
const chatsBoxRef = useRef<CapIconHandle | null>(null);
const reactionsBoxRef = useRef<CapIconHandle | null>(null);
- const selectHandler = (box: "caps" | "views" | "chats" | "reactions") => {
+ const selectHandler = (box: boxes) => {
setSelectedBox(box);
- if (selectedBox === box) {
- setSelectedBox(null);
- }
};
return (
<div className="flex flex-col gap-4 px-8 pt-8 w-full rounded-xl border bg-gray-1 border-gray-3">
- <div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-4">
- <StatBox
- onClick={() => selectHandler("caps")}
- isSelected={selectedBox === "caps"}
- title="Caps"
- value="100"
- onMouseEnter={() => capsBoxRef.current?.startAnimation()}
- onMouseLeave={() => capsBoxRef.current?.stopAnimation()}
- icon={<CapIcon ref={capsBoxRef} size={20} />}
- />
- <StatBox
- onClick={() => selectHandler("views")}
- isSelected={selectedBox === "views"}
- title="Views"
- value="2,768"
- onMouseEnter={() => viewsBoxRef.current?.startAnimation()}
- onMouseLeave={() => viewsBoxRef.current?.stopAnimation()}
- icon={<ClapIcon ref={viewsBoxRef} size={20} />}
- />
- <StatBox
- onClick={() => selectHandler("chats")}
- isSelected={selectedBox === "chats"}
- title="Comments"
- value="100"
- onMouseEnter={() => chatsBoxRef.current?.startAnimation()}
- onMouseLeave={() => chatsBoxRef.current?.stopAnimation()}
- icon={<ChatIcon ref={chatsBoxRef} size={20} />}
- />
- <StatBox
- onClick={() => selectHandler("reactions")}
- isSelected={selectedBox === "reactions"}
- title="Reactions"
- value="100"
- onMouseEnter={() => reactionsBoxRef.current?.startAnimation()}
- onMouseLeave={() => reactionsBoxRef.current?.stopAnimation()}
- icon={<ReactionIcon ref={reactionsBoxRef} size={20} />}
- />
+ <div className="flex flex-wrap gap-4">
+ {counts.caps && (
+ <StatBox
+ onClick={() => selectHandler("caps")}
+ isSelected={selectedBox === "caps"}
+ title="Caps"
+ value={counts.caps}
+ onMouseEnter={() => capsBoxRef.current?.startAnimation()}
+ onMouseLeave={() => capsBoxRef.current?.stopAnimation()}
+ icon={<CapIcon ref={capsBoxRef} size={20} />}
+ />
+ )}
+ {counts.views && (
+ <StatBox
+ onClick={() => selectHandler("views")}
+ isSelected={selectedBox === "views"}
+ title="Views"
+ value={counts.views}
+ onMouseEnter={() => viewsBoxRef.current?.startAnimation()}
+ onMouseLeave={() => viewsBoxRef.current?.stopAnimation()}
+ icon={<ClapIcon ref={viewsBoxRef} size={20} />}
+ />
+ )}
+ {counts.chats && (
+ <StatBox
+ onClick={() => selectHandler("comments")}
+ isSelected={selectedBox === "comments"}
+ title="Comments"
+ value={counts.chats}
+ onMouseEnter={() => chatsBoxRef.current?.startAnimation()}
+ onMouseLeave={() => chatsBoxRef.current?.stopAnimation()}
+ icon={<ChatIcon ref={chatsBoxRef} size={20} />}
+ />
+ )}
+ {counts.reactions && (
+ <StatBox
+ onClick={() => selectHandler("reactions")}
+ isSelected={selectedBox === "reactions"}
+ title="Reactions"
+ value={counts.reactions}
+ onMouseEnter={() => reactionsBoxRef.current?.startAnimation()}
+ onMouseLeave={() => reactionsBoxRef.current?.stopAnimation()}
+ icon={<ReactionIcon ref={reactionsBoxRef} size={20} />}
+ />
+ )}
</div>
- <ChartArea />
+ <ChartArea selectedMetric={selectedBox} />
</div>
);
}
@@ -96,7 +113,7 @@ function StatBox({
<div
{...props}
className={classNames(
- "flex flex-col flex-1 gap-2 px-8 py-6 bg-transparent rounded-xl border transition-all duration-200 cursor-pointer group h-fit hover:bg-gray-3 border-gray-5",
+ "flex flex-col flex-1 min-w-[150px] gap-2 px-8 py-6 bg-transparent rounded-xl border transition-all duration-200 cursor-pointer group h-fit hover:bg-gray-3 border-gray-5",
isSelected && "bg-gray-3 border-gray-8",
)}
>
diff --git a/apps/web/app/(org)/dashboard/analytics/components/TableCard.tsx b/apps/web/app/(org)/dashboard/analytics/components/TableCard.tsx
new file mode 100644
index 000000000..c960107bc
--- /dev/null
+++ b/apps/web/app/(org)/dashboard/analytics/components/TableCard.tsx
@@ -0,0 +1,274 @@
+import {
+ LogoBadge,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+} from "@cap/ui";
+import {
+ faAppleWhole,
+ faDesktop,
+ faMobileScreen,
+ faTablet,
+} from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import clsx from "clsx";
+import getUnicodeFlagIcon from "country-flag-icons/unicode";
+import Image from "next/image";
+
+const countryCodeToIcon = (countryCode: string) => {
+ return getUnicodeFlagIcon(countryCode.toUpperCase());
+};
+
+type BrowserType =
+ | "google-chrome"
+ | "firefox"
+ | "safari"
+ | "explorer"
+ | "opera"
+ | "brave"
+ | "vivaldi"
+ | "yandex"
+ | "duckduckgo"
+ | "internet-explorer"
+ | "samsung-internet"
+ | "uc-browser"
+ | "qq-browser"
+ | "maxthon"
+ | "arora"
+ | "lunascape";
+
+type OperatingSystemType = "windows" | "ios" | "linux" | "fedora" | "ubuntu";
+
+type DeviceType = "desktop" | "tablet" | "mobile";
+
+export interface CountryRowData {
+ countryCode: string;
+ name: string;
+ views: string;
+ comments: string;
+ reactions: string;
+ percentage: string;
+}
+
+export interface CityRowData {
+ countryCode: string;
+ name: string;
+ views: string;
+ comments: string;
+ reactions: string;
+ percentage: string;
+}
+
+export interface BrowserRowData {
+ browser: BrowserType;
+ name: string;
+ views: string;
+ comments: string;
+ reactions: string;
+ percentage: string;
+}
+
+export interface OSRowData {
+ os: OperatingSystemType;
+ name: string;
+ views: string;
+ comments: string;
+ reactions: string;
+ percentage: string;
+}
+
+export interface DeviceRowData {
+ device: DeviceType;
+ name: string;
+ views: string;
+ comments: string;
+ reactions: string;
+ percentage: string;
+}
+
+export interface CapRowData {
+ name: string;
+ views: string;
+ comments: string;
+ reactions: string;
+ percentage: string;
+}
+
+export interface TableCardProps {
+ title: string;
+ columns: string[];
+ tableClassname?: string;
+ type: "country" | "city" | "browser" | "os" | "device" | "cap";
+ rows:
+ | CountryRowData[]
+ | CityRowData[]
+ | BrowserRowData[]
+ | OSRowData[]
+ | DeviceRowData[]
+ | CapRowData[];
+}
+
+const TableCard = ({
+ title,
+ columns,
+ rows,
+ type,
+ tableClassname,
+}: TableCardProps) => {
+ return (
+ <div className="p-5 w-full rounded-xl border bg-gray-2 border-gray-4">
+ <p className="text-lg font-medium text-gray-12">{title}</p>
+ <div className="w-full">
+ <Table
+ className={clsx(
+ "w-full border-separate table-fixed border-spacing-y-0",
+ tableClassname,
+ )}
+ >
+ <TableHeader>
+ <TableRow className="w-full">
+ {columns.map((column) => (
+ <TableHead
+ key={column}
+ className="border-b px-[6px] text-nowrap border-gray-4 bg-gray-2 text-gray-10"
+ >
+ {column}
+ </TableHead>
+ ))}
+ </TableRow>
+ </TableHeader>
+ </Table>
+ <div className="h-[400px] overflow-auto custom-scroll pr-2">
+ <Table
+ className={clsx(
+ "w-full border-separate table-fixed border-spacing-y-2",
+ tableClassname,
+ )}
+ >
+ <TableBody className="before:content-[''] before:block w-full">
+ {rows.map((row) => (
+ <TableRow className="w-full" key={row.name}>
+ <TableCell className="p-2.5 text-sm rounded-l-lg border-l border-y text-gray-11 bg-gray-3 border-gray-5">
+ <div className="flex gap-2 items-center min-w-0">
+ <span className="flex-shrink-0 fill-[var(--gray-12)]">
+ {getIconForRow(row, type)}
+ </span>
+ <span className="truncate">{row.name}</span>
+ </div>
+ </TableCell>
+ <TableCell className="p-2.5 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
+ {row.views}
+ </TableCell>
+ <TableCell className="p-2.5 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
+ {row.comments}
+ </TableCell>
+ <TableCell className="p-2.5 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
+ {row.reactions}
+ </TableCell>
+ <TableCell className="p-2.5 text-sm text-nowrap rounded-r-lg border-r text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
+ {row.percentage}
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+const getIconForRow = (
+ row:
+ | CountryRowData
+ | CityRowData
+ | BrowserRowData
+ | OSRowData
+ | DeviceRowData
+ | CapRowData,
+ type: TableCardProps["type"],
+) => {
+ switch (type) {
+ case "country":
+ return countryCodeToIcon((row as CountryRowData).countryCode);
+ case "city":
+ return countryCodeToIcon((row as CityRowData).countryCode);
+ case "browser":
+ return <BrowserIcon browser={(row as BrowserRowData).browser} />;
+ case "os":
+ return <OperatingSystemIcon operatingSystem={(row as OSRowData).os} />;
+ case "device": {
+ const device = (row as DeviceRowData).device;
+ const iconMap = {
+ desktop: faDesktop,
+ tablet: faTablet,
+ mobile: faMobileScreen,
+ };
+ return (
+ <FontAwesomeIcon icon={iconMap[device]} className="text-gray-12" />
+ );
+ }
+ case "cap":
+ return <LogoBadge className="size-4" />;
+ default:
+ return null;
+ }
+};
+
+type OperatingSystemIconProps = {
+ operatingSystem: "windows" | "ios" | "linux" | "fedora" | "ubuntu";
+};
+
+const OperatingSystemIcon = ({ operatingSystem }: OperatingSystemIconProps) => {
+ if (operatingSystem === "ios") {
+ return <FontAwesomeIcon className="text-gray-12" icon={faAppleWhole} />;
+ } else {
+ return (
+ <Image
+ src={`/logos/os/${operatingSystem}.svg`}
+ alt={operatingSystem}
+ width={16}
+ height={16}
+ className="size-4"
+ />
+ );
+ }
+};
+
+type BrowserIconProps = {
+ browser:
+ | "google-chrome"
+ | "firefox"
+ | "safari"
+ | "explorer"
+ | "opera"
+ | "brave"
+ | "vivaldi"
+ | "yandex"
+ | "duckduckgo"
+ | "internet-explorer"
+ | "samsung-internet"
+ | "uc-browser"
+ | "qq-browser"
+ | "maxthon"
+ | "arora"
+ | "lunascape"
+ | "lunascape";
+};
+
+const BrowserIcon = ({ browser }: BrowserIconProps) => {
+ return (
+ <Image
+ src={`/logos/browsers/${browser}.svg`}
+ alt={browser}
+ width={16}
+ height={16}
+ className="size-4"
+ />
+ );
+};
+
+export default TableCard;
diff --git a/apps/web/app/(org)/dashboard/analytics/page.tsx b/apps/web/app/(org)/dashboard/analytics/page.tsx
index 37c38d9d8..bdadbaf0d 100644
--- a/apps/web/app/(org)/dashboard/analytics/page.tsx
+++ b/apps/web/app/(org)/dashboard/analytics/page.tsx
@@ -1,13 +1,386 @@
import Header from "./components/Header";
-import OtherStats from "./components/OtherStats";
+import OtherStats, { type OtherStatsData } from "./components/OtherStats";
import StatsChart from "./components/StatsChart";
export default function AnalyticsPage() {
return (
<div className="space-y-8">
<Header />
- <StatsChart />
- <OtherStats />
+ <StatsChart
+ counts={{
+ caps: "524",
+ views: "2,768",
+ chats: "100",
+ reactions: "170",
+ }}
+ />
+ <OtherStats data={mockData} />
</div>
);
}
+
+const mockData: OtherStatsData = {
+ countries: [
+ {
+ countryCode: "US",
+ name: "United States",
+ views: "8,452",
+ comments: "100",
+ reactions: "100",
+ percentage: "34.2%",
+ },
+ {
+ countryCode: "GB",
+ name: "United Kingdom",
+ views: "3,891",
+ comments: "100",
+ reactions: "100",
+ percentage: "15.7%",
+ },
+ {
+ countryCode: "CA",
+ name: "Canada",
+ views: "2,764",
+ comments: "100",
+ reactions: "100",
+ percentage: "11.2%",
+ },
+ {
+ countryCode: "DE",
+ name: "Germany",
+ views: "2,143",
+ comments: "100",
+ reactions: "100",
+ percentage: "8.7%",
+ },
+ {
+ countryCode: "FR",
+ name: "France",
+ views: "1,876",
+ comments: "100",
+ reactions: "100",
+ percentage: "7.6%",
+ },
+ {
+ countryCode: "AU",
+ name: "Australia",
+ views: "1,542",
+ comments: "100",
+ reactions: "100",
+ percentage: "6.2%",
+ },
+ {
+ countryCode: "JP",
+ name: "Japan",
+ views: "1,298",
+ comments: "100",
+ reactions: "100",
+ percentage: "5.2%",
+ },
+ {
+ countryCode: "BR",
+ name: "Brazil",
+ views: "987",
+ comments: "100",
+ reactions: "100",
+ percentage: "4.0%",
+ },
+ ],
+ cities: [
+ {
+ countryCode: "US",
+ name: "New York",
+ views: "3,421",
+ comments: "100",
+ reactions: "100",
+ percentage: "18.7%",
+ },
+ {
+ countryCode: "US",
+ name: "Los Angeles",
+ views: "2,876",
+ comments: "100",
+ reactions: "100",
+ percentage: "15.7%",
+ },
+ {
+ countryCode: "GB",
+ name: "London",
+ views: "2,145",
+ comments: "100",
+ reactions: "100",
+ percentage: "11.7%",
+ },
+ {
+ countryCode: "CA",
+ name: "Toronto",
+ views: "1,892",
+ comments: "100",
+ reactions: "100",
+ percentage: "10.3%",
+ },
+ {
+ countryCode: "US",
+ name: "San Francisco",
+ views: "1,654",
+ comments: "100",
+ reactions: "100",
+ percentage: "9.0%",
+ },
+ {
+ countryCode: "US",
+ name: "Chicago",
+ views: "1,432",
+ comments: "100",
+ reactions: "100",
+ percentage: "7.8%",
+ },
+ {
+ countryCode: "DE",
+ name: "Berlin",
+ views: "1,198",
+ comments: "100",
+ reactions: "100",
+ percentage: "6.5%",
+ },
+ {
+ countryCode: "US",
+ name: "Seattle",
+ views: "987",
+ comments: "100",
+ reactions: "100",
+ percentage: "5.4%",
+ },
+ {
+ countryCode: "AU",
+ name: "Sydney",
+ views: "876",
+ comments: "100",
+ reactions: "100",
+ percentage: "4.8%",
+ },
+ {
+ countryCode: "FR",
+ name: "Paris",
+ views: "743",
+ comments: "100",
+ reactions: "100",
+ percentage: "4.1%",
+ },
+ {
+ countryCode: "US",
+ name: "Boston",
+ views: "621",
+ comments: "100",
+ reactions: "100",
+ percentage: "3.4%",
+ },
+ ],
+ browsers: [
+ {
+ browser: "google-chrome",
+ name: "Chrome",
+ views: "12,456",
+ comments: "100",
+ reactions: "100",
+ percentage: "42.3%",
+ },
+ {
+ browser: "safari",
+ name: "Safari",
+ views: "6,234",
+ comments: "100",
+ reactions: "100",
+ percentage: "21.2%",
+ },
+ {
+ browser: "firefox",
+ name: "Firefox",
+ views: "4,187",
+ comments: "100",
+ reactions: "100",
+ percentage: "14.2%",
+ },
+ {
+ browser: "explorer",
+ name: "Edge",
+ views: "3,542",
+ comments: "100",
+ reactions: "100",
+ percentage: "12.0%",
+ },
+ {
+ browser: "brave",
+ name: "Brave",
+ views: "1,876",
+ comments: "100",
+ reactions: "100",
+ percentage: "6.4%",
+ },
+ {
+ browser: "opera",
+ name: "Opera",
+ views: "654",
+ comments: "100",
+ reactions: "100",
+ percentage: "2.2%",
+ },
+ {
+ browser: "vivaldi",
+ name: "Vivaldi",
+ views: "298",
+ comments: "100",
+ reactions: "100",
+ percentage: "1.0%",
+ },
+ {
+ browser: "yandex",
+ name: "Yandex",
+ views: "143",
+ comments: "100",
+ reactions: "100",
+ percentage: "0.5%",
+ },
+ {
+ browser: "duckduckgo",
+ name: "DuckDuckGo",
+ views: "67",
+ comments: "100",
+ reactions: "100",
+ percentage: "0.2%",
+ },
+ ],
+ operatingSystems: [
+ {
+ os: "windows",
+ name: "Windows",
+ views: "9,876",
+ comments: "100",
+ reactions: "100",
+ percentage: "38.7%",
+ },
+ {
+ os: "ios",
+ name: "macOS",
+ views: "7,432",
+ comments: "100",
+ reactions: "100",
+ percentage: "29.1%",
+ },
+ {
+ os: "linux",
+ name: "Linux",
+ views: "3,654",
+ comments: "100",
+ reactions: "100",
+ percentage: "14.3%",
+ },
+ {
+ os: "ubuntu",
+ name: "Ubuntu",
+ views: "2,187",
+ comments: "100",
+ reactions: "100",
+ percentage: "8.6%",
+ },
+ {
+ os: "fedora",
+ name: "Fedora",
+ views: "1,243",
+ comments: "100",
+ reactions: "100",
+ percentage: "4.9%",
+ },
+ ],
+ deviceTypes: [
+ {
+ device: "desktop",
+ name: "Desktop",
+ views: "2,456",
+ comments: "100",
+ reactions: "100",
+ percentage: "45.6%",
+ },
+ {
+ device: "tablet",
+ name: "Tablet",
+ views: "1,234",
+ comments: "100",
+ reactions: "100",
+ percentage: "23.4%",
+ },
+ {
+ device: "mobile",
+ name: "Mobile",
+ views: "1,789",
+ comments: "100",
+ reactions: "100",
+ percentage: "30.9%",
+ },
+ ],
+ topCaps: [
+ {
+ name: "Product Demo - Q4 2024",
+ views: "5,842",
+ comments: "100",
+ reactions: "100",
+ percentage: "28.3%",
+ },
+ {
+ name: "Tutorial: Getting Started",
+ views: "4,156",
+ comments: "100",
+ reactions: "100",
+ percentage: "20.1%",
+ },
+ {
+ name: "Team Meeting Highlights",
+ views: "3,421",
+ comments: "100",
+ reactions: "100",
+ percentage: "16.6%",
+ },
+ {
+ name: "Bug Fix Walkthrough",
+ views: "2,789",
+ comments: "100",
+ reactions: "100",
+ percentage: "13.5%",
+ },
+ {
+ name: "Feature Announcement",
+ views: "1,923",
+ comments: "100",
+ reactions: "100",
+ percentage: "9.3%",
+ },
+ {
+ name: "Customer Feedback Review",
+ views: "1,245",
+ comments: "100",
+ reactions: "100",
+ percentage: "6.0%",
+ },
+ {
+ name: "Sprint Retrospective",
+ views: "876",
+ comments: "100",
+ reactions: "100",
+ percentage: "4.2%",
+ },
+ {
+ name: "Design System Update",
+ views: "543",
+ comments: "100",
+ reactions: "100",
+ percentage: "2.6%",
+ },
+ {
+ name: "API Documentation Demo",
+ views: "289",
+ comments: "100",
+ reactions: "100",
+ percentage: "1.4%",
+ },
+ ],
+};
diff --git a/apps/web/app/(org)/dashboard/analytics/s/[id]/page.tsx b/apps/web/app/(org)/dashboard/analytics/s/[id]/page.tsx
new file mode 100644
index 000000000..702eca87f
--- /dev/null
+++ b/apps/web/app/(org)/dashboard/analytics/s/[id]/page.tsx
@@ -0,0 +1,18 @@
+import Header from "../../components/Header";
+import StatsChart from "../../components/StatsChart";
+
+export default function AnalyticsPage() {
+ return (
+ <div className="space-y-8">
+ <Header />
+ <StatsChart
+ counts={{
+ views: "2,768",
+ chats: "100",
+ reactions: "100",
+ }}
+ defaultSelectedBox="views"
+ />
+ </div>
+ );
+}
diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
index eb69e3db8..3e891a435 100644
--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx
@@ -11,6 +11,7 @@ import {
import type { ImageUpload, Video } from "@cap/web-domain";
import { HttpClient } from "@effect/platform";
import {
+ faChartSimple,
faCheck,
faCopy,
faDownload,
@@ -33,7 +34,6 @@ import { type PropsWithChildren, useState } from "react";
import { toast } from "sonner";
import { ConfirmationDialog } from "@/app/(org)/dashboard/_components/ConfirmationDialog";
import { useDashboardContext } from "@/app/(org)/dashboard/Contexts";
-import { useFeatureFlag } from "@/app/Layout/features";
import ProgressCircle, {
useUploadProgress,
} from "@/app/s/[videoId]/_components/ProgressCircle";
@@ -42,7 +42,6 @@ import {
VideoThumbnail,
} from "@/components/VideoThumbnail";
import { useEffectMutation, useRpcClient } from "@/lib/EffectRuntime";
-import { withRpc } from "@/lib/Rpcs";
import { usePublicEnv } from "@/utils/public-env";
import { PasswordDialog } from "../PasswordDialog";
import { SettingsDialog } from "../SettingsDialog";
@@ -362,27 +361,28 @@ export const CapCard = ({
)}
>
{isOwner && (
- <CapCardButton
- tooltipContent="Share"
- onClick={(e) => {
- e.stopPropagation();
- setIsSharingDialogOpen(true);
- }}
- className="delay-0"
- icon={<FontAwesomeIcon icon={faShare} />}
- />
+ <>
+ <CapCardButton
+ tooltipContent="Share"
+ onClick={(e) => {
+ e.stopPropagation();
+ setIsSharingDialogOpen(true);
+ }}
+ className="delay-0"
+ icon={<FontAwesomeIcon icon={faShare} />}
+ />
+ <CapCardButton
+ tooltipContent="Analytics"
+ onClick={(e) => {
+ e.stopPropagation();
+ router.push(`/dashboard/analytics/s/${cap.id}`);
+ }}
+ className="delay-0"
+ icon={<FontAwesomeIcon icon={faChartSimple} />}
+ />
+ </>
)}
- <CapCardButton
- tooltipContent="Download Cap"
- onClick={(e) => {
- e.stopPropagation();
- handleDownload();
- }}
- className="delay-0"
- icon={<FontAwesomeIcon icon={faDownload} />}
- />
-
{!isOwner && (
<CapCardButton
tooltipContent="Copy link"
@@ -417,22 +417,22 @@ export const CapCard = ({
/>
)}
- {isOwner && (
- <DropdownMenu modal={false} onOpenChange={setIsDropdownOpen}>
- <DropdownMenuTrigger asChild suppressHydrationWarning>
- <div>
- <CapCardButton
- tooltipContent="More options"
- className="delay-75"
- icon={<FontAwesomeIcon icon={faEllipsis} />}
- />
- </div>
- </DropdownMenuTrigger>
- <DropdownMenuContent
- align="end"
- sideOffset={5}
- suppressHydrationWarning
- >
+ <DropdownMenu modal={false} onOpenChange={setIsDropdownOpen}>
+ <DropdownMenuTrigger asChild suppressHydrationWarning>
+ <div>
+ <CapCardButton
+ tooltipContent="More options"
+ className="delay-75"
+ icon={<FontAwesomeIcon icon={faEllipsis} />}
+ />
+ </div>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent
+ align="end"
+ sideOffset={5}
+ suppressHydrationWarning
+ >
+ {isOwner && (
<DropdownMenuItem
onClick={(e) => {
e.stopPropagation();
@@ -443,59 +443,75 @@ export const CapCard = ({
<FontAwesomeIcon className="size-3" icon={faGear} />
<p className="text-sm text-gray-12">Settings</p>
</DropdownMenuItem>
- <DropdownMenuItem
- onClick={(e) => {
- e.stopPropagation();
- copyLinkHandler();
- toast.success("Link copied to clipboard");
- }}
- className="flex gap-2 items-center rounded-lg"
- >
- <FontAwesomeIcon className="size-3" icon={faLink} />
- <p className="text-sm text-gray-12">Copy link</p>
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={() => {
- toast.promise(duplicateMutation.mutateAsync(), {
- loading: "Duplicating cap...",
- success: "Cap duplicated successfully",
- error: "Failed to duplicate cap",
- });
- }}
- disabled={duplicateMutation.isPending || cap.hasActiveUpload}
- className="flex gap-2 items-center rounded-lg"
- >
- <FontAwesomeIcon className="size-3" icon={faCopy} />
- <p className="text-sm text-gray-12">Duplicate</p>
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={() => {
- if (!user.isPro) setUpgradeModalOpen(true);
- else setIsPasswordDialogOpen(true);
- }}
- className="flex gap-2 items-center rounded-lg"
- >
- <FontAwesomeIcon
- className="size-3"
- icon={passwordProtected ? faLock : faUnlock}
- />
- <p className="text-sm text-gray-12">
- {passwordProtected ? "Edit password" : "Add password"}
- </p>
- </DropdownMenuItem>
- <DropdownMenuItem
- onClick={(e) => {
- e.stopPropagation();
- setConfirmOpen(true);
- }}
- className="flex gap-2 items-center rounded-lg"
- >
- <FontAwesomeIcon className="size-3" icon={faTrash} />
- <p className="text-sm text-gray-12">Delete Cap</p>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenu>
- )}
+ )}
+ <DropdownMenuItem
+ onClick={(e) => {
+ e.stopPropagation();
+ handleDownload();
+ }}
+ className="flex gap-2 items-center rounded-lg"
+ >
+ <FontAwesomeIcon icon={faDownload} />
+ <p className="text-sm text-gray-12">Download</p>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={(e) => {
+ e.stopPropagation();
+ copyLinkHandler();
+ toast.success("Link copied to clipboard");
+ }}
+ className="flex gap-2 items-center rounded-lg"
+ >
+ <FontAwesomeIcon className="size-3" icon={faLink} />
+ <p className="text-sm text-gray-12">Copy link</p>
+ </DropdownMenuItem>
+ {isOwner && (
+ <>
+ <DropdownMenuItem
+ onClick={() => {
+ toast.promise(duplicateMutation.mutateAsync(), {
+ loading: "Duplicating cap...",
+ success: "Cap duplicated successfully",
+ error: "Failed to duplicate cap",
+ });
+ }}
+ disabled={
+ duplicateMutation.isPending || cap.hasActiveUpload
+ }
+ className="flex gap-2 items-center rounded-lg"
+ >
+ <FontAwesomeIcon className="size-3" icon={faCopy} />
+ <p className="text-sm text-gray-12">Duplicate</p>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={() => {
+ if (!user.isPro) setUpgradeModalOpen(true);
+ else setIsPasswordDialogOpen(true);
+ }}
+ className="flex gap-2 items-center rounded-lg"
+ >
+ <FontAwesomeIcon
+ className="size-3"
+ icon={passwordProtected ? faLock : faUnlock}
+ />
+ <p className="text-sm text-gray-12">
+ {passwordProtected ? "Edit password" : "Add password"}
+ </p>
+ </DropdownMenuItem>
+ <DropdownMenuItem
+ onClick={(e) => {
+ e.stopPropagation();
+ setConfirmOpen(true);
+ }}
+ className="flex gap-2 items-center rounded-lg"
+ >
+ <FontAwesomeIcon className="size-3" icon={faTrash} />
+ <p className="text-sm text-gray-12">Delete Cap</p>
+ </DropdownMenuItem>
+ </>
+ )}
+ </DropdownMenuContent>
+ </DropdownMenu>
<ConfirmationDialog
open={confirmOpen}