The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Replace modal with popover
Tim Wilsone1ba3c77d4d3
diff --git a/apps/web/ui/partners/design/lander-ai-banner.tsx b/apps/web/ui/partners/design/lander-ai-banner.tsxindex a9888f94b8..f0cdf71f47 100644--- a/apps/web/ui/partners/design/lander-ai-banner.tsx+++ b/apps/web/ui/partners/design/lander-ai-banner.tsx@@ -5,15 +5,16 @@ import { programLanderSimpleSchema } from "@/lib/zod/schemas/program-lander";import { X } from "@/ui/shared/icons";import {Button,+ ChevronDown,Grid,LoadingSpinner,- Modal,+ Popover,Sparkle3,useMediaQuery,} from "@dub/ui";import { AnimatePresence, motion } from "framer-motion";import { useAction } from "next-safe-action/hooks";-import { Dispatch, SetStateAction, useState } from "react";+import { Dispatch, PropsWithChildren, SetStateAction, useState } from "react";import { useForm, useWatch } from "react-hook-form";import { toast } from "sonner";import { useBrandingContext } from "./branding-context-provider";@@ -26,7 +27,8 @@ export function LanderAIBanner() {const { setValue } = useBrandingFormContext();const [bannerHidden, setBannerHidden] = useState(false);- const [showGenerateLanderModal, setShowGenerateLanderModal] = useState(false);+ const [showGenerateLanderPopover, setShowGenerateLanderPopover] =+ useState(false);const { isGeneratingLander, setIsGeneratingLander } = useBrandingContext();@@ -67,16 +69,52 @@ export function LanderAIBanner() {<span className="text-content-emphasis text-left text-sm font-medium">Generate your program landing page based on your website</span>- <Button- variant="success"- text="Generate"- className="ml-2 h-7 w-fit rounded-lg px-2.5"- onClick={() => setShowGenerateLanderModal(true)}- {...(isGeneratingLander && {- disabled: true,- icon: <LoadingSpinner className="size-3" />,- })}- />+ <GenerateLanderPopover+ showGenerateLanderPopover={showGenerateLanderPopover}+ setShowGenerateLanderPopover={setShowGenerateLanderPopover}+ onGenerate={async ({ websiteUrl }) => {+ setShowGenerateLanderPopover(false);+ setIsGeneratingLander(true);++ const result = await executeAsync({+ workspaceId: workspaceId!,+ websiteUrl,+ });++ try {+ const data = programLanderSimpleSchema.parse(+ result?.data,+ );+ if (!data.blocks.length)+ throw new Error("No blocks generated");++ setValue("landerData", data, { shouldDirty: true });+ } catch (e) {+ console.error("Error generating program lander", e);+ toast.error(+ "Failed to generate landing page. Please try again later.",+ );+ } finally {+ setIsGeneratingLander(false);+ }+ }}+ >+ <Button+ variant="success"+ className="group ml-2 h-7 w-fit rounded-lg pl-2.5 pr-2 data-[state=open]:bg-blue-600 data-[state=open]:ring-4 data-[state=open]:ring-blue-200"+ text={+ <div className="flex items-center gap-1">+ <span>Generate</span>+ <ChevronDown className="size-2.5 shrink-0 text-white transition-transform duration-75 group-data-[state=open]:-scale-y-100 [&_*]:stroke-2" />+ </div>+ }+ onClick={() => setShowGenerateLanderPopover(true)}+ {...(isGeneratingLander && {+ disabled: true,+ icon: <LoadingSpinner className="size-3" />,+ })}+ />+ </GenerateLanderPopover></div><div className="basis-0"><Button@@ -94,56 +132,36 @@ export function LanderAIBanner() {</motion.div>)}</AnimatePresence>- {(showBanner || showGenerateLanderModal) && (- <GenerateLanderModal- showGenerateLanderModal={showGenerateLanderModal}- setShowGenerateLanderModal={setShowGenerateLanderModal}- onGenerate={async ({ websiteUrl }) => {- setIsGeneratingLander(true);-- const result = await executeAsync({- workspaceId: workspaceId!,- websiteUrl,- });-- try {- const data = programLanderSimpleSchema.parse(result?.data);- if (!data.blocks.length) throw new Error("No blocks generated");-- setValue("landerData", data, { shouldDirty: true });- } catch (e) {- console.error("Error generating program lander", e);- toast.error(- "Failed to generate landing page. Please try again later.",- );- } finally {- setIsGeneratingLander(false);- }- }}- />- )}</>);}-type GenerateLanderModalProps = {- showGenerateLanderModal: boolean;- setShowGenerateLanderModal: Dispatch<SetStateAction<boolean>>;+type GenerateLanderPopoverProps = {+ showGenerateLanderPopover: boolean;+ setShowGenerateLanderPopover: Dispatch<SetStateAction<boolean>>;onGenerate: (data: { websiteUrl: string }) => void;};-function GenerateLanderModal(props: GenerateLanderModalProps) {+function GenerateLanderPopover({+ children,+ ...props+}: PropsWithChildren<GenerateLanderPopoverProps>) {return (- <Modal- showModal={props.showGenerateLanderModal}- setShowModal={props.setShowGenerateLanderModal}+ <Popover+ openPopover={props.showGenerateLanderPopover}+ setOpenPopover={props.setShowGenerateLanderPopover}+ align="end"+ side="bottom"+ content={<GenerateLanderPopoverInner {...props} />}>- <GenerateLanderModalInner {...props} />- </Modal>+ {children}+ </Popover>);}-function GenerateLanderModalInner({ setShowGenerateLanderModal, onGenerate }) {+function GenerateLanderPopoverInner({+ onGenerate,+}: Pick<GenerateLanderPopoverProps, "onGenerate">) {const { isMobile } = useMediaQuery();const { program } = useProgram();@@ -163,53 +181,39 @@ function GenerateLanderModalInner({ setShowGenerateLanderModal, onGenerate }) {className="p-4 pt-3"onSubmit={(e) => {e.stopPropagation();- handleSubmit(async ({ websiteUrl }) => {- setShowGenerateLanderModal(false);- onGenerate({ websiteUrl });- })(e);+ handleSubmit(+ async ({ websiteUrl }) => await onGenerate({ websiteUrl }),+ )(e);}}>- <h3 className="text-base font-semibold leading-6 text-neutral-800">- Generate a new landing page- </h3>- <p className="text-content-subtle mt-2 text-sm">- We'll use AI to generate a new landing page for your program, based on- content from your own website.- </p>-- <div className="mt-4 flex flex-col gap-6">- {/* Title */}- <label>- <span className="block text-sm font-medium text-neutral-700">- Website URL- </span>- <div className="mt-2 rounded-md shadow-sm">- <input- type="text"- placeholder="https://dub.co"- 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("websiteUrl")}- />- </div>- </label>- </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={() => setShowGenerateLanderModal(false)}- />- <Button- type="submit"- variant="primary"- loading={isSubmitting || isSubmitSuccessful}- text="Generate"- className="h-9 w-fit"- />+ <div className="flex items-end gap-2">+ <div className="flex flex-col gap-6">+ {/* Title */}+ <label>+ <span className="block text-sm font-medium text-neutral-700">+ Your website URL+ </span>+ <div className="mt-1.5 rounded-md shadow-sm">+ <input+ type="text"+ placeholder="https://dub.co"+ autoFocus={!isMobile}+ className="block w-full min-w-32 rounded-md border-neutral-300 py-1.5 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"+ {...register("websiteUrl", { required: true })}+ />+ </div>+ </label>+ </div>++ <div className="flex items-center justify-end gap-2">+ <Button+ type="submit"+ variant="primary"+ loading={isSubmitting || isSubmitSuccessful}+ text="Generate"+ className="h-[34px] w-fit"+ />+ </div></div></form></>diff --git a/packages/ui/src/icons/nucleo/chevron-down.tsx b/packages/ui/src/icons/nucleo/chevron-down.tsxnew file mode 100644index 0000000000..b48fc31b75--- /dev/null+++ b/packages/ui/src/icons/nucleo/chevron-down.tsx@@ -0,0 +1,24 @@+import { SVGProps } from "react";++export function ChevronDown(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">+ <polyline+ fill="none"+ points="15.25 6.5 9 12.75 2.75 6.5"+ 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.tsindex fc8163acc3..6fda78c3cf 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -38,6 +38,7 @@ export * from "./check";export * from "./check2";export * from "./checkbox-checked-fill";export * from "./checkbox-unchecked";+export * from "./chevron-down";export * from "./chevron-left";export * from "./chevron-right";export * from "./circle-check";