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.

fix displaying redirect

Kiran K488bfcb9713e
diff --git a/apps/web/app/api/domains/route.ts b/apps/web/app/api/domains/route.ts
index 0ef772f294..42c6a07c01 100644
--- a/apps/web/app/api/domains/route.ts
+++ b/apps/web/app/api/domains/route.ts
@@ -13,17 +13,6 @@ export const GET = withWorkspace(async ({ workspace }) => {
where: {
projectId: workspace.id,
},
- include: {
- links: {
- select: {
- url: true,
- rewrite: true,
- clicks: true,
- expiredUrl: true,
- noindex: true,
- },
- },
- },
});
return NextResponse.json(domains);
diff --git a/apps/web/app/api/links/[linkId]/route.ts b/apps/web/app/api/links/[linkId]/route.ts
index 3d8981a1b0..3e0aa77b7b 100644
--- a/apps/web/app/api/links/[linkId]/route.ts
+++ b/apps/web/app/api/links/[linkId]/route.ts
@@ -141,25 +141,6 @@ export const PUT = PATCH;
// DELETE /api/links/[linkId] – delete a link
export const DELETE = withWorkspace(async ({ headers, link }) => {
- if (link?.key === "_root") {
- const linksCount = await prisma.link.count({
- where: {
- domain: link.domain,
- NOT: {
- key: "_root",
- },
- },
- });
-
- if (linksCount > 0) {
- throw new DubApiError({
- code: "forbidden",
- message:
- "You cannot delete the root link. Please delete the domain instead.",
- });
- }
- }
-
await deleteLink(link!.id);
return NextResponse.json(
diff --git a/apps/web/ui/domains/domain-card.tsx b/apps/web/ui/domains/domain-card.tsx
index 196358bcd4..746a3b8fa7 100644
--- a/apps/web/ui/domains/domain-card.tsx
+++ b/apps/web/ui/domains/domain-card.tsx
@@ -47,13 +47,13 @@ import { useTransferDomainModal } from "../modals/transfer-domain-modal";
import DomainConfiguration from "./domain-configuration";
export default function DomainCard({ props }: { props: DomainProps }) {
+ const { slug: domain, primary, archived } = props || {};
+
const { id: workspaceId, slug, plan } = useWorkspace();
const { activeWorkspaceDomains } = useDomains();
- const { slug: domain, primary, archived } = props || {};
-
const { data: linkProps } = useSWR<LinkProps>(
- workspaceId && domain
+ workspaceId && domain && plan != "free"
? `/api/links/info?${new URLSearchParams({ workspaceId, domain, key: "_root" }).toString()}`
: null,
fetcher,
@@ -92,6 +92,7 @@ export default function DomainCard({ props }: { props: DomainProps }) {
const { data: totalEvents } = useSWR<{ clicks: number }>(
workspaceId &&
+ linkProps &&
`/api/analytics?event=clicks&workspaceId=${workspaceId}&domain=${domain}&key=_root&interval=all_unfiltered`,
fetcher,
{
@@ -153,22 +154,26 @@ export default function DomainCard({ props }: { props: DomainProps }) {
</p>
<ExternalLink className="h-5 w-5" />
</a>
- <NumberTooltip value={totalEvents?.clicks}>
- <Link
- href={`/${slug}/analytics?domain=${domain}&key=_root`}
- className="flex items-center space-x-1 rounded-md bg-gray-100 px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
- >
- <Chart className="h-4 w-4" />
- <p className="text-sm">
- {!totalEvents ? (
- <LoadingDots />
- ) : (
- nFormatter(totalEvents?.clicks)
- )}
- <span className="ml-1 hidden sm:inline-block">clicks</span>
- </p>
- </Link>
- </NumberTooltip>
+
+ {linkProps && (
+ <NumberTooltip value={totalEvents?.clicks}>
+ <Link
+ href={`/${slug}/analytics?domain=${domain}&key=_root`}
+ className="flex items-center space-x-1 rounded-md bg-gray-100 px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
+ >
+ <Chart className="h-4 w-4" />
+ <p className="text-sm">
+ {!totalEvents ? (
+ <LoadingDots />
+ ) : (
+ nFormatter(totalEvents?.clicks)
+ )}
+ <span className="ml-1 hidden sm:inline-block">clicks</span>
+ </p>
+ </Link>
+ </NumberTooltip>
+ )}
+
{primary && (
<span className="rounded-full bg-blue-500 px-3 py-0.5 text-xs text-white">
Primary Domain
@@ -347,21 +352,13 @@ export default function DomainCard({ props }: { props: DomainProps }) {
</div>
<div className="flex items-center space-x-2">
{linkProps ? (
- linkProps.url ? (
- <CheckCircleFill className="h-6 w-6 text-blue-500" />
- ) : (
- <XCircleFill className="h-6 w-6 text-gray-400" />
- )
+ <CheckCircleFill className="h-6 w-6 text-blue-500" />
) : (
- <LoadingCircle className="mr-1 h-5 w-5" />
+ <XCircleFill className="h-6 w-6 text-gray-400" />
)}
<div className="flex space-x-1">
<p className="text-sm text-gray-500">
- {linkProps
- ? linkProps.url
- ? `Redirects to`
- : `No redirect configured`
- : `Checking link status`}
+ {linkProps ? `Redirects to` : `No redirect configured`}
</p>
{linkProps?.url && (
<a