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.

misc fixes

Steven Teyae23010910da
diff --git a/apps/web/app/api/user/referrals-token/route.ts b/apps/web/app/api/user/referrals-token/route.ts
index 1fc168d442..bc73b5bbcb 100644
--- a/apps/web/app/api/user/referrals-token/route.ts
+++ b/apps/web/app/api/user/referrals-token/route.ts
@@ -1,16 +1,9 @@
import { withSession } from "@/lib/auth";
-import { createReferralsEmbedTokenSchema } from "@/lib/zod/schemas/token";
-import { API_DOMAIN } from "@dub/utils";
+import { dub } from "@/lib/dub";
import { NextResponse } from "next/server";
-import { z } from "zod";
export const GET = withSession(async ({ session }) => {
- // const { publicToken } = await dub.embedTokens.create({
- // programId: "prog_d8pl69xXCv4AoHNT281pHQdo",
- // partnerId: dubPartnerId,
- // });
-
- const partnerProps: z.infer<typeof createReferralsEmbedTokenSchema> = {
+ const { publicToken } = await dub.embedTokens.referrals({
programId: "prog_d8pl69xXCv4AoHNT281pHQdo",
tenantId: session.user.id,
partner: {
@@ -19,20 +12,6 @@ export const GET = withSession(async ({ session }) => {
image: session.user.image || null,
tenantId: session.user.id,
},
- };
-
- const { publicToken } = await fetch(`${API_DOMAIN}/tokens/embed/referrals`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- },
- body: JSON.stringify(partnerProps),
- }).then((res) => {
- if (!res.ok) {
- throw new Error(`API request failed with status ${res.status}`);
- }
- return res.json();
});
return NextResponse.json({ publicToken });
diff --git a/apps/web/package.json b/apps/web/package.json
index ec957c91f6..20ce50e6d3 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -67,7 +67,7 @@
"concurrently": "^8.0.1",
"csv-parse": "^5.5.6",
"date-fns": "^3.6.0",
- "dub": "^0.54.1",
+ "dub": "^0.58.0",
"fast-xml-parser": "^5.0.6",
"framer-motion": "^10.16.16",
"fuse.js": "^6.6.2",
diff --git a/apps/web/ui/modals/partner-link-modal.tsx b/apps/web/ui/modals/partner-link-modal.tsx
index b01edd648f..23d16b6daa 100644
--- a/apps/web/ui/modals/partner-link-modal.tsx
+++ b/apps/web/ui/modals/partner-link-modal.tsx
@@ -174,6 +174,7 @@ function PartnerLinkModalContent({
const shortLinkDomain = programEnrollment?.program?.domain ?? "dub.sh";
const [lockKey, setLockKey] = useState(Boolean(link));
+ const [isLoading, setIsLoading] = useState(false);
const form = useForm<PartnerLinkFormData>({
defaultValues: link
@@ -192,7 +193,7 @@ function PartnerLinkModalContent({
register,
watch,
handleSubmit,
- formState: { isDirty, isSubmitting, isSubmitSuccessful },
+ formState: { isDirty },
} = form;
const { isMobile } = useMediaQuery();
@@ -201,8 +202,8 @@ function PartnerLinkModalContent({
const [key, _url] = watch("key", "url");
const saveDisabled = useMemo(
- () => Boolean(isSubmitting || isSubmitSuccessful || (link && !isDirty)),
- [isSubmitting, isSubmitSuccessful, link, isDirty],
+ () => Boolean(isLoading || (link && !isDirty)),
+ [isLoading, link, isDirty],
);
const shortLink = useMemo(
@@ -218,44 +219,50 @@ function PartnerLinkModalContent({
<form
ref={formRef}
onSubmit={handleSubmit(async (data) => {
- const response = await fetch(
- `/api/partner-profile/programs/${programEnrollment?.program?.id}/links${
- link ? `/${link.id}` : ""
- }`,
- {
- method: link ? "PATCH" : "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- ...data,
- url: linkConstructor({
- domain: destinationDomain,
- key: data.url,
+ setIsLoading(true);
+ try {
+ const response = await fetch(
+ `/api/partner-profile/programs/${programEnrollment?.program?.id}/links${
+ link ? `/${link.id}` : ""
+ }`,
+ {
+ method: link ? "PATCH" : "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ ...data,
+ url: linkConstructor({
+ domain: destinationDomain,
+ key: data.url,
+ }),
}),
- }),
- },
- );
+ },
+ );
- const result = await response.json();
+ const result = await response.json();
- if (!response.ok) {
- const { error } = result;
- toast.error(error.message);
- }
+ if (!response.ok) {
+ const { error } = result;
+ toast.error(error.message);
+ return;
+ }
- await mutateSuffix(`/links`);
+ await mutateSuffix(`/links`);
- if (!link) {
- try {
- await copyToClipboard(result.shortLink);
- toast.success("Copied short link to clipboard!");
- } catch (err) {
- toast.success("Successfully created link!");
- }
- } else toast.success("Successfully updated short link!");
+ if (!link) {
+ try {
+ await copyToClipboard(result.shortLink);
+ toast.success("Copied short link to clipboard!");
+ } catch (err) {
+ toast.success("Successfully created link!");
+ }
+ } else toast.success("Successfully updated short link!");
- setShowPartnerLinkModal(false);
+ setShowPartnerLinkModal(false);
+ } finally {
+ setIsLoading(false);
+ }
})}
>
<div className="flex flex-col items-start justify-between gap-6 px-6 py-4">
@@ -422,7 +429,7 @@ function PartnerLinkModalContent({
<Button
type="submit"
disabled={saveDisabled}
- loading={isSubmitting || isSubmitSuccessful}
+ loading={isLoading}
text={
<span className="flex items-center gap-2">
{link ? "Save changes" : "Create link"}
diff --git a/packages/prisma/schema/schema.prisma b/packages/prisma/schema/schema.prisma
index 2f362ebb6b..14ff990c89 100644
--- a/packages/prisma/schema/schema.prisma
+++ b/packages/prisma/schema/schema.prisma
@@ -27,8 +27,6 @@ model User {
source String? // where the user came from
defaultWorkspace String? // slug of the user's default workspace
defaultPartnerId String? // the user's default partner ID
- dubPartnerId String? // this user's dub partner ID
-
// relational data
accounts Account[]
sessions Session[]
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e7d836b9eb..06899383fc 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -190,8 +190,8 @@ importers:
specifier: ^3.6.0
version: 3.6.0
dub:
- specifier: ^0.54.1
- version: 0.54.1([email protected])
+ specifier: ^0.58.0
+ version: 0.58.0([email protected])
fast-xml-parser:
specifier: ^5.0.6
version: 5.0.6
@@ -6609,10 +6609,15 @@ packages:
peerDependencies:
zod: '>= 3'
- resolution: {integrity: sha512-bSGe6oCfDxHi0dGgs2XLOVtdJJhoVLndq78gXY/s/mx3T21T5EO2+OkKjE/w62/2xOyC27de4ATMJzAJ0OVNGg==}
+ resolution: {integrity: sha512-zw/gK6Y1/3asHivqtXANkAGlMcKY2hmpW14vOElqpO6wO9js4FFcNWifAZzPVaq8JMhnshs29UjJP1aHornxaw==}
+ hasBin: true
peerDependencies:
+ '@modelcontextprotocol/sdk': ^1.5.0
zod: '>= 3'
+ peerDependenciesMeta:
+ '@modelcontextprotocol/sdk':
+ optional: true
resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==}
@@ -18574,7 +18579,7 @@ snapshots:
dependencies:
zod: 3.23.8
dependencies:
zod: 3.22.4