The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add branding form
Tim Wilson195a2b215964
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/landing/branding-settings-form.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/landing/branding-settings-form.tsxnew file mode 100644index 0000000000..5e5a024485--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/landing/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 "./page-client";++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/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/landing/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/landing/page-client.tsxindex 0832c3f1f8..5da6460754 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/landing/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/branding/landing/page-client.tsx@@ -1,7 +1,8 @@"use client";import useProgram from "@/lib/swr/use-program";-import { ProgramWithLanderDataProps } from "@/lib/types";+import { 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";@@ -9,64 +10,101 @@ import { LanderRewards } from "@/ui/partners/lander-rewards";import { Brush, Button, useScroll, Wordmark } from "@dub/ui";import { cn, PARTNERS_DOMAIN } from "@dub/utils";import { CSSProperties, useRef, useState } from "react";+import {+ FormProvider,+ useForm,+ useFormContext,+ useWatch,+} from "react-hook-form";+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>();+}export function ProgramBrandingLandingPageClient() {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 { 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 (- <div className="overflow-hidden rounded-lg border border-neutral-200 bg-neutral-100">- <div className="flex items-center justify-between border-b border-neutral-200 bg-white px-4 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="button"- onClick={() => alert("WIP")}- variant="primary"- text="Publish"- className="h-8 w-fit"- />+ <form 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-4 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="button"+ onClick={() => alert("WIP")}+ variant="primary"+ text="Publish"+ className="h-8 w-fit"+ />+ </div></div>- </div>- <div- className={cn(- "grid 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(- "h-full border-neutral-200 p-5 transition-opacity max-lg:border-b lg:w-[240px] lg:border-r",- !isSidePanelOpen && "opacity-0",- )}- >- <div className="rounded-lg border border-neutral-300 bg-white p-3 text-sm text-neutral-500">- WIP+ <div+ className={cn(+ "grid 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(+ "h-full 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-[calc(100vh-240px)] px-4 pt-4">+ {program && <LanderPreview program={program} />}+ </div></div>- <div className="h-[calc(100vh-240px)] px-4 pt-4">- {program && <LanderPreview program={program} />}- </div>- </div>- </div>+ </FormProvider>+ </form>);}@@ -76,6 +114,8 @@ function LanderPreview({ program }: { program: ProgramWithLanderDataProps }) {const landerData = program.landerData ?? { blocks: [] };+ const brandColor = useWatch({ name: "brandColor" });+return (<PreviewWindowurl={`${PARTNERS_DOMAIN}/${program?.slug}`}@@ -86,7 +126,7 @@ function LanderPreview({ program }: { program: ProgramWithLanderDataProps }) {<divstyle={{- "--brand": program.brandColor || "#000000",+ "--brand": brandColor || "#000000","--brand-ring": "rgb(from var(--brand) r g b / 0.2)",} as CSSProperties}