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.

More menu updates + keyboard shortcuts

Tim Wilsonff9fd35c78a2
diff --git a/apps/web/ui/modals/link-builder/ab-testing-modal.tsx b/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
index 0d0c5999b1..c4b486e3ae 100644
--- a/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
+++ b/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
@@ -252,14 +252,14 @@ function ABTestingModal({
content={
<div className="px-2 py-1 text-xs text-neutral-700">
Press{" "}
- <strong className="font-medium text-neutral-950">X</strong> to
+ <strong className="font-medium text-neutral-950">B</strong> to
open this quickly
</div>
}
side="right"
>
<kbd className="flex size-6 cursor-default items-center justify-center rounded-md border border-neutral-200 font-sans text-xs text-neutral-950">
- X
+ B
</kbd>
</Tooltip>
</div>
diff --git a/apps/web/ui/modals/link-builder/constants.ts b/apps/web/ui/modals/link-builder/constants.ts
index f462ea43eb..abee5333bf 100644
--- a/apps/web/ui/modals/link-builder/constants.ts
+++ b/apps/web/ui/modals/link-builder/constants.ts
@@ -2,17 +2,30 @@ import { ExpandedLinkProps } from "@/lib/types";
import {
CircleHalfDottedClock,
Crosshairs3,
+ Flask,
+ Icon,
Incognito,
InputPassword,
WindowSearch,
} from "@dub/ui/icons";
+import { Settings } from "lucide-react";
import { UseFormSetValue } from "react-hook-form";
import { LinkFormData } from ".";
import { getExpirationLabel } from "./expiration-modal";
import { getPasswordLabel } from "./password-modal";
import { getTargetingLabel } from "./targeting-modal";
-export const TOGGLES = [
+export const MORE_ITEMS: {
+ key: string;
+ icon: Icon;
+ label: string;
+ description?: string;
+ learnMoreUrl?: string;
+ shortcutKey: string;
+ type: string;
+ enabled?: (data: LinkFormData) => boolean;
+ add?: boolean;
+}[] = [
{
key: "rewrite",
icon: Incognito,
@@ -33,6 +46,22 @@ export const TOGGLES = [
shortcutKey: "s",
type: "boolean",
},
+ {
+ key: "tests",
+ icon: Flask,
+ label: "A/B Testing",
+ shortcutKey: "b",
+ type: "modal",
+ },
+ {
+ key: "advanced",
+ icon: Settings,
+ label: "Advanced Settings",
+ shortcutKey: "a",
+ type: "modal",
+ enabled: (data: LinkFormData) => Boolean(data.externalId || data.tenantId),
+ add: false,
+ },
];
export const MOBILE_MORE_ITEMS = [
diff --git a/apps/web/ui/modals/link-builder/more-dropdown.tsx b/apps/web/ui/modals/link-builder/more-dropdown.tsx
index d97bc09570..3a2dd309a2 100644
--- a/apps/web/ui/modals/link-builder/more-dropdown.tsx
+++ b/apps/web/ui/modals/link-builder/more-dropdown.tsx
@@ -8,13 +8,12 @@ import {
} from "@dub/ui";
import { Dots } from "@dub/ui/icons";
import { cn } from "@dub/utils";
-import { BeakerIcon, Settings } from "lucide-react";
import { useMemo, useState } from "react";
import { useFormContext } from "react-hook-form";
import { LinkFormData } from ".";
import { useABTestingModal } from "./ab-testing-modal";
import { useAdvancedModal } from "./advanced-modal";
-import { MOBILE_MORE_ITEMS, TOGGLES } from "./constants";
+import { MOBILE_MORE_ITEMS, MORE_ITEMS } from "./constants";
import { useExpirationModal } from "./expiration-modal";
import { usePasswordModal } from "./password-modal";
import { useTargetingModal } from "./targeting-modal";
@@ -28,9 +27,23 @@ export function MoreDropdown() {
const [openPopover, setOpenPopover] = useState(false);
const options = useMemo(() => {
- return [...(isMobile ? MOBILE_MORE_ITEMS : []), ...TOGGLES];
+ return [...(isMobile ? MOBILE_MORE_ITEMS : []), ...MORE_ITEMS];
}, [data, isMobile]);
+ const { PasswordModal, setShowPasswordModal } = usePasswordModal();
+ const { TargetingModal, setShowTargetingModal } = useTargetingModal();
+ const { ExpirationModal, setShowExpirationModal } = useExpirationModal();
+ const { AdvancedModal, setShowAdvancedModal } = useAdvancedModal();
+ const { ABTestingModal, setShowABTestingModal } = useABTestingModal();
+
+ const modalCallbacks = {
+ password: setShowPasswordModal,
+ targeting: setShowTargetingModal,
+ expiresAt: setShowExpirationModal,
+ tests: setShowABTestingModal,
+ advanced: setShowAdvancedModal,
+ };
+
useKeyboardShortcut(
options.map(({ shortcutKey }) => shortcutKey),
(e) => {
@@ -38,17 +51,13 @@ export function MoreDropdown() {
if (!option) return;
setOpenPopover(false);
- setValue(option.key as any, !data[option.key], { shouldDirty: true });
+ if (option.type === "modal") modalCallbacks[option.key]?.(true);
+ else
+ setValue(option.key as any, !data[option.key], { shouldDirty: true });
},
- { modal: true },
+ { modal: true, priority: 1 },
);
- const { PasswordModal, setShowPasswordModal } = usePasswordModal();
- const { TargetingModal, setShowTargetingModal } = useTargetingModal();
- const { ExpirationModal, setShowExpirationModal } = useExpirationModal();
- const { AdvancedModal, setShowAdvancedModal } = useAdvancedModal();
- const { ABTestingModal, setShowABTestingModal } = useABTestingModal();
-
return (
<>
<PasswordModal />
@@ -75,12 +84,7 @@ export function MoreDropdown() {
setOpenPopover(false);
if (option.type === "modal") {
- ({
- password: setShowPasswordModal,
- targeting: setShowTargetingModal,
- expiresAt: setShowExpirationModal,
- tests: setShowABTestingModal,
- })[option.key]?.(true);
+ modalCallbacks[option.key]?.(true);
} else
setValue(option.key as any, !enabled, {
shouldDirty: true,
@@ -91,24 +95,31 @@ export function MoreDropdown() {
text={
<div className="flex items-center justify-between gap-2">
<div className="flex items-center gap-1">
- <option.icon className="mr-1 size-4 text-neutral-950" />
+ <option.icon
+ className={cn(
+ "mr-1 size-4 text-neutral-950",
+ enabled && "text-blue-500",
+ )}
+ />
{option.type === "modal"
- ? enabled
+ ? enabled || ("add" in option && option.add === false)
? ""
: "Add "
: enabled
? "Remove "
: "Add "}
{option.label}
- <ProBadgeTooltip
- content={
- <SimpleTooltipContent
- title={option.description}
- cta="Learn more."
- href={option.learnMoreUrl}
- />
- }
- />
+ {option.description && option.learnMoreUrl && (
+ <ProBadgeTooltip
+ content={
+ <SimpleTooltipContent
+ title={option.description}
+ cta="Learn more."
+ href={option.learnMoreUrl}
+ />
+ }
+ />
+ )}
</div>
<kbd className="hidden size-6 cursor-default items-center justify-center rounded-md border border-neutral-200 font-sans text-xs text-neutral-800 sm:flex">
{option.shortcutKey.toUpperCase()}
@@ -118,58 +129,6 @@ export function MoreDropdown() {
/>
);
})}
-
- <Button
- variant="outline"
- className="h-9 justify-start px-2 text-sm text-neutral-700"
- textWrapperClassName="grow"
- onClick={() => {
- setOpenPopover(false);
- setShowAdvancedModal(true);
- }}
- text={
- <div className="flex items-center justify-between gap-2">
- <div className="flex items-center gap-1">
- <Settings
- className={cn(
- "mr-1 size-4 text-neutral-950",
- data.externalId && "text-blue-500",
- )}
- />
- Advanced Settings
- </div>
- <kbd className="hidden size-6 cursor-default items-center justify-center rounded-md border border-neutral-200 font-sans text-xs text-neutral-800 sm:flex">
- A
- </kbd>
- </div>
- }
- />
-
- <Button
- variant="outline"
- className="h-9 justify-start px-2 text-sm text-neutral-700"
- textWrapperClassName="grow"
- onClick={() => {
- setOpenPopover(false);
- setShowABTestingModal(true);
- }}
- text={
- <div className="flex items-center justify-between gap-2">
- <div className="flex items-center gap-1">
- <BeakerIcon
- className={cn(
- "mr-1 size-4 text-neutral-950",
- data.tests && "text-blue-500",
- )}
- />
- A/B Testing
- </div>
- <kbd className="hidden size-6 cursor-default items-center justify-center rounded-md border border-neutral-200 font-sans text-xs text-neutral-800 sm:flex">
- X
- </kbd>
- </div>
- }
- />
</div>
}
openPopover={openPopover}
diff --git a/apps/web/ui/modals/link-builder/options-list.tsx b/apps/web/ui/modals/link-builder/options-list.tsx
index 47fbb82a9a..8c877cd654 100644
--- a/apps/web/ui/modals/link-builder/options-list.tsx
+++ b/apps/web/ui/modals/link-builder/options-list.tsx
@@ -8,7 +8,9 @@ import { useFormContext } from "react-hook-form";
import useSWR from "swr";
import { useDebounce } from "use-debounce";
import { LinkFormData } from ".";
-import { MOBILE_MORE_ITEMS, TOGGLES } from "./constants";
+import { MOBILE_MORE_ITEMS, MORE_ITEMS } from "./constants";
+
+const TOGGLES = MORE_ITEMS.filter(({ type }) => type === "boolean");
export function OptionsList() {
const { isMobile } = useMediaQuery();
diff --git a/packages/ui/src/icons/nucleo/flask.tsx b/packages/ui/src/icons/nucleo/flask.tsx
new file mode 100644
index 0000000000..fcf7c705d8
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/flask.tsx
@@ -0,0 +1,46 @@
+import { SVGProps } from "react";
+
+export function Flask(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="5.068"
+ x2="12.932"
+ y1="11.25"
+ y2="11.25"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="5.75"
+ x2="12.25"
+ y1="1.75"
+ y2="1.75"
+ />
+ <path
+ d="M7.25,1.75V7l-3.628,7.065c-.513,.998,.212,2.185,1.334,2.185H13.044c1.122,0,1.847-1.187,1.334-2.185l-3.628-7.065V1.75"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 7cb5732c45..c3dea29b4a 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -83,6 +83,7 @@ export * from "./filter2";
export * from "./flag-wavy";
export * from "./flag2";
export * from "./flag6";
+export * from "./flask";
export * from "./folder";
export * from "./folder-bookmark";
export * from "./folder-lock";