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.

Final fixes to merge accounts (#3284)

Steven Teyff8dfd400367
diff --git a/apps/web/app/(ee)/api/cron/merge-partner-accounts/route.ts b/apps/web/app/(ee)/api/cron/merge-partner-accounts/route.ts
index 3442514735..6cd087bd35 100644
--- a/apps/web/app/(ee)/api/cron/merge-partner-accounts/route.ts
+++ b/apps/web/app/(ee)/api/cron/merge-partner-accounts/route.ts
@@ -191,30 +191,35 @@ export async function POST(req: Request) {
},
});
- // Bounty submissions to transfer to the target partner
- const bountySubmissions = await prisma.bountySubmission.findMany({
+ // only transfer bounty submissions if the target partner has no submissions for the same bounty
+ const bountySubmissionStats = await prisma.bountySubmission.groupBy({
+ by: ["bountyId"],
where: {
- programId: {
- in: programIdsToTransfer,
+ partnerId: {
+ in: [sourcePartnerId, targetPartnerId],
},
- partnerId: sourcePartnerId,
+ },
+ _count: {
+ partnerId: true,
},
});
+ const bountiesToTransfer = bountySubmissionStats
+ .filter(({ _count }) => _count.partnerId === 1)
+ .map(({ bountyId }) => bountyId);
- // Attempting to update all source submissions to the target partnerId fails
- // if the target already has submissions for the same bounties.
- if (bountySubmissions.length > 0) {
- await Promise.allSettled(
- bountySubmissions.map((submission) =>
- prisma.bountySubmission.update({
- where: {
- id: submission.id,
- },
- data: {
- partnerId: targetPartnerId,
- },
- }),
- ),
+ if (bountiesToTransfer.length > 0) {
+ const updatedBountySubmissions =
+ await prisma.bountySubmission.updateMany({
+ where: {
+ bountyId: { in: bountiesToTransfer },
+ partnerId: sourcePartnerId,
+ },
+ data: {
+ partnerId: targetPartnerId,
+ },
+ });
+ console.log(
+ `Transferred ${updatedBountySubmissions.count} bounty submissions`,
);
}
@@ -391,7 +396,7 @@ export async function POST(req: Request) {
},
],
{
- idempotencyKey: `merge-partner-accounts/${userId}`,
+ idempotencyKey: `${CACHE_KEY_PREFIX}/${userId}`,
},
);
console.log(prettyPrint(resendBatchEmailRes));
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-mode-section.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-mode-section.tsx
index ec7d18f9c6..45fb4b45dc 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-mode-section.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/payouts/program-payout-mode-section.tsx
@@ -72,7 +72,7 @@ function WebhookInfo() {
return (
<div className="flex items-start gap-2 rounded-md border border-amber-100 bg-amber-50 p-2.5">
<Webhook className="mt-0.5 size-3.5 shrink-0 text-amber-600" />
- <p className="text-xs font-medium leading-4 text-amber-800">
+ <p className="text-xs font-medium leading-4 text-amber-900">
Ensure webhooks are configured to listen for the{" "}
<code className="rounded bg-amber-200 px-1 py-0.5 font-mono text-xs text-amber-900">
payout.confirmed
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/security/scim.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/security/scim.tsx
index 8b85d34c3c..8b14dbd148 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/security/scim.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/security/scim.tsx
@@ -52,7 +52,8 @@ export function SCIM() {
return (
<>
- {configured ? <RemoveSCIMModal /> : <SCIMModal />}
+ <SCIMModal />
+ {configured && <RemoveSCIMModal />}
<div className="rounded-xl border border-neutral-200 bg-white">
<div className="relative flex flex-col gap-5 p-5">
<div className="flex flex-col gap-1">
diff --git a/apps/web/ui/modals/link-builder/ab-testing-modal.tsx b/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
index 128ac29bd4..bd01b843c0 100644
--- a/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
+++ b/apps/web/ui/modals/link-builder/ab-testing-modal.tsx
@@ -422,7 +422,7 @@ function ABTestingModal({
{testVariantsParent && (
<div className="mt-6 flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 p-4">
- <TriangleWarning className="mt-0.5 size-4 shrink-0 text-amber-500" />
+ <TriangleWarning className="mt-0.5 size-4 shrink-0 text-amber-600" />
<p className="text-sm font-medium text-amber-900">
Changing the original A/B test settings will impact your future
analytics and event tracking.
diff --git a/apps/web/ui/modals/remove-saml-modal.tsx b/apps/web/ui/modals/remove-saml-modal.tsx
index b76ded6f13..179329b5a0 100644
--- a/apps/web/ui/modals/remove-saml-modal.tsx
+++ b/apps/web/ui/modals/remove-saml-modal.tsx
@@ -1,6 +1,6 @@
import useSAML from "@/lib/swr/use-saml";
import useWorkspace from "@/lib/swr/use-workspace";
-import { BlurImage, Button, Logo, Modal } from "@dub/ui";
+import { Button, Modal, useMediaQuery } from "@dub/ui";
import { SAML_PROVIDERS } from "@dub/utils";
import {
Dispatch,
@@ -19,85 +19,112 @@ function RemoveSAMLModal({
setShowRemoveSAMLModal: Dispatch<SetStateAction<boolean>>;
}) {
const [removing, setRemoving] = useState(false);
- const { id, logo } = useWorkspace();
+ const [verification, setVerification] = useState("");
+ const { id } = useWorkspace();
const { saml, provider, mutate } = useSAML();
const currentProvider = useMemo(
() => SAML_PROVIDERS.find((p) => p.name.startsWith(provider!)),
[provider],
);
+ const confirmationText = "confirm remove saml";
+ const isVerified = verification === confirmationText;
+
+ const { isMobile } = useMediaQuery();
+
+ const removeSAML = async () => {
+ setRemoving(true);
+ if (!provider) {
+ toast.error("No SAML connection found");
+ setRemoving(false);
+ return;
+ }
+ const { clientID, clientSecret } = saml.connections[0];
+ const params = new URLSearchParams({
+ clientID,
+ clientSecret,
+ });
+
+ const res = await fetch(`/api/workspaces/${id}/saml?${params}`, {
+ method: "DELETE",
+ });
+ setRemoving(false);
+ if (res.ok) {
+ await mutate();
+ setShowRemoveSAMLModal(false);
+ toast.success("SAML removed successfully");
+ } else {
+ const { error } = await res.json();
+ toast.error(error.message);
+ }
+ };
+
return (
<Modal
showModal={showRemoveSAMLModal}
setShowModal={setShowRemoveSAMLModal}
+ className="max-w-md"
>
- <div className="flex flex-col items-center justify-center space-y-3 border-b border-neutral-200 px-4 py-4 pt-8 sm:px-16">
- {logo ? (
- <BlurImage
- src={logo}
- alt="Workspace logo"
- className="h-10 w-10 rounded-full"
- width={20}
- height={20}
- />
- ) : (
- <Logo />
- )}
+ <div className="space-y-2 border-b border-neutral-200 px-4 py-4 sm:px-6">
<h3 className="text-lg font-medium">Remove SAML</h3>
- <p className="text-center text-sm text-neutral-500">
- This will remove SAML from your workspace. Are you sure you want to
- continue?
+ <p className="text-sm text-neutral-500">
+ This will remove SAML from your workspace.{" "}
+ <strong className="font-semibold text-neutral-700">
+ This action can't be undone
+ </strong>{" "}
+ – proceed with caution.
</p>
</div>
- <div className="flex flex-col space-y-4 bg-neutral-50 px-4 py-8 text-left sm:px-16">
- <div className="flex items-center space-x-3 rounded-md border border-neutral-300 bg-white p-3">
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ await removeSAML();
+ }}
+ className="flex flex-col space-y-4 bg-neutral-50 px-4 py-4 sm:px-6"
+ >
+ <div className="relative flex items-center gap-3 rounded-md border border-neutral-300 bg-white p-4">
<img
src={currentProvider!.logo}
- alt={currentProvider!.name}
- className="h-8 w-8"
+ alt={currentProvider!.name + " logo"}
+ className="h-5 w-5"
/>
- <div className="flex flex-col">
- <h3 className="text-sm font-medium">
- {currentProvider!.name} SAML
- </h3>
- <p className="text-xs text-neutral-500">
- {currentProvider!.name} SAML is configured for your workspace.
- </p>
+ <h3 className="line-clamp-1 text-sm font-medium text-neutral-600">
+ {currentProvider!.name} SAML
+ </h3>
+ </div>
+
+ <div>
+ <label
+ htmlFor="verification"
+ className="block text-sm text-neutral-700"
+ >
+ To verify, type{" "}
+ <span className="font-semibold">{confirmationText}</span> below
+ </label>
+ <div className="relative mt-1 rounded-md shadow-sm">
+ <input
+ type="text"
+ name="verification"
+ id="verification"
+ pattern={confirmationText}
+ required
+ autoFocus={!isMobile}
+ autoComplete="off"
+ value={verification}
+ onChange={(e) => setVerification(e.target.value)}
+ className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-300 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ />
</div>
</div>
+
<Button
- text="Confirm remove"
+ text="Remove SAML"
variant="danger"
loading={removing}
- onClick={() => {
- setRemoving(true);
- if (!provider) {
- toast.error("No SAML connection found");
- return;
- }
- const { clientID, clientSecret } = saml.connections[0];
- const params = new URLSearchParams({
- clientID,
- clientSecret,
- });
-
- fetch(`/api/workspaces/${id}/saml?${params}`, {
- method: "DELETE",
- }).then(async (res) => {
- if (res.ok) {
- await mutate();
- setShowRemoveSAMLModal(false);
- toast.success("SAML removed successfully");
- } else {
- const { error } = await res.json();
- toast.error(error.message);
- }
- setRemoving(false);
- });
- }}
+ disabled={!isVerified}
/>
- </div>
+ </form>
</Modal>
);
}
diff --git a/apps/web/ui/modals/remove-scim-modal.tsx b/apps/web/ui/modals/remove-scim-modal.tsx
index eb47375d0e..190271d793 100644
--- a/apps/web/ui/modals/remove-scim-modal.tsx
+++ b/apps/web/ui/modals/remove-scim-modal.tsx
@@ -1,7 +1,7 @@
import useSCIM from "@/lib/swr/use-scim";
import useWorkspace from "@/lib/swr/use-workspace";
import { SAMLProviderProps } from "@/lib/types";
-import { BlurImage, Button, Logo, Modal } from "@dub/ui";
+import { Button, Modal, useMediaQuery } from "@dub/ui";
import { SAML_PROVIDERS } from "@dub/utils";
import {
Dispatch,
@@ -20,7 +20,8 @@ function RemoveSCIMModal({
setShowRemoveSCIMModal: Dispatch<SetStateAction<boolean>>;
}) {
const [removing, setRemoving] = useState(false);
- const { id: workspaceId, logo } = useWorkspace();
+ const [verification, setVerification] = useState("");
+ const { id: workspaceId } = useWorkspace();
const { scim, provider, mutate } = useSCIM();
const currentProvider = useMemo(
@@ -28,75 +29,104 @@ function RemoveSCIMModal({
[provider],
) as SAMLProviderProps;
+ const confirmationText = "confirm remove scim";
+ const isVerified = verification === confirmationText;
+
+ const { isMobile } = useMediaQuery();
+
+ const removeSCIM = async () => {
+ setRemoving(true);
+ if (!scim?.directories[0]) {
+ toast.error("No SCIM directories found");
+ setRemoving(false);
+ return;
+ }
+ const { id } = scim.directories[0];
+ const params = new URLSearchParams({
+ directoryId: id,
+ });
+
+ const res = await fetch(`/api/workspaces/${workspaceId}/scim?${params}`, {
+ method: "DELETE",
+ });
+ setRemoving(false);
+ if (res.ok) {
+ await mutate();
+ setShowRemoveSCIMModal(false);
+ toast.success("SCIM directory removed successfully");
+ } else {
+ const { error } = await res.json();
+ toast.error(error.message);
+ }
+ };
+
return (
<Modal
showModal={showRemoveSCIMModal}
setShowModal={setShowRemoveSCIMModal}
+ className="max-w-md"
>
- <div className="flex flex-col items-center justify-center space-y-3 border-b border-neutral-200 px-4 py-4 pt-8 sm:px-16">
- {logo ? (
- <BlurImage
- src={logo}
- alt="Workspace logo"
- className="h-10 w-10 rounded-full"
- width={20}
- height={20}
- />
- ) : (
- <Logo />
- )}
+ <div className="space-y-2 border-b border-neutral-200 px-4 py-4 sm:px-6">
<h3 className="text-lg font-medium">Remove SCIM Directory</h3>
- <p className="text-center text-sm text-neutral-500">
+ <p className="text-sm text-neutral-500">
This will remove the currently configured SCIM directory from your
- workspace. Are you sure you want to continue?
+ workspace.{" "}
+ <strong className="font-semibold text-neutral-700">
+ This action can't be undone
+ </strong>{" "}
+ – proceed with caution.
</p>
</div>
- <div className="flex flex-col space-y-4 bg-neutral-50 px-4 py-8 text-left sm:px-16">
- <div className="flex items-center space-x-3 rounded-md border border-neutral-300 bg-white p-3">
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ await removeSCIM();
+ }}
+ className="flex flex-col space-y-4 bg-neutral-50 px-4 py-4 sm:px-6"
+ >
+ <div className="relative flex items-center gap-3 rounded-md border border-neutral-300 bg-white p-4">
<img
src={currentProvider.logo}
alt={currentProvider.name + " logo"}
- className="h-8 w-8"
+ className="h-5 w-5"
/>
- <div className="flex flex-col">
- <h3 className="text-sm font-medium">{currentProvider.name} SCIM</h3>
- <p className="text-xs text-neutral-500">
- {currentProvider.name} SCIM is configured
- </p>
+ <h3 className="line-clamp-1 text-sm font-medium text-neutral-600">
+ {currentProvider.name} SCIM
+ </h3>
+ </div>
+
+ <div>
+ <label
+ htmlFor="verification"
+ className="block text-sm text-neutral-700"
+ >
+ To verify, type{" "}
+ <span className="font-semibold">{confirmationText}</span> below
+ </label>
+ <div className="relative mt-1 rounded-md shadow-sm">
+ <input
+ type="text"
+ name="verification"
+ id="verification"
+ pattern={confirmationText}
+ required
+ autoFocus={!isMobile}
+ autoComplete="off"
+ value={verification}
+ onChange={(e) => setVerification(e.target.value)}
+ className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-300 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"
+ />
</div>
</div>
+
<Button
- text="Confirm remove"
+ text="Remove SCIM Directory"
variant="danger"
loading={removing}
- onClick={() => {
- setRemoving(true);
- if (!scim?.directories[0]) {
- toast.error("No SCIM directories found");
- return;
- }
- const { id } = scim.directories[0];
- const params = new URLSearchParams({
- directoryId: id,
- });
-
- fetch(`/api/workspaces/${workspaceId}/scim?${params}`, {
- method: "DELETE",
- }).then(async (res) => {
- if (res.ok) {
- await mutate();
- setShowRemoveSCIMModal(false);
- toast.success("SCIM directory removed successfully");
- } else {
- const { error } = await res.json();
- toast.error(error.message);
- }
- setRemoving(false);
- });
- }}
+ disabled={!isVerified}
/>
- </div>
+ </form>
</Modal>
);
}
diff --git a/apps/web/ui/modals/remove-workspace-user-modal.tsx b/apps/web/ui/modals/remove-workspace-user-modal.tsx
index 3ee137298f..5ea3d09acd 100644
--- a/apps/web/ui/modals/remove-workspace-user-modal.tsx
+++ b/apps/web/ui/modals/remove-workspace-user-modal.tsx
@@ -92,7 +92,7 @@ function RemoveWorkspaceUserModal({
{restrictedTokens && restrictedTokens.length > 0 && (
<div className="space-y-3 rounded-lg border border-amber-200 bg-amber-50 p-4">
<div className="flex-shrink-0">
- <TriangleWarning className="size-5 text-amber-400" />
+ <TriangleWarning className="size-5 text-amber-600" />
</div>
<h3 className="text-sm font-semibold leading-5 text-amber-900">
diff --git a/apps/web/ui/modals/scim-modal.tsx b/apps/web/ui/modals/scim-modal.tsx
index b05e85eb28..a88026d22d 100644
--- a/apps/web/ui/modals/scim-modal.tsx
+++ b/apps/web/ui/modals/scim-modal.tsx
@@ -2,6 +2,7 @@ import useSCIM from "@/lib/swr/use-scim";
import useWorkspace from "@/lib/swr/use-workspace";
import { SAMLProviderProps } from "@/lib/types";
import {
+ BlurImage,
Button,
Copy,
InfoTooltip,
@@ -29,7 +30,7 @@ function SCIMModal({
showSCIMModal: boolean;
setShowSCIMModal: Dispatch<SetStateAction<boolean>>;
}) {
- const { id } = useWorkspace();
+ const { id, logo } = useWorkspace();
const [submitting, setSubmitting] = useState(false);
const { scim, provider, configured, mutate } = useSCIM();
const [selectedProvider, setSelectedProvider] = useState<
@@ -52,10 +53,20 @@ function SCIMModal({
<img
src={currentProvider.logo}
alt={`${provider} logo`}
- className="h-10 w-10"
+ className="size-10"
/>
<Refresh2 className="h-5 w-5 text-neutral-600" />
- <Logo />
+ {logo ? (
+ <BlurImage
+ src={logo}
+ alt="Workspace logo"
+ className="size-10 rounded-full"
+ width={20}
+ height={20}
+ />
+ ) : (
+ <Logo className="size-10 text-neutral-500" />
+ )}
</div>
) : (
<div className="rounded-full border border-neutral-200 p-3">
diff --git a/apps/web/ui/partners/fraud-risks/fraud-disclaimer-banner.tsx b/apps/web/ui/partners/fraud-risks/fraud-disclaimer-banner.tsx
index 468378d803..b0d69c0b83 100644
--- a/apps/web/ui/partners/fraud-risks/fraud-disclaimer-banner.tsx
+++ b/apps/web/ui/partners/fraud-risks/fraud-disclaimer-banner.tsx
@@ -5,12 +5,12 @@ export function FraudDisclaimerBanner({ className }: { className?: string }) {
return (
<div
className={cn(
- "flex items-start gap-3 rounded-lg border border-yellow-200 bg-yellow-50 px-4 py-2.5",
+ "flex items-start gap-3 rounded-lg border border-amber-200 bg-amber-50 px-4 py-2.5",
className,
)}
>
- <TriangleWarning className="mt-0.5 size-4 shrink-0 text-yellow-500" />
- <p className="flex-1 text-sm text-neutral-700">
+ <TriangleWarning className="mt-0.5 size-4 shrink-0 text-amber-600" />
+ <p className="flex-1 text-sm text-amber-900">
We recommend reviewing the flagged events thoroughly and potentially
reaching out to the partner before making a final decision.{" "}
<a
diff --git a/apps/web/ui/partners/merge-accounts/merge-account-form.tsx b/apps/web/ui/partners/merge-accounts/merge-account-form.tsx
index 3a9425dfc6..4c0b0a107f 100644
--- a/apps/web/ui/partners/merge-accounts/merge-account-form.tsx
+++ b/apps/web/ui/partners/merge-accounts/merge-account-form.tsx
@@ -100,17 +100,19 @@ export function MergeAccountForm({
</AccountInputGroup>
<div className="mt-2 flex flex-col gap-3 rounded-lg border border-amber-200 bg-amber-50 px-5 py-4">
- <AlertTriangle className="size-4 text-amber-500" />
+ <AlertTriangle className="size-4 text-amber-600" />
<h3 className="text-sm font-semibold leading-5 text-amber-900">
- This action can’t be undone.
+ This action can't be undone.
</h3>
<p className="text-sm font-normal leading-5 text-amber-900">
All data — including links, commissions, and payouts from{" "}
- {sourceAccount.email} will be merged into {targetAccount.email}.
+ {sourceAccount.email} will be transferred to {targetAccount.email}.
+ Duplicate bounty submissions from {sourceAccount.email} will also be
+ deleted.
<br />
<br />
After the merge, {sourceAccount.email} will be permanently deleted.
- If you’re unsure, please contact our support team before proceeding.
+ If you're unsure, please contact our support team before proceeding.
</p>
</div>
</div>
diff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prisma
index e095a1cbc4..0d5f5df827 100644
--- a/packages/prisma/schema/bounty.prisma
+++ b/packages/prisma/schema/bounty.prisma
@@ -86,7 +86,7 @@ model BountySubmission {
commission Commission? @relation(fields: [commissionId], references: [id], onDelete: Cascade)
program Program @relation(fields: [programId], references: [id], onDelete: Cascade)
user User? @relation(fields: [userId], references: [id])
- programEnrollment ProgramEnrollment? @relation(fields: [programId, partnerId], references: [programId, partnerId])
+ programEnrollment ProgramEnrollment? @relation(fields: [programId, partnerId], references: [programId, partnerId], onDelete: Cascade)
@@unique([bountyId, partnerId])
@@index([programId, partnerId])