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.

show in sidebar, fix stuff

Steven Tey6e2d431f0b8c
diff --git a/apps/web/app/api/tokens/embed/route.ts b/apps/web/app/api/tokens/embed/route.ts
index ca2db52fba..03e4422c55 100644
--- a/apps/web/app/api/tokens/embed/route.ts
+++ b/apps/web/app/api/tokens/embed/route.ts
@@ -36,8 +36,9 @@ export const POST = withWorkspace(
});
}
- // check if the partner exists based on the email and create or enroll them
- else if (partnerProps) {
+ // if there is no programEnrollment associated with the partnerId or tenantId, and partnerProps are provided
+ // check if the partner exists based on the email – if not, create them, if yes, enroll them
+ if (!programEnrollment && partnerProps) {
const program = await prisma.program.findUnique({
where: {
id: programId,
diff --git a/apps/web/app/api/user/embed-tokens/route.ts b/apps/web/app/api/user/embed-tokens/route.ts
index e957aa9c76..6832c524a7 100644
--- a/apps/web/app/api/user/embed-tokens/route.ts
+++ b/apps/web/app/api/user/embed-tokens/route.ts
@@ -1,5 +1,6 @@
import { withSession } from "@/lib/auth";
import { createEmbedTokenSchema } from "@/lib/zod/schemas/token";
+import { API_DOMAIN } from "@dub/utils";
import { NextResponse } from "next/server";
import { z } from "zod";
@@ -11,6 +12,7 @@ export const GET = withSession(async ({ session }) => {
const partnerProps: z.infer<typeof createEmbedTokenSchema> = {
programId: "prog_d8pl69xXCv4AoHNT281pHQdo",
+ tenantId: session.user.id,
partner: {
name: session.user.name,
email: session.user.email,
@@ -19,17 +21,14 @@ export const GET = withSession(async ({ session }) => {
},
};
- const { publicToken } = await fetch(
- "http://localhost:8888/api/tokens/embed",
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${process.env.DUB_API_KEY}`,
- },
- body: JSON.stringify(partnerProps),
+ const { publicToken } = await fetch(`${API_DOMAIN}/tokens/embed`, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${process.env.DUB_API_KEY}`,
},
- ).then((res) => {
+ body: JSON.stringify(partnerProps),
+ }).then((res) => {
if (!res.ok) {
throw new Error(`API request failed with status ${res.status}`);
}
diff --git a/apps/web/app/api/user/route.ts b/apps/web/app/api/user/route.ts
index efeec3b6c0..dab5a52ef3 100644
--- a/apps/web/app/api/user/route.ts
+++ b/apps/web/app/api/user/route.ts
@@ -36,7 +36,6 @@ export const GET = withSession(async ({ session }) => {
source: true,
defaultWorkspace: true,
defaultPartnerId: true,
- dubPartnerId: true,
passwordHash: true,
createdAt: true,
},
diff --git a/apps/web/app/app.dub.co/(dashboard)/account/settings/referrals/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/account/settings/referrals/page-client.tsx
index 6cb190cdf4..ed0bb7009c 100644
--- a/apps/web/app/app.dub.co/(dashboard)/account/settings/referrals/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/account/settings/referrals/page-client.tsx
@@ -6,23 +6,14 @@ import { DubEmbed } from "@dub/embed-react";
import { CursorRays, Hyperlink, InvoiceDollar, UserCheck } from "@dub/ui/icons";
import { fetcher } from "@dub/utils";
import { useSession } from "next-auth/react";
-import { useEffect } from "react";
import useSWRImmutable from "swr/immutable";
export function ReferralsPageClient() {
- const { data: session, status, update } = useSession();
- const dubPartnerId = session?.user?.["dubPartnerId"];
-
- useEffect(() => {
- if (session && !dubPartnerId) {
- console.log("no dubPartnerId found, updating session...");
- update();
- }
- }, [session, dubPartnerId]);
+ const { data: session, status } = useSession();
const { data: { publicToken } = {}, isLoading } = useSWRImmutable<{
publicToken: string;
- }>(dubPartnerId && "/api/user/embed-tokens", fetcher, {
+ }>(session && "/api/user/embed-tokens", fetcher, {
keepPreviousData: true,
});
@@ -30,7 +21,7 @@ export function ReferralsPageClient() {
return <LayoutLoader />;
}
- if (!dubPartnerId || !publicToken) {
+ if (!publicToken) {
return (
<AnimatedEmptyState
title="Refer a friend"
diff --git a/apps/web/lib/api/partners/create-and-enroll-partner.ts b/apps/web/lib/api/partners/create-and-enroll-partner.ts
index fb2e5deca3..917b31f1bb 100644
--- a/apps/web/lib/api/partners/create-and-enroll-partner.ts
+++ b/apps/web/lib/api/partners/create-and-enroll-partner.ts
@@ -97,7 +97,7 @@ export const createAndEnrollPartner = async ({
name: partner.name,
email: partner.email,
image: partner.image,
- country: partner.country ?? "US",
+ country: partner.country,
description: partner.description,
},
include: {
diff --git a/apps/web/lib/auth/utils.ts b/apps/web/lib/auth/utils.ts
index 3df3a157d2..2b21ef8efa 100644
--- a/apps/web/lib/auth/utils.ts
+++ b/apps/web/lib/auth/utils.ts
@@ -12,7 +12,6 @@ export interface Session {
isMachine: boolean;
defaultWorkspace?: string;
defaultPartnerId?: string;
- dubPartnerId?: string;
};
}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 376965242e..ff30e64da2 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -170,7 +170,6 @@ export interface UserProps {
source: string | null;
defaultWorkspace?: string;
defaultPartnerId?: string;
- dubPartnerId?: string;
isMachine: boolean;
hasPassword: boolean;
provider: string | null;
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
index e80ce60a9c..be3f0543e3 100644
--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
@@ -216,15 +216,11 @@ const NAV_AREAS: SidebarNavAreas<{
icon: ShieldCheck,
href: "/account/settings/security",
},
- ...(session?.user?.["dubPartnerId"]
- ? [
- {
- name: "Referrals",
- icon: Gift,
- href: "/account/settings/referrals",
- },
- ]
- : []),
+ {
+ name: "Referrals",
+ icon: Gift,
+ href: "/account/settings/referrals",
+ },
],
},
],
diff --git a/apps/web/ui/layout/sidebar/refer-button.tsx b/apps/web/ui/layout/sidebar/refer-button.tsx
index 43064caa94..61c1cff260 100644
--- a/apps/web/ui/layout/sidebar/refer-button.tsx
+++ b/apps/web/ui/layout/sidebar/refer-button.tsx
@@ -1,18 +1,13 @@
"use client";
import { Gift } from "@dub/ui/icons";
-import { useSession } from "next-auth/react";
import Link from "next/link";
import { usePathname } from "next/navigation";
export function ReferButton() {
const pathname = usePathname();
- const { data: session } = useSession();
- if (
- !session?.user?.["dubPartnerId"] ||
- pathname === "/account/settings/referrals"
- ) {
+ if (pathname === "/account/settings/referrals") {
return null;
}
diff --git a/apps/web/ui/layout/sidebar/user-dropdown.tsx b/apps/web/ui/layout/sidebar/user-dropdown.tsx
index edefb3f4cc..8ee4fb88c4 100644
--- a/apps/web/ui/layout/sidebar/user-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/user-dropdown.tsx
@@ -37,15 +37,13 @@ export default function UserDropdown() {
href="/account/settings"
onClick={() => setOpenPopover(false)}
/>
- {session?.user?.["dubPartnerId"] && (
- <UserOption
- as={Link}
- label="Refer and earn"
- icon={Gift}
- href="/account/settings/referrals"
- onClick={() => setOpenPopover(false)}
- />
- )}
+ <UserOption
+ as={Link}
+ label="Refer and earn"
+ icon={Gift}
+ href="/account/settings/referrals"
+ onClick={() => setOpenPopover(false)}
+ />
<UserOption
as="button"
type="button"