Skip to content

Commit f9148c0

Browse files
committed
improve conflict code toast to link to the partner
1 parent a86167d commit f9148c0

5 files changed

Lines changed: 57 additions & 51 deletions

File tree

apps/web/app/(ee)/api/discount-codes/route.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,15 @@ export const POST = withWorkspace(
100100
code,
101101
},
102102
},
103+
include: {
104+
partner: true,
105+
},
103106
});
104107

105108
if (duplicateByCode) {
106109
throw new DubApiError({
107-
code: "bad_request",
108-
message: `A discount with the code ${code} already exists in the program. Please choose a different code.`,
110+
code: "conflict",
111+
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.`,
109112
});
110113
}
111114
}

apps/web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"remark-gfm": "^4.0.0",
130130
"sanitize-html": "^2.17.0",
131131
"shiki": "^1.14.1",
132-
"sonner": "^1.4.41",
132+
"sonner": "^2.0.7",
133133
"streamdown": "^2.3.0",
134134
"stripe": "^18.2.0",
135135
"svix": "^1.76.1",

apps/web/ui/modals/add-discount-code-modal.tsx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { toast } from "sonner";
1818
import { useDebounce } from "use-debounce";
1919
import * as z from "zod/v4";
2020
import { ERROR_MAP } from "../partners/constants";
21-
import { X } from "../shared/icons";
21+
import { CustomToast } from "../shared/custom-toast";
22+
import { AlertCircleFill, X } from "../shared/icons";
2223
import { UpgradeRequiredToast } from "../shared/upgrade-required-toast";
2324

2425
type FormData = z.infer<typeof createDiscountCodeSchema>;
@@ -87,28 +88,30 @@ const AddDiscountCodeModal = ({
8788
toast.success("Discount code created and copied to clipboard!");
8889
},
8990
onError: (error) => {
90-
if (error) {
91-
const code = Object.keys(ERROR_MAP).find((key) =>
92-
error.startsWith(key),
93-
);
91+
const code = Object.keys(ERROR_MAP).find((key) =>
92+
error.startsWith(key),
93+
);
9494

95-
if (code) {
96-
const { title, ctaLabel, ctaUrl } = ERROR_MAP[code];
97-
const message = error.replace(`${code}: `, "");
95+
if (code) {
96+
const { title, ctaLabel, ctaUrl } = ERROR_MAP[code];
97+
const message = error.replace(`${code}: `, "");
9898

99-
toast.custom(() => (
100-
<UpgradeRequiredToast
101-
title={title}
102-
message={message}
103-
ctaLabel={ctaLabel}
104-
ctaUrl={ctaUrl}
105-
/>
106-
));
107-
return;
108-
}
99+
toast.custom(() => (
100+
<UpgradeRequiredToast
101+
title={title}
102+
message={message}
103+
ctaLabel={ctaLabel}
104+
ctaUrl={ctaUrl}
105+
/>
106+
));
107+
return;
108+
} else if (error.includes("already in use")) {
109+
toast.custom(() => (
110+
<CustomToast icon={AlertCircleFill}>{error}</CustomToast>
111+
));
112+
} else {
113+
toast.error(error);
109114
}
110-
111-
toast.error(error);
112115
},
113116
});
114117
};
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ReactMarkdown from "react-markdown";
1+
import { MarkdownDescription } from "./markdown-description";
22

33
export function CustomToast({
44
icon: Icon,
@@ -10,20 +10,9 @@ export function CustomToast({
1010
return (
1111
<div className="flex items-center gap-1.5 rounded-lg bg-white p-4 text-sm shadow-[0_4px_12px_#0000001a]">
1212
{Icon && <Icon className="size-[18px] shrink-0 text-black" />}
13-
<ReactMarkdown
14-
className="text-[13px] font-medium text-neutral-900"
15-
components={{
16-
a: ({ node, ...props }) => (
17-
<a
18-
{...props}
19-
target="_blank"
20-
className="text-neutral-500 underline transition-colors hover:text-neutral-800"
21-
/>
22-
),
23-
}}
24-
>
13+
<MarkdownDescription className="text-[13px] font-medium text-neutral-900">
2514
{children}
26-
</ReactMarkdown>
15+
</MarkdownDescription>
2716
</div>
2817
);
2918
}

pnpm-lock.yaml

Lines changed: 25 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)