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.

stash changes

Steven Tey71da837edcbb
diff --git a/apps/web/app/api/cron/usage/utils.ts b/apps/web/app/api/cron/usage/utils.ts
index ed5a7d6fc5..6a0121a1cf 100644
--- a/apps/web/app/api/cron/usage/utils.ts
+++ b/apps/web/app/api/cron/usage/utils.ts
@@ -55,15 +55,12 @@ export const updateUsage = async (skip?: number) => {
return;
}
- // Reset billing cycles for projects that:
- // - Are not on the free plan
- // - Are on the free plan but have not exceeded usage
- // - Have adjustedBillingCycleStart that matches today's date
+ // Reset billing cycles for projects that have
+ // adjustedBillingCycleStart that matches today's date
const billingReset = projects.filter(
- ({ usage, usageLimit, plan, billingCycleStart }) =>
- !(plan === "free" && usage > usageLimit) &&
+ ({ billingCycleStart }) =>
getAdjustedBillingCycleStart(billingCycleStart as number) ===
- new Date().getDate(),
+ new Date().getDate(),
);
// Get all projects that have exceeded usage
@@ -168,12 +165,18 @@ export const updateUsage = async (skip?: number) => {
);
}
+ const { plan, usage, usageLimit } = project;
+
return await prisma.project.update({
where: {
id: project.id,
},
data: {
- usage: 0,
+ // only reset usage if plan is not free or usage is not over usageLimit
+ ...((plan !== "free" || usage <= usageLimit) && {
+ usage: 0,
+ }),
+ linksUsage: 0,
sentEmails: {
deleteMany: {
type: {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
index 246dffa1b1..a33132e9f2 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx
@@ -3,6 +3,7 @@
import LinksContainer from "@/ui/links/links-container";
import { useAddEditLinkModal } from "@/ui/modals/add-edit-link-modal";
import {
+ Button,
IconMenu,
MaxWidthWrapper,
Popover,
@@ -30,43 +31,7 @@ export default function ProjectLinksClient() {
<div className="flex h-36 items-center border-b border-gray-200 bg-white">
<MaxWidthWrapper>
<div className="flex flex-col items-center justify-between sm:flex-row">
- {/* <div>
- <div className="flex items-end space-x-8">
- <h1 className="text-2xl text-gray-600">Links</h1>
- <Link
- href={`/${slug}/settings/billing`}
- className="rounded-lg px-2 py-1 transition-all hover:bg-gray-50"
- >
- {linksUsage !== undefined && linksLimit ? (
- <p className="text-sm text-gray-500">
- <NumberTooltip value={linksUsage}>
- <span className="text-xl font-semibold text-black">
- {nFormatter(linksUsage)}{" "}
- </span>
- </NumberTooltip>
- / {nFormatter(linksLimit, { full: true })}
- </p>
- ) : (
- <div className="h-5 w-32 animate-pulse rounded-md bg-gray-200" />
- )}
- </Link>
- </div>
- <ProgressBar
- value={linksUsage}
- max={linksLimit}
- className="mt-2 h-2"
- />
- </div> */}
- <div className="flex flex-col space-y-1">
- <h1 className="text-2xl text-gray-600">Links</h1>
- <p className="text-sm text-gray-500">
- Your plan includes{" "}
- <span className="font-medium text-black">
- {nFormatter(linksLimit, { full: true })}
- </span>{" "}
- links per month. Upgrade to add more.
- </p>
- </div>
+ <h1 className="text-2xl text-gray-600">Links</h1>
<div className="flex">
<AddEditLinkButton />
<AddLinkOptions />
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index cea5c1463d..0bd53373d2 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -609,22 +609,26 @@ function AddEditLinkButton({
}: {
setShowAddEditLinkModal: Dispatch<SetStateAction<boolean>>;
}) {
+ const { slug, exceededLinks } = useProject();
+ const { setShowUpgradePlanModal } = useContext(ModalContext);
+
const onKeyDown = useCallback((e: KeyboardEvent) => {
const target = e.target as HTMLElement;
const existingModalBackdrop = document.getElementById("modal-backdrop");
// only open modal with keyboard shortcut if:
- // - project has not exceeded usage limit
// - c is pressed
// - user is not pressing cmd/ctrl + c
// - user is not typing in an input or textarea
// - there is no existing modal backdrop (i.e. no other modal is open)
+ // - project has not exceeded links limit
if (
e.key === "c" &&
!e.metaKey &&
!e.ctrlKey &&
target.tagName !== "INPUT" &&
target.tagName !== "TEXTAREA" &&
- !existingModalBackdrop
+ !existingModalBackdrop &&
+ !(slug && exceededLinks)
) {
e.preventDefault(); // or else it'll show up in the input field since that's getting auto-selected
setShowAddEditLinkModal(true);
@@ -641,12 +645,14 @@ function AddEditLinkButton({
// - pasted content is a valid URL
// - user is not typing in an input or textarea
// - there is no existing modal backdrop (i.e. no other modal is open)
+ // - project has not exceeded links limit
if (
pastedContent &&
isValidUrl(pastedContent) &&
target.tagName !== "INPUT" &&
target.tagName !== "TEXTAREA" &&
- !existingModalBackdrop
+ !existingModalBackdrop &&
+ !(slug && exceededLinks)
) {
setShowAddEditLinkModal(true);
}
@@ -662,15 +668,22 @@ function AddEditLinkButton({
}, [onKeyDown]);
return (
- <button
+ <Button
+ text="Create link"
+ shortcut="C"
+ disabledTooltip={
+ slug && exceededLinks ? (
+ <TooltipContent
+ title="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."
+ cta="Upgrade to Pro"
+ onClick={() => {
+ setShowUpgradePlanModal(true);
+ }}
+ />
+ ) : undefined
+ }
onClick={() => setShowAddEditLinkModal(true)}
- className="group flex items-center space-x-3 rounded-md border border-black bg-black px-3 py-2 text-sm font-medium text-white transition-all duration-75 hover:bg-white hover:text-black active:scale-95"
- >
- <p>Create link</p>
- <kbd className="hidden rounded bg-zinc-700 px-2 py-0.5 text-xs font-light text-gray-400 transition-all duration-75 group-hover:bg-gray-100 group-hover:text-gray-500 md:inline-block">
- C
- </kbd>
- </button>
+ />
);
}
diff --git a/packages/ui/src/button.tsx b/packages/ui/src/button.tsx
index fc8bc3b451..7557c02054 100644
--- a/packages/ui/src/button.tsx
+++ b/packages/ui/src/button.tsx
@@ -7,9 +7,10 @@ import { Tooltip } from "./tooltip";
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
text: string;
- variant?: "primary" | "secondary" | "success" | "danger";
+ variant?: "primary" | "secondary" | "outline" | "success" | "danger";
loading?: boolean;
icon?: ReactNode;
+ shortcut?: string;
disabledTooltip?: string | ReactNode;
}
@@ -18,14 +19,20 @@ export function Button({
variant = "primary",
loading,
icon,
+ shortcut,
disabledTooltip,
...props
}: ButtonProps) {
if (disabledTooltip) {
return (
<Tooltip content={disabledTooltip}>
- <div className="flex h-10 w-full cursor-not-allowed items-center justify-center rounded-md border border-gray-200 bg-gray-100 px-4 text-sm text-gray-400 transition-all focus:outline-none">
+ <div className="flex h-10 w-full cursor-not-allowed items-center justify-center space-x-2 rounded-md border border-gray-200 bg-gray-100 px-4 text-sm text-gray-400 transition-all focus:outline-none">
<p>{text}</p>
+ {shortcut && (
+ <kbd className="hidden rounded bg-zinc-200 px-2 py-0.5 text-xs font-light text-gray-400 md:inline-block">
+ {shortcut}
+ </kbd>
+ )}
</div>
</Tooltip>
);
@@ -35,7 +42,7 @@ export function Button({
// if onClick is passed, it's a "button" type, otherwise it's being used in a form, hence "submit"
type={props.onClick ? "button" : "submit"}
className={cn(
- "flex h-10 w-full items-center justify-center space-x-2 rounded-md border px-4 text-sm transition-all focus:outline-none",
+ "group flex h-10 w-full items-center justify-center space-x-2 rounded-md border px-4 text-sm transition-all focus:outline-none",
props.disabled || loading
? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"
: {
@@ -43,6 +50,8 @@ export function Button({
variant === "primary",
"border-gray-200 bg-white text-gray-500 hover:border-black hover:text-black":
variant === "secondary",
+ "border-transparent text-gray-500 transition-all duration-75 hover:bg-gray-100":
+ variant === "outline",
"border-blue-500 bg-blue-500 text-white hover:bg-white hover:text-blue-500":
variant === "success",
"border-red-500 bg-red-500 text-white hover:bg-white hover:text-red-500":
@@ -55,6 +64,11 @@ export function Button({
>
{loading ? <LoadingSpinner /> : icon ? icon : null}
<p>{text}</p>
+ {shortcut && (
+ <kbd className="hidden rounded bg-zinc-700 px-2 py-0.5 text-xs font-light text-gray-400 transition-all duration-75 group-hover:bg-gray-100 group-hover:text-gray-500 md:inline-block">
+ {shortcut}
+ </kbd>
+ )}
</button>
);
}