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.

feat: introduce ai limitation UI

flooorianflo44629e04db58
diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.ts
index ca3ff0b535..9201c70d1d 100644
--- a/apps/web/lib/auth/index.ts
+++ b/apps/web/lib/auth/index.ts
@@ -235,6 +235,8 @@ export const withAuth = (
logo: true,
usage: true,
usageLimit: true,
+ aiUsage: true,
+ aiLimit: true,
linksUsage: true,
linksLimit: true,
domainsLimit: true,
diff --git a/apps/web/ui/charts/simple-pie-chart.tsx b/apps/web/ui/charts/simple-pie-chart.tsx
new file mode 100644
index 0000000000..372bf84602
--- /dev/null
+++ b/apps/web/ui/charts/simple-pie-chart.tsx
@@ -0,0 +1,41 @@
+import { Pie } from "@visx/shape";
+
+type PieChartData = {
+ name: string;
+ value: number;
+ color: string;
+};
+
+export default function SimplePieChart({ data }: { data: PieChartData[] }) {
+ return (
+ <svg width={40} height={40}>
+ <g transform={`translate(20, 20)`}>
+ <Pie
+ data={data}
+ pieValue={(d) => d.value}
+ outerRadius={16}
+ innerRadius={10}
+ cornerRadius={2}
+ padAngle={0}
+ >
+ {(pie) => {
+ return pie.arcs.map((arc, i) => {
+ return (
+ <g key={i}>
+ <path
+ d={pie.path(arc) || ""}
+ fill="currentColor"
+ className={arc.data.color}
+ stroke="white"
+ strokeWidth={1}
+ strokeLinecap="round"
+ />
+ </g>
+ );
+ });
+ }}
+ </Pie>
+ </g>
+ </svg>
+ );
+}
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 5bbeb2dc23..f167dd8171 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -59,6 +59,7 @@ import Preview from "./preview";
import TagsSection from "./tags-section";
import UTMSection from "./utm-section";
import { useCompletion } from "ai/react";
+import SimplePieChart from "@/ui/charts/simple-pie-chart";
function AddEditLinkModal({
showAddEditLinkModal,
@@ -77,7 +78,7 @@ function AddEditLinkModal({
const { slug } = params;
const router = useRouter();
const pathname = usePathname();
- const { id: workspaceId, plan } = useWorkspace();
+ const { id: workspaceId, aiUsage, aiLimit, nextPlan } = useWorkspace();
const [keyError, setKeyError] = useState<string | null>(null);
const [urlError, setUrlError] = useState<string | null>(null);
@@ -512,16 +513,73 @@ function AddEditLinkModal({
</Tooltip>
<Tooltip
content={
- !url
- ? "Please enter a destination URL to generate AI Short Link."
- : "Create Short Link with AI"
+ !url ? (
+ "Please enter a destination URL to generate AI Short Link."
+ ) : aiUsage && aiLimit ? (
+ aiUsage + (generatedKeys.length - 1) < aiLimit ? (
+ <div className="flex items-center gap-4 px-4 py-2">
+ <div>
+ <span className="block max-w-xs text-center text-sm text-gray-700">
+ Create a short link using AI
+ </span>
+ {aiUsage && aiLimit && (
+ <span className="text-xs text-gray-500">
+ {aiLimit -
+ aiUsage -
+ (generatedKeys.length - 1)}
+ /{aiLimit} left
+ </span>
+ )}
+ </div>
+ {aiUsage && aiLimit && (
+ <SimplePieChart
+ data={[
+ {
+ name: "Used",
+ value:
+ aiUsage + (generatedKeys.length - 1),
+ color: "text-gray-200",
+ },
+ {
+ name: "Remaining",
+ value:
+ aiLimit -
+ aiUsage -
+ (generatedKeys.length - 1),
+ color: "text-black",
+ },
+ ]}
+ />
+ )}
+ </div>
+ ) : (
+ <TooltipContent
+ title="You've reached your AI usage limit. Upgrade to Pro to get more AI credits."
+ cta={`Upgrade to ${nextPlan.name}`}
+ onClick={() => {
+ queryParams({
+ set: {
+ upgrade: nextPlan.name.toLowerCase(),
+ },
+ });
+ }}
+ />
+ )
+ ) : (
+ "Create a short link using AI"
+ )
}
>
<button
className="ml-2 flex h-6 w-6 items-center justify-center rounded-md text-gray-500 transition-colors duration-75 hover:bg-gray-100 active:bg-gray-200 disabled:cursor-not-allowed"
onClick={generateAIKey}
disabled={
- generatingAIKey || generatingRandomKey || !url
+ generatingAIKey ||
+ generatingRandomKey ||
+ !url ||
+ (aiUsage && aiLimit
+ ? aiUsage + (generatedKeys.length - 1) >= aiLimit
+ : false)
}
type="button"
>