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.

CustomToast

Steven Tey542fc5db096f
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
index a5e5fadfcb..9fc5394e9f 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx
@@ -9,6 +9,8 @@ import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { useConfirmModal } from "@/ui/modals/confirm-modal";
import { CountryCombobox } from "@/ui/partners/country-combobox";
import { useMergePartnerAccountsModal } from "@/ui/partners/merge-accounts/merge-partner-accounts-modal";
+import { CustomToast } from "@/ui/shared/custom-toast";
+import { AlertCircleFill } from "@/ui/shared/icons";
import {
Button,
buttonVariants,
@@ -204,7 +206,16 @@ function ProfileForm({
message: error.serverError,
});
- toast.error(error.serverError);
+ if (error.serverError?.includes("merge your partner accounts")) {
+ toast.custom(() => (
+ <CustomToast icon={AlertCircleFill}>
+ Email already in use. Do you want to [merge your partner
+ accounts](https://d.to/merge-partners) instead?
+ </CustomToast>
+ ));
+ } else {
+ toast.error(error.serverError);
+ }
},
});
diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.ts
index 4f4c87a9fa..3f1d4b651a 100644
--- a/apps/web/lib/actions/partners/update-partner-profile.ts
+++ b/apps/web/lib/actions/partners/update-partner-profile.ts
@@ -9,7 +9,7 @@ import {
deepEqual,
nanoid,
} from "@dub/utils";
-import { PartnerProfileType } from "@prisma/client";
+import { PartnerProfileType, Prisma } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { stripe } from "../../stripe";
import z from "../../zod";
@@ -116,44 +116,58 @@ export const updatePartnerProfileAction = authPartnerActionClient
).url
: null;
- const updatedPartner = await prisma.partner.update({
- where: {
- id: partner.id,
- },
- data: {
- name,
- email,
- description,
- ...(imageUrl && { image: imageUrl }),
- country,
- profileType,
- companyName,
- },
- });
-
- waitUntil(
- (async () => {
- const shouldExpireCache = !deepEqual(
- {
- name: partner.name,
- image: partner.image,
- },
- {
- name: updatedPartner.name,
- image: updatedPartner.image,
- },
- );
+ try {
+ const updatedPartner = await prisma.partner.update({
+ where: {
+ id: partner.id,
+ },
+ data: {
+ name,
+ email,
+ description,
+ ...(imageUrl && { image: imageUrl }),
+ country,
+ profileType,
+ companyName,
+ },
+ });
- if (!shouldExpireCache) {
- return;
- }
+ waitUntil(
+ (async () => {
+ const shouldExpireCache = !deepEqual(
+ {
+ name: partner.name,
+ image: partner.image,
+ },
+ {
+ name: updatedPartner.name,
+ image: updatedPartner.image,
+ },
+ );
+
+ if (!shouldExpireCache) {
+ return;
+ }
+
+ qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/invalidate-for-partners`,
+ body: {
+ partnerId: partner.id,
+ },
+ });
+ })(),
+ );
+ } catch (error) {
+ console.error(error);
+ if (
+ error instanceof Prisma.PrismaClientKnownRequestError &&
+ error.code === "P2002"
+ ) {
+ throw new Error(
+ "Email already in use. Do you want to merge your partner accounts instead? (https://d.to/merge-partners)",
+ );
+ }
- qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/invalidate-for-partners`,
- body: {
- partnerId: partner.id,
- },
- });
- })(),
- );
+ throw new Error(error.message);
+ }
});
diff --git a/apps/web/ui/shared/custom-toast.tsx b/apps/web/ui/shared/custom-toast.tsx
new file mode 100644
index 0000000000..e6dc298b4f
--- /dev/null
+++ b/apps/web/ui/shared/custom-toast.tsx
@@ -0,0 +1,29 @@
+import ReactMarkdown from "react-markdown";
+
+export function CustomToast({
+ icon: Icon,
+ children,
+}: {
+ icon?: React.ComponentType<{ className?: string }>;
+ children: string;
+}) {
+ 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"
+ />
+ ),
+ }}
+ >
+ {children}
+ </ReactMarkdown>
+ </div>
+ );
+}
diff --git a/apps/web/ui/workspaces/invite-teammates-form.tsx b/apps/web/ui/workspaces/invite-teammates-form.tsx
index 6acf881cc0..005e8d6460 100644
--- a/apps/web/ui/workspaces/invite-teammates-form.tsx
+++ b/apps/web/ui/workspaces/invite-teammates-form.tsx
@@ -9,6 +9,7 @@ import posthog from "posthog-js";
import { useFieldArray, useForm } from "react-hook-form";
import { toast } from "sonner";
import { mutate } from "swr";
+import { CustomToast } from "../shared/custom-toast";
import { CheckCircleFill } from "../shared/icons";
import { UpgradeRequiredToast } from "../shared/upgrade-required-toast";
@@ -68,7 +69,11 @@ export function InviteTeammatesForm({
if (saveOnly) {
toast.custom(
- () => <InviteSavedToast teammates={teammates.length} />,
+ () => (
+ <CustomToast icon={CheckCircleFill}>
+ {`${pluralize("Invitation", teammates.length)} saved. You'll need a pro plan to invite teammates. [Learn more](https://dub.co/help/article/how-to-invite-teammates)`}
+ </CustomToast>
+ ),
{ duration: 7000 },
);
} else {
@@ -167,22 +172,3 @@ export function InviteTeammatesForm({
</form>
);
}
-
-function InviteSavedToast({ teammates }: { teammates: number }) {
- return (
- <div className="flex items-center gap-1.5 rounded-lg bg-white p-4 text-sm shadow-[0_4px_12px_#0000001a]">
- <CheckCircleFill className="size-5 shrink-0 text-black" />
- <p className="text-[13px] font-medium text-neutral-900">
- {pluralize("Invitation", teammates)} saved. You'll need a pro plan to
- invite teammates.{" "}
- <a
- href="https://dub.co/help/article/how-to-invite-teammates"
- target="_blank"
- className="text-neutral-500 underline transition-colors hover:text-neutral-800"
- >
- Learn more
- </a>
- </p>
- </div>
- );
-}