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.

create LinkLogo reusable component

Steven Teydc476237777e
diff --git a/apps/web/ui/links/link-card.tsx b/apps/web/ui/links/link-card.tsx
index 1dd6c0d60d..c296754983 100644
--- a/apps/web/ui/links/link-card.tsx
+++ b/apps/web/ui/links/link-card.tsx
@@ -10,7 +10,6 @@ import { Chart, Delete, ThreeDots } from "@/ui/shared/icons";
import {
Avatar,
BadgeTooltip,
- BlurImage,
Button,
CopyButton,
IconMenu,
@@ -24,7 +23,6 @@ import {
} from "@dub/ui";
import { LinkifyTooltipContent } from "@dub/ui/src/tooltip";
import {
- GOOGLE_FAVICON_URL,
HOME_DOMAIN,
cn,
fetcher,
@@ -45,7 +43,6 @@ import {
QrCode,
TimerOff,
Lock,
- Globe,
Copy,
CopyCheck,
} from "lucide-react";
@@ -56,6 +53,7 @@ import { useEffect, useMemo, useRef, useState } from "react";
import { toast } from "sonner";
import useSWR, { mutate } from "swr";
import { useTransferLinkModal } from "../modals/transfer-link-modal";
+import LinkLogo from "./link-logo";
export default function LinkCard({
props,
@@ -281,18 +279,8 @@ export default function LinkCard({
)}
</div>
</Tooltip>
- ) : apexDomain ? (
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${apexDomain}`}
- alt={apexDomain}
- className="h-8 w-8 rounded-full sm:h-10 sm:w-10"
- width={20}
- height={20}
- />
) : (
- <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-100 px-0 sm:h-10 sm:w-10">
- <Globe className="h-4 w-4 text-gray-600 sm:h-5 sm:w-5" />
- </div>
+ <LinkLogo apexDomain={apexDomain} />
)}
{/*
Here, we're manually setting ml-* values because if we do space-x-* in the parent div,
diff --git a/apps/web/ui/links/link-logo.tsx b/apps/web/ui/links/link-logo.tsx
new file mode 100644
index 0000000000..fa68297021
--- /dev/null
+++ b/apps/web/ui/links/link-logo.tsx
@@ -0,0 +1,23 @@
+import { BlurImage } from "@dub/ui";
+import { GOOGLE_FAVICON_URL } from "@dub/utils";
+import { Globe } from "lucide-react";
+
+export default function LinkLogo({
+ apexDomain,
+}: {
+ apexDomain?: string | null;
+}) {
+ return apexDomain ? (
+ <BlurImage
+ src={`${GOOGLE_FAVICON_URL}${apexDomain}`}
+ alt={apexDomain}
+ className="h-8 w-8 rounded-full sm:h-10 sm:w-10"
+ width={20}
+ height={20}
+ />
+ ) : (
+ <div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-100 px-0 sm:h-10 sm:w-10">
+ <Globe className="h-4 w-4 text-gray-600 sm:h-5 sm:w-5" />
+ </div>
+ );
+}
diff --git a/apps/web/ui/modals/archive-link-modal.tsx b/apps/web/ui/modals/archive-link-modal.tsx
index 37cfc4c889..a37e1f7a9d 100644
--- a/apps/web/ui/modals/archive-link-modal.tsx
+++ b/apps/web/ui/modals/archive-link-modal.tsx
@@ -1,6 +1,6 @@
import { LinkProps } from "@/lib/types";
-import { BlurImage, Button, Modal, useToastWithUndo } from "@dub/ui";
-import { GOOGLE_FAVICON_URL, getApexDomain, linkConstructor } from "@dub/utils";
+import { Button, Modal, useToastWithUndo } from "@dub/ui";
+import { getApexDomain, linkConstructor } from "@dub/utils";
import { useParams } from "next/navigation";
import {
Dispatch,
@@ -12,6 +12,7 @@ import {
} from "react";
import { toast } from "sonner";
import { mutate } from "swr";
+import LinkLogo from "../links/link-logo";
const sendArchiveRequest = (archived: boolean, id: string, slug?: string) => {
const baseUrl = `/api/links/${id}/archive`;
@@ -98,13 +99,7 @@ function ArchiveLinkModal({
setShowModal={setShowArchiveLinkModal}
>
<div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 text-center sm:px-16">
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${apexDomain}`}
- alt={apexDomain}
- className="h-10 w-10 rounded-full"
- width={20}
- height={20}
- />
+ <LinkLogo apexDomain={apexDomain} />
<h3 className="text-lg font-medium">
{archived ? "Archive" : "Unarchive"} {shortlink}
</h3>
diff --git a/apps/web/ui/modals/delete-link-modal.tsx b/apps/web/ui/modals/delete-link-modal.tsx
index 019fc8f60c..72dbd95a51 100644
--- a/apps/web/ui/modals/delete-link-modal.tsx
+++ b/apps/web/ui/modals/delete-link-modal.tsx
@@ -1,7 +1,7 @@
import { LinkProps } from "@/lib/types";
-import { BlurImage, Button, Modal, useMediaQuery } from "@dub/ui";
-import { GOOGLE_FAVICON_URL, getApexDomain, linkConstructor } from "@dub/utils";
-import { useParams, useSearchParams } from "next/navigation";
+import { Button, Modal, useMediaQuery } from "@dub/ui";
+import { getApexDomain, linkConstructor } from "@dub/utils";
+import { useParams } from "next/navigation";
import {
Dispatch,
SetStateAction,
@@ -11,6 +11,7 @@ import {
} from "react";
import { toast } from "sonner";
import { mutate } from "swr";
+import LinkLogo from "../links/link-logo";
function DeleteLinkModal({
showDeleteLinkModal,
@@ -23,7 +24,6 @@ function DeleteLinkModal({
}) {
const params = useParams() as { slug?: string };
const { slug } = params;
- const searchParams = useSearchParams();
const [deleting, setDeleting] = useState(false);
const apexDomain = getApexDomain(props.url);
@@ -45,13 +45,7 @@ function DeleteLinkModal({
setShowModal={setShowDeleteLinkModal}
>
<div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 text-center sm:px-16">
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${apexDomain}`}
- alt={apexDomain}
- className="h-10 w-10 rounded-full"
- width={20}
- height={20}
- />
+ <LinkLogo apexDomain={apexDomain} />
<h3 className="text-lg font-medium">Delete {shortlink}</h3>
<p className="text-sm text-gray-500">
Warning: Deleting this link will remove all of its stats. This action
diff --git a/apps/web/ui/modals/link-qr-modal.tsx b/apps/web/ui/modals/link-qr-modal.tsx
index d241741857..4268cf7b9f 100644
--- a/apps/web/ui/modals/link-qr-modal.tsx
+++ b/apps/web/ui/modals/link-qr-modal.tsx
@@ -40,6 +40,7 @@ import {
import { HexColorInput, HexColorPicker } from "react-colorful";
import { toast } from "sonner";
import { useDebouncedCallback } from "use-debounce";
+import LinkLogo from "../links/link-logo";
function LinkQRModalHelper({
showLinkQRModal,
@@ -66,21 +67,7 @@ export function QRCodePicker({
}) {
const anchorRef = useRef<HTMLAnchorElement>(null);
const { logo, plan } = useProject();
- const { avatarUrl, apexDomain } = useMemo(() => {
- try {
- if (!props.url) return { avatarUrl: null, apexDomain: null };
- const apexDomain = getApexDomain(props.url);
- return {
- avatarUrl: `${GOOGLE_FAVICON_URL}${apexDomain}`,
- apexDomain,
- };
- } catch (e) {
- return {
- avatarUrl: null,
- apexDomain: null,
- };
- }
- }, [props]);
+ const apexDomain = props.url ? getApexDomain(props.url) : null;
const qrLogoUrl = useMemo(() => {
if (logo && plan !== "free") return logo;
@@ -141,17 +128,7 @@ export function QRCodePicker({
return (
<>
<div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 sm:px-16">
- {avatarUrl ? (
- <BlurImage
- src={avatarUrl}
- alt={apexDomain}
- className="h-10 w-10 rounded-full"
- width={40}
- height={40}
- />
- ) : (
- <Logo />
- )}
+ <LinkLogo apexDomain={apexDomain} />
<h3 className="text-lg font-medium">Download QR Code</h3>
</div>
diff --git a/apps/web/ui/modals/transfer-link-modal.tsx b/apps/web/ui/modals/transfer-link-modal.tsx
index a9ab24801e..e6b4442525 100644
--- a/apps/web/ui/modals/transfer-link-modal.tsx
+++ b/apps/web/ui/modals/transfer-link-modal.tsx
@@ -1,16 +1,9 @@
import useProjects from "@/lib/swr/use-projects";
import { LinkProps } from "@/lib/types";
-import {
- BlurImage,
- Button,
- InputSelect,
- InputSelectItemProps,
- Modal,
-} from "@dub/ui";
+import { Button, InputSelect, InputSelectItemProps, Modal } from "@dub/ui";
import {
APP_NAME,
DUB_LOGO,
- GOOGLE_FAVICON_URL,
getApexDomain,
isDubDomain,
linkConstructor,
@@ -25,6 +18,7 @@ import {
} from "react";
import { toast } from "sonner";
import { mutate } from "swr";
+import LinkLogo from "../links/link-logo";
function TransferLinkModal({
showTransferLinkModal,
@@ -92,13 +86,7 @@ function TransferLinkModal({
}}
>
<div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 text-center sm:px-16">
- <BlurImage
- src={`${GOOGLE_FAVICON_URL}${apexDomain}`}
- alt={apexDomain}
- className="h-10 w-10 rounded-full"
- width={20}
- height={20}
- />
+ <LinkLogo apexDomain={apexDomain} />
<h3 className="text-lg font-medium">Transfer {shortlink}</h3>
<p className="text-sm text-gray-500">
Transfer this link and its analytics to another {APP_NAME} project.