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.

support mailto links in program resources with envelope icon display

Kiran Kc6b0f41d2003
diff --git a/apps/web/app/(ee)/app.dub.co/embed/referrals/resources.tsx b/apps/web/app/(ee)/app.dub.co/embed/referrals/resources.tsx
index cf64052941..bfc813809b 100644
--- a/apps/web/app/(ee)/app.dub.co/embed/referrals/resources.tsx
+++ b/apps/web/app/(ee)/app.dub.co/embed/referrals/resources.tsx
@@ -2,6 +2,7 @@ import { programResourcesSchema } from "@/lib/zod/schemas/program-resources";
import { ResourceCard } from "@/ui/partners/resources/resource-card";
import { ResourceSection } from "@/ui/partners/resources/resource-section";
import { FileContent, TAB_ITEM_ANIMATION_SETTINGS } from "@dub/ui";
+import { Envelope } from "@dub/ui/icons";
import {
formatFileSize,
getApexDomain,
@@ -52,11 +53,15 @@ export function ReferralsEmbedResources({
resourceType="link"
icon={
<div className="bg-bg-subtle flex size-full items-center justify-center">
- <img
- src={`${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`}
- alt={link.name}
- className="size-6 rounded-full object-contain"
- />
+ {link.url.startsWith("mailto:") ? (
+ <Envelope className="text-content-emphasis size-4" />
+ ) : (
+ <img
+ src={`${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`}
+ alt={link.name}
+ className="size-6 rounded-full object-contain"
+ />
+ )}
</div>
}
title={link.name}
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/resources/page.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/resources/page.tsx
index 6fbd47981c..4bb941977f 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/resources/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/resources/page.tsx
@@ -6,7 +6,14 @@ import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { ResourceCard } from "@/ui/partners/resources/resource-card";
import { ResourceSection } from "@/ui/partners/resources/resource-section";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
-import { FileContent, FileZip2, Link4, Palette2, Post } from "@dub/ui/icons";
+import {
+ Envelope,
+ FileContent,
+ FileZip2,
+ Link4,
+ Palette2,
+ Post,
+} from "@dub/ui/icons";
import {
formatFileSize,
getApexDomain,
@@ -72,11 +79,15 @@ export default function PartnerProgramResourcesPage() {
resourceType="link"
icon={
<div className="flex size-full items-center justify-center bg-neutral-50">
- <img
- src={`${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`}
- alt={link.name}
- className="size-6 rounded-full object-contain"
- />
+ {link.url.startsWith("mailto:") ? (
+ <Envelope className="size-4 text-neutral-800" />
+ ) : (
+ <img
+ src={`${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`}
+ alt={link.name}
+ className="size-6 rounded-full object-contain"
+ />
+ )}
</div>
}
title={link.name}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/resources/program-brand-assets/index.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/resources/program-brand-assets/index.tsx
index 2c064ddddf..888fd576ca 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/resources/program-brand-assets/index.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/resources/program-brand-assets/index.tsx
@@ -11,6 +11,7 @@ import {
} from "@/lib/zod/schemas/program-resources";
import { ResourceCard } from "@/ui/partners/resources/resource-card";
import { AnimatedSizeContainer, Button, FileContent } from "@dub/ui";
+import { Envelope } from "@dub/ui/icons";
import {
capitalize,
formatFileSize,
@@ -214,11 +215,15 @@ export function ProgramBrandAssets() {
resourceType="link"
icon={
<div className="flex size-full items-center justify-center bg-neutral-50">
- <img
- src={`${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`}
- alt={link.name}
- className="size-6 rounded-full object-contain"
- />
+ {link.url.startsWith("mailto:") ? (
+ <Envelope className="size-4 text-neutral-800" />
+ ) : (
+ <img
+ src={`${GOOGLE_FAVICON_URL}${getApexDomain(link.url)}`}
+ alt={link.name}
+ className="size-6 rounded-full object-contain"
+ />
+ )}
</div>
}
title={link.name}
diff --git a/apps/web/lib/actions/partners/program-resources/add-program-resource.ts b/apps/web/lib/actions/partners/program-resources/add-program-resource.ts
index 1684ad7d14..1e0f26c842 100644
--- a/apps/web/lib/actions/partners/program-resources/add-program-resource.ts
+++ b/apps/web/lib/actions/partners/program-resources/add-program-resource.ts
@@ -7,6 +7,7 @@ import {
programResourceColorSchema,
programResourceFileSchema,
programResourceLinkSchema,
+ programResourceLinkUrlSchema,
} from "@/lib/zod/schemas/program-resources";
import { R2_URL } from "@dub/utils";
import * as z from "zod/v4";
@@ -43,7 +44,7 @@ const colorResourceSchema = baseResourceSchema.extend({
// Schema for link resources
const linkResourceSchema = baseResourceSchema.extend({
resourceType: z.literal("link"),
- url: z.url(),
+ url: programResourceLinkUrlSchema,
});
// Combined schema that can handle any resource type
diff --git a/apps/web/lib/actions/partners/program-resources/update-program-resource.ts b/apps/web/lib/actions/partners/program-resources/update-program-resource.ts
index 66c9a8b25c..885b2b2b66 100644
--- a/apps/web/lib/actions/partners/program-resources/update-program-resource.ts
+++ b/apps/web/lib/actions/partners/program-resources/update-program-resource.ts
@@ -7,6 +7,7 @@ import {
programResourceColorSchema,
programResourceFileSchema,
programResourceLinkSchema,
+ programResourceLinkUrlSchema,
programResourcesSchema,
} from "@/lib/zod/schemas/program-resources";
import { R2_URL } from "@dub/utils";
@@ -48,7 +49,7 @@ const updateColorSchema = baseUpdateSchema.extend({
const updateLinkSchema = baseUpdateSchema.extend({
resourceType: z.literal("link"),
name: z.string().min(1).optional(),
- url: z.url().optional(),
+ url: programResourceLinkUrlSchema.optional(),
});
// Combined schema that can handle any resource type
diff --git a/apps/web/lib/zod/schemas/program-resources.ts b/apps/web/lib/zod/schemas/program-resources.ts
index 46b70b2da6..c701f7d2fc 100644
--- a/apps/web/lib/zod/schemas/program-resources.ts
+++ b/apps/web/lib/zod/schemas/program-resources.ts
@@ -22,10 +22,15 @@ export const programResourceColorSchema = z.object({
color: z.string(),
});
+// Allow http(s) and mailto links, but block dangerous schemes (e.g. javascript:, data:)
+export const programResourceLinkUrlSchema = z.url({
+ protocol: /^(https?|mailto)$/,
+});
+
export const programResourceLinkSchema = z.object({
id: z.string(),
name: z.string(),
- url: z.url(),
+ url: programResourceLinkUrlSchema,
});
export const programResourcesSchema = z.object({