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.

feat: share same state of aiUsage

flooorianflof05b8febc1b5
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index dd17626753..2124a82191 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -160,7 +160,7 @@ function AddEditLinkModal({
},
onFinish: (_, completion) => {
setGeneratedKeys((prev) => [...prev, completion]);
- setAiUsage(aiUsage ? aiUsage + 1 : 1);
+ setAiUsage((prev) => (prev ? prev + 1 : 1));
},
});
@@ -682,7 +682,7 @@ function AddEditLinkModal({
<CommentsSection {...{ props, data, setData }} />
<UTMSection {...{ props, data, setData }} />
<OGSection
- {...{ props, data, setData }}
+ {...{ props, data, setData, aiUsage, setAiUsage }}
generatingMetatags={generatingMetatags}
/>
<CloakingSection {...{ data, setData }} />
diff --git a/apps/web/ui/modals/add-edit-link-modal/og-section.tsx b/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
index b139ceaca9..e1d9082a47 100644
--- a/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/og-section.tsx
@@ -29,16 +29,20 @@ export default function OGSection({
props,
data,
setData,
+ aiUsage,
+ setAiUsage,
generatingMetatags,
}: {
props?: LinkProps;
data: LinkProps;
setData: Dispatch<SetStateAction<LinkProps>>;
+ aiUsage?: number;
+ setAiUsage: Dispatch<SetStateAction<number>>;
generatingMetatags: boolean;
}) {
- const { id: workspaceId, plan, aiUsage, aiLimit, nextPlan } = useWorkspace();
+ const { id: workspaceId, aiLimit, nextPlan } = useWorkspace();
- const { title, description, image, proxy, url } = data;
+ const { title, description, image, proxy } = data;
const {
completion: completionTitle,
@@ -50,6 +54,9 @@ export default function OGSection({
onError: (error) => {
toast.error(error.message);
},
+ onFinish: () => {
+ setAiUsage((prev) => (prev ? prev + 1 : 1));
+ },
});
const generateTitle = async () => {
@@ -74,6 +81,9 @@ export default function OGSection({
onError: (error) => {
toast.error(error.message);
},
+ onFinish: () => {
+ setAiUsage((prev) => (prev ? prev + 1 : 1));
+ },
});
const generateDescription = async () => {
@@ -380,7 +390,7 @@ export default function OGSection({
: "Create an optimized description using AI.",
}}
>
- {generatingTitle ? (
+ {generatingDescription ? (
<LoadingCircle />
) : (
<Magic className="h-4 w-4" />