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.

improve conflict code toast to link to the partner

Steven Teyf9148c09c33e
diff --git a/apps/web/app/(ee)/api/discount-codes/route.ts b/apps/web/app/(ee)/api/discount-codes/route.ts
index db5f9870a5..35abe56ebe 100644
--- a/apps/web/app/(ee)/api/discount-codes/route.ts
+++ b/apps/web/app/(ee)/api/discount-codes/route.ts
@@ -100,12 +100,15 @@ export const POST = withWorkspace(
code,
},
},
+ include: {
+ partner: true,
+ },
});
if (duplicateByCode) {
throw new DubApiError({
- code: "bad_request",
- message: `A discount with the code ${code} already exists in the program. Please choose a different code.`,
+ code: "conflict",
+ message: `This discount code "${code}" is already in use by [${duplicateByCode.partner.email}](https://app.dub.co/${workspace.slug}/program/partners/${duplicateByCode.partner.id}). Please choose a different code.`,
});
}
}
diff --git a/apps/web/package.json b/apps/web/package.json
index 32181801d1..ca16b4d597 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -129,7 +129,7 @@
"remark-gfm": "^4.0.0",
"sanitize-html": "^2.17.0",
"shiki": "^1.14.1",
- "sonner": "^1.4.41",
+ "sonner": "^2.0.7",
"streamdown": "^2.3.0",
"stripe": "^18.2.0",
"svix": "^1.76.1",
diff --git a/apps/web/ui/modals/add-discount-code-modal.tsx b/apps/web/ui/modals/add-discount-code-modal.tsx
index 5c361cd8c8..bbdf5ac6b8 100644
--- a/apps/web/ui/modals/add-discount-code-modal.tsx
+++ b/apps/web/ui/modals/add-discount-code-modal.tsx
@@ -18,7 +18,8 @@ import { toast } from "sonner";
import { useDebounce } from "use-debounce";
import * as z from "zod/v4";
import { ERROR_MAP } from "../partners/constants";
-import { X } from "../shared/icons";
+import { CustomToast } from "../shared/custom-toast";
+import { AlertCircleFill, X } from "../shared/icons";
import { UpgradeRequiredToast } from "../shared/upgrade-required-toast";
type FormData = z.infer<typeof createDiscountCodeSchema>;
@@ -87,28 +88,30 @@ const AddDiscountCodeModal = ({
toast.success("Discount code created and copied to clipboard!");
},
onError: (error) => {
- if (error) {
- const code = Object.keys(ERROR_MAP).find((key) =>
- error.startsWith(key),
- );
+ const code = Object.keys(ERROR_MAP).find((key) =>
+ error.startsWith(key),
+ );
- if (code) {
- const { title, ctaLabel, ctaUrl } = ERROR_MAP[code];
- const message = error.replace(`${code}: `, "");
+ if (code) {
+ const { title, ctaLabel, ctaUrl } = ERROR_MAP[code];
+ const message = error.replace(`${code}: `, "");
- toast.custom(() => (
- <UpgradeRequiredToast
- title={title}
- message={message}
- ctaLabel={ctaLabel}
- ctaUrl={ctaUrl}
- />
- ));
- return;
- }
+ toast.custom(() => (
+ <UpgradeRequiredToast
+ title={title}
+ message={message}
+ ctaLabel={ctaLabel}
+ ctaUrl={ctaUrl}
+ />
+ ));
+ return;
+ } else if (error.includes("already in use")) {
+ toast.custom(() => (
+ <CustomToast icon={AlertCircleFill}>{error}</CustomToast>
+ ));
+ } else {
+ toast.error(error);
}
-
- toast.error(error);
},
});
};
diff --git a/apps/web/ui/shared/custom-toast.tsx b/apps/web/ui/shared/custom-toast.tsx
index e6dc298b4f..5666c6d6d9 100644
--- a/apps/web/ui/shared/custom-toast.tsx
+++ b/apps/web/ui/shared/custom-toast.tsx
@@ -1,4 +1,4 @@
-import ReactMarkdown from "react-markdown";
+import { MarkdownDescription } from "./markdown-description";
export function CustomToast({
icon: Icon,
@@ -10,20 +10,9 @@ export function CustomToast({
return (
<div className="flex items-center gap-1.5 rounded-lg bg-white p-4 text-sm shadow-[0_4px_12px_#0000001a]">
{Icon && <Icon className="size-[18px] shrink-0 text-black" />}
- <ReactMarkdown
- className="text-[13px] font-medium text-neutral-900"
- components={{
- a: ({ node, ...props }) => (
- <a
- {...props}
- target="_blank"
- className="text-neutral-500 underline transition-colors hover:text-neutral-800"
- />
- ),
- }}
- >
+ <MarkdownDescription className="text-[13px] font-medium text-neutral-900">
{children}
- </ReactMarkdown>
+ </MarkdownDescription>
</div>
);
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index bf6031bf85..1925b54eef 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -366,8 +366,8 @@ importers:
specifier: ^1.14.1
version: 1.14.1
sonner:
- specifier: ^1.4.41
+ specifier: ^2.0.7
streamdown:
specifier: ^2.3.0
@@ -672,7 +672,7 @@ importers:
dependencies:
'@hubspot/cli':
specifier: ^7.6.2
devDependencies:
'@types/node':
specifier: 18.11.9
@@ -11964,6 +11964,12 @@ packages:
react: ^18.0.0
react-dom: ^18.0.0
+ resolution: {integrity: sha512-W6ZN4p58k8aDKA4XPcx2hpIQXBRAgyiWVkYhT7CvK6D3iAu7xjvVyhQHg2/iaKJZ1XVJ4r7XuwGL+WGEK37i9w==}
+ peerDependencies:
+ react: ^18.0.0 || ^19.0.0 || ^19.0.0-rc
+ react-dom: ^18.0.0 || ^19.0.0 || ^19.0.0-rc
+
resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==}
engines: {node: '>=0.10.0'}
@@ -14502,9 +14508,9 @@ snapshots:
'@babel/core': 7.24.5
'@babel/helper-plugin-utils': 7.25.9
dependencies:
- '@babel/core': 7.28.4
+ '@babel/core': 7.24.5
'@babel/helper-plugin-utils': 7.27.1
optional: true
@@ -15334,7 +15340,7 @@ snapshots:
- encoding
- supports-color
dependencies:
'@hubspot/local-dev-lib': 3.19.1
'@hubspot/project-parsing-lib': 0.8.6(@hubspot/[email protected])
@@ -15365,7 +15371,7 @@ snapshots:
yargs: 17.7.2
yargs-parser: 21.1.1
optionalDependencies:
'@modelcontextprotocol/sdk': 1.13.3
transitivePeerDependencies:
- '@babel/core'
@@ -15403,7 +15409,7 @@ snapshots:
react-dom: 18.3.1([email protected])
optional: true
dependencies:
'@babel/code-frame': 7.26.2
'@babel/parser': 7.26.2
@@ -15430,7 +15436,7 @@ snapshots:
'@vitejs/plugin-react': 4.7.0([email protected](@types/[email protected])([email protected]))
ansi-to-html: 0.7.2
babel-plugin-macros: 3.1.0
chalk: 5.4.1
class-variance-authority: 0.7.0
cli-progress: 3.12.0
@@ -15449,7 +15455,7 @@ snapshots:
react-dom: 18.3.1([email protected])
request: 2.88.2
storybook: 8.6.14([email protected])
tailwind-merge: 2.6.0
tailwindcss-animate: 1.0.7
typescript: 4.7.4
@@ -20478,11 +20484,11 @@ snapshots:
resolve: 1.22.6
optional: true
dependencies:
'@babel/helper-annotate-as-pure': 7.27.3
'@babel/helper-module-imports': 7.25.9
- '@babel/plugin-syntax-jsx': 7.27.1(@babel/[email protected])
+ '@babel/plugin-syntax-jsx': 7.27.1(@babel/[email protected])
lodash: 4.17.21
picomatch: 2.3.1
@@ -27267,6 +27273,11 @@ snapshots:
react: 19.1.3
react-dom: 19.1.3([email protected])
+ dependencies:
+ react: 19.1.3
+ react-dom: 19.1.3([email protected])
+
@@ -27566,12 +27577,12 @@ snapshots:
tslib: 2.6.2
optional: true
dependencies:
client-only: 0.0.1
react: 18.3.1
optionalDependencies:
- '@babel/core': 7.28.4
+ '@babel/core': 7.24.5
babel-plugin-macros: 3.1.0
optional: true