The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Fixed multi-user emails, loading spinner
Steven Teyaf181fd6a593
diff --git a/app/ui/button.tsx b/app/ui/button.tsxindex edd1384791..f6c6861d93 100644--- a/app/ui/button.tsx+++ b/app/ui/button.tsx@@ -1,6 +1,6 @@"use client";-import { LoadingDots } from "#/ui/icons";+import { LoadingSpinner } from "#/ui/icons";import Tooltip from "#/ui/tooltip";import { cn } from "#/lib/utils";import { ReactNode } from "react";@@ -36,7 +36,7 @@ export default function Button({// if onClick is passed, it's a "button" type, otherwise it's being used in a form, hence "submit"type={onClick ? "button" : "submit"}className={cn(- "flex h-10 w-full items-center justify-center space-x-2 rounded-md border text-sm transition-all focus:outline-none",+ "flex h-10 w-full items-center justify-center space-x-2 rounded-md border px-4 text-sm transition-all focus:outline-none",disabled || loading? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400": {@@ -51,14 +51,8 @@ export default function Button({{...(onClick ? { onClick } : {})}disabled={disabled || loading}>- {loading ? (- <LoadingDots color="#808080" />- ) : (- <>- {icon}- <p>{text}</p>- </>- )}+ {loading ? <LoadingSpinner /> : icon ? icon : null}+ <p>{text}</p></button>);}diff --git a/app/ui/form.tsx b/app/ui/form.tsxindex 88a135301c..385b1438df 100644--- a/app/ui/form.tsx+++ b/app/ui/form.tsx@@ -53,7 +53,7 @@ export default function Form({<div className="flex items-center justify-between rounded-b-lg border-t border-gray-200 bg-gray-50 p-3 sm:px-10"><p className="text-sm text-gray-500">{helpText}</p>- <div className="w-32">+ <div><Buttontext="Save Changes"loading={saving}diff --git a/app/ui/icons/loading-spinner.module.css b/app/ui/icons/loading-spinner.module.cssindex 2b1ac0afe4..3504c36d2c 100644--- a/app/ui/icons/loading-spinner.module.css+++ b/app/ui/icons/loading-spinner.module.css@@ -1,74 +1,67 @@.spinner {- color: gray;- display: inline-block;position: relative;- width: 70px;- height: 70px;- transform: scale(0.3) translateX(-90px) translateY(-5px);+ top: 50%;+ left: 50%;}.spinner div {- transform-origin: 40px 40px;animation: spinner 1.2s linear infinite;-}-.spinner div:after {- content: " ";- display: block;+ background: gray;position: absolute;- top: 5px;- left: 37px;- width: 6px;- height: 20px;- border-radius: 20%;- background: black;+ border-radius: 1rem;+ width: 30%;+ height: 8%;+ left: -10%;+ top: -4%;}.spinner div:nth-child(1) {- transform: rotate(0deg);- animation-delay: -1.1s;+ animation-delay: -1.2s;+ transform: rotate(1deg) translate(120%);}.spinner div:nth-child(2) {- transform: rotate(30deg);- animation-delay: -1s;+ animation-delay: -1.1s;+ transform: rotate(30deg) translate(120%);}.spinner div:nth-child(3) {- transform: rotate(60deg);- animation-delay: -0.9s;+ animation-delay: -1s;+ transform: rotate(60deg) translate(120%);}.spinner div:nth-child(4) {- transform: rotate(90deg);- animation-delay: -0.8s;+ animation-delay: -0.9s;+ transform: rotate(90deg) translate(120%);}.spinner div:nth-child(5) {- transform: rotate(120deg);- animation-delay: -0.7s;+ animation-delay: -0.8s;+ transform: rotate(120deg) translate(120%);}.spinner div:nth-child(6) {- transform: rotate(150deg);- animation-delay: -0.6s;+ animation-delay: -0.7s;+ transform: rotate(150deg) translate(120%);}.spinner div:nth-child(7) {- transform: rotate(180deg);- animation-delay: -0.5s;+ animation-delay: -0.6s;+ transform: rotate(180deg) translate(120%);}.spinner div:nth-child(8) {- transform: rotate(210deg);- animation-delay: -0.4s;+ animation-delay: -0.5s;+ transform: rotate(210deg) translate(120%);}.spinner div:nth-child(9) {- transform: rotate(240deg);- animation-delay: -0.3s;+ animation-delay: -0.4s;+ transform: rotate(240deg) translate(120%);}.spinner div:nth-child(10) {- transform: rotate(270deg);- animation-delay: -0.2s;+ animation-delay: -0.3s;+ transform: rotate(270deg) translate(120%);}.spinner div:nth-child(11) {- transform: rotate(300deg);- animation-delay: -0.1s;+ animation-delay: -0.2s;+ transform: rotate(300deg) translate(120%);}.spinner div:nth-child(12) {- transform: rotate(330deg);- animation-delay: 0s;+ animation-delay: -0.1s;+ transform: rotate(330deg) translate(120%);}+@keyframes spinner {0% {opacity: 1;diff --git a/app/ui/icons/loading-spinner.tsx b/app/ui/icons/loading-spinner.tsxindex 1c8e704aa4..f5a24c8007 100644--- a/app/ui/icons/loading-spinner.tsx+++ b/app/ui/icons/loading-spinner.tsx@@ -1,20 +1,14 @@+import { cn } from "#/lib/utils";import styles from "./loading-spinner.module.css";-export default function LoadingSpinner() {+export default function LoadingSpinner({ className }: { className?: string }) {return (- <div className={styles.spinner}>- <div></div>- <div></div>- <div></div>- <div></div>- <div></div>- <div></div>- <div></div>- <div></div>- <div></div>- <div></div>- <div></div>- <div></div>+ <div className={cn("h-5 w-5", className)}>+ <div className={cn(styles.spinner, "h-5 w-5", className)}>+ {[...Array(12)].map((_, i) => (+ <div key={i} />+ ))}+ </div></div>);}diff --git a/components/app/links/link-filters.tsx b/components/app/links/link-filters.tsxindex e3b2ec6f70..a288450cba 100644--- a/components/app/links/link-filters.tsx+++ b/components/app/links/link-filters.tsx@@ -133,7 +133,7 @@ const SearchBox = ({ searchInputRef }) => {<div className="relative"><div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">{isValidating && searchInputRef.current?.value.length > 0 ? (- <LoadingSpinner />+ <LoadingSpinner className="h-4 w-4" />) : (<Search className="h-4 w-4 text-gray-400" />)}diff --git a/emails/clicks-summary.tsx b/emails/clicks-summary.tsxindex dff97c5b03..2f24c38467 100644--- a/emails/clicks-summary.tsx+++ b/emails/clicks-summary.tsx@@ -19,6 +19,7 @@ import { DUB_LOGO } from "../lib/constants";import { nFormatter, truncate } from "../lib/utils";export default function ClicksSummary({+ email = "[email protected]",projectName = "Acme",projectSlug = "acme",totalClicks = 63689,@@ -46,6 +47,7 @@ export default function ClicksSummary({},],}: {+ email: string;projectName: string;projectSlug: string;totalClicks: number;@@ -55,7 +57,6 @@ export default function ClicksSummary({clicks: number;}[];}) {- const inactiveUser = createdLinks === 0;return (<Html><Head />@@ -134,7 +135,7 @@ export default function ClicksSummary({</Section></>)}- {inactiveUser ? (+ {createdLinks === 0 ? (<><Text className="text-sm leading-6 text-black">It looks like you haven't created any links in the last 30@@ -168,11 +169,11 @@ export default function ClicksSummary({)}<Hr className="mx-0 my-6 w-full border border-gray-200" /><Text className="text-[12px] leading-6 text-gray-500">- This email was intended for members of the{" "}- <span className="text-black">{projectName}</span> project on Dub.- If you were not expecting this email, you can ignore this email.- If you are concerned about your account's safety, please reply to- this email to get in touch with us.+ This email was intended for{" "}+ <span className="text-black">{email}</span>. If you were not+ expecting this email, you can ignore this email. If you are+ concerned about your account's safety, please reply to this email+ to get in touch with us.</Text></Container></Body>diff --git a/emails/domain-deleted.tsx b/emails/domain-deleted.tsxindex 6fbce7faef..8ceee4f281 100644--- a/emails/domain-deleted.tsx+++ b/emails/domain-deleted.tsx@@ -15,12 +15,12 @@ import {import { DUB_LOGO } from "../lib/constants";export default function DomainDeleted({+ email = "[email protected]",domain = "dub.sh",- projectName = "Dub",projectSlug = "dub",}: {+ email: string;domain: string;- projectName: string;projectSlug: string;}) {return (@@ -72,11 +72,11 @@ export default function DomainDeleted({</Text><Hr className="mx-0 my-6 w-full border border-gray-200" /><Text className="text-[12px] leading-6 text-gray-500">- This email was intended for members of the{" "}- <span className="text-black">{projectName}</span> project on- Dub.If you were not expecting this email, you can ignore this- email. If you are concerned about your account's safety, please- reply to this email to get in touch with us.+ This email was intended for{" "}+ <span className="text-black">{email}</span>. If you were not+ expecting this email, you can ignore this email. If you are+ concerned about your account's safety, please reply to this email+ to get in touch with us.</Text></Container></Body>diff --git a/emails/index.ts b/emails/index.tsindex e40f60ee1f..0aa064dd65 100644--- a/emails/index.ts+++ b/emails/index.ts@@ -10,7 +10,7 @@ export const sendEmail = async ({marketing,test,}: {- email: string | string[];+ email: string;subject: string;react:| ReactElement<any, string | JSXElementConstructor<any>>diff --git a/emails/invalid-domain.tsx b/emails/invalid-domain.tsxindex abe547b8dc..1d54852f81 100644--- a/emails/invalid-domain.tsx+++ b/emails/invalid-domain.tsx@@ -15,13 +15,13 @@ import {import { DUB_LOGO } from "../lib/constants";export default function InvalidDomain({+ email = "[email protected]",domain = "dub.sh",- projectName = "Dub",projectSlug = "dub",invalidDays = 14,}: {+ email: string;domain: string;- projectName: string;projectSlug: string;invalidDays: number;}): JSX.Element {@@ -85,11 +85,11 @@ export default function InvalidDomain({</Text><Hr className="mx-0 my-6 w-full border border-gray-200" /><Text className="text-[12px] leading-6 text-gray-500">- This email was intended for members of the{" "}- <span className="text-black">{projectName}</span> project on Dub.- If you were not expecting this email, you can ignore this email.- If you are concerned about your account's safety, please reply to- this email to get in touch with us.+ This email was intended for{" "}+ <span className="text-black">{email}</span>. If you were not+ expecting this email, you can ignore this email. If you are+ concerned about your account's safety, please reply to this email+ to get in touch with us.</Text></Container></Body>diff --git a/lib/cron/domains.tsx b/lib/cron/domains.tsxindex a3d5de76d0..811e5c5e12 100644--- a/lib/cron/domains.tsx+++ b/lib/cron/domains.tsx@@ -57,7 +57,6 @@ export const handleDomainUpdates = async ({},},},- take: 50,},_count: {select: {@@ -123,16 +122,18 @@ export const handleDomainUpdates = async ({}`,type: "cron",}),- limiter.schedule(() =>- sendEmail({- subject: `Your domain ${domain} has been deleted`,- email: emails,- react: DomainDeleted({- domain,- projectName,- projectSlug,+ emails.map((email) =>+ limiter.schedule(() =>+ sendEmail({+ subject: `Your domain ${domain} has been deleted`,+ email,+ react: DomainDeleted({+ email,+ domain,+ projectSlug,+ }),}),- }),+ ),),]);}@@ -191,17 +192,19 @@ const sendDomainInvalidEmail = async ({message: `Domain *${domain}* is invalid for ${invalidDays} days, email sent.`,type: "cron",}),- limiter.schedule(() =>- sendEmail({- subject: `Your domain ${domain} needs to be configured`,- email: emails,- react: InvalidDomain({- domain,- projectName,- projectSlug,- invalidDays,+ emails.map((email) =>+ limiter.schedule(() =>+ sendEmail({+ subject: `Your domain ${domain} needs to be configured`,+ email,+ react: InvalidDomain({+ email,+ domain,+ projectSlug,+ invalidDays,+ }),}),- }),+ ),),prisma.sentEmail.create({data: {diff --git a/lib/cron/usage.tsx b/lib/cron/usage.tsxindex c3cab18761..b03361b390 100644--- a/lib/cron/usage.tsx+++ b/lib/cron/usage.tsx@@ -28,7 +28,6 @@ export const updateUsage = async () => {select: {user: true,},- take: 50,},domains: {where: {@@ -115,18 +114,26 @@ export const updateUsage = async () => {const emails = project.users.map((user) => user.user.email) as string[];- limiter.schedule(() =>- sendEmail({- subject: `Your 30-day Dub summary for ${project.name}`,- email: emails,- react: ClicksSummary({- projectName: project.name,- projectSlug: project.slug,- totalClicks: project.usage,- createdLinks:- createdLinks.status === "fulfilled" ? createdLinks.value : 0,- topLinks: topLinks.status === "fulfilled" ? topLinks.value : [],- }),+ await Promise.allSettled(+ emails.map((email) => {+ limiter.schedule(() =>+ sendEmail({+ subject: `Your 30-day Dub summary for ${project.name}`,+ email,+ react: ClicksSummary({+ email,+ projectName: project.name,+ projectSlug: project.slug,+ totalClicks: project.usage,+ createdLinks:+ createdLinks.status === "fulfilled"+ ? createdLinks.value+ : 0,+ topLinks:+ topLinks.status === "fulfilled" ? topLinks.value : [],+ }),+ }),+ );}),);}@@ -163,16 +170,18 @@ const sendUsageLimitEmail = async (type: "first" | "second",) => {return await Promise.allSettled([- limiter.schedule(() =>- sendEmail({- subject: `You have exceeded your Dub usage limit`,- email: emails,- react: UsageExceeded({- project,- type,+ emails.map((email) => {+ limiter.schedule(() =>+ sendEmail({+ subject: `You have exceeded your Dub usage limit`,+ email,+ react: UsageExceeded({+ project,+ type,+ }),}),- }),- ),+ );+ }),prisma.sentEmail.create({data: {project: {diff --git a/package.json b/package.jsonindex 740cacb0cf..f6324125d2 100644--- a/package.json+++ b/package.json@@ -75,7 +75,7 @@"rehype-pretty-code": "^0.9.5","rehype-slug": "^5.1.0","remark-gfm": "^3.0.1",- "resend": "^0.16.0",+ "resend": "0.16.0","shiki": "^0.14.1","sonner": "^0.5.0","stripe": "^12.12.0",diff --git a/yarn.lock b/yarn.lockindex d1f4456e68..016f473ff4 100644--- a/yarn.lock+++ b/yarn.lock@@ -7810,7 +7810,7 @@ require-directory@^2.1.1:resolved "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz"integrity sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==-resend@^0.16.0:version "0.16.0"resolved "https://registry.yarnpkg.com/resend/-/resend-0.16.0.tgz#3904dca47616d919df8abb26e38ad9e8a4f8f5e7"integrity sha512-6NnrtEapGD6FtnhRUrtDdfgQFH2av5cTkrnElUh6AjTzGrHXiMpD/GRwT46pqpA6i/AXSDXKV7Wh/hHQJLKFew==