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.

added final changes

Steven Teye01eb5e2eace
diff --git a/emails/AccountCreated.tsx b/emails/AccountCreated.tsx
deleted file mode 100644
index 86cf24adc0..0000000000
--- a/emails/AccountCreated.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-import Head from "./components/Head";
-import Header from "./components/Header";
-import Footer from "./components/Footer";
-import {
- Mjml,
- MjmlBody,
- MjmlSection,
- MjmlColumn,
- MjmlText,
- MjmlImage,
- MjmlSpacer,
-} from "mjml-react";
-import ButtonPrimary from "./components/ButtonPrimary";
-import {
- leadingTight,
- leadingRelaxed,
- textBase,
- textXl,
-} from "./components/theme";
-
-const AccountCreated = ({ name }: { name?: string }): JSX.Element => {
- return (
- <Mjml>
- <Head />
- <MjmlBody width={600}>
- <Header loose />
- <MjmlSection padding="0">
- <MjmlColumn>
- <MjmlImage
- cssClass="hero"
- padding="0 0 40px"
- align="left"
- src="https://s3.amazonaws.com/lab.campsh.com/bb-hero%402x.jpg"
- />
- </MjmlColumn>
- </MjmlSection>
- <MjmlSection padding="0 24px" cssClass="smooth">
- <MjmlColumn>
- <MjmlText
- cssClass="paragraph"
- padding="0"
- fontSize={textXl}
- lineHeight={leadingTight}
- >
- {name}, your table awaits.
- </MjmlText>
- <MjmlText
- padding="24px 0 0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- cssClass="paragraph"
- >
- Thank you for joining BookBook! We’re excited to help you enjoy
- great meals without any begging, guessing, waiting or phone calls.
- Just a couple taps, and the table is yours.
- </MjmlText>
- <MjmlSpacer height="24px" />
- <ButtonPrimary
- link={"https://app.dub.sh/"}
- uiText={"Create a project"}
- />
- <MjmlSpacer height="24px" />
- <MjmlText
- padding="0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- cssClass="paragraph"
- >
- Enjoy!
- <br />
- The BookBook Team
- </MjmlText>
- </MjmlColumn>
- </MjmlSection>
- <Footer />
- </MjmlBody>
- </Mjml>
- );
-};
-
-export default AccountCreated;
diff --git a/emails/DomainInvalid.tsx b/emails/DomainInvalid.tsx
deleted file mode 100644
index 680d209738..0000000000
--- a/emails/DomainInvalid.tsx
+++ /dev/null
@@ -1,60 +0,0 @@
-import Head from "./components/Head";
-import Header from "./components/Header";
-import Footer from "./components/Footer";
-import ButtonPrimary from "./components/ButtonPrimary";
-import { leadingRelaxed, textBase, textLg, textSm } from "./components/theme";
-
-import {
- Mjml,
- MjmlBody,
- MjmlSection,
- MjmlColumn,
- MjmlText,
- MjmlSpacer,
- MjmlDivider,
-} from "mjml-react";
-
-const DomainInvalid = ({
- domain,
- projectSlug,
-}: {
- domain: string;
- projectSlug: string;
-}): JSX.Element => {
- return (
- <Mjml>
- <Head />
- <MjmlBody width={500}>
- <Header title="Invalid Domain Configuration" />
- <MjmlSection cssClass="smooth">
- <MjmlColumn>
- <MjmlText cssClass="paragraph">Hey there!</MjmlText>
- <MjmlText cssClass="paragraph">
- We noticed that your domain <code>{domain}</code> for your Dub
- project{" "}
- <a href={`https://app.dub.sh/${projectSlug}`} target="_blank">
- {projectSlug}↗
- </a>{" "}
- has been invalid for 25 days.
- </MjmlText>
- <MjmlText cssClass="paragraph">
- If your domain remains unconfigured for 30 days, your project will
- be automatically deleted.
- </MjmlText>
- <ButtonPrimary
- link={`https://app.dub.sh/${projectSlug}/settings`}
- uiText="Configure my domain"
- />
- <MjmlText cssClass="paragraph">
- If you do not want to keep this project on Dub, you can safely
- ignore this email.
- </MjmlText>
- </MjmlColumn>
- </MjmlSection>
- <Footer />
- </MjmlBody>
- </Mjml>
- );
-};
-
-export default DomainInvalid;
diff --git a/emails/InvalidDomain.tsx b/emails/InvalidDomain.tsx
new file mode 100644
index 0000000000..5deed869ac
--- /dev/null
+++ b/emails/InvalidDomain.tsx
@@ -0,0 +1,87 @@
+import Head from "./components/Head";
+import Header from "./components/Header";
+import Footer from "./components/Footer";
+import ButtonPrimary from "./components/ButtonPrimary";
+import Divider from "./components/Divider";
+import {
+ Mjml,
+ MjmlBody,
+ MjmlSection,
+ MjmlColumn,
+ MjmlText,
+ MjmlWrapper,
+} from "mjml-react";
+import { grayDark, purple } from "./components/theme";
+
+export default function InvalidDomain({
+ domain,
+ projectSlug,
+ invalidDays,
+}: {
+ domain: string;
+ projectSlug: string;
+ invalidDays: number;
+}): JSX.Element {
+ return (
+ <Mjml>
+ <Head />
+ <MjmlBody width={500}>
+ <MjmlWrapper cssClass="container">
+ <Header title="Invalid Domain Configuration" />
+ <MjmlSection cssClass="smooth">
+ <MjmlColumn>
+ <MjmlText cssClass="paragraph">Hey there!</MjmlText>
+ <MjmlText cssClass="paragraph">
+ I did a scan of all our projects and noticed that your domain{" "}
+ <code>
+ <a
+ rel="nofollow"
+ style={{
+ textDecoration: "none",
+ color: `${purple} !important`,
+ }}
+ >
+ {domain}
+ </a>
+ </code>{" "}
+ for your Dub project{" "}
+ <a href={`https://app.dub.sh/${projectSlug}`} target="_blank">
+ {projectSlug}↗
+ </a>{" "}
+ has been invalid for {invalidDays} days.
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ If your domain remains unconfigured for 30 days, your project
+ will be automatically deleted. Please click the link below to
+ configure your domain.
+ </MjmlText>
+ <ButtonPrimary
+ link={`https://app.dub.sh/${projectSlug}/settings`}
+ uiText="Configure my domain"
+ />
+ <MjmlText cssClass="paragraph">
+ If you do not want to keep this project on Dub, you can{" "}
+ <a
+ href={`https://app.dub.sh/${projectSlug}/settings`}
+ target="_blank"
+ >
+ delete it
+ </a>{" "}
+ or simply ignore this email.{" "}
+ {invalidDays < 28 &&
+ `I will remind you about this again in ${
+ 28 - invalidDays
+ } days.`}
+ </MjmlText>
+ <MjmlText cssClass="paragraph" color={grayDark}>
+ Steven from Dub
+ </MjmlText>
+ <Divider />
+ </MjmlColumn>
+ </MjmlSection>
+ <Footer />
+ </MjmlWrapper>
+ </MjmlBody>
+ </Mjml>
+ );
+}
diff --git a/emails/LoginLink.tsx b/emails/LoginLink.tsx
index a08d44fd05..c91902cc21 100644
--- a/emails/LoginLink.tsx
+++ b/emails/LoginLink.tsx
@@ -2,79 +2,55 @@ import Head from "./components/Head";
import Header from "./components/Header";
import Footer from "./components/Footer";
import ButtonPrimary from "./components/ButtonPrimary";
-import { leadingRelaxed, textBase, textSm } from "./components/theme";
-
+import Divider from "./components/Divider";
import {
Mjml,
MjmlBody,
MjmlSection,
MjmlColumn,
MjmlText,
- MjmlSpacer,
- MjmlDivider,
+ MjmlWrapper,
} from "mjml-react";
+import { purple } from "./components/theme";
-const LoginLink = ({ url }: { url: string }): JSX.Element => {
+export default function LoginLink({ url }: { url: string }): JSX.Element {
return (
<Mjml>
<Head />
- <MjmlBody width={400}>
- <Header title="Your Login Link" />
- <MjmlSection padding="0" cssClass="smooth">
- <MjmlColumn>
- <MjmlText
- padding="8px 0"
- fontSize={textSm}
- lineHeight={leadingRelaxed}
- >
- Welcome to Dub!
- </MjmlText>
- <MjmlText
- padding="8px 0"
- fontSize={textSm}
- lineHeight={leadingRelaxed}
- >
- Please click the magic link below to sign in to your account.
- </MjmlText>
- <ButtonPrimary link={url} uiText="Sign In" />
- <MjmlText
- cssClass="paragraph"
- padding="8px 0"
- fontSize={textSm}
- lineHeight={leadingRelaxed}
- >
- You can also copy the link below and paste it into the browser of
- your choice.
- </MjmlText>
- <MjmlSpacer height="8px" />
- <MjmlText
- cssClass="paragraph"
- padding="10px 0"
- fontSize={textSm}
- lineHeight={leadingRelaxed}
- >
- {url.replace(/^https?:\/\//, "")}
- </MjmlText>
- <MjmlDivider
- borderColor="#666"
- borderStyle="dotted"
- borderWidth="1px"
- padding="16px 0 0"
- ></MjmlDivider>
- <MjmlText
- padding="16px 0"
- fontSize={textSm}
- lineHeight={leadingRelaxed}
- cssClass="paragraph"
- >
- If you did not request this email you can safely ignore it.
- </MjmlText>
- </MjmlColumn>
- </MjmlSection>
- <Footer />
+ <MjmlBody width={500}>
+ <MjmlWrapper cssClass="container">
+ <Header title="Your Login Link" />
+ <MjmlSection cssClass="smooth">
+ <MjmlColumn>
+ <MjmlText cssClass="paragraph">Welcome to Dub!</MjmlText>
+ <MjmlText cssClass="paragraph">
+ Please click the magic link below to sign in to your account.
+ </MjmlText>
+ <ButtonPrimary link={url} uiText="Sign In" />
+ <MjmlText cssClass="paragraph">
+ If you're on a mobile device, you can also copy the link below
+ and paste it into the browser of your choice.
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ <a
+ rel="nofollow"
+ style={{
+ textDecoration: "none",
+ color: `${purple} !important`,
+ }}
+ >
+ {url.replace(/^https?:\/\//, "")}
+ </a>
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ If you did not request this email, you can safely ignore it.
+ </MjmlText>
+ <Divider />
+ </MjmlColumn>
+ </MjmlSection>
+ <Footer footnote={false} />
+ </MjmlWrapper>
</MjmlBody>
</Mjml>
);
-};
-
-export default LoginLink;
+}
diff --git a/emails/NewSignIn.tsx b/emails/NewSignIn.tsx
deleted file mode 100644
index db69a3442d..0000000000
--- a/emails/NewSignIn.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-import { ReactElement } from "react";
-import Head from "./components/Head";
-import Header from "./components/Header";
-import Footer from "./components/Footer";
-import {
- leadingTight,
- leadingRelaxed,
- textBase,
- textLg,
-} from "./components/theme";
-
-import {
- Mjml,
- MjmlBody,
- MjmlSection,
- MjmlColumn,
- MjmlText,
- MjmlSpacer,
- MjmlDivider,
-} from "mjml-react";
-
-type NewSignInProps = {
- name: string;
- headline: string;
- body: ReactElement;
- bulletedList: ReactElement;
-};
-
-const NewSignIn: React.FC<NewSignInProps> = ({
- name,
- headline,
- body,
- bulletedList,
-}) => {
- return (
- <Mjml>
- <Head />
- <MjmlBody width={400}>
- <Header />
- <MjmlSection padding="0 24px" cssClass="smooth">
- <MjmlColumn>
- <MjmlDivider
- borderColor="#666"
- borderStyle="dotted"
- borderWidth="1px"
- padding="8px 0"
- ></MjmlDivider>
- <MjmlText
- padding="24px 0 8px"
- fontSize={textLg}
- lineHeight={leadingTight}
- cssClass="paragraph"
- >
- {headline}
- </MjmlText>
- <MjmlText
- padding="16px 0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- cssClass="paragraph"
- >
- Hello {name},
- </MjmlText>
- <MjmlText
- cssClass="paragraph"
- padding="0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- >
- <>{body}</>
- </MjmlText>
- <MjmlSpacer height="16px" />
- {bulletedList}
- <MjmlText
- padding="16px 0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- cssClass="paragraph"
- >
- ♥,
- <br />
- The BookBook Team
- </MjmlText>
- <MjmlDivider
- borderColor="#666"
- borderStyle="dotted"
- borderWidth="1px"
- padding="20px 0 8px"
- ></MjmlDivider>
- </MjmlColumn>
- </MjmlSection>
- <Footer />
- </MjmlBody>
- </Mjml>
- );
-};
-
-export default NewSignIn;
diff --git a/emails/ProjectDeleted.tsx b/emails/ProjectDeleted.tsx
new file mode 100644
index 0000000000..babb3892ca
--- /dev/null
+++ b/emails/ProjectDeleted.tsx
@@ -0,0 +1,75 @@
+import Head from "./components/Head";
+import Header from "./components/Header";
+import Footer from "./components/Footer";
+import ButtonPrimary from "./components/ButtonPrimary";
+import Divider from "./components/Divider";
+import {
+ Mjml,
+ MjmlBody,
+ MjmlSection,
+ MjmlColumn,
+ MjmlText,
+ MjmlWrapper,
+} from "mjml-react";
+import { grayDark, purple } from "./components/theme";
+
+export default function ProjectDeleted({
+ domain,
+ projectSlug,
+}: {
+ domain: string;
+ projectSlug: string;
+}): JSX.Element {
+ return (
+ <Mjml>
+ <Head />
+ <MjmlBody width={500}>
+ <MjmlWrapper cssClass="container">
+ <Header title="Project Deleted" />
+ <MjmlSection cssClass="smooth">
+ <MjmlColumn>
+ <MjmlText cssClass="paragraph">Hey there!</MjmlText>
+ <MjmlText cssClass="paragraph">
+ Just wanted to let you know that your domain{" "}
+ <code>
+ <a
+ rel="nofollow"
+ style={{
+ textDecoration: "none",
+ color: `${purple} !important`,
+ }}
+ >
+ {domain}
+ </a>
+ </code>{" "}
+ for your Dub project{" "}
+ <a href={`https://app.dub.sh/${projectSlug}`} target="_blank">
+ {projectSlug}↗
+ </a>{" "}
+ has been invalid for 30 days. As a result, your project has been
+ deleted from Dub.
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ If you would like to restore the project, you can easily create
+ it again on Dub with the link below.
+ </MjmlText>
+ <ButtonPrimary
+ link={`https://app.dub.sh/`}
+ uiText="Create a new project"
+ />
+ <MjmlText cssClass="paragraph">
+ If you did not want to keep this project on Dub anyway, you can
+ simply ignore this email.
+ </MjmlText>
+ <MjmlText cssClass="paragraph" color={grayDark}>
+ Steven from Dub
+ </MjmlText>
+ <Divider />
+ </MjmlColumn>
+ </MjmlSection>
+ <Footer />
+ </MjmlWrapper>
+ </MjmlBody>
+ </Mjml>
+ );
+}
diff --git a/emails/Reservation.tsx b/emails/Reservation.tsx
deleted file mode 100644
index 5c6f1a1878..0000000000
--- a/emails/Reservation.tsx
+++ /dev/null
@@ -1,88 +0,0 @@
-import { ReactElement } from "react";
-import Head from "./components/Head";
-import Header from "./components/Header";
-import Footer from "./components/Footer";
-import ButtonPrimary from "./components/ButtonPrimary";
-import {
- leadingTight,
- leadingRelaxed,
- textBase,
- textLg,
-} from "./components/theme";
-
-import {
- Mjml,
- MjmlBody,
- MjmlSection,
- MjmlColumn,
- MjmlText,
- MjmlSpacer,
- MjmlDivider,
-} from "mjml-react";
-
-type ReservationProps = {
- headline: string;
- body: ReactElement;
- bulletedList: ReactElement;
- ctaText?: string;
-};
-
-const Reservation: React.FC<ReservationProps> = ({
- headline,
- body,
- bulletedList,
- ctaText,
-}) => {
- return (
- <Mjml>
- <Head />
- <MjmlBody width={400}>
- <Header />
- <MjmlSection padding="0 24px" cssClass="smooth">
- <MjmlColumn>
- <MjmlDivider
- borderColor="#666"
- borderStyle="dotted"
- borderWidth="1px"
- padding="8px 0"
- ></MjmlDivider>
- <MjmlText
- padding="24px 0"
- fontSize={textLg}
- lineHeight={leadingTight}
- cssClass="paragraph"
- >
- {headline}
- </MjmlText>
- {bulletedList}
- <MjmlSpacer height="16px" />
- <MjmlText
- cssClass="paragraph"
- padding="0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- >
- <>{body}</>
- </MjmlText>
- {ctaText && (
- <>
- <MjmlSpacer height="24px" />
- <ButtonPrimary link={"#"} uiText={ctaText} />
- <MjmlSpacer height="8px" />
- </>
- )}
- <MjmlDivider
- borderColor="#666"
- borderStyle="dotted"
- borderWidth="1px"
- padding="32px 0 0"
- ></MjmlDivider>
- </MjmlColumn>
- </MjmlSection>
- <Footer />
- </MjmlBody>
- </Mjml>
- );
-};
-
-export default Reservation;
diff --git a/emails/ResetPassword.tsx b/emails/ResetPassword.tsx
deleted file mode 100644
index 26f38f6216..0000000000
--- a/emails/ResetPassword.tsx
+++ /dev/null
@@ -1,85 +0,0 @@
-import { ReactElement } from "react";
-import Head from "./components/Head";
-import Header from "./components/Header";
-import Footer from "./components/Footer";
-import ButtonPrimary from "./components/ButtonPrimary";
-import { leadingRelaxed, textBase } from "./components/theme";
-
-import {
- Mjml,
- MjmlBody,
- MjmlSection,
- MjmlColumn,
- MjmlText,
- MjmlSpacer,
- MjmlDivider,
-} from "mjml-react";
-
-type ResetPasswordProps = {
- name: string;
- body: ReactElement;
- ctaText: string;
-};
-
-const ResetPassword: React.FC<ResetPasswordProps> = ({
- name,
- body,
- ctaText,
-}) => {
- return (
- <Mjml>
- <Head />
- <MjmlBody width={400}>
- <Header />
- <MjmlSection padding="0 24px" cssClass="smooth">
- <MjmlColumn>
- <MjmlDivider
- borderColor="#666"
- borderStyle="dotted"
- borderWidth="1px"
- padding="8px 0 16px 0"
- ></MjmlDivider>
- <MjmlText
- padding="16px 0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- cssClass="paragraph"
- >
- Hello {name},
- </MjmlText>
- <MjmlText
- cssClass="paragraph"
- padding="0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- >
- <>{body}</>
- </MjmlText>
- <MjmlSpacer height="24px" />
- <ButtonPrimary link={"#"} uiText={ctaText} />
- <MjmlSpacer height="8px" />
- <MjmlText
- padding="16px 0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- cssClass="paragraph"
- >
- ♥,
- <br />
- The BookBook Team
- </MjmlText>
- <MjmlDivider
- borderColor="#666"
- borderStyle="dotted"
- borderWidth="1px"
- padding="16px 0 0"
- ></MjmlDivider>
- </MjmlColumn>
- </MjmlSection>
- <Footer />
- </MjmlBody>
- </Mjml>
- );
-};
-
-export default ResetPassword;
diff --git a/emails/UsageExceeded.tsx b/emails/UsageExceeded.tsx
new file mode 100644
index 0000000000..a4838b875d
--- /dev/null
+++ b/emails/UsageExceeded.tsx
@@ -0,0 +1,73 @@
+import Head from "./components/Head";
+import Header from "./components/Header";
+import Footer from "./components/Footer";
+import ButtonPrimary from "./components/ButtonPrimary";
+import Divider from "./components/Divider";
+import {
+ Mjml,
+ MjmlBody,
+ MjmlSection,
+ MjmlColumn,
+ MjmlText,
+ MjmlWrapper,
+} from "mjml-react";
+import { getPlanFromUsageLimit } from "@/lib/stripe/constants";
+import { nFormatter } from "@/lib/utils";
+import { grayDark } from "./components/theme";
+
+export default function UsageExceeded({
+ usage,
+ usageLimit,
+ type,
+}: {
+ usage: number;
+ usageLimit: number;
+ type: "first" | "second";
+}): JSX.Element {
+ return (
+ <Mjml>
+ <Head />
+ <MjmlBody width={500}>
+ <MjmlWrapper cssClass="container">
+ <Header title="Usage Limit Exceeded" />
+ <MjmlSection cssClass="smooth">
+ <MjmlColumn>
+ <MjmlText cssClass="paragraph">Hey there!</MjmlText>
+ <MjmlText cssClass="paragraph">
+ Just wanted to reach out and let you know that your account has
+ exceeded the
+ <strong> {getPlanFromUsageLimit(usageLimit)} Plan </strong>
+ limit of <strong>{nFormatter(usageLimit)} link clicks</strong>.
+ You have used{" "}
+ <strong>{nFormatter(usage, 2)} link clicks</strong> across all
+ your projects in your current billing cycle.
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ All your existing links will continue to work, and I'm still
+ collecting data on them, but you'll need to upgrade to view
+ their stats, edit them, or add more links.
+ </MjmlText>
+ <ButtonPrimary
+ link={`https://app.dub.sh/settings`}
+ uiText="Upgrade my plan"
+ />
+ <MjmlText cssClass="paragraph">
+ To be respectful of your inbox,{" "}
+ {type === "first"
+ ? "I will only send you one more email about this in 3 days"
+ : "this will be the last time I'll email you about this"}
+ . Feel free to ignore this email if you don't plan on upgrading,
+ or reply to let me know if you have any questions!
+ </MjmlText>
+ <MjmlText cssClass="paragraph" color={grayDark}>
+ Steven from Dub
+ </MjmlText>
+ <Divider />
+ </MjmlColumn>
+ </MjmlSection>
+ <Footer />
+ </MjmlWrapper>
+ </MjmlBody>
+ </Mjml>
+ );
+}
diff --git a/emails/WelcomeEmail.tsx b/emails/WelcomeEmail.tsx
new file mode 100644
index 0000000000..777cf629a8
--- /dev/null
+++ b/emails/WelcomeEmail.tsx
@@ -0,0 +1,91 @@
+import Head from "./components/Head";
+import Header from "./components/Header";
+import Footer from "./components/Footer";
+import Divider from "./components/Divider";
+import {
+ Mjml,
+ MjmlBody,
+ MjmlSection,
+ MjmlColumn,
+ MjmlText,
+ MjmlWrapper,
+ MjmlImage,
+} from "mjml-react";
+import { grayDark } from "./components/theme";
+
+export default function WelcomeEmail({ name }: { name?: string }): JSX.Element {
+ return (
+ <Mjml>
+ <Head />
+ <MjmlBody width={500}>
+ <MjmlWrapper cssClass="container">
+ <Header title="Welcome to Dub" />
+ <MjmlSection padding="0">
+ <MjmlColumn>
+ <MjmlImage
+ cssClass="hero"
+ padding="0"
+ align="left"
+ src="https://raw.githubusercontent.com/steven-tey/dub/main/public/static/thumbnail.png"
+ />
+ </MjmlColumn>
+ </MjmlSection>
+ <MjmlSection cssClass="smooth">
+ <MjmlColumn>
+ <MjmlText cssClass="paragraph">
+ Thanks for signing up{name && `, ${name}`}!
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ My name is Steven, and I'm the creator of Dub - the open-source
+ Bitly alternative. I'm excited to have you on board!
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ Here's a few things you can do:
+ </MjmlText>
+ <MjmlText cssClass="li">
+ •&nbsp;&nbsp;Create a custom{" "}
+ <a href="https://app.dub.sh/links" target="_blank">
+ Dub.sh short link
+ </a>
+ </MjmlText>
+ <MjmlText cssClass="li">
+ •&nbsp;&nbsp;Create a new{" "}
+ <a href="https://app.dub.sh/" target="_blank">
+ project
+ </a>{" "}
+ and add your custom domain
+ </MjmlText>
+ <MjmlText cssClass="li">
+ •&nbsp;&nbsp;Star the repo on{" "}
+ <a href="https://github.com/steven-tey/dub" target="_blank">
+ GitHub
+ </a>
+ </MjmlText>
+ <MjmlText cssClass="li">
+ •&nbsp;&nbsp;Follow us on{" "}
+ <a href="https://twitter.com/dubdotsh/" target="_blank">
+ Twitter
+ </a>
+ </MjmlText>
+ <MjmlText cssClass="paragraph">
+ Let me know if you have any questions or feedback. I'm always
+ happy to help!
+ </MjmlText>
+ <MjmlText cssClass="paragraph" color={grayDark}>
+ P.S.: You'll receive an email from Trustpilot in the next couple
+ of days - if you enjoyed using Dub, it would mean a lot if you
+ could leave a review; if not, I'd love to hear what I can do to
+ improve Dub!
+ </MjmlText>
+ <MjmlText cssClass="paragraph" color={grayDark}>
+ Steven from Dub
+ </MjmlText>
+ <Divider />
+ </MjmlColumn>
+ </MjmlSection>
+ <Footer unsubscribe />
+ </MjmlWrapper>
+ </MjmlBody>
+ </Mjml>
+ );
+}
diff --git a/emails/components/BulletedList.tsx b/emails/components/BulletedList.tsx
deleted file mode 100644
index 6cbb13f529..0000000000
--- a/emails/components/BulletedList.tsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import { MjmlText } from "mjml-react";
-import { leadingRelaxed, textBase } from "./theme";
-
-type BulletedListProps = {
- items: string[];
-};
-
-const BulletedList: React.FC<BulletedListProps> = ({ items }) => {
- return (
- <>
- {items.map((item) => (
- <MjmlText
- padding="1px 0 0"
- fontSize={textBase}
- lineHeight={leadingRelaxed}
- cssClass="li"
- key={item}
- >
- •&nbsp;&nbsp;{item}
- </MjmlText>
- ))}
- </>
- );
-};
-
-export default BulletedList;
diff --git a/emails/components/ButtonPrimary.tsx b/emails/components/ButtonPrimary.tsx
index 21f9cfefd7..dd3bfbdead 100644
--- a/emails/components/ButtonPrimary.tsx
+++ b/emails/components/ButtonPrimary.tsx
@@ -2,17 +2,43 @@ import { MjmlButton } from "mjml-react";
import { black, white, grayLight } from "./theme";
import { leadingTight, textSm, borderBase } from "./theme";
-type ButtonPrimaryProps = {
+export default function ButtonPrimary({
+ link,
+ uiText,
+}: {
link: string;
uiText: string;
-};
-
-const ButtonPrimary: React.FC<ButtonPrimaryProps> = ({ link, uiText }) => {
+}): JSX.Element {
return (
- <MjmlButton href={link} cssClass="button">
- {uiText}
- </MjmlButton>
+ <>
+ <MjmlButton
+ lineHeight={leadingTight}
+ fontSize={textSm}
+ fontWeight={600}
+ height={32}
+ align="left"
+ href={link}
+ backgroundColor={black}
+ color={grayLight}
+ borderRadius={borderBase}
+ cssClass="light-mode"
+ >
+ {uiText}
+ </MjmlButton>
+ <MjmlButton
+ lineHeight={leadingTight}
+ fontSize={textSm}
+ fontWeight={600}
+ height={32}
+ align="left"
+ href={link}
+ backgroundColor={white}
+ color={black}
+ borderRadius={borderBase}
+ cssClass="dark-mode"
+ >
+ {uiText}
+ </MjmlButton>
+ </>
);
-};
-
-export default ButtonPrimary;
+}
diff --git a/emails/components/Divider.tsx b/emails/components/Divider.tsx
new file mode 100644
index 0000000000..b3ec7d3297
--- /dev/null
+++ b/emails/components/Divider.tsx
@@ -0,0 +1,21 @@
+import { MjmlDivider } from "mjml-react";
+import { grayLight, grayDark } from "./theme";
+
+export default function Divider(): JSX.Element {
+ return (
+ <>
+ <MjmlDivider
+ cssClass="light-mode"
+ borderColor={grayLight}
+ borderWidth="1px"
+ padding="24px 24px 0px"
+ ></MjmlDivider>
+ <MjmlDivider
+ cssClass="dark-mode"
+ borderColor={grayDark}
+ borderWidth="1px"
+ padding="24px 24px 0px"
+ ></MjmlDivider>
+ </>
+ );
+}
diff --git a/emails/components/Footer.tsx b/emails/components/Footer.tsx
index 7f43ef7744..e6f03ef985 100644
--- a/emails/components/Footer.tsx
+++ b/emails/components/Footer.tsx
@@ -1,11 +1,16 @@
import { MjmlSection, MjmlColumn, MjmlText } from "mjml-react";
-import { grayDark, textSm } from "./theme";
-export default function Footer({ unsubscribe }: { unsubscribe?: boolean }) {
+export default function Footer({
+ unsubscribe,
+ footnote = true,
+}: {
+ unsubscribe?: boolean;
+ footnote?: boolean;
+}): JSX.Element {
return (
<MjmlSection cssClass="smooth">
<MjmlColumn>
- <MjmlText cssClass="footer" fontSize={textSm} color={grayDark}>
+ <MjmlText cssClass="footer">
© {new Date().getFullYear()} Dub.sh
{unsubscribe && (
<>
@@ -16,6 +21,12 @@ export default function Footer({ unsubscribe }: { unsubscribe?: boolean }) {
</>
)}
</MjmlText>
+ {footnote && (
+ <MjmlText cssClass="footer">
+ If you have any feedback or questions about this email, simply reply
+ to it. I'd love to hear from you!
+ </MjmlText>
+ )}
</MjmlColumn>
</MjmlSection>
);
diff --git a/emails/components/Head.tsx b/emails/components/Head.tsx
index 6653bcca38..51124192c8 100644
--- a/emails/components/Head.tsx
+++ b/emails/components/Head.tsx
@@ -1,4 +1,4 @@
-import React, { ReactElement } from "react";
+import React from "react";
import {
MjmlHead,
MjmlFont,
@@ -7,19 +7,9 @@ import {
MjmlStyle,
MjmlRaw,
} from "mjml-react";
-import {
- black,
- blue,
- borderBase,
- grayDark,
- grayLight,
- purple,
- textSm,
-} from "./theme";
-
-type HeadProps = { children?: ReactElement };
+import { black, blue, grayDark, grayLight, purple } from "./theme";
-const Head: React.FC<HeadProps> = ({ children }) => {
+export default function Head(): JSX.Element {
return (
<MjmlHead>
<>
@@ -29,9 +19,14 @@ const Head: React.FC<HeadProps> = ({ children }) => {
</MjmlRaw>
<MjmlFont
name="Inter"
- href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700"
+ href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700"
/>
<MjmlStyle>{`
+ .container {
+ border: solid 1px ${grayLight};
+ border-radius: 8px;
+ background-position-y: 50%;
+ }
strong {
font-weight: 700;
}
@@ -39,42 +34,45 @@ const Head: React.FC<HeadProps> = ({ children }) => {
-webkit-font-smoothing: antialiased;
}
.title > * {
- font-weight: 400 !important;
font-size: 24px !important;
}
.paragraph > * {
font-size: 14px !important;
line-height: 24px !important;
}
- .paragraph a {
+ .li > * {
+ font-size: 14px !important;
+ line-height: 12px !important;
+ }
+ .paragraph a, .li a {
color: ${blue} !important;
text-decoration: none;
}
- .paragraph code {
+ .paragraph code, .li code {
color: ${purple} !important;
}
- .li {
- text-indent: -18px;
- margin-left: 24px;
- display: inline-block;
- }
.footer {
- padding: 24px 24px 48px !important;
- border-top: 1px solid ${grayDark};
+ padding: 0 24px 24px !important;
+ }
+ .footer > * {
+ font-size: 13px !important;
+ line-height: 22px !important;
+ color: ${grayDark} !important;
}
.footer a {
- text-decoration: none !important;
color: ${grayDark} !important;
+ text-decoration: none;
}
- .button {
- border-radius: 3rem !important;
- color: ${black} !important;
- align-items: left !important;
- height: 32px !important;
- font-weight: 600 !important;
- font-size: ${textSm} !important;
+ .dark-mode {
+ display: none;
}
@media (min-width:480px) {
+ body {
+ padding: 48px 0;
+ }
+ .container {
+ padding: 0 48px;
+ }
td.hero {
padding-left: 24px !important;
padding-right: 24px !important;
@@ -84,17 +82,20 @@ const Head: React.FC<HeadProps> = ({ children }) => {
body {
background: ${black};
}
+ .container {
+ border: solid 1px ${grayDark};
+ }
.logo > * {
filter: invert(1) !important;
}
.title > * {
color: #fff !important;
}
- .paragraph > * {
+ .paragraph > *, .li > * {
color: #fff !important;
}
.dark-mode {
- display: inherit;
+ display: block;
}
.light-mode {
display: none;
@@ -104,10 +105,7 @@ const Head: React.FC<HeadProps> = ({ children }) => {
<MjmlAttributes>
<MjmlAll font-family='Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif' />
</MjmlAttributes>
- {children}
</>
</MjmlHead>
);
-};
-
-export default Head;
+}
diff --git a/emails/components/Header.tsx b/emails/components/Header.tsx
index 67aeafdaa8..65b46ba653 100644
--- a/emails/components/Header.tsx
+++ b/emails/components/Header.tsx
@@ -1,11 +1,11 @@
import { MjmlSection, MjmlColumn, MjmlImage, MjmlText } from "mjml-react";
-const Header = ({ title }: { title: string }) => {
+export default function Header({ title }: { title: string }): JSX.Element {
return (
<MjmlSection>
<MjmlColumn>
<MjmlImage
- padding="32px 0"
+ padding="12px 0 24px"
width="44px"
height="44px"
align="center"
@@ -18,6 +18,4 @@ const Header = ({ title }: { title: string }) => {
</MjmlColumn>
</MjmlSection>
);
-};
-
-export default Header;
+}
diff --git a/emails/components/theme.ts b/emails/components/theme.ts
index f8ab9bab18..e61dff9a28 100644
--- a/emails/components/theme.ts
+++ b/emails/components/theme.ts
@@ -5,7 +5,7 @@ export const purple = "#bd11e0";
export const blue = "#2563EB";
export const gold = "#fadf98";
export const grayDark = "#888";
-export const grayLight = "#f5f5f5";
+export const grayLight = "#eaeaea";
// Typography
export const textSm = 14;
diff --git a/emails/index.ts b/emails/index.ts
index 3aedfa51fe..b1624c4637 100644
--- a/emails/index.ts
+++ b/emails/index.ts
@@ -14,7 +14,7 @@ const sendMail = buildSendMail({
host: "smtp.postmarkapp.com",
...transportConfig,
}),
- defaultFrom: "[email protected]",
+ defaultFrom: "Dub <[email protected]>",
configPath: "./mailing.config.json",
});
@@ -25,6 +25,6 @@ export const sendMarketingMail = buildSendMail({
host: "smtp-broadcasts.postmarkapp.com",
...transportConfig,
}),
- defaultFrom: "[email protected]",
+ defaultFrom: "Steven from Dub <[email protected]>",
configPath: "./mailing.config.json",
});
diff --git a/emails/previews/Account.tsx b/emails/previews/Account.tsx
index d60122de3d..6030f61c4b 100644
--- a/emails/previews/Account.tsx
+++ b/emails/previews/Account.tsx
@@ -1,12 +1,12 @@
-import Login from "../LoginLink";
-import AccountCreated from "../AccountCreated";
+import { default as LoginLinkEmail } from "../LoginLink";
+import { default as WelcomeEmailChild } from "../WelcomeEmail";
export function LoginLink() {
return (
- <Login url="http://app.localhost:3000/api/auth/callback/email?callbackUrl=http%3A%2F%2Fapp.localhost%3A3000%2Flogin&token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&[email protected]" />
+ <LoginLinkEmail url="http://app.localhost:3000/api/auth/callback/email?callbackUrl=http%3A%2F%2Fapp.localhost%3A3000%2Flogin&token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&[email protected]" />
);
}
-export function accountCreated() {
- return <AccountCreated name="Steven" />;
+export function WelcomeEmail() {
+ return <WelcomeEmailChild name="Steven Tey" />;
}
diff --git a/emails/previews/Notifications.tsx b/emails/previews/Notifications.tsx
index bb1705f9ac..41cd7b3655 100644
--- a/emails/previews/Notifications.tsx
+++ b/emails/previews/Notifications.tsx
@@ -1,5 +1,21 @@
-import DomainInvalid from "../DomainInvalid";
+import { default as InvalidDomainEmail } from "../InvalidDomain";
+import { default as ProjectDeletedEmail } from "../ProjectDeleted";
+import { default as UsageExceededEmail } from "../UsageExceeded";
export function InvalidDomain() {
- return <DomainInvalid domain="google.com" projectSlug="google" />;
+ return (
+ <InvalidDomainEmail
+ domain="google.com"
+ projectSlug="google"
+ invalidDays={14}
+ />
+ );
+}
+
+export function ProjectDeleted() {
+ return <ProjectDeletedEmail domain="google.com" projectSlug="google" />;
+}
+
+export function UsageExceeded() {
+ return <UsageExceededEmail usage={2406} usageLimit={1000} type="first" />;
}
diff --git a/lib/cron.tsx b/lib/cron.tsx
deleted file mode 100644
index 97f6d50c5e..0000000000
--- a/lib/cron.tsx
+++ /dev/null
@@ -1,180 +0,0 @@
-import prisma from "@/lib/prisma";
-import { redis, deleteProject, getUsage } from "@/lib/upstash";
-import { removeDomain } from "./domains";
-import sendMail from "emails";
-
-export const handleDomainUpdates = async (
- projectId: string,
- domain: string,
- createdAt: Date,
- verified: boolean,
- changed: boolean
-) => {
- if (changed) {
- await log(`Domain *${domain}* changed status to *${verified}*`);
- }
-
- if (verified) return;
-
- const invalidDays = Math.floor(
- (new Date().getTime() - new Date(createdAt).getTime()) / (1000 * 3600 * 24)
- );
-
- if (invalidDays > 25) {
- await log(`Domain *${domain}* is invalid for ${invalidDays} days`);
- const owner = await prisma.project.findUnique({
- where: { id: projectId },
- select: {
- users: {
- where: {
- role: "owner",
- },
- select: {
- user: {
- select: {
- email: true,
- },
- },
- },
- },
- },
- });
- sendMail({
- subject: "Your Dub.sh Login Link",
- to: "email.com",
- });
- }
-
- if (invalidDays > 30) {
- const hasLinks = await redis.exists(`${domain}:links`);
- if (hasLinks === 0) {
- // only delete if there are no resources recorded (links, stats, etc.)
- return await Promise.all([
- prisma.project.delete({
- where: {
- domain,
- },
- }),
- removeDomain(domain),
- deleteProject(domain),
- log(`Domain *${domain}* has been invalid for > 30 days, deleting.`),
- ]);
- } else {
- return await log(
- `Domain *${domain}* has been invalid for > 30 days but has links, not deleting.`
- );
- }
- }
- return;
-};
-
-export const updateUsage = async () => {
- const users = await prisma.user.findMany({
- select: {
- id: true,
- email: true,
- usageLimit: true,
- stripeId: true,
- billingCycleStart: true,
- projects: {
- select: {
- project: {
- select: {
- id: true,
- domain: true,
- domainVerified: true,
- },
- },
- },
- where: {
- role: "owner",
- },
- },
- },
- });
-
- const response = await Promise.all(
- users.map(
- async ({ id, email, usageLimit, billingCycleStart, projects }) => {
- // if user has no projects, don't update usage
- if (projects.length === 0) return;
-
- const usageArr = await Promise.all(
- projects.map(async ({ project: { id, domain, domainVerified } }) => {
- return {
- id,
- usage: domainVerified
- ? await getUsage(domain, billingCycleStart)
- : 0,
- };
- })
- );
- let totalUsage = usageArr.reduce((acc, { usage }) => acc + usage, 0);
- let ownerExceededUsage = totalUsage > usageLimit;
-
- if (ownerExceededUsage) {
- await log(
- `${email} is over usage limit. Usage: ${totalUsage}, Limit: ${usageLimit}`
- );
- }
-
- const [updateUser, updateProjects] = await Promise.all([
- prisma.user.update({
- where: {
- id,
- },
- data: {
- usage: totalUsage,
- },
- }),
- Promise.all(
- usageArr.map(async ({ id, usage }) => {
- return await prisma.project.update({
- where: {
- id,
- },
- data: {
- usage,
- ownerExceededUsage,
- },
- });
- })
- ),
- ]);
-
- return {
- updateUser,
- updateProjects,
- };
- }
- )
- );
-
- return response;
-};
-
-export const log = async (message: string) => {
- /* Log a message to the console */
- if (!process.env.DUB_SLACK_HOOK) return;
- try {
- return await fetch(process.env.DUB_SLACK_HOOK, {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- body: JSON.stringify({
- blocks: [
- {
- type: "section",
- text: {
- type: "mrkdwn",
- text: message,
- },
- },
- ],
- }),
- });
- } catch (e) {
- console.log(`Failed to log to Vercel Slack. Error: ${e}`);
- }
-};
diff --git a/lib/cron/domains.tsx b/lib/cron/domains.tsx
new file mode 100644
index 0000000000..bf4a01edbf
--- /dev/null
+++ b/lib/cron/domains.tsx
@@ -0,0 +1,127 @@
+import { redis, deleteProject } from "@/lib/upstash";
+import { removeDomain } from "@/lib/domains";
+import { log } from "@/lib/cron/utils";
+import sendMail from "emails";
+import InvalidDomain from "emails/InvalidDomain";
+import ProjectDeleted from "emails/ProjectDeleted";
+
+export const handleDomainUpdates = async (
+ projectSlug: string,
+ domain: string,
+ createdAt: Date,
+ verified: boolean,
+ changed: boolean,
+ sentEmails: string[]
+) => {
+ if (changed) {
+ await log(`Domain *${domain}* changed status to *${verified}*`);
+ }
+
+ if (verified) return;
+
+ const invalidDays = Math.floor(
+ (new Date().getTime() - new Date(createdAt).getTime()) / (1000 * 3600 * 24)
+ );
+
+ if (invalidDays >= 14 && invalidDays < 28) {
+ await log(`Domain *${domain}* is invalid for ${invalidDays} days`);
+ const sentFirstDomainInvalidEmail = sentEmails.includes(
+ "firstDomainInvalidEmail"
+ );
+ if (!sentFirstDomainInvalidEmail) {
+ sendDomainInvalidEmail(projectSlug, domain, invalidDays, "first");
+ }
+ } else if (invalidDays >= 28) {
+ const sentSecondDomainInvalidEmail = sentEmails.includes(
+ "secondDomainInvalidEmail"
+ );
+ if (!sentSecondDomainInvalidEmail) {
+ sendDomainInvalidEmail(projectSlug, domain, invalidDays, "second");
+ }
+ }
+
+ if (invalidDays >= 30) {
+ const hasLinks = await redis.exists(`${domain}:links`);
+ if (hasLinks === 0) {
+ // only delete if there are no resources recorded (links, stats, etc.)
+ const ownerEmail = await getProjectOwnerEmail(projectSlug);
+ return await Promise.all([
+ prisma.project.delete({
+ where: {
+ domain,
+ },
+ }),
+ removeDomain(domain),
+ deleteProject(domain),
+ log(`Domain *${domain}* has been invalid for > 30 days, deleting.`),
+ sendMail({
+ subject: `Your project ${projectSlug} has been deleted`,
+ to: ownerEmail,
+ from: "Steven from Dub <[email protected]>",
+ component: (
+ <ProjectDeleted domain={domain} projectSlug={projectSlug} />
+ ),
+ }),
+ ]);
+ } else {
+ return await log(
+ `Domain *${domain}* has been invalid for > 30 days but has links, not deleting.`
+ );
+ }
+ }
+ return;
+};
+
+const sendDomainInvalidEmail = async (
+ projectSlug: string,
+ domain: string,
+ invalidDays: number,
+ type: "first" | "second"
+) => {
+ const ownerEmail = await getProjectOwnerEmail(projectSlug);
+ return await Promise.all([
+ sendMail({
+ subject: `Your domain ${domain} needs to be configured`,
+ to: ownerEmail,
+ from: "Steven from Dub <[email protected]>",
+ component: (
+ <InvalidDomain
+ domain={domain}
+ projectSlug={projectSlug}
+ invalidDays={invalidDays}
+ />
+ ),
+ }),
+ prisma.sentEmail.create({
+ data: {
+ project: {
+ connect: {
+ slug: projectSlug,
+ },
+ },
+ type: `${type}DomainInvalidEmail`,
+ },
+ }),
+ ]);
+};
+
+const getProjectOwnerEmail = async (projectSlug: string) => {
+ const owner = await prisma.project.findUnique({
+ where: { slug: projectSlug },
+ select: {
+ users: {
+ where: {
+ role: "owner",
+ },
+ select: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ },
+ },
+ });
+ return owner?.users[0].user.email;
+};
diff --git a/lib/cron/usage.tsx b/lib/cron/usage.tsx
new file mode 100644
index 0000000000..d6a37f8c8d
--- /dev/null
+++ b/lib/cron/usage.tsx
@@ -0,0 +1,158 @@
+import prisma from "@/lib/prisma";
+import { getUsage } from "@/lib/upstash";
+import { log } from "./utils";
+import sendMail from "emails";
+import UsageExceeded from "emails/UsageExceeded";
+
+export const updateUsage = async () => {
+ const users = await prisma.user.findMany({
+ select: {
+ id: true,
+ email: true,
+ usageLimit: true,
+ stripeId: true,
+ billingCycleStart: true,
+ projects: {
+ select: {
+ project: {
+ select: {
+ id: true,
+ domain: true,
+ domainVerified: true,
+ },
+ },
+ },
+ where: {
+ role: "owner",
+ },
+ },
+ sentEmails: true,
+ },
+ });
+
+ const response = await Promise.all(
+ users.map(
+ async ({
+ id,
+ email,
+ usageLimit,
+ billingCycleStart,
+ projects,
+ sentEmails,
+ }) => {
+ // if user has no projects, don't update usage
+ if (projects.length === 0) return;
+
+ const usageArr = await Promise.all(
+ projects.map(async ({ project: { id, domain, domainVerified } }) => {
+ return {
+ id,
+ usage: domainVerified
+ ? await getUsage(domain, billingCycleStart)
+ : 0,
+ };
+ })
+ );
+ let totalUsage = usageArr.reduce((acc, { usage }) => acc + usage, 0);
+ let ownerExceededUsage = totalUsage > usageLimit;
+
+ if (ownerExceededUsage) {
+ await log(
+ `${email} is over usage limit. Usage: ${totalUsage}, Limit: ${usageLimit}`
+ );
+ const sentFirstUsageLimitEmail = sentEmails.some(
+ (email) => email.type === "firstUsageLimitEmail"
+ );
+ if (!sentFirstUsageLimitEmail) {
+ sendUsageLimitEmail(email, totalUsage, usageLimit, "first");
+ } else {
+ const sentSecondUsageLimitEmail = sentEmails.some(
+ (email) => email.type === "secondUsageLimitEmail"
+ );
+ if (!sentSecondUsageLimitEmail) {
+ const daysSinceFirstEmail = Math.floor(
+ (new Date().getTime() -
+ new Date(sentEmails[0].createdAt).getTime()) /
+ (1000 * 3600 * 24)
+ );
+ if (daysSinceFirstEmail >= 3) {
+ sendUsageLimitEmail(email, totalUsage, usageLimit, "second");
+ }
+ }
+ }
+ }
+
+ const newBillingCycle = new Date().getDate() === billingCycleStart;
+
+ const [updateUser, updateProjects] = await Promise.all([
+ prisma.user.update({
+ where: {
+ id,
+ },
+ data: {
+ usage: totalUsage,
+ // reset usage email warnings if it's a new billing cycle
+ ...(newBillingCycle && {
+ sentEmails: {
+ deleteMany: {
+ type: {
+ in: ["firstUsageLimitEmail", "secondUsageLimitEmail"],
+ },
+ },
+ },
+ }),
+ },
+ }),
+ Promise.all(
+ usageArr.map(async ({ id, usage }) => {
+ return await prisma.project.update({
+ where: {
+ id,
+ },
+ data: {
+ usage,
+ ownerExceededUsage,
+ },
+ });
+ })
+ ),
+ ]);
+
+ return {
+ updateUser,
+ updateProjects,
+ };
+ }
+ )
+ );
+
+ return response;
+};
+
+const sendUsageLimitEmail = async (
+ email: string,
+ usage: number,
+ usageLimit: number,
+ type: "first" | "second"
+) => {
+ return await Promise.all([
+ sendMail({
+ subject: `You have exceeded your Dub usage limit`,
+ to: email,
+ from: "Steven from Dub <[email protected]>",
+ component: (
+ <UsageExceeded usage={usage} usageLimit={usageLimit} type={type} />
+ ),
+ }),
+ prisma.sentEmail.create({
+ data: {
+ user: {
+ connect: {
+ email,
+ },
+ },
+ type: `${type}UsageLimitEmail`,
+ },
+ }),
+ ]);
+};
diff --git a/lib/cron/utils.ts b/lib/cron/utils.ts
new file mode 100644
index 0000000000..94b7c10b65
--- /dev/null
+++ b/lib/cron/utils.ts
@@ -0,0 +1,25 @@
+export const log = async (message: string) => {
+ /* Log a message to the console */
+ if (!process.env.DUB_SLACK_HOOK) return;
+ try {
+ return await fetch(process.env.DUB_SLACK_HOOK, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ blocks: [
+ {
+ type: "section",
+ text: {
+ type: "mrkdwn",
+ text: message,
+ },
+ },
+ ],
+ }),
+ });
+ } catch (e) {
+ console.log(`Failed to log to Vercel Slack. Error: ${e}`);
+ }
+};
diff --git a/lib/middleware/link.ts b/lib/middleware/link.ts
index c200a7b66a..e06d6eb10a 100644
--- a/lib/middleware/link.ts
+++ b/lib/middleware/link.ts
@@ -2,13 +2,6 @@ import { NextRequest, NextFetchEvent, NextResponse } from "next/server";
import { redis, recordClick } from "@/lib/upstash";
import { parse, detectBot } from "@/lib/middleware/utils";
import { LinkProps } from "../types";
-import { Ratelimit } from "@upstash/ratelimit";
-import { Redis } from "@upstash/redis";
-
-const ratelimit = new Ratelimit({
- redis: Redis.fromEnv(),
- limiter: Ratelimit.slidingWindow(10, "60 s"),
-});
export default async function LinkMiddleware(
req: NextRequest,
@@ -30,7 +23,8 @@ export default async function LinkMiddleware(
if (target) {
const isBot = detectBot(req);
- ev.waitUntil(recordClick(hostname, req, key)); // increment click count
+ const noTrack = req.headers.get("dub-no-track");
+ if (!noTrack) ev.waitUntil(recordClick(hostname, req, key)); // track the click only if there is no `dub-no-track` header
if (image && description && isBot) {
// rewrite to proxy page (dub.sh/proxy/[domain]/[key])
diff --git a/lib/upstash.ts b/lib/upstash.ts
index 6517873468..da04a801a0 100644
--- a/lib/upstash.ts
+++ b/lib/upstash.ts
@@ -274,7 +274,6 @@ export async function getUsage(
results = await pipeline.exec();
}
const usage = results.reduce((acc, curr) => acc + curr, 0);
- await redis.setex(`usage:${hostname}`, 3600, usage); // cache for 1 hour
return usage;
}
diff --git a/pages/api/auth/[...nextauth].tsx b/pages/api/auth/[...nextauth].tsx
index 4f616c0590..1e949d919d 100644
--- a/pages/api/auth/[...nextauth].tsx
+++ b/pages/api/auth/[...nextauth].tsx
@@ -1,9 +1,11 @@
import NextAuth, { type NextAuthOptions } from "next-auth";
import EmailProvider from "next-auth/providers/email";
+import GoogleProvider from "next-auth/providers/google";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import prisma from "@/lib/prisma";
-import sendMail from "emails";
+import sendMail, { sendMarketingMail } from "emails";
import LoginLink from "emails/LoginLink";
+import WelcomeEmail from "emails/WelcomeEmail";
const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
@@ -18,6 +20,10 @@ export const authOptions: NextAuthOptions = {
});
},
}),
+ GoogleProvider({
+ clientId: process.env.GOOGLE_CLIENT_ID,
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET,
+ }),
],
adapter: PrismaAdapter(prisma),
session: { strategy: "jwt" },
@@ -44,6 +50,19 @@ export const authOptions: NextAuthOptions = {
return session;
},
},
+ events: {
+ async signIn(message) {
+ if (message.isNewUser) {
+ const email = message.user.email;
+ sendMarketingMail({
+ subject: "✨ Welcome to Dub",
+ to: email,
+ bcc: process.env.TRUSTPILOT_BCC_EMAIL,
+ component: <WelcomeEmail />,
+ });
+ }
+ },
+ },
};
export default NextAuth(authOptions);
diff --git a/pages/api/cron/domains.ts b/pages/api/cron/domains.ts
index 0c0a57148a..5b91c9213d 100644
--- a/pages/api/cron/domains.ts
+++ b/pages/api/cron/domains.ts
@@ -6,7 +6,7 @@ import {
getDomainResponse,
verifyDomain,
} from "@/lib/domains";
-import { handleDomainUpdates } from "@/lib/cron";
+import { handleDomainUpdates } from "@/lib/cron/domains";
/**
* Cron to check if domains are verified.
@@ -19,10 +19,11 @@ async function handler(_req: NextApiRequest, res: NextApiResponse) {
try {
const projects = await prisma.project.findMany({
select: {
- id: true,
+ slug: true,
domain: true,
domainVerified: true,
createdAt: true,
+ sentEmails: true,
},
orderBy: {
domainLastChecked: "asc",
@@ -68,11 +69,12 @@ async function handler(_req: NextApiRequest, res: NextApiResponse) {
const changed = newDomainVerified !== domainVerified;
const updates = await handleDomainUpdates(
- project.id,
+ project.slug,
domain,
createdAt,
newDomainVerified,
- changed
+ changed,
+ project.sentEmails.map((email) => email.type)
);
return {
diff --git a/pages/api/cron/links.ts b/pages/api/cron/links.ts
index 344c112737..4eef8fb508 100644
--- a/pages/api/cron/links.ts
+++ b/pages/api/cron/links.ts
@@ -1,7 +1,7 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { verifySignature } from "@upstash/qstash/nextjs";
import { redis } from "@/lib/upstash";
-import { log } from "@/lib/cron";
+import { log } from "@/lib/cron/utils";
/**
* Cron to delete generic links (links created on dub.sh) that are older than 30 days.
diff --git a/pages/api/cron/usage.ts b/pages/api/cron/usage.ts
index c49568980e..2e7eaca322 100644
--- a/pages/api/cron/usage.ts
+++ b/pages/api/cron/usage.ts
@@ -1,6 +1,6 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { verifySignature } from "@upstash/qstash/nextjs";
-import { updateUsage } from "@/lib/cron";
+import { updateUsage } from "@/lib/cron/usage";
/**
* Cron to update the usage stats of each project.
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index df6208d23d..57615104cf 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -25,6 +25,7 @@ model User {
accounts Account[]
sessions Session[]
projects ProjectUsers[]
+ sentEmails SentEmail[]
createdAt DateTime @default(now())
}
@@ -64,19 +65,20 @@ model VerificationToken {
}
model Project {
- id String @id @default(cuid())
- name String
- slug String @unique
- logo String?
- domain String @unique
- domainVerified Boolean @default(false)
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
- domainLastChecked DateTime @default(now())
- usage Int @default(0)
- ownerUsageLimit Int @default(1000)
- ownerExceededUsage Boolean @default(false)
- users ProjectUsers[]
+ id String @id @default(cuid())
+ name String
+ slug String @unique
+ logo String?
+ domain String @unique
+ domainVerified Boolean @default(false)
+ createdAt DateTime @default(now())
+ updatedAt DateTime @updatedAt
+ users ProjectUsers[]
+ domainLastChecked DateTime @default(now())
+ usage Int @default(0)
+ ownerUsageLimit Int @default(1000)
+ ownerExceededUsage Boolean @default(false)
+ sentEmails SentEmail[]
}
model ProjectUsers {
@@ -90,4 +92,21 @@ model ProjectUsers {
projectId String
@@unique([userId, projectId])
+}
+
+enum EmailType {
+ firstDomainInvalidEmail
+ secondDomainInvalidEmail
+ firstUsageLimitEmail
+ secondUsageLimitEmail
+}
+
+model SentEmail {
+ id String @id @default(cuid())
+ type EmailType
+ createdAt DateTime @default(now())
+ user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
+ userId String?
+ project Project? @relation(fields: [projectId], references: [id], onDelete: Cascade)
+ projectId String?
}
\ No newline at end of file