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.

Update link-qr-modal.tsx

Steven Teybb963e54cfbf
diff --git a/apps/web/ui/modals/link-qr-modal.tsx b/apps/web/ui/modals/link-qr-modal.tsx
index 7520047067..f3d79e9556 100644
--- a/apps/web/ui/modals/link-qr-modal.tsx
+++ b/apps/web/ui/modals/link-qr-modal.tsx
@@ -26,7 +26,7 @@ import {
linkConstructor,
} from "@dub/utils";
import { motion } from "framer-motion";
-import { Check, ChevronRight } from "lucide-react";
+import { Check, ChevronRight, Link2 } from "lucide-react";
import {
Dispatch,
SetStateAction,
@@ -121,7 +121,7 @@ export function QRCodePicker({
[props, fgColor, showLogo, qrLogoUrl],
);
- const [copied, setCopied] = useState(false);
+ const [copiedImage, setCopiedImage] = useState(false);
const copyToClipboard = async () => {
try {
const canvas = await getQRAsCanvas(qrData, "image/png", true);
@@ -129,13 +129,15 @@ export function QRCodePicker({
// @ts-ignore
const item = new ClipboardItem({ "image/png": blob });
await navigator.clipboard.write([item]);
- setCopied(true);
- setTimeout(() => setCopied(false), 2000);
+ setCopiedImage(true);
+ setTimeout(() => setCopiedImage(false), 2000);
});
} catch (e) {
throw e;
}
};
+ const [copiedURL, setCopiedURL] = useState(false);
+
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">
@@ -185,32 +187,115 @@ export function QRCodePicker({
/>
<div className="grid grid-cols-2 gap-2 px-4 sm:px-16">
- <button
- onClick={async () => {
- toast.promise(copyToClipboard, {
- loading: "Copying QR code to clipboard...",
- success: "Copied QR code to clipboard!",
- error: "Failed to copy",
- });
- }}
- className="flex items-center justify-center gap-2 rounded-md border border-black bg-black px-5 py-1.5 text-sm text-white transition-all hover:bg-white hover:text-black"
- >
- {copied ? (
+ <QrDropdown
+ button={
<>
- <Check className="h-4 w-4" /> <p>Copied</p>
+ <Clipboard />
+ <p>Copy</p>
</>
- ) : (
+ }
+ >
+ <>
+ <button
+ onClick={async () => {
+ toast.promise(copyToClipboard, {
+ loading: "Copying QR code to clipboard...",
+ success: "Copied QR code to clipboard!",
+ error: "Failed to copy",
+ });
+ }}
+ className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu
+ text="Image"
+ icon={
+ copiedImage ? (
+ <Check className="h-4 w-4" />
+ ) : (
+ <Photo className="h-4 w-4" />
+ )
+ }
+ />
+ </button>
+ <button
+ onClick={() => {
+ navigator.clipboard.writeText(
+ `https://api.dub.co/qr?url=${linkConstructor({
+ key: props.key,
+ domain: props.domain,
+ })}`,
+ );
+ toast.success("Copied QR code URL to clipboard!");
+ setCopiedURL(true);
+ setTimeout(() => setCopiedURL(false), 2000);
+ }}
+ className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu
+ text="URL"
+ icon={
+ copiedURL ? (
+ <Check className="h-4 w-4" />
+ ) : (
+ <Link2 className="h-4 w-4" />
+ )
+ }
+ />
+ </button>
+ </>
+ </QrDropdown>
+ <QrDropdown
+ button={
<>
- <Clipboard className="h-4 w-4" /> <p>Copy</p>
+ <Download />
+ <p>Export</p>
</>
- )}
- </button>
- <QrDropdown
- download={download}
- qrData={qrData}
- showLogo={showLogo}
- logo={qrLogoUrl}
- />
+ }
+ >
+ <>
+ <button
+ onClick={() => {
+ download(
+ getQRAsSVGDataUri({
+ ...qrData,
+ ...(qrData.imageSettings && {
+ imageSettings: {
+ ...qrData.imageSettings,
+ src: logo || "https://dub.co/_static/logo.svg",
+ },
+ }),
+ }),
+ "svg",
+ );
+ }}
+ className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu text="SVG" icon={<Photo className="h-4 w-4" />} />
+ </button>
+ <button
+ onClick={async () => {
+ download(
+ (await getQRAsCanvas(qrData, "image/png")) as string,
+ "png",
+ );
+ }}
+ className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu text="PNG" icon={<Photo className="h-4 w-4" />} />
+ </button>
+ <button
+ onClick={async () => {
+ download(
+ (await getQRAsCanvas(qrData, "image/jpeg")) as string,
+ "jpg",
+ );
+ }}
+ className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
+ >
+ <IconMenu text="JPEG" icon={<Photo className="h-4 w-4" />} />
+ </button>
+ </>
+ </QrDropdown>
</div>
{/* This will be used to prompt downloads. */}
@@ -375,49 +460,17 @@ function AdvancedSettings({
);
}
-function QrDropdown({ download, qrData, showLogo, logo }) {
+function QrDropdown({
+ button,
+ children,
+}: {
+ button: JSX.Element;
+ children: JSX.Element;
+}) {
const [openPopover, setOpenPopover] = useState(false);
return (
<Popover
- content={
- <div className="grid w-full gap-1 p-2 sm:w-40">
- <button
- onClick={() => {
- download(
- getQRAsSVGDataUri({
- ...qrData,
- ...(showLogo && {
- imageSettings: {
- ...qrData.imageSettings,
- src: logo || "https://dub.co/_static/logo.svg",
- },
- }),
- }),
- "svg",
- );
- }}
- className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
- >
- <IconMenu text="SVG" icon={<Photo className="h-4 w-4" />} />
- </button>
- <button
- onClick={async () => {
- download(await getQRAsCanvas(qrData, "image/png"), "png");
- }}
- className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
- >
- <IconMenu text="PNG" icon={<Photo className="h-4 w-4" />} />
- </button>
- <button
- onClick={async () => {
- download(await getQRAsCanvas(qrData, "image/jpeg"), "jpg");
- }}
- className="w-full rounded-md p-2 text-left text-sm font-medium text-gray-500 transition-all duration-75 hover:bg-gray-100"
- >
- <IconMenu text="JPEG" icon={<Photo className="h-4 w-4" />} />
- </button>
- </div>
- }
+ content={<div className="grid w-full gap-1 p-2 sm:w-40">{children}</div>}
align="center"
openPopover={openPopover}
setOpenPopover={setOpenPopover}
@@ -426,8 +479,7 @@ function QrDropdown({ download, qrData, showLogo, logo }) {
onClick={() => setOpenPopover(!openPopover)}
className="flex w-full items-center justify-center gap-2 rounded-md border border-black bg-black px-5 py-1.5 text-sm text-white transition-all hover:bg-white hover:text-black"
>
- <Download />
- Export
+ {button}
</button>
</Popover>
);