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.

return dashboardId

Kiran K7c3ceea8f2c5
diff --git a/apps/web/lib/api/links/get-links-for-workspace.ts b/apps/web/lib/api/links/get-links-for-workspace.ts
index 17e21243bf..42f37e24b7 100644
--- a/apps/web/lib/api/links/get-links-for-workspace.ts
+++ b/apps/web/lib/api/links/get-links-for-workspace.ts
@@ -84,7 +84,7 @@ export async function getLinksForWorkspace({
orderBy: {
[sort]: "desc",
},
- take: 1,
+ take: pageSize,
skip: (page - 1) * pageSize,
});
diff --git a/apps/web/lib/api/links/utils/transform-link.ts b/apps/web/lib/api/links/utils/transform-link.ts
index e758669d19..01f6419821 100644
--- a/apps/web/lib/api/links/utils/transform-link.ts
+++ b/apps/web/lib/api/links/utils/transform-link.ts
@@ -1,8 +1,9 @@
-import { Link, Tag } from "@prisma/client";
+import { Dashboard, Link, Tag } from "@prisma/client";
export type LinkWithTags = Link & {
tags?: { tag: Pick<Tag, "id" | "name" | "color"> }[];
webhooks?: { webhookId: string }[];
+ dashboard?: Dashboard | null;
};
// Transform link with additional properties
@@ -10,8 +11,8 @@ export const transformLink = (link: LinkWithTags) => {
const tags = (link.tags || []).map(({ tag }) => tag);
const webhookIds = link.webhooks?.map(({ webhookId }) => webhookId) ?? [];
- // remove webhooks array from link
- const { webhooks, ...rest } = link;
+ // remove webhooks array, dashboard from link
+ const { webhooks, dashboard, ...rest } = link;
return {
...rest,
@@ -20,5 +21,6 @@ export const transformLink = (link: LinkWithTags) => {
webhookIds,
qrCode: `https://api.dub.co/qr?url=${link.shortLink}?qr=1`,
workspaceId: link.projectId ? `ws_${link.projectId}` : null,
+ dashboardId: dashboard?.id || null,
};
};
diff --git a/apps/web/lib/swr/use-links.ts b/apps/web/lib/swr/use-links.ts
index 46112cd18c..fb5c938ac7 100644
--- a/apps/web/lib/swr/use-links.ts
+++ b/apps/web/lib/swr/use-links.ts
@@ -34,6 +34,7 @@ export default function useLinks(
workspaceId,
includeUser: "true",
includeWebhooks: "true",
+ includeDashboard: "true",
...opts,
},
{
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 44d2813a29..c6c66f756e 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -22,6 +22,7 @@ export type LinkProps = Link;
export interface LinkWithTagsProps extends LinkProps {
tags: TagProps[];
webhookIds: string[];
+ dashboardId: string | null;
}
export interface SimpleLinkProps {
diff --git a/apps/web/ui/links/link-details-column.tsx b/apps/web/ui/links/link-details-column.tsx
index 01dce7fa5d..b482b5eb9e 100644
--- a/apps/web/ui/links/link-details-column.tsx
+++ b/apps/web/ui/links/link-details-column.tsx
@@ -3,12 +3,20 @@ import { TagProps } from "@/lib/types";
import {
Button,
CardList,
+ Copy,
+ Tick,
Tooltip,
useMediaQuery,
useRouterStuff,
} from "@dub/ui";
import { CursorRays, InvoiceDollar, UserCheck } from "@dub/ui/src/icons";
-import { cn, currencyFormatter, nFormatter, timeAgo } from "@dub/utils";
+import {
+ APP_DOMAIN,
+ cn,
+ currencyFormatter,
+ nFormatter,
+ timeAgo,
+} from "@dub/utils";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
import {
@@ -18,6 +26,7 @@ import {
useRef,
useState,
} from "react";
+import { toast } from "sonner";
import { useShareDashboardModal } from "../modals/share-dashboard-modal";
import { LinkControls } from "./link-controls";
import { ResponseLink } from "./links-container";
@@ -129,6 +138,7 @@ function AnalyticsBadge({ link }: { link: ResponseLink }) {
const { slug } = useWorkspace();
const { isMobile } = useMediaQuery();
const { variant } = useContext(CardList.Context);
+ const [copied, setCopied] = useState(false);
const stats = useMemo(
() => [
@@ -197,14 +207,37 @@ function AnalyticsBadge({ link }: { link: ResponseLink }) {
})}`
: "No clicks yet"}
</p>
- <Button
- text="Share dashboard"
- className="h-7 px-2"
- onClick={() => {
- setShowShareDashboardModal(true);
- setModalShowCount((c) => c + 1);
- }}
- />
+
+ <div className="inline-flex items-start justify-start gap-2">
+ <Button
+ text={link.dashboardId ? "Edit sharing" : "Share dashboard"}
+ className="h-7 w-full px-2"
+ onClick={() => {
+ setShowShareDashboardModal(true);
+ setModalShowCount((c) => c + 1);
+ }}
+ />
+
+ {link.dashboardId && (
+ <button
+ className="inline-flex h-7 items-center justify-center rounded-md border border-neutral-300 bg-white p-2 hover:bg-gray-50 active:bg-gray-100"
+ onClick={() => {
+ navigator.clipboard.writeText(
+ `${APP_DOMAIN}/share/${link.dashboardId}`,
+ );
+ setCopied(true);
+ toast.success("Copied to clipboard");
+ setTimeout(() => setCopied(false), 3000);
+ }}
+ >
+ {copied ? (
+ <Tick className="h-4 w-4 text-gray-500" />
+ ) : (
+ <Copy className="h-4 w-4 text-gray-500" />
+ )}
+ </button>
+ )}
+ </div>
</div>
}
>