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.

Finish QR stuff

Tim Wilson96c2450728ce
diff --git a/apps/web/ui/modals/partner-link-modal.tsx b/apps/web/ui/modals/partner-link-modal.tsx
index efc5601802..13a1711477 100644
--- a/apps/web/ui/modals/partner-link-modal.tsx
+++ b/apps/web/ui/modals/partner-link-modal.tsx
@@ -10,6 +10,7 @@ import {
SimpleTooltipContent,
useEnterSubmit,
useKeyboardShortcut,
+ useLocalStorage,
useMediaQuery,
} from "@dub/ui";
import { Pen2, QRCode as QRCodeIcon } from "@dub/ui/icons";
@@ -25,6 +26,7 @@ import {
} from "react";
import { useForm } from "react-hook-form";
import TextareaAutosize from "react-textarea-autosize";
+import type { QRCodeDesign } from "./partner-link-qr-modal";
import { usePartnerLinkQRModal } from "./partner-link-qr-modal";
interface PartnerLinkFormData {
@@ -55,6 +57,91 @@ export function PartnerLinkModal({
);
}
+function QRCodePreview({
+ shortLink,
+ shortLinkDomain,
+ _key,
+}: {
+ shortLink: string;
+ shortLinkDomain: string;
+ _key: string;
+}) {
+ const { programEnrollment } = useProgramEnrollment();
+ const { isMobile } = useMediaQuery();
+
+ const [data, setData] = useLocalStorage<QRCodeDesign>(
+ `partner-qr-code-design-${programEnrollment?.program?.id}`,
+ {
+ fgColor: "#000000",
+ },
+ );
+
+ const { LinkQRModal, setShowLinkQRModal } = usePartnerLinkQRModal({
+ props: {
+ domain: shortLinkDomain,
+ key: _key,
+ },
+ onSave: (data) => setData(data),
+ });
+
+ return (
+ <div>
+ <LinkQRModal />
+ <div className="flex items-center gap-2">
+ <h4 className="text-sm font-medium text-neutral-700">QR Code</h4>
+ <InfoTooltip
+ content={
+ <SimpleTooltipContent
+ title="Set a custom QR code design to improve click-through rates."
+ cta="Learn more."
+ href="https://dub.co/help/article/custom-qr-codes"
+ />
+ }
+ />
+ </div>
+ <div className="relative mt-2 h-24 overflow-hidden rounded-md border border-neutral-300">
+ <Button
+ type="button"
+ variant="secondary"
+ icon={<Pen2 className="mx-px size-4" />}
+ className="absolute right-2 top-2 z-10 h-8 w-fit bg-white px-1.5"
+ onClick={() => setShowLinkQRModal(true)}
+ disabled={!_key}
+ />
+ {!isMobile && (
+ <ShimmerDots className="opacity-30 [mask-image:radial-gradient(40%_80%,transparent_50%,black)]" />
+ )}
+ {_key ? (
+ <AnimatePresence mode="wait">
+ <motion.div
+ key={shortLink}
+ initial={{ filter: "blur(2px)", opacity: 0.4 }}
+ animate={{ filter: "blur(0px)", opacity: 1 }}
+ exit={{ filter: "blur(2px)", opacity: 0.4 }}
+ transition={{ duration: 0.1 }}
+ className="relative flex size-full items-center justify-center"
+ >
+ <QRCode
+ url={shortLink}
+ scale={0.5}
+ hideLogo
+ fgColor={data.fgColor}
+ />
+ </motion.div>
+ </AnimatePresence>
+ ) : (
+ <div className="flex size-full flex-col items-center justify-center gap-2">
+ <QRCodeIcon className="size-5 text-neutral-700" />
+ <p className="max-w-32 text-center text-xs text-neutral-700">
+ Enter a short link to generate a QR code
+ </p>
+ </div>
+ )}
+ </div>
+ </div>
+ );
+}
+
function PartnerLinkModalContent({
setShowPartnerLinkModal,
}: {
@@ -203,54 +290,11 @@ function PartnerLinkModalContent({
/>
</div>
- <div>
- <div className="flex items-center gap-2">
- <h4 className="text-sm font-medium text-neutral-700">QR Code</h4>
- <InfoTooltip
- content={
- <SimpleTooltipContent
- title="Set a custom QR code design to improve click-through rates."
- cta="Learn more."
- href="https://dub.co/help/article/custom-qr-codes"
- />
- }
- />
- </div>
- <div className="relative mt-2 h-24 overflow-hidden rounded-md border border-neutral-300">
- <Button
- type="button"
- variant="secondary"
- icon={<Pen2 className="mx-px size-4" />}
- className="absolute right-2 top-2 z-10 h-8 w-fit bg-white px-1.5"
- onClick={() => setShowLinkQRModal(true)}
- disabled={!key}
- />
- {!isMobile && (
- <ShimmerDots className="opacity-30 [mask-image:radial-gradient(40%_80%,transparent_50%,black)]" />
- )}
- {key ? (
- <AnimatePresence mode="wait">
- <motion.div
- key={shortLink}
- initial={{ filter: "blur(2px)", opacity: 0.4 }}
- animate={{ filter: "blur(0px)", opacity: 1 }}
- exit={{ filter: "blur(2px)", opacity: 0.4 }}
- transition={{ duration: 0.1 }}
- className="relative flex size-full items-center justify-center"
- >
- <QRCode url={shortLink} scale={0.5} hideLogo />
- </motion.div>
- </AnimatePresence>
- ) : (
- <div className="flex size-full flex-col items-center justify-center gap-2">
- <QRCodeIcon className="size-5 text-neutral-700" />
- <p className="max-w-32 text-center text-xs text-neutral-700">
- Enter a short link to generate a QR code
- </p>
- </div>
- )}
- </div>
- </div>
+ <QRCodePreview
+ shortLink={shortLink}
+ shortLinkDomain={shortLinkDomain}
+ _key={key}
+ />
</div>
</div>
diff --git a/apps/web/ui/modals/partner-link-qr-modal.tsx b/apps/web/ui/modals/partner-link-qr-modal.tsx
index 6aa73e3f69..1c6d27ac64 100644
--- a/apps/web/ui/modals/partner-link-qr-modal.tsx
+++ b/apps/web/ui/modals/partner-link-qr-modal.tsx
@@ -22,7 +22,6 @@ import {
PropsWithChildren,
SetStateAction,
useCallback,
- useId,
useMemo,
useRef,
useState,
@@ -76,7 +75,6 @@ function PartnerLinkQRModalInner({
showLinkQRModal: boolean;
setShowLinkQRModal: Dispatch<SetStateAction<boolean>>;
} & PartnerLinkQRModalProps) {
- const id = useId();
const { isMobile } = useMediaQuery();
const url = useMemo(() => {