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.

add advanced settings

Kiran K5b239ff80c60
diff --git a/apps/web/ui/modals/link-builder/advanced-modal.tsx b/apps/web/ui/modals/link-builder/advanced-modal.tsx
new file mode 100644
index 0000000000..fb4c660d33
--- /dev/null
+++ b/apps/web/ui/modals/link-builder/advanced-modal.tsx
@@ -0,0 +1,215 @@
+import {
+ Button,
+ Modal,
+ SimpleTooltipContent,
+ Tooltip,
+ useKeyboardShortcut,
+} from "@dub/ui";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useId,
+ useMemo,
+ useState,
+} from "react";
+import { useForm, useFormContext } from "react-hook-form";
+import { LinkFormData } from ".";
+
+function AdvancedModal({
+ showAdvancedModal,
+ setShowAdvancedModal,
+}: {
+ showAdvancedModal: boolean;
+ setShowAdvancedModal: Dispatch<SetStateAction<boolean>>;
+}) {
+ const id = useId();
+
+ const {
+ watch: watchParent,
+ getValues: getValuesParent,
+ setValue: setValueParent,
+ } = useFormContext<LinkFormData>();
+
+ const {
+ register,
+ handleSubmit,
+ formState: { isDirty },
+ } = useForm<Pick<LinkFormData, "externalId" | "identifier">>({
+ values: {
+ externalId: getValuesParent("externalId"),
+ identifier: getValuesParent("identifier"),
+ },
+ });
+
+ const [externalIdParent, identifierParent] = watchParent([
+ "externalId",
+ "identifier",
+ ]);
+
+ useKeyboardShortcut("a", () => setShowAdvancedModal(true), {
+ modal: true,
+ });
+
+ const parentEnabled = Boolean(externalIdParent || identifierParent);
+
+ return (
+ <Modal
+ showModal={showAdvancedModal}
+ setShowModal={setShowAdvancedModal}
+ className="sm:max-w-[500px]"
+ >
+ <form
+ className="px-5 py-4"
+ onSubmit={(e) => {
+ e.stopPropagation();
+ handleSubmit((data) => {
+ setValueParent("externalId", data.externalId, {
+ shouldDirty: true,
+ });
+ setValueParent("identifier", data.identifier, {
+ shouldDirty: true,
+ });
+ setShowAdvancedModal(false);
+ })(e);
+ }}
+ >
+ <div className="flex items-center justify-between">
+ <h3 className="text-lg font-medium">Advanced Options</h3>
+ <div className="max-md:hidden">
+ <Tooltip
+ content={
+ <div className="px-2 py-1 text-xs text-gray-700">
+ Press <strong className="font-medium text-gray-950">A</strong>{" "}
+ to open this quickly
+ </div>
+ }
+ side="right"
+ >
+ <kbd className="flex size-6 cursor-default items-center justify-center gap-1 rounded-md border border-gray-200 font-sans text-xs text-gray-950">
+ A
+ </kbd>
+ </Tooltip>
+ </div>
+ </div>
+
+ <div className="mt-6 flex flex-col gap-6">
+ {/* External ID */}
+ <div>
+ <div className="flex items-center gap-2">
+ <label
+ htmlFor={`${id}-external-id`}
+ className="block text-sm font-medium text-gray-700"
+ >
+ External ID
+ </label>
+ <Tooltip
+ content={
+ <SimpleTooltipContent
+ title="A unique identifier for this link in your system."
+ cta="Learn more about external IDs."
+ href="https://dub.co/help/article/external-ids"
+ />
+ }
+ />
+ </div>
+ <div className="mt-2 rounded-md shadow-sm">
+ <input
+ id={`${id}-external-id`}
+ type="text"
+ placeholder="Eg: 123456"
+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
+ {...register("externalId")}
+ />
+ </div>
+ </div>
+
+ {/* Identifier */}
+ <div>
+ <div className="flex items-center gap-2">
+ <label
+ htmlFor={`${id}-identifier`}
+ className="block text-sm font-medium text-gray-700"
+ >
+ Identifier
+ </label>
+ <Tooltip
+ content={
+ <SimpleTooltipContent
+ title="A unique string to identify this link."
+ cta="Learn more about identifiers."
+ href="https://dub.co/help/article/link-identifiers"
+ />
+ }
+ />
+ </div>
+ <div className="mt-2 rounded-md shadow-sm">
+ <input
+ id={`${id}-identifier`}
+ type="text"
+ placeholder="Eg: david"
+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"
+ {...register("identifier")}
+ />
+ </div>
+ </div>
+ </div>
+
+ <div className="mt-6 flex items-center justify-between">
+ <div>
+ {parentEnabled && (
+ <button
+ type="button"
+ className="text-xs font-medium text-gray-700 transition-colors hover:text-gray-950"
+ onClick={() => {
+ setValueParent("externalId", null, { shouldDirty: true });
+ setValueParent("identifier", null, { shouldDirty: true });
+ setShowAdvancedModal(false);
+ }}
+ >
+ Remove advanced options
+ </button>
+ )}
+ </div>
+ <div className="flex items-center gap-2">
+ <Button
+ type="button"
+ variant="secondary"
+ text="Cancel"
+ className="h-9 w-fit"
+ onClick={() => setShowAdvancedModal(false)}
+ />
+ <Button
+ type="submit"
+ variant="primary"
+ text="Save"
+ className="h-9 w-fit"
+ disabled={!isDirty}
+ />
+ </div>
+ </div>
+ </form>
+ </Modal>
+ );
+}
+
+export function useAdvancedModal() {
+ const [showAdvancedModal, setShowAdvancedModal] = useState(false);
+
+ const AdvancedModalCallback = useCallback(() => {
+ return (
+ <AdvancedModal
+ showAdvancedModal={showAdvancedModal}
+ setShowAdvancedModal={setShowAdvancedModal}
+ />
+ );
+ }, [showAdvancedModal, setShowAdvancedModal]);
+
+ return useMemo(
+ () => ({
+ setShowAdvancedModal,
+ AdvancedModal: AdvancedModalCallback,
+ }),
+ [setShowAdvancedModal, AdvancedModalCallback],
+ );
+}
diff --git a/apps/web/ui/modals/link-builder/more-dropdown.tsx b/apps/web/ui/modals/link-builder/more-dropdown.tsx
index 8253683cbf..d4e220be07 100644
--- a/apps/web/ui/modals/link-builder/more-dropdown.tsx
+++ b/apps/web/ui/modals/link-builder/more-dropdown.tsx
@@ -7,9 +7,12 @@ import {
useMediaQuery,
} from "@dub/ui";
import { Dots } from "@dub/ui/src/icons";
+import { cn } from "@dub/utils";
+import { Settings } from "lucide-react";
import { useContext, useMemo, useState } from "react";
import { useFormContext } from "react-hook-form";
import { LinkFormData, LinkModalContext } from ".";
+import { useAdvancedModal } from "./advanced-modal";
import { MOBILE_MORE_ITEMS, TOGGLES } from "./constants";
import { useExpirationModal } from "./expiration-modal";
import { usePasswordModal } from "./password-modal";
@@ -48,12 +51,14 @@ export function MoreDropdown() {
const { PasswordModal, setShowPasswordModal } = usePasswordModal();
const { TargetingModal, setShowTargetingModal } = useTargetingModal();
const { ExpirationModal, setShowExpirationModal } = useExpirationModal();
+ const { AdvancedModal, setShowAdvancedModal } = useAdvancedModal();
return (
<>
<PasswordModal />
<TargetingModal />
<ExpirationModal />
+ <AdvancedModal />
<Popover
align="start"
content={
@@ -113,6 +118,41 @@ export function MoreDropdown() {
/>
);
})}
+
+ <Button
+ variant="outline"
+ className="h-9 justify-start px-2 text-sm text-gray-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-gray-950",
+ (data.externalId || data.identifier) && "text-blue-500",
+ )}
+ />
+ Advanced
+ <ProBadgeTooltip
+ content={
+ <SimpleTooltipContent
+ title="Advanced settings"
+ cta="Learn more."
+ href="https://dub.co/docs/advanced-settings"
+ />
+ }
+ />
+ </div>
+ <kbd className="hidden size-6 cursor-default items-center justify-center rounded-md border border-gray-200 font-sans text-xs text-gray-800 sm:flex">
+ A
+ </kbd>
+ </div>
+ }
+ />
</div>
}
openPopover={openPopover}