The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add Link Design modal
Tim Wilson936b3b76a143
diff --git a/apps/web/ui/modals/add-edit-link-modal-new/index.tsx b/apps/web/ui/modals/add-edit-link-modal-new/index.tsxindex dfbbfcb20f..e12ffc28a5 100644--- a/apps/web/ui/modals/add-edit-link-modal-new/index.tsx+++ b/apps/web/ui/modals/add-edit-link-modal-new/index.tsx@@ -19,8 +19,8 @@ import {} from "@dub/ui";import { ArrowTurnLeft } from "@dub/ui/src/icons";import {- DEFAULT_LINK_PROPS,deepEqual,+ DEFAULT_LINK_PROPS,getApexDomain,getUrlWithoutUTMParams,isValidUrl,@@ -28,7 +28,14 @@ import {} from "@dub/utils";import { useParams, useSearchParams } from "next/navigation";import posthog from "posthog-js";-import { Dispatch, SetStateAction, useEffect, useMemo, useRef } from "react";+import {+ createContext,+ Dispatch,+ SetStateAction,+ useEffect,+ useMemo,+ useRef,+} from "react";import {Controller,FormProvider,@@ -43,6 +50,10 @@ import { LinkPreview } from "./link-preview";import { useMetatags } from "./use-metatags";import { UTMBuilder } from "./utm-builder";+export const LinkModalContext = createContext<{+ generatingMetatags: boolean;+}>({ generatingMetatags: false });+export type LinkFormData = LinkWithTagsProps;type AddEditLinkModalProps = {@@ -188,222 +199,225 @@ function AddEditLinkModalInner({});}}>- <form- onSubmit={handleSubmit(async (data) => {- // @ts-ignore – exclude extra attributes from `data` object before sending to API- const { user, tags, tagId, ...rest } = data;- const bodyData = {- ...rest,- // Map tags to tagIds- tagIds: tags.map(({ id }) => id),- };-- try {- const res = await fetch(endpoint.url, {- method: endpoint.method,- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify(bodyData),- });-- if (res.status === 200) {- await mutate(- (key) =>- typeof key === "string" && key.startsWith("/api/links"),- undefined,- { revalidate: true },- );- const data = await res.json();- posthog.capture(props ? "link_updated" : "link_created", data);-- // copy shortlink to clipboard when adding a new link- if (!props) {- try {- await navigator.clipboard.writeText(data.shortLink);- toast.success("Copied shortlink to clipboard!");- } catch (e) {- console.error(- "Failed to automatically copy shortlink to clipboard.",- e,- );- toast.success("Successfully created link!");- }- } else toast.success("Successfully updated shortlink!");-- setShowAddEditLinkModal(false);- } else {- const { error } = await res.json();-- if (error) {- if (error.message.includes("Upgrade to")) {- toast.custom(() => (- <UpgradeRequiredToast- title={`You've discovered a ${nextPlan.name} feature!`}- message={error.message}- />- ));- } else {- toast.error(error.message);- }- const message = error.message.toLowerCase();+ <LinkModalContext.Provider value={{ generatingMetatags }}>+ <form+ onSubmit={handleSubmit(async (data) => {+ // @ts-ignore – exclude extra attributes from `data` object before sending to API+ const { user, tags, tagId, ...rest } = data;+ const bodyData = {+ ...rest,+ // Map tags to tagIds+ tagIds: tags.map(({ id }) => id),+ };++ try {+ const res = await fetch(endpoint.url, {+ method: endpoint.method,+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify(bodyData),+ });++ if (res.status === 200) {+ await mutate(+ (key) =>+ typeof key === "string" && key.startsWith("/api/links"),+ undefined,+ { revalidate: true },+ );+ const data = await res.json();+ posthog.capture(props ? "link_updated" : "link_created", data);++ // copy shortlink to clipboard when adding a new link+ if (!props) {+ try {+ await navigator.clipboard.writeText(data.shortLink);+ toast.success("Copied shortlink to clipboard!");+ } catch (e) {+ console.error(+ "Failed to automatically copy shortlink to clipboard.",+ e,+ );+ toast.success("Successfully created link!");+ }+ } else toast.success("Successfully updated shortlink!");- if (message.includes("key"))- setError("key", { message: error.message });- else if (message.includes("url"))- setError("url", { message: error.message });- else setError("root", { message: "Failed to save link" });+ setShowAddEditLinkModal(false);} else {- setError("root", { message: "Failed to save link" });- toast.error("Failed to save link");+ const { error } = await res.json();++ if (error) {+ if (error.message.includes("Upgrade to")) {+ toast.custom(() => (+ <UpgradeRequiredToast+ title={`You've discovered a ${nextPlan.name} feature!`}+ message={error.message}+ />+ ));+ } else {+ toast.error(error.message);+ }+ const message = error.message.toLowerCase();++ if (message.includes("key"))+ setError("key", { message: error.message });+ else if (message.includes("url"))+ setError("url", { message: error.message });+ else setError("root", { message: "Failed to save link" });+ } else {+ setError("root", { message: "Failed to save link" });+ toast.error("Failed to save link");+ }}+ } catch (e) {+ setError("root", { message: "Failed to save link" });+ console.error("Failed to save link", e);+ toast.error("Failed to save link");}- } catch (e) {- setError("root", { message: "Failed to save link" });- console.error("Failed to save link", e);- toast.error("Failed to save link");- }- })}- >- <div className="flex items-center justify-between px-6 py-4">- <div className="flex items-center gap-4">- <LinkLogo apexDomain={getApexDomain(debouncedUrl)} />- <h3 className="!mt-0 max-w-sm truncate text-lg font-medium">- {props ? `Edit ${shortLink}` : "Create new link"}- </h3>+ })}+ >+ <div className="flex items-center justify-between px-6 py-4">+ <div className="flex items-center gap-4">+ <LinkLogo apexDomain={getApexDomain(debouncedUrl)} />+ <h3 className="!mt-0 max-w-sm truncate text-lg font-medium">+ {props ? `Edit ${shortLink}` : "Create new link"}+ </h3>+ </div>+ {!homepageDemo && (+ <button+ type="button"+ onClick={() => {+ setShowAddEditLinkModal(false);+ if (searchParams.has("newLink")) {+ queryParams({+ del: ["newLink"],+ });+ }+ }}+ className="group hidden rounded-full p-2 text-gray-500 transition-all duration-75 hover:bg-gray-100 focus:outline-none active:bg-gray-200 md:block"+ >+ <X className="h-5 w-5" />+ </button>+ )}</div>- {!homepageDemo && (- <button- type="button"- onClick={() => {- setShowAddEditLinkModal(false);- if (searchParams.has("newLink")) {- queryParams({- del: ["newLink"],- });- }- }}- className="group hidden rounded-full p-2 text-gray-500 transition-all duration-75 hover:bg-gray-100 focus:outline-none active:bg-gray-200 md:block"- >- <X className="h-5 w-5" />- </button>- )}- </div>-- <div className="grid w-full gap-y-6 max-md:max-h-[calc(100dvh-200px)] max-md:overflow-auto md:grid-cols-[2fr_1fr] md:[&>div]:max-h-[calc(100dvh-200px)]">- <div className="scrollbar-hide px-6 md:overflow-auto">- <div className="grid gap-8 py-4">- <Controller- name="url"- control={control}- render={({ field }) => (- <DestinationUrlInput++ <div className="grid w-full gap-y-6 max-md:max-h-[calc(100dvh-200px)] max-md:overflow-auto md:grid-cols-[2fr_1fr] md:[&>div]:max-h-[calc(100dvh-200px)]">+ <div className="scrollbar-hide px-6 md:overflow-auto">+ <div className="grid gap-8 py-4">+ <Controller+ name="url"+ control={control}+ render={({ field }) => (+ <DestinationUrlInput+ domain={domain}+ _key={key}+ value={field.value}+ domains={domains}+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => {+ clearErrors("url");+ field.onChange(e.target.value);+ }}+ required={key !== "_root"}+ error={errors.url?.message || undefined}+ showEnterToSubmit={false}+ />+ )}+ />++ {key !== "_root" && (+ <ShortLinkInput+ ref={keyRef}domain={domain}_key={key}- value={field.value}- domains={domains}- onChange={(e: React.ChangeEvent<HTMLInputElement>) => {- clearErrors("url");- field.onChange(e.target.value);+ existingLinkProps={props}+ error={errors.key?.message || undefined}+ onChange={(d) => {+ clearErrors("key");+ if (d.domain !== undefined) setValue("domain", d.domain);+ if (d.key !== undefined) setValue("key", d.key);}}- required={key !== "_root"}- error={errors.url?.message || undefined}- showEnterToSubmit={false}+ data={data}+ saving={isSubmitting || isSubmitSuccessful}+ loading={loading}+ domains={domains}/>)}- />- {key !== "_root" && (- <ShortLinkInput- ref={keyRef}- domain={domain}- _key={key}- existingLinkProps={props}- error={errors.key?.message || undefined}- onChange={(d) => {- clearErrors("key");- if (d.domain !== undefined) setValue("domain", d.domain);- if (d.key !== undefined) setValue("key", d.key);- }}- data={data}- saving={isSubmitting || isSubmitSuccessful}- loading={loading}- domains={domains}- />- )}-- <UTMBuilder />-- <div>- <div className="flex items-center gap-2">- <label- htmlFor="comments"- className="block text-sm font-medium text-gray-700"- >- Comments- </label>- <InfoTooltip- content={- <SimpleTooltipContent- title="Use comments to add context to your short links – for you and your team."- cta="Learn more."- href="https://dub.co/help/article/link-comments"+ <UTMBuilder />++ <div>+ <div className="flex items-center gap-2">+ <label+ htmlFor="comments"+ className="block text-sm font-medium text-gray-700"+ >+ Comments+ </label>+ <InfoTooltip+ content={+ <SimpleTooltipContent+ title="Use comments to add context to your short links – for you and your team."+ cta="Learn more."+ href="https://dub.co/help/article/link-comments"+ />+ }+ />+ </div>+ <Controller+ name="comments"+ control={control}+ render={({ field }) => (+ <TextareaAutosize+ id="comments"+ name="comments"+ minRows={3}+ className="mt-2 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"+ placeholder="Add comments"+ value={field.value ?? ""}+ onChange={(e) => field.onChange(e.target.value)}/>- }+ )}/></div>- <Controller- name="comments"- control={control}- render={({ field }) => (- <TextareaAutosize- name="comments"- minRows={3}- className="mt-2 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"- placeholder="Add comments"- value={field.value ?? ""}- onChange={(e) => field.onChange(e.target.value)}- />- )}- /></div></div>- </div>- <div className="scrollbar-hide px-6 md:overflow-auto md:pl-0 md:pr-4">- <div className="relative">- <div className="absolute inset-0 rounded-xl border border-gray-200 bg-gray-50 [mask-image:linear-gradient(to_bottom,black,transparent)]"></div>- <div className="relative min-h-[300px] p-4">- <LinkPreview generatingMetatags={generatingMetatags} />+ <div className="scrollbar-hide px-6 md:overflow-auto md:pl-0 md:pr-4">+ <div className="relative">+ <div className="absolute inset-0 rounded-xl border border-gray-200 bg-gray-50 [mask-image:linear-gradient(to_bottom,black,transparent)]"></div>+ <div className="relative min-h-[300px] p-4">+ <LinkPreview />+ </div></div></div></div>- </div>- <div className="flex items-center justify-between border-t border-gray-100 bg-gray-50 p-4">- <div></div>- {homepageDemo ? (- <Button- disabledTooltip="This is a demo link. You can't edit it."- text="Save changes"- className="h-8 w-fit"- />- ) : (- <Button- type="submit"- disabled={saveDisabled}- loading={isSubmitting || isSubmitSuccessful}- text={- <span className="flex items-center gap-2">- {props ? "Save changes" : "Create link"}- <div className="rounded border border-white/20 p-1">- <ArrowTurnLeft className="size-3.5" />- </div>- </span>- }- className="h-8 w-fit pl-2.5 pr-1.5"- />- )}- </div>- </form>+ <div className="flex items-center justify-between border-t border-gray-100 bg-gray-50 p-4">+ <div></div>+ {homepageDemo ? (+ <Button+ disabledTooltip="This is a demo link. You can't edit it."+ text="Save changes"+ className="h-8 w-fit"+ />+ ) : (+ <Button+ type="submit"+ disabled={saveDisabled}+ loading={isSubmitting || isSubmitSuccessful}+ text={+ <span className="flex items-center gap-2">+ {props ? "Save changes" : "Create link"}+ <div className="rounded border border-white/20 p-1">+ <ArrowTurnLeft className="size-3.5" />+ </div>+ </span>+ }+ className="h-8 w-fit pl-2.5 pr-1.5"+ />+ )}+ </div>+ </form>+ </LinkModalContext.Provider></Modal>);}diff --git a/apps/web/ui/modals/add-edit-link-modal-new/link-preview.tsx b/apps/web/ui/modals/add-edit-link-modal-new/link-preview.tsxindex 77f366ba86..dbc5cabdf0 100644--- a/apps/web/ui/modals/add-edit-link-modal-new/link-preview.tsx+++ b/apps/web/ui/modals/add-edit-link-modal-new/link-preview.tsx@@ -2,24 +2,31 @@ import {Button,FileUpload,Icon,- LoadingCircle,ShimmerDots,+ useKeyboardShortcut,useMediaQuery,} from "@dub/ui";import {Facebook,GlobePointer,LinkedIn,+ LoadingCircle,NucleoPhoto,Pen2,Twitter,} from "@dub/ui/src/icons";-import { cn, getDomainWithoutWWW, resizeImage } from "@dub/utils";+import {+ cn,+ getDomainWithoutWWW,+ isValidUrl as isValidUrlFn,+ resizeImage,+} from "@dub/utils";import {ChangeEvent,ComponentType,PropsWithChildren,useCallback,+ useContext,useMemo,useRef,useState,@@ -28,7 +35,8 @@ import { useFormContext } from "react-hook-form";import ReactTextareaAutosize from "react-textarea-autosize";import { toast } from "sonner";import { useDebounce } from "use-debounce";-import { LinkFormData } from ".";+import { LinkFormData, LinkModalContext } from ".";+import { useOGModal } from "./og-modal";const tabs = ["default", "facebook", "linkedin", "x"] as const;type Tab = (typeof tabs)[number];@@ -61,11 +69,7 @@ const tabComponents: Record<Tab, ComponentType<OGPreviewProps>> = {x: XOGPreview,};-export function LinkPreview({- generatingMetatags,-}: {- generatingMetatags: boolean;-}) {+export function LinkPreview() {const { watch, setValue } = useFormContext<LinkFormData>();const { title, description, image, url, password } = watch();@@ -75,6 +79,14 @@ export function LinkPreview({return getDomainWithoutWWW(debouncedUrl) ?? null;}, [password, debouncedUrl]);+ const isValidUrl = useMemo(() => isValidUrlFn(debouncedUrl), [debouncedUrl]);++ const { OGModal, setShowOGModal } = useOGModal();+ useKeyboardShortcut("d", () => setShowOGModal(true), {+ modal: true,+ enabled: isValidUrl,+ });+const [selectedTab, setSelectedTab] = useState<Tab>("default");const onImageChange = (image: string) => {@@ -86,6 +98,7 @@ export function LinkPreview({return (<div>+ <OGModal /><div className="flex items-center justify-between"><h2 className="text-sm font-medium text-gray-700">Link Preview</h2><Button@@ -93,7 +106,8 @@ export function LinkPreview({variant="outline"icon={<Pen2 className="mx-px size-4" />}className="h-7 w-fit px-1"- onClick={() => toast.info("WIP")}+ onClick={() => setShowOGModal(true)}+ //disabledTooltip={isValidUrl ? undefined : "Enter a URL to customize"}/></div><div className="mt-2.5 grid grid-cols-4 gap-2">@@ -125,28 +139,24 @@ export function LinkPreview({hostname={hostname}password={password}>- <ImagePreview- image={image}- onImageChange={onImageChange}- generatingMetatags={generatingMetatags}- />+ <ImagePreview image={image} onImageChange={onImageChange} /></OGPreview></div></div>);}-const ImagePreview = ({+export const ImagePreview = ({image,onImageChange,- generatingMetatags,}: {image: string | null;onImageChange: (image: string) => void;- generatingMetatags?: boolean;}) => {const { isMobile } = useMediaQuery();+ const { generatingMetatags } = useContext(LinkModalContext);+const inputFileRef = useRef<HTMLInputElement>(null);const [resizing, setResizing] = useState(false);diff --git a/apps/web/ui/modals/add-edit-link-modal-new/og-modal.tsx b/apps/web/ui/modals/add-edit-link-modal-new/og-modal.tsxnew file mode 100644index 0000000000..e59a973186--- /dev/null+++ b/apps/web/ui/modals/add-edit-link-modal-new/og-modal.tsx@@ -0,0 +1,359 @@+import useWorkspace from "@/lib/swr/use-workspace";+import { UpgradeRequiredToast } from "@/ui/shared/upgrade-required-toast";+import { Button, ButtonTooltip, FileUpload, Modal, Tooltip } from "@dub/ui";+import { LoadingCircle, Magic } from "@dub/ui/src/icons";+import { resizeImage } from "@dub/utils";+import { useCompletion } from "ai/react";+import posthog from "posthog-js";+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useContext,+ useEffect,+ useMemo,+ useState,+} from "react";+import { useForm, useFormContext } from "react-hook-form";+import TextareaAutosize from "react-textarea-autosize";+import { toast } from "sonner";+import { LinkFormData, LinkModalContext } from ".";++function OGModal({+ showOGModal,+ setShowOGModal,+}: {+ showOGModal: boolean;+ setShowOGModal: Dispatch<SetStateAction<boolean>>;+}) {+ // Rerender the modal when the showOGModal state changes to reset the form's values+ return showOGModal ? (+ <OGModalInner showOGModal={showOGModal} setShowOGModal={setShowOGModal} />+ ) : null;+}++function OGModalInner({+ showOGModal,+ setShowOGModal,+}: {+ showOGModal: boolean;+ setShowOGModal: Dispatch<SetStateAction<boolean>>;+}) {+ const { id: workspaceId, mutate, exceededAI } = useWorkspace();++ const { generatingMetatags } = useContext(LinkModalContext);+ const {+ getValues: getValuesParent,+ watch: watchParent,+ setValue: setValueParent,+ } = useFormContext<LinkFormData>();++ const { watch, setValue, getValues, reset } = useForm<+ Pick<LinkFormData, "image" | "title" | "description" | "proxy">+ >({+ defaultValues: {+ image: getValuesParent("image"),+ title: getValuesParent("title"),+ description: getValuesParent("description"),+ proxy: getValuesParent("proxy"),+ },+ });++ const url = watchParent("url");+ const { image, title, description } = watch();++ const [resizing, setResizing] = useState(false);++ const {+ completion: completionTitle,+ isLoading: generatingTitle,+ complete: completeTitle,+ } = useCompletion({+ api: `/api/ai/completion?workspaceId=${workspaceId}`,+ id: "metatags-title-ai",+ onError: (error) => {+ if (error.message.includes("Upgrade to Pro")) {+ toast.custom(() => (+ <UpgradeRequiredToast+ title="You've exceeded your AI usage limit"+ message={error.message}+ />+ ));+ } else {+ toast.error(error.message);+ }+ },+ onFinish: (_, completion) => {+ mutate();+ posthog.capture("ai_meta_title_generated", {+ title: completion,+ url,+ });+ },+ });++ const generateTitle = async () => {+ completeTitle(+ `You are an SEO expert. Generate an SEO-optimized meta title (max 120 characters) for the following URL:++ - URL: ${url}+ - Meta title: ${title}+ - Meta description: ${description}.++ Only respond with the title without quotation marks or special characters.+ `,+ );+ };++ useEffect(() => {+ if (completionTitle) setValue("title", completionTitle);+ }, [completionTitle]);++ const {+ completion: completionDescription,+ isLoading: generatingDescription,+ complete: completeDescription,+ } = useCompletion({+ api: `/api/ai/completion?workspaceId=${workspaceId}`,+ id: "metatags-description-ai",+ onError: (error) => {+ if (error.message.includes("Upgrade to Pro")) {+ toast.custom(() => (+ <UpgradeRequiredToast+ title="You've exceeded your AI usage limit"+ message={error.message}+ />+ ));+ } else {+ toast.error(error.message);+ }+ },+ onFinish: (_, completion) => {+ mutate();+ posthog.capture("ai_meta_description_generated", {+ description: completion,+ url,+ });+ },+ });++ const generateDescription = async () => {+ completeDescription(+ `You are an SEO expert. Generate an SEO-optimized meta description (max 240 characters) for the following URL:++ - URL: ${url}+ - Meta title: ${title}+ - Meta description: ${description}.++ Only respond with the description without quotation marks or special characters.`,+ );+ };++ useEffect(() => {+ if (completionDescription) setValue("description", completionDescription);+ }, [completionDescription]);++ return (+ <Modal+ showModal={showOGModal}+ setShowModal={setShowOGModal}+ className="max-w-[500px]"+ >+ <form+ className="px-5 py-4"+ // For some reason using handleSubmit causes the link modal's form to submit+ onSubmit={(e) => {+ e.preventDefault();+ e.stopPropagation();++ setShowOGModal(false);+ (["image", "title", "description", "proxy"] as const).forEach((key) =>+ setValueParent(key, getValues(key)),+ );+ }}+ >+ <div className="flex items-center justify-between">+ <h3 className="text-lg font-medium">Link Design</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">D</strong>{" "}+ to open this quickly+ </div>+ }+ side="right"+ >+ <kbd className="flex size-6 cursor-default items-center justify-center rounded-md border border-gray-200 text-xs text-gray-950">+ D+ </kbd>+ </Tooltip>+ </div>+ </div>++ <div className="scrollbar-hide -m-1 mt-6 flex max-h-[calc(100dvh-250px)] flex-col gap-6 overflow-y-auto p-1">+ <div>+ <div className="flex items-center justify-between">+ <span className="block text-sm font-medium text-gray-700">+ Image+ </span>+ </div>+ <FileUpload+ accept="images"+ variant="default"+ imageSrc={image}+ onChange={async ({ file }) => {+ setResizing(true);++ const image = await resizeImage(file);+ setValue("image", image);+ setValue("proxy", true);++ // Delay to prevent flickering+ setTimeout(() => setResizing(false), 500);+ }}+ loading={generatingMetatags || resizing}+ clickToUpload={true}+ showHoverOverlay={false}+ accessibilityLabel="OG image upload"+ className="mt-2"+ content={+ <>+ <p>Drag and drop or click to upload.</p>+ <p className="mt-1">Recommended: 1200 x 630 pixels</p>+ </>+ }+ />+ </div>++ {/* Title */}+ <div>+ <div className="flex items-center justify-between">+ <p className="block text-sm font-medium text-gray-700">Title</p>+ <div className="flex items-center gap-2">+ <p className="text-sm text-gray-500">+ {title?.length || 0}/120+ </p>+ <ButtonTooltip+ tooltipContent="Generate an optimized title using AI."+ onClick={generateTitle}+ disabled={generatingTitle || !title || exceededAI}+ className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"+ >+ {generatingTitle ? (+ <LoadingCircle />+ ) : (+ <Magic className="h-4 w-4" />+ )}+ </ButtonTooltip>+ </div>+ </div>+ <div className="relative mt-1 flex rounded-md shadow-sm">+ {generatingMetatags && (+ <div className="absolute flex h-full w-full items-center justify-center rounded-md border border-gray-300 bg-white">+ <LoadingCircle />+ </div>+ )}+ <TextareaAutosize+ name="title"+ id="title"+ minRows={2}+ maxLength={120}+ 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"+ placeholder="Add a title..."+ value={title || ""}+ onChange={(e) => {+ setValue("title", e.target.value);+ }}+ aria-invalid="true"+ />+ </div>+ </div>++ {/* Description */}+ <div>+ <div className="flex items-center justify-between">+ <p className="block text-sm font-medium text-gray-700">+ Description+ </p>+ <div className="flex items-center gap-2">+ <p className="text-sm text-gray-500">+ {description?.length || 0}/240+ </p>+ <ButtonTooltip+ tooltipContent="Generate an optimized description using AI."+ onClick={generateDescription}+ disabled={generatingDescription || !description}+ className="flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"+ >+ {generatingDescription ? (+ <LoadingCircle />+ ) : (+ <Magic className="h-4 w-4" />+ )}+ </ButtonTooltip>+ </div>+ </div>+ <div className="relative mt-1 flex rounded-md shadow-sm">+ {generatingMetatags && (+ <div className="absolute flex h-full w-full items-center justify-center rounded-md border border-gray-300 bg-white">+ <LoadingCircle />+ </div>+ )}+ <TextareaAutosize+ name="description"+ id="description"+ minRows={3}+ maxLength={240}+ 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"+ placeholder="Add a description..."+ value={description || ""}+ onChange={(e) => setValue("description", e.target.value)}+ aria-invalid="true"+ />+ </div>+ </div>+ </div>++ <div className="mt-6 flex justify-end">+ <div className="flex items-center gap-2">+ <Button+ type="button"+ variant="secondary"+ text="Cancel"+ className="h-9 w-fit"+ onClick={() => {+ reset();+ setShowOGModal(false);+ }}+ />+ <Button+ type="submit"+ variant="primary"+ text="Save changes"+ className="h-9 w-fit"+ />+ </div>+ </div>+ </form>+ </Modal>+ );+}++export function useOGModal() {+ const [showOGModal, setShowOGModal] = useState(false);++ const OGModalCallback = useCallback(() => {+ return (+ <OGModal showOGModal={showOGModal} setShowOGModal={setShowOGModal} />+ );+ }, [showOGModal, setShowOGModal]);++ return useMemo(+ () => ({+ setShowOGModal,+ OGModal: OGModalCallback,+ }),+ [setShowOGModal, OGModalCallback],+ );+}diff --git a/packages/ui/src/hooks/use-keyboard-shortcut.tsx b/packages/ui/src/hooks/use-keyboard-shortcut.tsxindex e676c208e7..f799f493a6 100644--- a/packages/ui/src/hooks/use-keyboard-shortcut.tsx+++ b/packages/ui/src/hooks/use-keyboard-shortcut.tsx@@ -42,7 +42,10 @@ export function KeyboardShortcutProvider({export function useKeyboardShortcut(key: KeyboardShortcutListener["key"],callback: (e: KeyboardEvent) => void,- options: Pick<KeyboardShortcutListener, "enabled" | "priority"> = {},+ options: { modal?: boolean } & Pick<+ KeyboardShortcutListener,+ "enabled" | "priority"+ > = {},) {const id = useId();@@ -59,7 +62,7 @@ export function useKeyboardShortcut(e.ctrlKey ||target.tagName === "INPUT" ||target.tagName === "TEXTAREA" ||- existingModalBackdrop+ !!existingModalBackdrop !== !!options.modal)return;