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.

WIP modals

Tim Wilson173274623c7d
diff --git a/apps/web/ui/partners/design/add-block-modal.tsx b/apps/web/ui/partners/design/add-block-modal.tsx
deleted file mode 100644
index de316deb40..0000000000
--- a/apps/web/ui/partners/design/add-block-modal.tsx
+++ /dev/null
@@ -1,66 +0,0 @@
-"use client";
-
-import { Modal } from "@dub/ui";
-import {
- Dispatch,
- SetStateAction,
- useCallback,
- useMemo,
- useState,
-} from "react";
-
-type AddBlockModalProps = {
- showAddBlockModal: boolean;
- setShowAddBlockModal: Dispatch<SetStateAction<boolean>>;
-};
-
-function AddBlockModal(props: AddBlockModalProps) {
- return (
- <Modal
- showModal={props.showAddBlockModal}
- setShowModal={props.setShowAddBlockModal}
- >
- <AddBlockModalInner {...props} />
- </Modal>
- );
-}
-
-function AddBlockModalInner({ setShowAddBlockModal }: AddBlockModalProps) {
- return (
- <>
- <div className="p-4 pt-3">
- <h3 className="text-base font-semibold leading-6 text-neutral-800">
- Insert block
- </h3>
- <div className="mt-4 grid grid-cols-2 gap-4">
- {[...Array(4)].map((_, idx) => (
- <div key={idx} className="h-48 rounded-md bg-neutral-100" />
- ))}
-
- <div className="col-span-2 h-20 rounded-md bg-neutral-100" />
- </div>
- </div>
- </>
- );
-}
-
-export function useAddBlockModal() {
- const [showAddBlockModal, setShowAddBlockModal] = useState(false);
-
- const AddBlockModalCallback = useCallback(() => {
- return (
- <AddBlockModal
- showAddBlockModal={showAddBlockModal}
- setShowAddBlockModal={setShowAddBlockModal}
- />
- );
- }, [showAddBlockModal, setShowAddBlockModal]);
-
- return useMemo(
- () => ({
- setShowAddBlockModal,
- AddBlockModal: AddBlockModalCallback,
- }),
- [setShowAddBlockModal, AddBlockModalCallback],
- );
-}
diff --git a/apps/web/ui/partners/design/branding-form.tsx b/apps/web/ui/partners/design/branding-form.tsx
index d65cf87387..7acda786b7 100644
--- a/apps/web/ui/partners/design/branding-form.tsx
+++ b/apps/web/ui/partners/design/branding-form.tsx
@@ -9,7 +9,7 @@ import {
ProgramWithLanderDataProps,
} from "@/lib/types";
import { programLanderSchema } from "@/lib/zod/schemas/program-lander";
-import { useEditHeroModal } from "@/ui/partners/design/edit-hero-modal";
+import { useEditHeroModal } from "@/ui/partners/design/modals/edit-hero-modal";
import { PreviewWindow } from "@/ui/partners/design/preview-window";
import { BLOCK_COMPONENTS } from "@/ui/partners/lander-blocks";
import { LanderHero } from "@/ui/partners/lander-hero";
@@ -44,14 +44,14 @@ import {
import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";
-import { useAddBlockModal } from "./add-block-modal";
import { BrandingSettingsForm } from "./branding-settings-form";
+import { useAddBlockModal } from "./modals/add-block-modal";
export type BrandingFormData = {
landerData: z.infer<typeof programLanderSchema>;
} & Pick<ProgramProps, "logo" | "wordmark" | "brandColor">;
-export function useProgramBrandingForm() {
+export function useBrandingFormContext() {
return useFormContext<BrandingFormData>();
}
@@ -159,7 +159,7 @@ function LanderPreview({ program }: { program: ProgramWithLanderDataProps }) {
const scrollRef = useRef<HTMLDivElement>(null);
const scrolled = useScroll(0, { container: scrollRef });
- const { control, setValue } = useProgramBrandingForm();
+ const { control, setValue } = useBrandingFormContext();
const [landerData, brandColor, logo, wordmark] = useWatch({
control,
name: ["landerData", "brandColor", "logo", "wordmark"],
diff --git a/apps/web/ui/partners/design/branding-settings-form.tsx b/apps/web/ui/partners/design/branding-settings-form.tsx
index b5aea8f46f..d87fffd455 100644
--- a/apps/web/ui/partners/design/branding-settings-form.tsx
+++ b/apps/web/ui/partners/design/branding-settings-form.tsx
@@ -7,10 +7,10 @@ import { cn } from "@dub/utils/src";
import { flightRouterStateSchema } from "next/dist/server/app-render/types";
import { ReactNode, useId } from "react";
import { Controller } from "react-hook-form";
-import { useProgramBrandingForm } from "./branding-form";
+import { useBrandingFormContext } from "./branding-form";
export function BrandingSettingsForm() {
- const { control } = useProgramBrandingForm();
+ const { control } = useBrandingFormContext();
return (
<div>
diff --git a/apps/web/ui/partners/design/modals/accordion-block-modal.tsx b/apps/web/ui/partners/design/modals/accordion-block-modal.tsx
new file mode 100644
index 0000000000..210b371273
--- /dev/null
+++ b/apps/web/ui/partners/design/modals/accordion-block-modal.tsx
@@ -0,0 +1,70 @@
+export function AccordionBlockThumbnail() {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="168"
+ height="100"
+ fill="none"
+ viewBox="0 0 168 100"
+ className="h-auto w-full"
+ >
+ <path
+ fill="#E5E5E5"
+ d="M31 22.234v.216h106v-.431H31zm106 35.789v-.216H31v.431h106z"
+ />
+ <text
+ xmlSpace="preserve"
+ fill="#262626"
+ fontSize="6.894"
+ fontWeight="600"
+ letterSpacing="-.02em"
+ style={{ whiteSpace: "pre" }}
+ >
+ <tspan x="31" y="36.807">
+ Question 1
+ </tspan>
+ </text>
+ <path
+ stroke="#737373"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="0.646"
+ d="m130.106 30.852-4.309 4.308M125.797 30.852l4.309 4.308"
+ />
+ <text
+ xmlSpace="preserve"
+ fill="#262626"
+ fontSize="6.894"
+ letterSpacing="-.02em"
+ style={{ whiteSpace: "pre" }}
+ >
+ <tspan x="31" y="47.807">
+ Here’s the answer!
+ </tspan>
+ </text>
+ <path
+ fill="#E5E5E5"
+ d="M31 58.023v.216h106v-.431H31zm106 21.342v-.215H31v.43h106z"
+ />
+ <text
+ xmlSpace="preserve"
+ fill="#262626"
+ fontSize="6.894"
+ fontWeight="600"
+ letterSpacing="-.02em"
+ style={{ whiteSpace: "pre" }}
+ >
+ <tspan x="31" y="70.871">
+ Question 2
+ </tspan>
+ </text>
+ <path
+ stroke="#737373"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="0.646"
+ d="M127.951 66.217v4.955M125.474 68.693h4.955"
+ />
+ </svg>
+ );
+}
diff --git a/apps/web/ui/partners/design/modals/add-block-modal.tsx b/apps/web/ui/partners/design/modals/add-block-modal.tsx
new file mode 100644
index 0000000000..dfe36d5fe6
--- /dev/null
+++ b/apps/web/ui/partners/design/modals/add-block-modal.tsx
@@ -0,0 +1,145 @@
+"use client";
+
+import { Modal } from "@dub/ui";
+import {
+ Dispatch,
+ Fragment,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+import { useWatch } from "react-hook-form";
+import { useBrandingFormContext } from "../branding-form";
+import { AccordionBlockThumbnail } from "./accordion-block-modal";
+import { FilesBlockThumbnail } from "./files-block-modal";
+import { ImageBlockThumbnail } from "./image-block-modal";
+import { TextBlockModal, TextBlockThumbnail } from "./text-block-modal";
+
+type AddBlockModalProps = {
+ showAddBlockModal: boolean;
+ setShowAddBlockModal: Dispatch<SetStateAction<boolean>>;
+};
+
+function AddBlockModal(props: AddBlockModalProps) {
+ return (
+ <Modal
+ showModal={props.showAddBlockModal}
+ setShowModal={props.setShowAddBlockModal}
+ >
+ <AddBlockModalInner {...props} />
+ </Modal>
+ );
+}
+
+const Blocks = [
+ {
+ id: "text",
+ label: "Text",
+ description: "Share more program information and content",
+ modal: TextBlockModal,
+ thumbnail: <TextBlockThumbnail />,
+ },
+ {
+ id: "image",
+ label: "Image",
+ description: "Add nice visuals to accompany your content",
+ modal: TextBlockModal,
+ thumbnail: <ImageBlockThumbnail />,
+ },
+ {
+ id: "files",
+ label: "Files",
+ description: "Provide helpful files to potential partners",
+ modal: TextBlockModal,
+ thumbnail: <FilesBlockThumbnail />,
+ },
+ {
+ id: "accordion",
+ label: "Accordion",
+ description: "Expanding and collapsing, great for FAQs",
+ modal: TextBlockModal,
+ thumbnail: <AccordionBlockThumbnail />,
+ },
+] as const;
+
+function AddBlockModalInner({ setShowAddBlockModal }: AddBlockModalProps) {
+ const [modalState, setModalState] = useState<
+ null | "text" | "image" | "files" | "accordion"
+ >(null);
+
+ const { control, setValue } = useBrandingFormContext();
+ const landerData = useWatch({
+ control,
+ name: "landerData",
+ });
+
+ return (
+ <>
+ <div className="p-4 pt-3">
+ <h3 className="text-base font-semibold leading-6 text-neutral-800">
+ Insert block
+ </h3>
+ <div className="mt-4 grid grid-cols-2 gap-4">
+ {Blocks.map((block) => (
+ <Fragment key={block.id}>
+ <block.modal
+ showModal={modalState === block.id}
+ setShowModal={(show) =>
+ setModalState((s) =>
+ show ? block.id : s === block.id ? null : s,
+ )
+ }
+ onSubmit={(data) => {
+ alert("added block");
+ setModalState(null);
+ setShowAddBlockModal(false);
+ }}
+ />
+ <button
+ type="button"
+ onClick={() => setModalState(block.id)}
+ className="flex flex-col gap-4 rounded-md border border-transparent bg-neutral-100 p-4 text-left outline-none ring-black/10 transition-all duration-150 hover:border-neutral-800 hover:ring focus-visible:border-neutral-800"
+ >
+ <div className="flex h-24 items-center justify-center overflow-hidden rounded-md border border-neutral-200 bg-white">
+ {block.thumbnail}
+ </div>
+ <div className="flex flex-col gap-1">
+ <span className="text-sm font-semibold text-neutral-900">
+ {block.label}
+ </span>
+ <p className="text-sm tracking-[-0.01em] text-neutral-500">
+ {block.description}
+ </p>
+ </div>
+ </button>
+ </Fragment>
+ ))}
+
+ {/* <div className="col-span-2 h-20 rounded-md bg-neutral-100" /> */}
+ </div>
+ </div>
+ </>
+ );
+}
+
+export function useAddBlockModal() {
+ const [showAddBlockModal, setShowAddBlockModal] = useState(false);
+
+ const AddBlockModalCallback = useCallback(() => {
+ return (
+ <AddBlockModal
+ showAddBlockModal={showAddBlockModal}
+ setShowAddBlockModal={setShowAddBlockModal}
+ />
+ );
+ }, [showAddBlockModal, setShowAddBlockModal]);
+
+ return useMemo(
+ () => ({
+ setShowAddBlockModal,
+ AddBlockModal: AddBlockModalCallback,
+ }),
+ [setShowAddBlockModal, AddBlockModalCallback],
+ );
+}
diff --git a/apps/web/ui/partners/design/edit-hero-modal.tsx b/apps/web/ui/partners/design/modals/edit-hero-modal.tsx
similarity index 97%
rename from apps/web/ui/partners/design/edit-hero-modal.tsx
rename to apps/web/ui/partners/design/modals/edit-hero-modal.tsx
index 6d3819b054..46d1398759 100644
--- a/apps/web/ui/partners/design/edit-hero-modal.tsx
+++ b/apps/web/ui/partners/design/modals/edit-hero-modal.tsx
@@ -11,7 +11,7 @@ import {
useState,
} from "react";
import { useForm } from "react-hook-form";
-import { BrandingFormData, useProgramBrandingForm } from "./branding-form";
+import { BrandingFormData, useBrandingFormContext } from "../branding-form";
type EditHeroModalProps = {
showEditHeroModal: boolean;
@@ -35,7 +35,7 @@ function EditHeroModalInner({ setShowEditHeroModal }: EditHeroModalProps) {
const { program } = useProgram();
const { getValues: getValuesParent, setValue: setValueParent } =
- useProgramBrandingForm();
+ useBrandingFormContext();
const {
register,
diff --git a/apps/web/ui/partners/design/modals/files-block-modal.tsx b/apps/web/ui/partners/design/modals/files-block-modal.tsx
new file mode 100644
index 0000000000..6844d7fe0e
--- /dev/null
+++ b/apps/web/ui/partners/design/modals/files-block-modal.tsx
@@ -0,0 +1,72 @@
+import { useId } from "react";
+
+export function FilesBlockThumbnail() {
+ const id = useId();
+
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="168"
+ height="100"
+ fill="none"
+ viewBox="0 0 168 100"
+ className="h-auto w-full"
+ >
+ <g clipPath={`url(#${id}-a)`}>
+ <path
+ fill="#fff"
+ d="M26.27 30.595H181.5v39.811H26.27a4.77 4.77 0 0 1-4.77-4.77v-30.27a4.77 4.77 0 0 1 4.77-4.771"
+ />
+ <path
+ stroke="#E5E5E5"
+ d="M26.27 30.595H181.5v39.811H26.27a4.77 4.77 0 0 1-4.77-4.77v-30.27a4.77 4.77 0 0 1 4.77-4.771Z"
+ />
+ <path
+ stroke="#E5E5E5"
+ strokeWidth="0.659"
+ d="M32.859 39.63h14.493a3.624 3.624 0 0 1 3.623 3.624v14.493a3.623 3.623 0 0 1-3.623 3.623H32.859a3.624 3.624 0 0 1-3.624-3.623V43.254a3.624 3.624 0 0 1 3.624-3.624Z"
+ />
+ <path
+ fill="#000"
+ d="M48.105 50.5a7.905 7.905 0 0 0-15.81 0 7.905 7.905 0 0 0 15.81 0"
+ />
+ <circle
+ cx="1.854"
+ cy="1.854"
+ r="1.854"
+ fill="#fff"
+ transform="matrix(-1 0 0 1 44.718 50.145)"
+ />
+ <path fill="#fff" d="M42.046 46.503H38.73l-3.154 7.35h3.317z" />
+ <text
+ xmlSpace="preserve"
+ fill="#262626"
+ fontSize="9.223"
+ fontWeight="500"
+ letterSpacing="-.02em"
+ style={{ whiteSpace: "pre" }}
+ >
+ <tspan x="61.845" y="47.942">
+ Primary logo
+ </tspan>
+ </text>
+ <text
+ xmlSpace="preserve"
+ fill="#737373"
+ fontSize="7.906"
+ letterSpacing="-.02em"
+ style={{ whiteSpace: "pre" }}
+ >
+ <tspan x="61.845" y="60.145">
+ SVG
+ </tspan>
+ </text>
+ </g>
+ <defs>
+ <clipPath id={`${id}-a`}>
+ <path fill="#fff" d="M0 0h168v100H0z" />
+ </clipPath>
+ </defs>
+ </svg>
+ );
+}
diff --git a/apps/web/ui/partners/design/modals/image-block-modal.tsx b/apps/web/ui/partners/design/modals/image-block-modal.tsx
new file mode 100644
index 0000000000..eb8120668f
--- /dev/null
+++ b/apps/web/ui/partners/design/modals/image-block-modal.tsx
@@ -0,0 +1,10 @@
+export function ImageBlockThumbnail() {
+ return (
+ <div className="relative aspect-[4/3] w-1/2 overflow-hidden rounded">
+ <img
+ src="https://assets.dub.co/misc/fun-thumbnail.jpg"
+ className="object-cover"
+ />
+ </div>
+ );
+}
diff --git a/apps/web/ui/partners/design/modals/text-block-modal.tsx b/apps/web/ui/partners/design/modals/text-block-modal.tsx
new file mode 100644
index 0000000000..17e897fd6b
--- /dev/null
+++ b/apps/web/ui/partners/design/modals/text-block-modal.tsx
@@ -0,0 +1,140 @@
+"use client";
+
+import { Button, Modal, useEnterSubmit, useMediaQuery } from "@dub/ui";
+import { Dispatch, SetStateAction, useId } from "react";
+import { useForm } from "react-hook-form";
+
+type TextBlockFormData = {
+ title: string;
+ content: string;
+};
+
+type TextBlockModalProps = {
+ showModal: boolean;
+ setShowModal: Dispatch<SetStateAction<boolean>>;
+ defaultValues?: Partial<TextBlockFormData>;
+ onSubmit: (data: TextBlockFormData) => void;
+};
+
+export function TextBlockModal(props: TextBlockModalProps) {
+ return (
+ <Modal showModal={props.showModal} setShowModal={props.setShowModal}>
+ <TextBlockModalInner {...props} />
+ </Modal>
+ );
+}
+
+function TextBlockModalInner({
+ setShowModal,
+ onSubmit,
+ defaultValues,
+}: TextBlockModalProps) {
+ const id = useId();
+ const { isMobile } = useMediaQuery();
+ const { handleSubmit, register } = useForm<TextBlockFormData>({
+ defaultValues,
+ });
+
+ const { handleKeyDown } = useEnterSubmit();
+
+ return (
+ <>
+ <div className="p-4 pt-3">
+ <h3 className="text-base font-semibold leading-6 text-neutral-800">
+ Add Text
+ </h3>
+ <form
+ className="mt-4 flex flex-col gap-6"
+ onSubmit={(e) => {
+ e.stopPropagation();
+ handleSubmit(async (data) => {
+ setShowModal(false);
+ onSubmit(data);
+ })(e);
+ }}
+ >
+ {/* Title */}
+ <div>
+ <label
+ htmlFor={`${id}-title`}
+ className="flex items-center gap-2 text-sm font-medium text-neutral-700"
+ >
+ Section heading
+ </label>
+ <div className="mt-2 rounded-md shadow-sm">
+ <input
+ id={`${id}-title`}
+ type="text"
+ placeholder="Title"
+ autoFocus={!isMobile}
+ className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ {...register("title")}
+ />
+ </div>
+ </div>
+
+ {/* Description */}
+ <div>
+ <label
+ htmlFor={`${id}-content`}
+ className="flex items-center gap-2 text-sm font-medium text-neutral-700"
+ >
+ Content
+ </label>
+ <div className="mt-2 rounded-md shadow-sm">
+ <textarea
+ id={`${id}-content`}
+ rows={12}
+ maxLength={240}
+ onKeyDown={handleKeyDown}
+ placeholder="Start typing (markdown supported)"
+ className="block max-h-64 min-h-16 w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ {...register("content")}
+ />
+ </div>
+ </div>
+
+ <div className="flex items-center justify-end gap-2">
+ <Button
+ onClick={() => setShowModal(false)}
+ variant="secondary"
+ text="Cancel"
+ className="h-8 w-fit px-3"
+ />
+ <Button
+ type="submit"
+ variant="primary"
+ text="Add"
+ className="h-8 w-fit px-3"
+ />
+ </div>
+ </form>
+ </div>
+ </>
+ );
+}
+
+export function TextBlockThumbnail() {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="168"
+ height="100"
+ fill="none"
+ viewBox="0 0 168 100"
+ className="h-auto w-full"
+ >
+ <path fill="#D9D9D9" d="M34 43h2v14h-2z"></path>
+ <text
+ xmlSpace="preserve"
+ fill="#262626"
+ fontSize="13"
+ style={{ whiteSpace: "pre" }}
+ >
+ <tspan x="40" y="54.727">
+ About Acme
+ </tspan>
+ </text>
+ </svg>
+ );
+}