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.

Quick user survey

Steven Tey8c2dee2c0bd4
diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
index 4d74ac3c76..f914e5e5bd 100644
--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
@@ -1,9 +1,10 @@
import NavTabs from "@/ui/layout/nav-tabs";
import UpgradeBanner from "@/ui/layout/upgrade-banner";
import UserDropdown from "@/ui/layout/user-dropdown";
+import UserSurveyPopupContent from "@/ui/layout/user-survey";
import WorkspaceSwitcher from "@/ui/layout/workspace-switcher";
import { Divider } from "@/ui/shared/icons";
-import { Logo, MaxWidthWrapper } from "@dub/ui";
+import { Logo, MaxWidthWrapper, Popup } from "@dub/ui";
import { HOME_DOMAIN, constructMetadata } from "@dub/utils";
import Link from "next/link";
import { ReactNode, Suspense } from "react";
@@ -15,6 +16,9 @@ export const metadata = constructMetadata();
export default function Layout({ children }: { children: ReactNode }) {
return (
<Providers>
+ <Popup hiddenCookieId="hideUserSurveyPopup">
+ <UserSurveyPopupContent />
+ </Popup>
<div className="min-h-screen w-full bg-gray-50">
<div className="sticky left-0 right-0 top-0 z-20 border-b border-gray-200 bg-white">
<MaxWidthWrapper>
diff --git a/apps/web/ui/layout/user-survey.tsx b/apps/web/ui/layout/user-survey.tsx
new file mode 100644
index 0000000000..4682e928f1
--- /dev/null
+++ b/apps/web/ui/layout/user-survey.tsx
@@ -0,0 +1,125 @@
+"use client";
+
+import {
+ Logo,
+ Label,
+ RadioGroup,
+ RadioGroupItem,
+ PopupContext,
+ Twitter,
+ LinkedIn,
+ ProductHunt,
+ Google,
+ Github,
+} from "@dub/ui";
+import { cn } from "@dub/utils";
+import { Globe, X } from "lucide-react";
+import { useContext, useState } from "react";
+
+const options = [
+ {
+ value: "twitter",
+ label: "Twitter/X",
+ icon: Twitter,
+ },
+ {
+ value: "linkedin",
+ label: "LinkedIn",
+ icon: LinkedIn,
+ },
+ {
+ value: "product-hunt",
+ label: "Product Hunt",
+ icon: ProductHunt,
+ },
+ {
+ value: "google",
+ label: "Google",
+ icon: Google,
+ },
+ {
+ value: "github",
+ label: "GitHub",
+ icon: Github,
+ },
+ {
+ value: "other",
+ label: "Other",
+ icon: Globe,
+ },
+];
+
+export default function UserSurveyPopupContent() {
+ const { hidePopup } = useContext(PopupContext);
+ const [source, setSource] = useState<string | undefined>(undefined);
+
+ return (
+ <div className="fixed bottom-4 z-40 mx-2 rounded-lg border border-gray-200 bg-white p-4 shadow-md sm:left-4 sm:mx-auto sm:max-w-sm">
+ <button
+ className="absolute right-2.5 top-2.5 rounded-full p-1 transition-colors hover:bg-gray-100 active:scale-90"
+ onClick={hidePopup}
+ >
+ <X className="h-4 w-4 text-gray-500" />
+ </button>
+ <div className="flex flex-col space-y-4">
+ <Logo className="h-8 w-8" />
+ <p className="text-sm font-medium text-gray-800">
+ Where did you hear about Dub?
+ </p>
+ <form
+ onSubmit={(e) => {
+ e.preventDefault();
+
+ setTimeout(() => {
+ hidePopup();
+ }, 5000);
+ }}
+ >
+ <RadioGroup
+ name="source"
+ required
+ value={source}
+ onValueChange={(value) => {
+ setSource(value);
+ }}
+ className="grid grid-cols-2 gap-4"
+ >
+ {options.map((option) => (
+ <div
+ key={option.value}
+ className={cn(
+ "group flex flex-col rounded-md border border-gray-200 bg-white transition-all hover:border-gray-500 hover:ring-4 hover:ring-gray-200 active:scale-[0.98]",
+ {
+ "border-gray-500 ring-4 ring-gray-200":
+ source === option.value,
+ },
+ )}
+ >
+ <RadioGroupItem
+ value={option.value}
+ id={option.value}
+ className="hidden"
+ />
+ <Label
+ htmlFor={option.value}
+ className="flex cursor-pointer items-center space-x-4 px-4 py-2"
+ >
+ <option.icon
+ className={cn(
+ "h-5 w-5 grayscale transition-all group-hover:grayscale-0",
+ {
+ "h-4 w-4": option.value === "twitter",
+ "text-gray-600": option.value === "other",
+ },
+ )}
+ />
+ <p className="text-gray-600">{option.label}</p>
+ </Label>
+ </div>
+ ))}
+ </RadioGroup>
+ </form>
+ </div>
+ </div>
+ );
+}
diff --git a/packages/ui/src/icons/index.tsx b/packages/ui/src/icons/index.tsx
index 3f7d83dc07..a6a2d3f49e 100644
--- a/packages/ui/src/icons/index.tsx
+++ b/packages/ui/src/icons/index.tsx
@@ -20,6 +20,7 @@ export { default as Facebook } from "./facebook";
export { default as Github } from "./github";
export { default as Google } from "./google";
export { default as LinkedIn } from "./linkedin";
+export { default as ProductHunt } from "./product-hunt";
export { default as Twitter } from "./twitter";
export { default as Unsplash } from "./unsplash";
export { default as YouTube } from "./youtube";
diff --git a/packages/ui/src/icons/linkedin.tsx b/packages/ui/src/icons/linkedin.tsx
index 874b6cda2c..486d632508 100644
--- a/packages/ui/src/icons/linkedin.tsx
+++ b/packages/ui/src/icons/linkedin.tsx
@@ -1,3 +1,5 @@
+import { cn } from "@dub/utils";
+
export default function LinkedIn({ className }: { className?: string }) {
return (
<svg
@@ -5,7 +7,7 @@ export default function LinkedIn({ className }: { className?: string }) {
width="24"
height="24"
viewBox="0 0 24 24"
- className={className}
+ className={cn("text-[#0A66C2]", className)}
>
<path
fill="currentColor"
diff --git a/packages/ui/src/icons/product-hunt.tsx b/packages/ui/src/icons/product-hunt.tsx
new file mode 100644
index 0000000000..731523d16f
--- /dev/null
+++ b/packages/ui/src/icons/product-hunt.tsx
@@ -0,0 +1,20 @@
+export default function ProductHunt({ className }: { className?: string }) {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 26.245 26.256"
+ width="64"
+ height="64"
+ className={className}
+ >
+ <path
+ d="M26.254 13.128c0 7.253-5.875 13.128-13.128 13.128S-.003 20.382-.003 13.128 5.872 0 13.125 0s13.128 5.875 13.128 13.128"
+ fill="#ff6055"
+ />
+ <path
+ d="M14.876 13.128h-3.72V9.2h3.72c1.083 0 1.97.886 1.97 1.97s-.886 1.97-1.97 1.97m0-6.564H8.53v13.128h2.626v-3.938h3.72c2.538 0 4.595-2.057 4.595-4.595s-2.057-4.595-4.595-4.595"
+ fill="#fff"
+ />
+ </svg>
+ );
+}
diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx
index 374b43f68b..64238383f8 100644
--- a/packages/ui/src/index.tsx
+++ b/packages/ui/src/index.tsx
@@ -41,6 +41,6 @@ export * from "./icon-menu";
export * from "./inline-snippet";
export * from "./link-logo";
export * from "./link-preview";
-export * from "./product-hunt";
+export * from "./popup";
export * from "./progress-bar";
export * from "./tab-select";
diff --git a/packages/ui/src/product-hunt.tsx b/packages/ui/src/popup.tsx
similarity index 58%
rename from packages/ui/src/product-hunt.tsx
rename to packages/ui/src/popup.tsx
index 7ab65840a2..2d0ccecb2b 100644
--- a/packages/ui/src/product-hunt.tsx
+++ b/packages/ui/src/popup.tsx
@@ -3,43 +3,59 @@ import Cookies from "js-cookie";
import { X } from "lucide-react";
import Image from "next/image";
import Link from "next/link";
-import { useState } from "react";
+import { ReactNode, createContext, useContext, useState } from "react";
import { ClientOnly } from "./client-only";
-export function ProductHunt() {
- const [closed, setClosed] = useState(
- Cookies.get("hideProductHuntBanner") === "1",
- );
- const handleClose = () => {
- setClosed(true);
- Cookies.set("hideProductHuntBanner", "1");
+export const PopupContext = createContext<{
+ hidePopup: () => void;
+}>({
+ hidePopup: () => {},
+});
+
+export function Popup({
+ children,
+ hiddenCookieId,
+}: {
+ children: ReactNode;
+ hiddenCookieId: string;
+}) {
+ const [hidden, setHidden] = useState(Cookies.get(hiddenCookieId) === "1");
+ const hidePopup = () => {
+ setHidden(true);
+ Cookies.set(hiddenCookieId, "1");
};
return (
<ClientOnly>
- <AnimatePresence>
- {!closed && <ProductHuntPopup handleClose={handleClose} />}
- </AnimatePresence>
+ <PopupContext.Provider value={{ hidePopup }}>
+ <AnimatePresence>
+ {!hidden && (
+ <motion.div
+ key="popup"
+ initial={{ opacity: 0, y: 50 }}
+ animate={{ opacity: 1, y: 0 }}
+ exit={{ y: 250 }}
+ >
+ {children}
+ </motion.div>
+ )}
+ </AnimatePresence>
+ </PopupContext.Provider>
</ClientOnly>
);
}
-export function ProductHuntPopup({ handleClose }: { handleClose: () => void }) {
+export const ProductHuntPopupContent = () => {
+ const { hidePopup } = useContext(PopupContext);
return (
- <motion.div
- key="product-hunt-banner"
- className="xs:left-4 xs:mx-auto xs:max-w-xs group fixed bottom-4 z-40 mx-2 rounded-lg border border-gray-200 bg-white p-2 pb-4 pr-4 shadow-md"
- initial={{ opacity: 0, y: 50 }}
- animate={{ opacity: 1, y: 0 }}
- exit={{ y: 250 }}
- >
+ <div className="xs:left-4 xs:mx-auto xs:max-w-xs group fixed bottom-4 z-40 mx-2 rounded-lg border border-gray-200 bg-white p-2 pb-4 pr-4 shadow-md">
<div className="invisible absolute right-4 top-4 h-3 w-3 group-hover:invisible sm:visible">
<div className="absolute inset-0 m-auto h-3 w-3 animate-ping items-center justify-center rounded-full bg-green-500" />
<div className="absolute inset-0 z-10 m-auto h-3 w-3 rounded-full bg-green-500" />
</div>
<button
className="visible absolute right-2.5 top-2.5 rounded-full p-1 transition-colors hover:bg-gray-100 active:scale-90 group-hover:visible sm:invisible"
- onClick={handleClose}
+ onClick={hidePopup}
>
<X className="h-4 w-4 text-gray-500" />
</button>
@@ -63,6 +79,6 @@ export function ProductHuntPopup({ handleClose }: { handleClose: () => void }) {
</p>
</div>
</Link>
- </motion.div>
+ </div>
);
-}
+};