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.

Merge branch 'main' into staging-sandbox

Kiran K73f55c0a911e
diff --cc apps/web/lib/api/workspaces/delete-workspace.ts
index ac2a9ee854,9dcbf4f133..513719606f
--- a/apps/web/lib/api/workspaces/delete-workspace.ts
+++ b/apps/web/lib/api/workspaces/delete-workspace.ts
@@@ -58,37 -34,38 +57,50 @@@ export async function deleteWorkspace
defaultWorkspace: null,
},
}),
- ]).then((results) => {
- console.log(prettyPrint(results));
+
+ // Remove the API keys
+ prisma.restrictedToken.deleteMany({
+ where: {
+ projectId: {
+ in: workspaces.map(({ id }) => id),
+ },
+ },
+ }),
+
+ prisma.project.update({
+ where: {
+ id: workspace.id,
+ },
+ data: {
+ stagingWorkspaceId: null,
+ },
+ }),
+ ]);
+
++ const logoKey = getWorkspaceLogoStorageKey({
++ workspaceId: workspace.id,
++ logoUrl: workspace.logo,
+ });
+
waitUntil(
- Promise.all(
- workspaces.map((workspace) =>
+ Promise.allSettled([
- // Remove the API keys
- prisma.restrictedToken.deleteMany({
- where: {
- projectId: workspace.id,
- },
- }),
-
+ // Cancel the workspace's Stripe subscription if exists
+ workspace.stripeId &&
+ cancelSubscription({ customerId: workspace.stripeId }),
+
+ // Delete workspace logo if it's a custom logo stored in R2
- workspace.logo &&
- workspace.logo.startsWith(`${R2_URL}/logos/${workspace.id}`) &&
- storage.delete({ key: workspace.logo.replace(`${R2_URL}/`, "") }),
-
- // Queue the workspace for deletion
- qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/workspaces/delete`,
- body: {
- workspaceId: workspace.id,
- },
- }),
- ]).then((results) => {
- console.log(prettyPrint(results));
- }),
++ logoKey && storage.delete({ key: logoKey }),
++
++ // Queue the workspace(s) for deletion
++ ...workspaces.map((ws) =>
+ qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/workspaces/delete`,
+ body: {
- workspaceId: workspace.id,
++ workspaceId: ws.id,
+ },
+ }),
+ ),
- ),
++ ]),
);
}
@@@ -137,65 -114,24 +149,27 @@@ export async function deleteWorkspaceAd
);
}
- const customDomains = await prisma.domain.findMany({
- where: {
- projectId: workspace.id,
- },
- select: {
- slug: true,
- },
- });
-
- // delete all domains, links, and uploaded images associated with the workspace
- const deleteDomainsLinksResponse = await Promise.allSettled(
- customDomains.map(({ slug }) =>
- markDomainAsDeleted({
- domain: slug,
- }),
- ),
- );
-
- console.log(
- `Deleted ${customDomains.length} custom domains for ${workspace.slug}`,
- deleteDomainsLinksResponse,
- );
-
- // Delete folders
- const deleteFoldersResponse = await prisma.folder.deleteMany({
- where: {
- projectId: workspace.id,
- },
- });
-
- console.log(
- `Deleted ${deleteFoldersResponse.count} folders for ${workspace.slug}`,
- );
-
- // Delete customers
- const deleteCustomersResponse = await prisma.customer.deleteMany({
- where: {
- projectId: workspace.id,
- },
- });
-
- console.log(
- `Deleted ${deleteCustomersResponse.count} customers for ${workspace.slug}`,
- );
-
+ const logoKey = getWorkspaceLogoStorageKey({
+ workspaceId: workspace.id,
+ logoUrl: workspace.logo,
+ });
+
const deleteWorkspaceResponse = await Promise.allSettled([
// delete workspace logo if it's a custom logo stored in R2
- workspace.logo &&
- workspace.logo.startsWith(`${R2_URL}/logos/${workspace.id}`) &&
- storage.delete({ key: workspace.logo.replace(`${R2_URL}/`, "") }),
+ logoKey && storage.delete({ key: logoKey }),
+
// if they have a Stripe subscription, cancel it
- workspace.stripeId && cancelSubscription(workspace.stripeId),
- // delete the workspace
- prisma.project.delete({
- where: {
- slug: workspace.slug,
+ workspace.stripeId &&
+ cancelSubscription({
+ customerId: workspace.stripeId,
+ reason: "Customer was banned from Dub",
+ }),
+
+ // Queue the workspace for deletion
+ qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/workspaces/delete`,
+ body: {
+ workspaceId: workspace.id,
},
}),
]);
diff --cc apps/web/ui/layout/sidebar/workspace-dropdown.tsx
index 5534310d7d,09402872c0..9b1be62098
--- a/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
+++ b/apps/web/ui/layout/sidebar/workspace-dropdown.tsx
@@@ -163,82 -151,64 +153,78 @@@ function WorkspaceList(
[link, programId, pathname, selected.slug],
);
+ const current = workspaces.find((w) => w.slug === selected.slug);
+ const activeSlug =
+ current && isStagingEnvironment(current.environment)
+ ? workspaces.find((w) => w.stagingWorkspaceId === current.id)?.slug ??
+ selected.slug
+ : selected.slug;
+
return (
- <div className="relative w-full">
- <div
- ref={scrollRef}
- onScroll={updateScrollProgress}
- className="w-xs max-h-84 relative w-full overflow-auto rounded-xl bg-white text-base sm:w-72 sm:text-sm"
- >
- {/* Current workspace section */}
- <div className="flex flex-col gap-2.5 border-b border-neutral-200 px-3 pb-3 sm:p-3">
- <div className="flex items-center gap-x-2.5">
- <BlurImage
- src={selected.image}
- width={28}
- height={28}
- alt={selected.name}
- className="size-9 shrink-0 overflow-hidden rounded-full sm:size-8"
- draggable={false}
- />
- <div className="min-w-0">
- <div className="truncate text-base font-medium leading-5 text-neutral-900 sm:text-sm">
- {selected.name}
- </div>
- {selected.slug && (
- <div
- className={cn(
- "truncate text-sm capitalize leading-tight sm:text-xs",
- getPlanColor(selected.plan),
- )}
- >
- {selected.plan}
- {membersCount > 0
- ? ` · ${membersCount} ${pluralize("member", membersCount)}`
- : ""}
- </div>
- )}
+ <div className="w-xs relative w-full rounded-xl bg-white text-base sm:w-72 sm:text-sm">
+ {/* Current workspace section */}
+ <div className="flex flex-col gap-2.5 border-b border-neutral-200 px-3 pb-3 sm:p-3">
+ <div className="flex items-center gap-x-2.5">
+ <BlurImage
+ src={selected.image}
+ width={28}
+ height={28}
+ alt={selected.name}
+ className="size-9 shrink-0 overflow-hidden rounded-full sm:size-8"
+ draggable={false}
+ />
+ <div className="min-w-0">
+ <div className="truncate text-base font-medium leading-5 text-neutral-900 sm:text-sm">
+ {selected.name}
</div>
+ {selected.slug && (
+ <div
+ className={cn(
+ "truncate text-sm capitalize leading-tight sm:text-xs",
+ getPlanColor(selected.plan),
+ )}
+ >
+ {selected.plan}
+ {membersCount > 0
+ ? ` · ${membersCount} ${pluralize("member", membersCount)}`
+ : ""}
+ </div>
+ )}
</div>
+ </div>
- {/* Settings and Invite members options */}
- <div className="flex flex-row gap-1">
+ {/* Settings and Invite members options */}
+ <div className="flex flex-row gap-1">
+ <Link
+ href={`/${selected.slug ? selected.slug : "account"}/settings`}
+ className="flex items-center justify-start gap-x-2 rounded-lg border border-neutral-200 px-2 py-1 text-neutral-700 outline-none transition-all duration-75 hover:bg-neutral-100/50 focus-visible:ring-2 focus-visible:ring-black/50 active:bg-neutral-200/80"
+ onClick={() => setOpenPopover(false)}
+ >
+ <Gear className="size-4 text-neutral-800" />
+ <span className="block truncate text-sm">Settings</span>
+ </Link>
+ {selected.slug && (
<Link
- href={`/${selected.slug ? selected.slug : "account"}/settings`}
- className="text-content-emphasis flex w-full items-center justify-center gap-x-2 rounded-lg border border-neutral-200 px-2 py-1 outline-none transition-all duration-75 hover:bg-neutral-100/50 focus-visible:ring-2 focus-visible:ring-black/50 active:bg-neutral-200/80"
+ href={`/${selected.slug}/settings/people`}
+ className="flex items-center justify-start gap-x-2 rounded-lg border border-neutral-200 px-2 py-1 text-neutral-700 outline-none transition-all duration-75 hover:bg-neutral-100/50 focus-visible:ring-2 focus-visible:ring-black/50 active:bg-neutral-200/80"
onClick={() => setOpenPopover(false)}
>
- <Gear className="text-content-emphasis size-4" />
- <span className="block truncate text-sm">Settings</span>
+ <UserPlus className="size-4 text-neutral-800" />
+ <span className="block truncate text-sm">Invite members</span>
</Link>
- {selected.slug && (
- <Link
- href={`/${selected.slug}/settings/people`}
- className="text-content-emphasis flex w-full items-center justify-center gap-x-2 rounded-lg border border-neutral-200 px-2 py-1 outline-none transition-all duration-75 hover:bg-neutral-100/50 focus-visible:ring-2 focus-visible:ring-black/50 active:bg-neutral-200/80"
- onClick={() => setOpenPopover(false)}
- >
- <UserPlus className="text-content-emphasis size-4" />
- <span className="block truncate text-sm">Invite</span>
- </Link>
- )}
- </div>
-
- <WorkspaceEnvironmentSwitcher
- href={href}
- onNavigate={() => setOpenPopover(false)}
- workspaces={workspaces}
- selectedWorkspace={selected}
- />
+ )}
</div>
+
- {/* Workspaces section */}
++ <WorkspaceEnvironmentSwitcher
++ href={href}
++ onNavigate={() => setOpenPopover(false)}
++ workspaces={workspaces}
++ selectedWorkspace={selected}
++ />
+ </div>
+
+ {/* Workspaces section */}
+ <ScrollContainer className="max-h-[min(260px,calc(100vh-300px))]">
<div className="p-1">
<p className="px-2 py-2 text-xs font-medium text-neutral-500">
Workspaces