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.

send thanks

Steven Tey11eeaa69178d
diff --git a/apps/web/app/admin.dub.co/components/send-thanks.tsx b/apps/web/app/admin.dub.co/components/send-thanks.tsx
new file mode 100644
index 0000000000..99800e28d3
--- /dev/null
+++ b/apps/web/app/admin.dub.co/components/send-thanks.tsx
@@ -0,0 +1,65 @@
+"use client";
+
+import { LoadingSpinner } from "@dub/ui";
+import { cn } from "@dub/utils";
+import { useFormStatus } from "react-dom";
+import { toast } from "sonner";
+
+export default function SendThanks() {
+ return (
+ <div className="flex flex-col space-y-5">
+ <form
+ action={async (formData) => {
+ if (
+ !confirm(
+ `This will send an email to ${formData.get("email")} with a thank you message. Are you sure?`,
+ )
+ ) {
+ return;
+ }
+ await fetch("/api/admin/send-thanks", {
+ method: "POST",
+ body: JSON.stringify({
+ email: formData.get("email"),
+ }),
+ }).then(async (res) => {
+ if (res.ok) {
+ toast.success("Successfully sent email");
+ } else {
+ const error = await res.text();
+ toast.error(error);
+ }
+ });
+ }}
+ >
+ <Form />
+ </form>
+ </div>
+ );
+}
+
+const Form = () => {
+ const { pending } = useFormStatus();
+
+ return (
+ <div className="relative flex w-full rounded-md shadow-sm">
+ <input
+ name="email"
+ id="email"
+ type="email"
+ required
+ disabled={pending}
+ autoComplete="off"
+ className={cn(
+ "block w-full rounded-md border-gray-300 text-sm text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500",
+ pending && "bg-gray-100",
+ )}
+ placeholder="[email protected]"
+ aria-invalid="true"
+ />
+ {pending && (
+ <LoadingSpinner className="absolute inset-y-0 right-2 my-auto h-full w-5 text-gray-400" />
+ )}
+ </div>
+ );
+};
diff --git a/apps/web/app/admin.dub.co/page.tsx b/apps/web/app/admin.dub.co/page.tsx
index d36c7ba41f..f339c13a92 100644
--- a/apps/web/app/admin.dub.co/page.tsx
+++ b/apps/web/app/admin.dub.co/page.tsx
@@ -2,6 +2,7 @@ import { constructMetadata } from "@dub/utils";
import ImpersonateUser from "./components/impersonate-user";
import ImpersonateWorkspace from "./components/impersonate-workspace";
import RefreshDomain from "./components/refresh-domain";
+import SendThanks from "./components/send-thanks";
export const metadata = constructMetadata({
title: "Dub Admin",
@@ -13,13 +14,13 @@ export default function AdminPage() {
<div className="mx-auto flex w-full max-w-screen-sm flex-col divide-y divide-gray-200 overflow-auto bg-white">
<div className="flex flex-col space-y-4 px-5 py-10">
<h2 className="text-xl font-semibold">Impersonate User</h2>
- <p className="text-sm text-gray-500">Get a login link for a user.</p>
+ <p className="text-sm text-gray-500">Get a login link for a user</p>
<ImpersonateUser />
</div>
<div className="flex flex-col space-y-4 px-5 py-10">
<h2 className="text-xl font-semibold">Impersonate Workspace</h2>
<p className="text-sm text-gray-500">
- Get a login link for the owner of a workspace.
+ Get a login link for the owner of a workspace
</p>
<ImpersonateWorkspace />
</div>
@@ -30,6 +31,11 @@ export default function AdminPage() {
</p>
<RefreshDomain />
</div>
+ <div className="flex flex-col space-y-4 px-5 py-10">
+ <h2 className="text-xl font-semibold">Send Thanks</h2>
+ <p className="text-sm text-gray-500">Send thank you email to a user</p>
+ <SendThanks />
+ </div>
</div>
);
}
diff --git a/apps/web/app/api/admin/send-thanks/route.ts b/apps/web/app/api/admin/send-thanks/route.ts
new file mode 100644
index 0000000000..5b0b0b9b94
--- /dev/null
+++ b/apps/web/app/api/admin/send-thanks/route.ts
@@ -0,0 +1,23 @@
+import { withAdmin } from "@/lib/auth";
+import { sendEmail } from "emails";
+import UpgradeEmail from "emails/upgrade-email";
+import { NextResponse } from "next/server";
+
+// POST /api/admin/send-thanks
+export const POST = withAdmin(async ({ req }) => {
+ const { email } = await req.json();
+
+ await sendEmail({
+ email,
+ subject: "Thank you for upgrading to Dub.co Pro!",
+ react: UpgradeEmail({
+ name: null,
+ email,
+ plan: "pro",
+ }),
+ marketing: true,
+ bcc: process.env.TRUSTPILOT_BCC_EMAIL,
+ });
+
+ return NextResponse.json({ success: true });
+});
diff --git a/apps/web/emails/index.ts b/apps/web/emails/index.ts
index f9b3cc59fa..19f0def350 100644
--- a/apps/web/emails/index.ts
+++ b/apps/web/emails/index.ts
@@ -10,6 +10,7 @@ export const sendEmail = async ({
email,
subject,
from,
+ bcc,
text,
react,
marketing,
@@ -17,6 +18,7 @@ export const sendEmail = async ({
email: string;
subject: string;
from?: string;
+ bcc?: string;
text?: string;
react?: ReactElement<any, string | JSXElementConstructor<any>>;
marketing?: boolean;
@@ -44,6 +46,7 @@ export const sendEmail = async ({
: `${process.env.NEXT_PUBLIC_APP_NAME} <system@${process.env.NEXT_PUBLIC_APP_DOMAIN}>`,
To: email,
+ Bcc: bcc,
ReplyTo: process.env.NEXT_PUBLIC_IS_DUB
: `support@${process.env.NEXT_PUBLIC_APP_DOMAIN}`,