The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
added email notification
Steven Teye4e5a5553fc5
diff --git a/app/api/cron/import/utils.ts b/app/api/cron/import/utils.tsindex ae93388dcd..9f5cb27dfa 100644--- a/app/api/cron/import/utils.ts+++ b/app/api/cron/import/utils.ts@@ -1,6 +1,7 @@import prisma from "#/lib/prisma";import { redis } from "#/lib/upstash";import { sendEmail } from "emails";+import LinksImported from "emails/links-imported";// recursive function to check if pagination.searchAfter is not an empty string, else break// rate limit for /groups/{group_guid}/bitlinks is 1500 per hour or 150 per minute@@ -88,6 +89,38 @@ export const importLinksFromBitly = async ({await new Promise((resolve) => setTimeout(resolve, 500));if (nextSearchAfter === "") {+ const project = await prisma.project.findUnique({+ where: {+ id: projectId,+ },+ select: {+ name: true,+ slug: true,+ users: {+ where: {+ role: "owner",+ },+ select: {+ user: {+ select: {+ email: true,+ },+ },+ },+ },+ links: {+ select: {+ domain: true,+ key: true,+ createdAt: true,+ },+ take: 5,+ },+ },+ });+ const ownerEmail = project?.users[0].user.email ?? "";+ const links = project?.links ?? [];+await Promise.all([// delete key from redisredis.del(`import:bitly:${projectId}`),@@ -103,10 +136,19 @@ export const importLinksFromBitly = async ({}),// send email to user- // sendEmail({- // subject: `Your Bitly links have been imported!`,- // email: user- // })+ sendEmail({+ subject: `Your Bitly links have been imported!`,+ email: ownerEmail,+ react: LinksImported({+ email: ownerEmail,+ provider: "Bitly",+ count,+ links,+ domains,+ projectName: project?.name ?? "",+ projectSlug: project?.slug ?? "",+ }),+ }),]);return count;} else {diff --git a/emails/links-imported.tsx b/emails/links-imported.tsxnew file mode 100644index 0000000000..62eb2379d2--- /dev/null+++ b/emails/links-imported.tsx@@ -0,0 +1,153 @@+import {+ Body,+ Link,+ Container,+ Column,+ Row,+ Head,+ Heading,+ Hr,+ Html,+ Img,+ Preview,+ Section,+ Tailwind,+ Text,+} from "@react-email/components";+import { linkConstructor, timeAgo } from "../lib/utils";+import { DUB_LOGO } from "../lib/constants";+import Footer from "./components/footer";++export default function LinksImported({+ email = "[email protected]",+ provider = "Bitly",+ count = 1020,+ links = [+ {+ domain: "ac.me",+ key: "sales",+ createdAt: new Date("2023-07-16T00:00:00.000Z"),+ },+ {+ domain: "ac.me",+ key: "instagram",+ createdAt: new Date("2023-07-01T00:00:00.000Z"),+ },+ {+ domain: "ac.me",+ key: "facebook",+ createdAt: new Date("2023-06-18T00:00:00.000Z"),+ },+ {+ domain: "ac.me",+ key: "twitter",+ createdAt: new Date("2023-06-01T00:00:00.000Z"),+ },+ {+ domain: "ac.me",+ key: "linkedin",+ createdAt: new Date("2023-05-16T00:00:00.000Z"),+ },+ ],+ projectName = "Acme",+ projectSlug = "acme",+ domains = ["ac.me"],+}: {+ email: string;+ provider: "Bitly" | "Short.io";+ count: number;+ links: {+ domain: string;+ key: string;+ createdAt: Date;+ }[];+ projectName: string;+ projectSlug: string;+ domains: string[];+}) {+ return (+ <Html>+ <Head />+ <Preview>Your {provider} links have been imported</Preview>+ <Tailwind>+ <Body className="mx-auto my-auto bg-white font-sans">+ <Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">+ <Section className="mt-8">+ <Img+ src={DUB_LOGO}+ width="40"+ height="40"+ alt="Dub"+ className="mx-auto my-0"+ />+ </Section>+ <Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">+ Your {provider} links have been imported+ </Heading>+ <Text className="text-sm leading-6 text-black">+ We have successfully{" "}+ <strong>+ imported {Intl.NumberFormat("en-us").format(count)} links+ </strong>{" "}+ from {provider} into your Dub project,{" "}+ <Link+ href={`https://app.dub.sh/${projectSlug}`}+ className="font-medium text-blue-600 no-underline"+ >+ {projectName}↗+ </Link>{" "}+ , for the domain{domains.length > 1 ? "s" : ""}{" "}+ <strong>{domains.join(", ")}</strong>.+ </Text>+ {links.length > 0 && (+ <Section>+ <Row className="pb-2">+ <Column align="left" className="text-sm text-gray-500">+ Link+ </Column>+ <Column align="right" className="text-sm text-gray-500">+ Created+ </Column>+ </Row>+ {links.map(({ domain, key, createdAt }, index) => (+ <div key={index}>+ <Row>+ <Column align="left" className="text-sm font-medium">+ {linkConstructor({ domain, key, pretty: true })}+ </Column>+ <Column align="right" className="text-sm text-gray-600">+ {timeAgo(createdAt)}+ </Column>+ </Row>+ {index !== links.length - 1 && (+ <Hr className="my-2 w-full border border-gray-200" />+ )}+ </div>+ ))}+ </Section>+ )}+ <Section className="my-8 text-center">+ <Link+ className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"+ href={`https://app.dub.sh/${projectSlug}`}+ >+ View {Intl.NumberFormat("en-us").format(count - 5)} more links+ </Link>+ </Section>+ <Text className="text-sm leading-6 text-black">+ If you haven't already{" "}+ <Link+ href={`https://app.dub.sh/${projectSlug}/domains`}+ className="font-medium text-blue-600 no-underline"+ >+ verified your domain{domains.length > 1 ? "s" : ""}+ </Link>+ , you will need to do it before you can start using your links.+ </Text>+ <Footer email={email} />+ </Container>+ </Body>+ </Tailwind>+ </Html>+ );+}diff --git a/lib/api/domains.ts b/lib/api/domains.tsindex dfe12b8923..5692b0565e 100644--- a/lib/api/domains.ts+++ b/lib/api/domains.ts@@ -230,18 +230,18 @@ export async function changeDomainForImages(domain: string, newDomain: string) {/* Delete a domain and all links & images associated with with */export async function deleteDomainAndLinks(domain: string) {- // const links = await prisma.link.findMany({- // where: {- // domain,- // },- // });- // const pipeline = redis.pipeline();- // links.forEach(({ key }) => {- // pipeline.del(`${domain}:${key}`);- // });- // pipeline.del(`root:${domain}`);+ const links = await prisma.link.findMany({+ where: {+ domain,+ },+ });+ const pipeline = redis.pipeline();+ links.forEach(({ key }) => {+ pipeline.del(`${domain}:${key}`);+ });+ pipeline.del(`root:${domain}`);return await Promise.allSettled([- // pipeline.exec(), // delete all links from redis+ pipeline.exec(), // delete all links from redis// remove all images from cloudinarycloudinary.v2.api.delete_resources_by_prefix(domain),// remove the domain from Verceldiff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsxindex 6461369771..6f3372fb15 100644--- a/pages/app/[slug]/index.tsx+++ b/pages/app/[slug]/index.tsx@@ -29,7 +29,7 @@ export default function ProjectLinks() {<Popovercontent={<div className="w-full p-2 md:w-52">- <button+ {/* <buttononClick={() => {}}className="flex w-full items-center justify-between space-x-2 rounded-md p-2 hover:bg-gray-100 active:bg-gray-200">@@ -37,7 +37,7 @@ export default function ProjectLinks() {text="Bulk create links"icon={<FilePlus2 className="h-4 w-4" />}/>- </button>+ </button> */}<buttononClick={() => {setOpenPopover(false);