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 EditHeroModal

Tim Wilson15fac70b0801
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/page-client.tsx
index bd4e81779c..d191fde804 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/page-client.tsx
@@ -1,444 +1,7 @@
"use client";
-import { updateProgramAction } from "@/lib/actions/partners/update-program";
-import useProgram from "@/lib/swr/use-program";
-import useWorkspace from "@/lib/swr/use-workspace";
-import {
- ProgramLanderData,
- ProgramProps,
- ProgramWithLanderDataProps,
-} from "@/lib/types";
-import { programLanderSchema } from "@/lib/zod/schemas/program-lander";
-import { PreviewWindow } from "@/ui/partners/design/preview-window";
-import { BLOCK_COMPONENTS } from "@/ui/partners/lander-blocks";
-import { LanderHero } from "@/ui/partners/lander-hero";
-import { LanderRewards } from "@/ui/partners/lander-rewards";
-import {
- Brush,
- Button,
- Grid,
- Pen2,
- Plus2,
- Tooltip,
- Trash,
- useScroll,
- Wordmark,
-} from "@dub/ui";
-import { cn, PARTNERS_DOMAIN } from "@dub/utils";
-import { ArrowDown, ArrowUp } from "lucide-react";
-import { useAction } from "next-safe-action/hooks";
-import {
- CSSProperties,
- PropsWithChildren,
- useCallback,
- useRef,
- useState,
-} from "react";
-import {
- FormProvider,
- useForm,
- useFormContext,
- useWatch,
-} from "react-hook-form";
-import { toast } from "sonner";
-import { mutate } from "swr";
-import { z } from "zod";
-import { BrandingSettingsForm } from "./branding-settings-form";
-
-type FormData = {
- landerData: z.infer<typeof programLanderSchema>;
-} & Pick<ProgramProps, "logo" | "wordmark" | "brandColor">;
-
-export function useProgramBrandingForm() {
- return useFormContext<FormData>();
-}
+import { BrandingForm } from "@/ui/partners/design/branding-form";
export function ProgramBrandingLandingPageClient() {
- const { id: workspaceId } = useWorkspace();
- const { program } = useProgram<ProgramWithLanderDataProps>({
- query: { includeLanderData: true },
- });
-
- const [isSidePanelOpen, setIsSidePanelOpen] = useState(true);
-
- const form = useForm<FormData>({
- values: {
- logo: program?.logo ?? null,
- wordmark: program?.wordmark ?? null,
- brandColor: program?.brandColor ?? null,
- landerData: program?.landerData ?? { blocks: [] },
- },
- });
-
- const {
- handleSubmit,
- reset,
- formState: { isSubmitting },
- } = form;
-
- const { executeAsync } = useAction(updateProgramAction, {
- async onSuccess() {
- toast.success("Program updated successfully.");
- mutate(`/api/programs/${program?.id}?workspaceId=${workspaceId}`);
- },
- onError({ error }) {
- console.error(error);
- toast.error("Failed to update program.");
- },
- });
-
- return (
- <form
- onSubmit={handleSubmit(async (data) => {
- await executeAsync({
- workspaceId: workspaceId!,
- programId: program!.id,
- ...data,
- });
-
- // Reset isDirty state
- reset(data);
- })}
- className="overflow-hidden rounded-lg border border-neutral-200 bg-neutral-100"
- >
- <FormProvider {...form}>
- <div className="flex items-center justify-between border-b border-neutral-200 bg-white px-5 py-3">
- <div className="grow basis-0">
- <Button
- type="button"
- onClick={() => setIsSidePanelOpen(!isSidePanelOpen)}
- data-state={isSidePanelOpen ? "open" : "closed"}
- variant="secondary"
- icon={<Brush className="size-4" />}
- className="hidden size-8 p-0 lg:flex"
- />
- </div>
- <span className="text-center text-xs font-medium text-neutral-500">
- Landing page
- </span>
- <div className="flex grow basis-0 justify-end">
- <Button
- type="submit"
- variant="primary"
- text="Publish"
- loading={isSubmitting}
- className="h-8 w-fit px-3"
- />
- </div>
- </div>
- <div
- className={cn(
- "grid h-[calc(100vh-186px)] grid-cols-1 transition-[grid-template-columns]",
- isSidePanelOpen
- ? "lg:grid-cols-[240px_minmax(0,1fr)]"
- : "lg:grid-cols-[0px_minmax(0,1fr)]",
- )}
- >
- <div className="h-full overflow-hidden">
- <div
- className={cn(
- "scrollbar-hide h-full overflow-y-auto border-neutral-200 p-5 transition-opacity max-lg:border-b lg:w-[240px] lg:border-r",
- !isSidePanelOpen && "opacity-0",
- )}
- >
- <BrandingSettingsForm />
- </div>
- </div>
- <div className="h-full overflow-hidden px-4 pt-4">
- {program && <LanderPreview program={program} />}
- </div>
- </div>
- </FormProvider>
- </form>
- );
+ return <BrandingForm />;
}
-
-function LanderPreview({ program }: { program: ProgramWithLanderDataProps }) {
- const scrollRef = useRef<HTMLDivElement>(null);
- const scrolled = useScroll(0, { container: scrollRef });
-
- const { control, setValue } = useProgramBrandingForm();
- const [landerData, brandColor, logo, wordmark] = useWatch({
- control,
- name: ["landerData", "brandColor", "logo", "wordmark"],
- });
-
- const updateBlocks = useCallback(
- (
- fn: (blocks: ProgramLanderData["blocks"]) => ProgramLanderData["blocks"],
- ) => {
- return setValue(
- "landerData",
- {
- ...landerData,
- blocks: fn(landerData.blocks),
- },
- {
- shouldDirty: true,
- },
- );
- },
- [landerData],
- );
-
- return (
- <PreviewWindow
- url={`${PARTNERS_DOMAIN}/${program?.slug}`}
- scrollRef={scrollRef}
- >
- <div className="relative z-0 mx-auto min-h-screen w-full bg-white">
- <div
- style={
- {
- "--brand": brandColor || "#000000",
- "--brand-ring": "rgb(from var(--brand) r g b / 0.2)",
- } as CSSProperties
- }
- >
- <header className={"sticky top-0 z-10 bg-white/90 backdrop-blur-sm"}>
- <div className="mx-auto flex max-w-screen-sm items-center justify-between px-6 py-4">
- {/* Bottom border when scrolled */}
- <div
- className={cn(
- "absolute inset-x-0 bottom-0 h-px bg-neutral-200 opacity-0 transition-opacity duration-300 [mask-image:linear-gradient(90deg,transparent,black,transparent)]",
- scrolled && "opacity-100",
- )}
- />
-
- <div className="animate-fade-in my-0.5 block">
- {wordmark || logo ? (
- <img
- className="max-h-7 max-w-32"
- src={(wordmark ?? logo) as string}
- />
- ) : (
- <Wordmark className="h-7" />
- )}
- </div>
-
- <div className="flex items-center gap-2" {...{ inert: "" }}>
- <Button
- type="button"
- variant="secondary"
- text="Log in"
- className="animate-fade-in h-8 w-fit text-neutral-600"
- />
- <Button
- type="button"
- text="Apply"
- className="animate-fade-in h-8 w-fit border-[var(--brand)] bg-[var(--brand)] hover:bg-[var(--brand)] hover:ring-[var(--brand-ring)]"
- />
- </div>
- </div>
- </header>
- <div className="group relative mt-6">
- <EditIndicatorGrid />
- <EditToolbar />
- <div className="mx-auto max-w-screen-sm">
- <div className="px-6">
- <LanderHero program={program} />
- </div>
- </div>
- </div>
- <div className="mx-auto max-w-screen-sm">
- <div className="px-6">
- {/* Program details grid */}
- <LanderRewards
- program={{
- rewards: program.rewards ?? [],
- defaultDiscount:
- program.discounts?.find(
- (d) => d.id === program.defaultDiscountId,
- ) || null,
- }}
- />
-
- {/* Buttons */}
- <div
- className="animate-scale-in-fade mt-10 flex flex-col gap-2 [animation-delay:400ms] [animation-fill-mode:both]"
- {...{ inert: "" }}
- >
- <Button
- type="button"
- text="Apply today"
- className="border-[var(--brand)] bg-[var(--brand)] hover:bg-[var(--brand)] hover:ring-[var(--brand-ring)]"
- />
- </div>
- </div>
- </div>
-
- {/* Content blocks */}
- <div className="relative z-0 mt-6 grid grid-cols-1">
- {landerData?.blocks.map((block, idx) => {
- const Component = BLOCK_COMPONENTS[block.type];
- return Component ? (
- <div key={block.id} className="group relative py-10">
- <EditIndicatorGrid />
-
- {/* Edit toolbar */}
-
- <EditToolbar
- onMoveUp={
- idx !== 0
- ? () =>
- updateBlocks((blocks) =>
- moveItem(blocks, idx, idx - 1),
- )
- : undefined
- }
- onMoveDown={
- idx !== landerData.blocks.length - 1
- ? () =>
- updateBlocks((blocks) =>
- moveItem(blocks, idx, idx + 1),
- )
- : undefined
- }
- onDelete={() =>
- updateBlocks((blocks) => blocks.toSpliced(idx, 1))
- }
- />
-
- {/* Insert block button */}
- <div
- className={cn(
- "pointer-events-none absolute inset-0 opacity-0",
- "transition-opacity duration-150 group-hover:opacity-100 group-has-[+div:hover]:opacity-100",
- )}
- >
- <div className="absolute inset-x-0 top-0 z-10 hidden group-first:block">
- <div className="pointer-events-auto absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
- <InsertBlockButton />
- </div>
- </div>
- <div className="absolute inset-x-0 bottom-0 z-10">
- <div className="pointer-events-auto absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
- <InsertBlockButton />
- </div>
- </div>
- </div>
-
- <div
- className="relative mx-auto max-w-screen-sm"
- {...{ inert: "" }}
- >
- <div className="px-6">
- <Component block={block} logo={program.logo} preview />
- </div>
- </div>
- </div>
- ) : null;
- })}
- </div>
- </div>
- </div>
- </PreviewWindow>
- );
-}
-
-function InsertBlockButton() {
- return (
- <Button
- type="button"
- text="Insert block"
- onClick={() => toast.info("WIP")}
- icon={<Plus2 className="size-2.5" />}
- variant="secondary"
- className="h-6 w-fit gap-1 px-2.5 text-xs"
- />
- );
-}
-
-function EditIndicatorGrid() {
- return (
- <div className="border-subtle pointer-events-none absolute inset-y-0 left-1/2 w-[1080px] max-w-[calc(100cqw-32px)] -translate-x-1/2 overflow-hidden rounded-xl border opacity-0 transition-opacity duration-150 group-hover:opacity-100">
- <Grid
- cellSize={60}
- className="text-border-subtle inset-[unset] left-1/2 top-1/2 h-[max(1200px,100%)] w-[1200px] -translate-x-1/2 -translate-y-1/2"
- />
- </div>
- );
-}
-
-function EditToolbar({
- onMoveUp,
- onMoveDown,
- onDelete,
-}: {
- onMoveUp?: () => void;
- onMoveDown?: () => void;
- onDelete?: () => void;
-}) {
- return (
- <div className="absolute inset-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
- <div className="absolute right-6 top-2">
- <div className="flex items-center rounded-md border border-neutral-200 bg-white p-1 shadow-sm">
- <EditToolbarTooltip content="Edit">
- <Button
- type="button"
- variant="outline"
- icon={<Pen2 className="size-4" />}
- className="size-7 rounded p-0"
- onClick={() => toast.info("WIP")}
- />
- </EditToolbarTooltip>
- {onMoveUp && (
- <EditToolbarTooltip content="Move up">
- <Button
- type="button"
- variant="outline"
- icon={<ArrowUp className="size-4" />}
- className="size-7 rounded p-0"
- onClick={onMoveUp}
- />
- </EditToolbarTooltip>
- )}
- {onMoveDown && (
- <EditToolbarTooltip content="Move down">
- <Button
- type="button"
- variant="outline"
- icon={<ArrowDown className="size-4" />}
- className="size-7 rounded p-0"
- onClick={onMoveDown}
- />
- </EditToolbarTooltip>
- )}
- {onDelete && (
- <EditToolbarTooltip content="Delete">
- <Button
- type="button"
- variant="outline"
- icon={<Trash className="size-4" />}
- className="size-7 rounded p-0"
- onClick={onDelete}
- />
- </EditToolbarTooltip>
- )}
- </div>
- </div>
- </div>
- );
-}
-
-function EditToolbarTooltip({
- content,
- children,
-}: PropsWithChildren<{ content: string }>) {
- return (
- <Tooltip
- content={
- <div className="px-2 py-1 text-xs text-neutral-600">{content}</div>
- }
- disableHoverableContent
- >
- <div>{children}</div>
- </Tooltip>
- );
-}
-
-const moveItem = <T extends any>(array: T[], from: number, to: number) => {
- const newArray = array.slice();
- newArray.splice(to, 0, newArray.splice(from, 1)[0]);
- return newArray;
-};
diff --git a/apps/web/lib/zod/schemas/program-lander.ts b/apps/web/lib/zod/schemas/program-lander.ts
index 19fdf6dd17..067d8c512c 100644
--- a/apps/web/lib/zod/schemas/program-lander.ts
+++ b/apps/web/lib/zod/schemas/program-lander.ts
@@ -66,5 +66,7 @@ export const programLanderBlockSchema = z.discriminatedUnion("type", [
]);
export const programLanderSchema = z.object({
+ title: z.string().optional(),
+ description: z.string().optional(),
blocks: z.array(programLanderBlockSchema),
});
diff --git a/apps/web/ui/partners/design/branding-form.tsx b/apps/web/ui/partners/design/branding-form.tsx
new file mode 100644
index 0000000000..dc731a6334
--- /dev/null
+++ b/apps/web/ui/partners/design/branding-form.tsx
@@ -0,0 +1,457 @@
+"use client";
+
+import { updateProgramAction } from "@/lib/actions/partners/update-program";
+import useProgram from "@/lib/swr/use-program";
+import useWorkspace from "@/lib/swr/use-workspace";
+import {
+ ProgramLanderData,
+ ProgramProps,
+ ProgramWithLanderDataProps,
+} from "@/lib/types";
+import { programLanderSchema } from "@/lib/zod/schemas/program-lander";
+import { useEditHeroModal } from "@/ui/partners/design/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";
+import { LanderRewards } from "@/ui/partners/lander-rewards";
+import {
+ Brush,
+ Button,
+ Grid,
+ Pen2,
+ Plus2,
+ Tooltip,
+ Trash,
+ useScroll,
+ Wordmark,
+} from "@dub/ui";
+import { cn, PARTNERS_DOMAIN } from "@dub/utils";
+import { ArrowDown, ArrowUp } from "lucide-react";
+import { useAction } from "next-safe-action/hooks";
+import {
+ CSSProperties,
+ PropsWithChildren,
+ useCallback,
+ useRef,
+ useState,
+} from "react";
+import {
+ FormProvider,
+ useForm,
+ useFormContext,
+ useWatch,
+} from "react-hook-form";
+import { toast } from "sonner";
+import { mutate } from "swr";
+import { z } from "zod";
+import { BrandingSettingsForm } from "./branding-settings-form";
+
+export type BrandingFormData = {
+ landerData: z.infer<typeof programLanderSchema>;
+} & Pick<ProgramProps, "logo" | "wordmark" | "brandColor">;
+
+export function useProgramBrandingForm() {
+ return useFormContext<BrandingFormData>();
+}
+
+export function BrandingForm() {
+ const { id: workspaceId } = useWorkspace();
+ const { program } = useProgram<ProgramWithLanderDataProps>({
+ query: { includeLanderData: true },
+ });
+
+ const [isSidePanelOpen, setIsSidePanelOpen] = useState(true);
+
+ const form = useForm<BrandingFormData>({
+ values: {
+ logo: program?.logo ?? null,
+ wordmark: program?.wordmark ?? null,
+ brandColor: program?.brandColor ?? null,
+ landerData: program?.landerData ?? { blocks: [] },
+ },
+ });
+
+ const {
+ handleSubmit,
+ reset,
+ formState: { isSubmitting },
+ } = form;
+
+ const { executeAsync } = useAction(updateProgramAction, {
+ async onSuccess() {
+ toast.success("Program updated successfully.");
+ mutate(`/api/programs/${program?.id}?workspaceId=${workspaceId}`);
+ },
+ onError({ error }) {
+ console.error(error);
+ toast.error("Failed to update program.");
+ },
+ });
+
+ return (
+ <form
+ onSubmit={handleSubmit(async (data) => {
+ await executeAsync({
+ workspaceId: workspaceId!,
+ programId: program!.id,
+ ...data,
+ });
+
+ // Reset isDirty state
+ reset(data);
+ })}
+ className="overflow-hidden rounded-lg border border-neutral-200 bg-neutral-100"
+ >
+ <FormProvider {...form}>
+ <div className="flex items-center justify-between border-b border-neutral-200 bg-white px-5 py-3">
+ <div className="grow basis-0">
+ <Button
+ type="button"
+ onClick={() => setIsSidePanelOpen(!isSidePanelOpen)}
+ data-state={isSidePanelOpen ? "open" : "closed"}
+ variant="secondary"
+ icon={<Brush className="size-4" />}
+ className="hidden size-8 p-0 lg:flex"
+ />
+ </div>
+ <span className="text-center text-xs font-medium text-neutral-500">
+ Landing page
+ </span>
+ <div className="flex grow basis-0 justify-end">
+ <Button
+ type="submit"
+ variant="primary"
+ text="Publish"
+ loading={isSubmitting}
+ className="h-8 w-fit px-3"
+ />
+ </div>
+ </div>
+ <div
+ className={cn(
+ "grid h-[calc(100vh-186px)] grid-cols-1 transition-[grid-template-columns]",
+ isSidePanelOpen
+ ? "lg:grid-cols-[240px_minmax(0,1fr)]"
+ : "lg:grid-cols-[0px_minmax(0,1fr)]",
+ )}
+ >
+ <div className="h-full overflow-hidden">
+ <div
+ className={cn(
+ "scrollbar-hide h-full overflow-y-auto border-neutral-200 p-5 transition-opacity max-lg:border-b lg:w-[240px] lg:border-r",
+ !isSidePanelOpen && "opacity-0",
+ )}
+ >
+ <BrandingSettingsForm />
+ </div>
+ </div>
+ <div className="h-full overflow-hidden px-4 pt-4">
+ {program && <LanderPreview program={program} />}
+ </div>
+ </div>
+ </FormProvider>
+ </form>
+ );
+}
+
+function LanderPreview({ program }: { program: ProgramWithLanderDataProps }) {
+ const scrollRef = useRef<HTMLDivElement>(null);
+ const scrolled = useScroll(0, { container: scrollRef });
+
+ const { control, setValue } = useProgramBrandingForm();
+ const [landerData, brandColor, logo, wordmark] = useWatch({
+ control,
+ name: ["landerData", "brandColor", "logo", "wordmark"],
+ });
+
+ const updateBlocks = useCallback(
+ (
+ fn: (blocks: ProgramLanderData["blocks"]) => ProgramLanderData["blocks"],
+ ) => {
+ return setValue(
+ "landerData",
+ {
+ ...landerData,
+ blocks: fn(landerData.blocks),
+ },
+ {
+ shouldDirty: true,
+ },
+ );
+ },
+ [landerData],
+ );
+
+ const { setShowEditHeroModal, EditHeroModal } = useEditHeroModal();
+
+ return (
+ <>
+ <EditHeroModal />
+ <PreviewWindow
+ url={`${PARTNERS_DOMAIN}/${program?.slug}`}
+ scrollRef={scrollRef}
+ >
+ <div className="relative z-0 mx-auto min-h-screen w-full bg-white">
+ <div
+ style={
+ {
+ "--brand": brandColor || "#000000",
+ "--brand-ring": "rgb(from var(--brand) r g b / 0.2)",
+ } as CSSProperties
+ }
+ >
+ <header
+ className={"sticky top-0 z-10 bg-white/90 backdrop-blur-sm"}
+ >
+ <div className="mx-auto flex max-w-screen-sm items-center justify-between px-6 py-4">
+ {/* Bottom border when scrolled */}
+ <div
+ className={cn(
+ "absolute inset-x-0 bottom-0 h-px bg-neutral-200 opacity-0 transition-opacity duration-300 [mask-image:linear-gradient(90deg,transparent,black,transparent)]",
+ scrolled && "opacity-100",
+ )}
+ />
+
+ <div className="animate-fade-in my-0.5 block">
+ {wordmark || logo ? (
+ <img
+ className="max-h-7 max-w-32"
+ src={(wordmark ?? logo) as string}
+ />
+ ) : (
+ <Wordmark className="h-7" />
+ )}
+ </div>
+
+ <div className="flex items-center gap-2" {...{ inert: "" }}>
+ <Button
+ type="button"
+ variant="secondary"
+ text="Log in"
+ className="animate-fade-in h-8 w-fit text-neutral-600"
+ />
+ <Button
+ type="button"
+ text="Apply"
+ className="animate-fade-in h-8 w-fit border-[var(--brand)] bg-[var(--brand)] hover:bg-[var(--brand)] hover:ring-[var(--brand-ring)]"
+ />
+ </div>
+ </div>
+ </header>
+ <div className="group relative mt-6">
+ <EditIndicatorGrid />
+ <EditToolbar onEdit={() => setShowEditHeroModal(true)} />
+ <div className="mx-auto max-w-screen-sm">
+ <div className="px-6">
+ <LanderHero program={program} />
+ </div>
+ </div>
+ </div>
+ <div className="mx-auto max-w-screen-sm">
+ <div className="px-6">
+ {/* Program details grid */}
+ <LanderRewards
+ program={{
+ rewards: program.rewards ?? [],
+ defaultDiscount:
+ program.discounts?.find(
+ (d) => d.id === program.defaultDiscountId,
+ ) || null,
+ }}
+ />
+
+ {/* Buttons */}
+ <div
+ className="animate-scale-in-fade mt-10 flex flex-col gap-2 [animation-delay:400ms] [animation-fill-mode:both]"
+ {...{ inert: "" }}
+ >
+ <Button
+ type="button"
+ text="Apply today"
+ className="border-[var(--brand)] bg-[var(--brand)] hover:bg-[var(--brand)] hover:ring-[var(--brand-ring)]"
+ />
+ </div>
+ </div>
+ </div>
+
+ {/* Content blocks */}
+ <div className="relative z-0 mt-6 grid grid-cols-1">
+ {landerData?.blocks.map((block, idx) => {
+ const Component = BLOCK_COMPONENTS[block.type];
+ return Component ? (
+ <div key={block.id} className="group relative py-10">
+ <EditIndicatorGrid />
+
+ {/* Edit toolbar */}
+
+ <EditToolbar
+ onEdit={() => toast.info("WIP")}
+ onMoveUp={
+ idx !== 0
+ ? () =>
+ updateBlocks((blocks) =>
+ moveItem(blocks, idx, idx - 1),
+ )
+ : undefined
+ }
+ onMoveDown={
+ idx !== landerData.blocks.length - 1
+ ? () =>
+ updateBlocks((blocks) =>
+ moveItem(blocks, idx, idx + 1),
+ )
+ : undefined
+ }
+ onDelete={() =>
+ updateBlocks((blocks) => blocks.toSpliced(idx, 1))
+ }
+ />
+
+ {/* Insert block button */}
+ <div
+ className={cn(
+ "pointer-events-none absolute inset-0 opacity-0",
+ "transition-opacity duration-150 group-hover:opacity-100 group-has-[+div:hover]:opacity-100",
+ )}
+ >
+ <div className="absolute inset-x-0 top-0 z-10 hidden group-first:block">
+ <div className="pointer-events-auto absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
+ <InsertBlockButton />
+ </div>
+ </div>
+ <div className="absolute inset-x-0 bottom-0 z-10">
+ <div className="pointer-events-auto absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
+ <InsertBlockButton />
+ </div>
+ </div>
+ </div>
+
+ <div
+ className="relative mx-auto max-w-screen-sm"
+ {...{ inert: "" }}
+ >
+ <div className="px-6">
+ <Component block={block} logo={program.logo} preview />
+ </div>
+ </div>
+ </div>
+ ) : null;
+ })}
+ </div>
+ </div>
+ </div>
+ </PreviewWindow>
+ </>
+ );
+}
+
+function InsertBlockButton() {
+ return (
+ <Button
+ type="button"
+ text="Insert block"
+ onClick={() => toast.info("WIP")}
+ icon={<Plus2 className="size-2.5" />}
+ variant="secondary"
+ className="h-6 w-fit gap-1 px-2.5 text-xs"
+ />
+ );
+}
+
+function EditIndicatorGrid() {
+ return (
+ <div className="border-subtle pointer-events-none absolute inset-y-0 left-1/2 w-[1080px] max-w-[calc(100cqw-32px)] -translate-x-1/2 overflow-hidden rounded-xl border opacity-0 transition-opacity duration-150 group-hover:opacity-100">
+ <Grid
+ cellSize={60}
+ className="text-border-subtle inset-[unset] left-1/2 top-1/2 h-[max(1200px,100%)] w-[1200px] -translate-x-1/2 -translate-y-1/2"
+ />
+ </div>
+ );
+}
+
+function EditToolbar({
+ onEdit,
+ onMoveUp,
+ onMoveDown,
+ onDelete,
+}: {
+ onEdit?: () => void;
+ onMoveUp?: () => void;
+ onMoveDown?: () => void;
+ onDelete?: () => void;
+}) {
+ return (
+ <div className="absolute inset-0 opacity-0 transition-opacity duration-150 group-hover:opacity-100">
+ <div className="absolute right-6 top-2">
+ <div className="flex items-center rounded-md border border-neutral-200 bg-white p-1 shadow-sm">
+ {onEdit && (
+ <EditToolbarTooltip content="Edit">
+ <Button
+ type="button"
+ variant="outline"
+ icon={<Pen2 className="size-4" />}
+ className="size-7 rounded p-0"
+ onClick={onEdit}
+ />
+ </EditToolbarTooltip>
+ )}
+ {onMoveUp && (
+ <EditToolbarTooltip content="Move up">
+ <Button
+ type="button"
+ variant="outline"
+ icon={<ArrowUp className="size-4" />}
+ className="size-7 rounded p-0"
+ onClick={onMoveUp}
+ />
+ </EditToolbarTooltip>
+ )}
+ {onMoveDown && (
+ <EditToolbarTooltip content="Move down">
+ <Button
+ type="button"
+ variant="outline"
+ icon={<ArrowDown className="size-4" />}
+ className="size-7 rounded p-0"
+ onClick={onMoveDown}
+ />
+ </EditToolbarTooltip>
+ )}
+ {onDelete && (
+ <EditToolbarTooltip content="Delete">
+ <Button
+ type="button"
+ variant="outline"
+ icon={<Trash className="size-4" />}
+ className="size-7 rounded p-0"
+ onClick={onDelete}
+ />
+ </EditToolbarTooltip>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function EditToolbarTooltip({
+ content,
+ children,
+}: PropsWithChildren<{ content: string }>) {
+ return (
+ <Tooltip
+ content={
+ <div className="px-2 py-1 text-xs text-neutral-600">{content}</div>
+ }
+ disableHoverableContent
+ >
+ <div>{children}</div>
+ </Tooltip>
+ );
+}
+
+const moveItem = <T extends any>(array: T[], from: number, to: number) => {
+ const newArray = array.slice();
+ newArray.splice(to, 0, newArray.splice(from, 1)[0]);
+ return newArray;
+};
diff --git a/apps/web/ui/partners/design/branding-settings-form.tsx b/apps/web/ui/partners/design/branding-settings-form.tsx
new file mode 100644
index 0000000000..b5aea8f46f
--- /dev/null
+++ b/apps/web/ui/partners/design/branding-settings-form.tsx
@@ -0,0 +1,136 @@
+"use client";
+
+import { ProgramColorPicker } from "@/ui/partners/program-color-picker";
+import { FileUpload } from "@dub/ui";
+import { Plus } from "@dub/ui/icons";
+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";
+
+export function BrandingSettingsForm() {
+ const { control } = useProgramBrandingForm();
+
+ return (
+ <div>
+ <div className="grid grid-cols-1 gap-10">
+ <div className="flex flex-col gap-6">
+ <FormRow
+ label="Logo"
+ description="A square logo that will be used in various parts of your program"
+ >
+ {(id) => (
+ <Controller
+ control={control}
+ name="logo"
+ rules={{ required: flightRouterStateSchema }}
+ render={({ field }) => (
+ <FileUpload
+ id={id}
+ accept="images"
+ className="h-14 rounded-lg border border-neutral-300 p-1"
+ iconClassName="size-4 text-neutral-800"
+ previewClassName="object-contain"
+ icon={Plus}
+ variant="plain"
+ imageSrc={field.value}
+ readFile
+ onChange={({ src }) => field.onChange(src)}
+ content={null}
+ maxFileSizeMB={2}
+ />
+ )}
+ />
+ )}
+ </FormRow>
+
+ <Divider />
+
+ <FormRow
+ label="Wordmark"
+ description="A full-sized logo used on the program application form"
+ >
+ {(id) => (
+ <Controller
+ control={control}
+ name="wordmark"
+ rules={{ required: false }}
+ render={({ field }) => (
+ <FileUpload
+ id={id}
+ accept="images"
+ className="h-20 rounded-lg border border-neutral-300 p-1"
+ iconClassName="size-4 text-neutral-800"
+ previewClassName="object-contain"
+ icon={Plus}
+ variant="plain"
+ imageSrc={field.value}
+ readFile
+ onChange={({ src }) => field.onChange(src)}
+ content={null}
+ maxFileSizeMB={2}
+ />
+ )}
+ />
+ )}
+ </FormRow>
+
+ <Divider />
+
+ <FormRow label="Brand color" inline>
+ {(id) => (
+ <Controller
+ control={control}
+ name="brandColor"
+ render={({ field }) => (
+ <ProgramColorPicker
+ color={field.value}
+ onChange={field.onChange}
+ id={id}
+ />
+ )}
+ />
+ )}
+ </FormRow>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+const Divider = () => <hr className="border-neutral-300" />;
+
+function FormRow({
+ label,
+ description,
+ inline = false,
+ children,
+}: {
+ label: string;
+ description?: string;
+ inline?: boolean;
+ children: (id: string) => ReactNode;
+}) {
+ const id = useId();
+
+ return (
+ <div
+ className={cn(
+ "flex flex-col justify-between gap-6",
+ inline && "flex-row items-center",
+ )}
+ >
+ <div className="flex flex-col gap-1">
+ <label className="text-sm font-medium text-neutral-800" htmlFor={id}>
+ {label}
+ </label>
+ {description && (
+ <p className="text-xs text-neutral-500">{description}</p>
+ )}
+ </div>
+
+ <div>{children(id)}</div>
+ </div>
+ );
+}
diff --git a/apps/web/ui/partners/design/edit-hero-modal.tsx b/apps/web/ui/partners/design/edit-hero-modal.tsx
new file mode 100644
index 0000000000..a8202d7b15
--- /dev/null
+++ b/apps/web/ui/partners/design/edit-hero-modal.tsx
@@ -0,0 +1,152 @@
+"use client";
+
+import useProgram from "@/lib/swr/use-program";
+import { Button, Modal, useEnterSubmit, useMediaQuery } from "@dub/ui";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useId,
+ useMemo,
+ useState,
+} from "react";
+import { useForm } from "react-hook-form";
+import { BrandingFormData, useProgramBrandingForm } from "./branding-form";
+
+type EditHeroModalProps = {
+ showEditHeroModal: boolean;
+ setShowEditHeroModal: Dispatch<SetStateAction<boolean>>;
+};
+
+function EditHeroModal(props: EditHeroModalProps) {
+ return (
+ <Modal
+ showModal={props.showEditHeroModal}
+ setShowModal={props.setShowEditHeroModal}
+ >
+ <EditHeroModalInner {...props} />
+ </Modal>
+ );
+}
+
+function EditHeroModalInner({ setShowEditHeroModal }: EditHeroModalProps) {
+ const id = useId();
+ const { isMobile } = useMediaQuery();
+ const { program } = useProgram();
+
+ const { getValues: getValuesParent, setValue: setValueParent } =
+ useProgramBrandingForm();
+
+ const {
+ register,
+ handleSubmit,
+ formState: { isDirty },
+ } = useForm<Pick<BrandingFormData, "landerData">>({
+ values: {
+ landerData: getValuesParent("landerData"),
+ },
+ });
+
+ const { handleKeyDown } = useEnterSubmit();
+
+ return (
+ <>
+ <form
+ className="px-5 py-4"
+ onSubmit={(e) => {
+ e.stopPropagation();
+ handleSubmit(({ landerData }) => {
+ setValueParent("landerData", landerData, {
+ shouldDirty: true,
+ });
+ setShowEditHeroModal(false);
+ })(e);
+ }}
+ >
+ <h3 className="text-base font-medium leading-none text-neutral-800">
+ Title and Description
+ </h3>
+
+ <div className="mt-4 flex flex-col gap-6">
+ {/* Title */}
+ <div>
+ <label
+ htmlFor={`${id}-title`}
+ className="flex items-center gap-2 text-sm font-medium text-neutral-700"
+ >
+ Title
+ </label>
+ <div className="mt-2 rounded-md shadow-sm">
+ <input
+ id={`${id}-title`}
+ type="text"
+ placeholder={`Join the ${program?.name} affiliate program`}
+ 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("landerData.title")}
+ />
+ </div>
+ </div>
+
+ {/* Description */}
+ <div>
+ <label
+ htmlFor={`${id}-description`}
+ className="flex items-center gap-2 text-sm font-medium text-neutral-700"
+ >
+ Description
+ </label>
+ <div className="mt-2 rounded-md shadow-sm">
+ <textarea
+ id={`${id}-description`}
+ rows={3}
+ onKeyDown={handleKeyDown}
+ placeholder={`Share ${program?.name} with your audience and for each subscription generated through your referral, you'll earn a share of the revenue on any plans they purchase.`}
+ 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("landerData.description")}
+ />
+ </div>
+ </div>
+ </div>
+
+ <div className="mt-4 flex items-center justify-end gap-2">
+ <Button
+ type="button"
+ variant="secondary"
+ text="Cancel"
+ className="h-9 w-fit"
+ onClick={() => setShowEditHeroModal(false)}
+ />
+ <Button
+ type="submit"
+ variant="primary"
+ text="Save"
+ className="h-9 w-fit"
+ disabled={!isDirty}
+ />
+ </div>
+ </form>
+ </>
+ );
+}
+
+export function useEditHeroModal() {
+ const [showEditHeroModal, setShowEditHeroModal] = useState(false);
+
+ const EditHeroModalCallback = useCallback(() => {
+ return (
+ <EditHeroModal
+ showEditHeroModal={showEditHeroModal}
+ setShowEditHeroModal={setShowEditHeroModal}
+ />
+ );
+ }, [showEditHeroModal, setShowEditHeroModal]);
+
+ return useMemo(
+ () => ({
+ setShowEditHeroModal,
+ EditHeroModal: EditHeroModalCallback,
+ }),
+ [setShowEditHeroModal, EditHeroModalCallback],
+ );
+}