Skip to content

Open-source status page, incident response and uptime monitoring

feat: progress bar (#596)

Maximilian Kaske3d258a59ddaa
diff --git a/apps/web/src/app/discord/page.tsx b/apps/web/src/app/(redirect)/discord/page.tsx
similarity index 100%
rename from apps/web/src/app/discord/page.tsx
rename to apps/web/src/app/(redirect)/discord/page.tsx
diff --git a/apps/web/src/app/(redirect)/docs/page.tsx b/apps/web/src/app/(redirect)/docs/page.tsx
new file mode 100644
index 000000000..415541f6a
--- /dev/null
+++ b/apps/web/src/app/(redirect)/docs/page.tsx
@@ -0,0 +1,5 @@
+import { redirect } from "next/navigation";
+
+export default function DiscordRedirect() {
+ return redirect("https://docs.openstatus.dev");
+}
diff --git a/apps/web/src/app/github/page.tsx b/apps/web/src/app/(redirect)/github/page.tsx
similarity index 100%
rename from apps/web/src/app/github/page.tsx
rename to apps/web/src/app/(redirect)/github/page.tsx
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/customer-portal-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/customer-portal-button.tsx
index 4efbeb54e..40c49d5f0 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/customer-portal-button.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/customer-portal-button.tsx
@@ -30,7 +30,7 @@ export function CustomerPortalButton({ workspaceSlug }: Props) {
return (
<Button
size="sm"
- variant="outline"
+ variant="secondary"
onClick={getUserCustomerPortal}
disabled={isPending}
>
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/plan.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/plan.tsx
index af0a5a026..6bb343f5b 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/plan.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/plan.tsx
@@ -4,9 +4,7 @@ import { useTransition } from "react";
import { useRouter } from "next/navigation";
import type { Workspace, WorkspacePlan } from "@openstatus/db/src/schema";
-import { Button } from "@openstatus/ui";
-import { LoadingAnimation } from "@/components/loading-animation";
import { PricingTable } from "@/components/marketing/pricing/pricing-table";
import { getStripe } from "@/lib/stripe/client";
import { api } from "@/trpc/client";
@@ -42,33 +40,16 @@ export const SettingsPlan = ({ workspace }: { workspace: Workspace }) => {
};
return (
- <div className="grid gap-4">
- <div className="grid gap-6">
- <div>
- <Button
- onClick={getUserCustomerPortal}
- variant="outline"
- disabled={isPending}
- >
- {isPending ? (
- <LoadingAnimation variant="inverse" />
- ) : (
- "Customer Portal"
- )}
- </Button>
- </div>
- <PricingTable
- currentPlan={workspace.plan}
- isLoading={isPending}
- events={{
- // REMINDER: redirecting to customer portal as a fallback because the free plan has no price
- free: getUserCustomerPortal,
- starter: () => getCheckoutSession("starter"),
- pro: () => getCheckoutSession("pro"),
- team: () => getCheckoutSession("team"),
- }}
- />
- </div>
- </div>
+ <PricingTable
+ currentPlan={workspace.plan}
+ isLoading={isPending}
+ events={{
+ // REMINDER: redirecting to customer portal as a fallback because the free plan has no price
+ free: getUserCustomerPortal,
+ starter: () => getCheckoutSession("starter"),
+ pro: () => getCheckoutSession("pro"),
+ team: () => getCheckoutSession("team"),
+ }}
+ />
);
};
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/page.tsx
index 6f2657531..f2fab3420 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/page.tsx
@@ -1,13 +1,40 @@
+import { getLimits } from "@openstatus/plans";
+import { Progress, Separator } from "@openstatus/ui";
+
import { api } from "@/trpc/server";
import { SettingsPlan } from "./_components/plan";
export default async function BillingPage() {
const workspace = await api.workspace.getWorkspace.query();
+ const currentNumbers = await api.workspace.getCurrentWorkspaceNumbers.query();
+
+ const limits = getLimits(workspace.plan);
+
return (
- <div className="grid gap-3">
- <h3 className="text-lg font-medium">
- <span className="capitalize">{workspace.plan}</span> plan
- </h3>
+ <div className="grid gap-4">
+ <div className="flex items-center justify-between gap-3">
+ <h3 className="text-lg font-medium">
+ <span className="capitalize">{workspace.plan}</span> plan
+ </h3>
+ <CustomerPortalButton workspaceSlug={workspace.slug} />
+ </div>
+ <div className="grid max-w-lg gap-3">
+ {Object.entries(currentNumbers).map(([key, value]) => {
+ const limit = limits[key as keyof typeof currentNumbers];
+ return (
+ <div key={key}>
+ <div className="text-muted-foreground mb-1 flex items-center justify-between">
+ <p className="text-sm capitalize">{key.replace("-", " ")}</p>
+ <p className="text-xs">
+ <span className="text-foreground">{value}</span> / {limit}
+ </p>
+ </div>
+ <Progress value={(value / limit) * 100} />
+ </div>
+ );
+ })}
+ </div>
+ <Separator className="my-4" />
<SettingsPlan workspace={workspace} />
</div>
);
diff --git a/apps/web/src/components/layout/app-header.tsx b/apps/web/src/components/layout/app-header.tsx
index 3b39cbc0b..e8bb9424a 100644
--- a/apps/web/src/components/layout/app-header.tsx
+++ b/apps/web/src/components/layout/app-header.tsx
@@ -34,7 +34,7 @@ export function AppHeader() {
<ul className="flex gap-2">
<li className="w-full">
<Button variant="link" asChild>
- <Link href="https://docs.openstatus.dev" target="_blank">
+ <Link href="/docs" target="_blank">
Docs
<ArrowUpRight className="ml-1 h-4 w-4 flex-shrink-0" />
</Link>
diff --git a/apps/web/src/components/marketing/pricing/pricing-plan-radio.tsx b/apps/web/src/components/marketing/pricing/pricing-plan-radio.tsx
index 4966834b6..519ffea80 100644
--- a/apps/web/src/components/marketing/pricing/pricing-plan-radio.tsx
+++ b/apps/web/src/components/marketing/pricing/pricing-plan-radio.tsx
@@ -30,7 +30,7 @@ export function PricingPlanRadio() {
key === "team" && "bg-muted/50",
)}
>
- <span className="capitalize">{key}</span>
+ <span className="text-sm capitalize">{key}</span>
<span className="text-muted-foreground mt-1 text-xs font-light">
{allPlans[key].price}€/month
</span>
diff --git a/packages/api/src/router/workspace.ts b/packages/api/src/router/workspace.ts
index 69f0324a7..f602a3b17 100644
--- a/packages/api/src/router/workspace.ts
+++ b/packages/api/src/router/workspace.ts
@@ -2,14 +2,18 @@ import { TRPCError } from "@trpc/server";
import { generateSlug } from "random-word-slugs";
import { z } from "zod";
-import { and, eq } from "@openstatus/db";
+import { and, eq, sql } from "@openstatus/db";
import {
+ monitor,
+ notification,
+ page,
selectWorkspaceSchema,
user,
usersToWorkspaces,
workspace,
workspacePlanSchema,
} from "@openstatus/db/src/schema";
+import { Limits } from "@openstatus/plans";
import { createTRPCRouter, protectedProcedure } from "../trpc";
@@ -154,4 +158,28 @@ export const workspaceRouter = createTRPCRouter({
.returning()
.get();
}),
+
+ getCurrentWorkspaceNumbers: protectedProcedure.query(async (opts) => {
+ const currentNumbers = await opts.ctx.db.transaction(async (tx) => {
+ const notifications = await tx
+ .select({ count: sql<number>`count(*)` })
+ .from(notification)
+ .where(eq(notification.workspaceId, opts.ctx.workspace.id));
+ const monitors = await tx
+ .select({ count: sql<number>`count(*)` })
+ .from(monitor)
+ .where(eq(monitor.workspaceId, opts.ctx.workspace.id));
+ const pages = await tx
+ .select({ count: sql<number>`count(*)` })
+ .from(page)
+ .where(eq(page.workspaceId, opts.ctx.workspace.id));
+ return {
+ "notification-channels": notifications?.[0].count || 0,
+ monitors: monitors?.[0].count || 0,
+ "status-pages": pages?.[0].count || 0,
+ } satisfies Partial<Limits>;
+ });
+
+ return currentNumbers;
+ }),
});
diff --git a/packages/plans/src/index.ts b/packages/plans/src/index.ts
index f712a0a20..5f52ac8ba 100644
--- a/packages/plans/src/index.ts
+++ b/packages/plans/src/index.ts
@@ -1,6 +1,7 @@
-export { allPlans } from "./config";
-export { getLimit } from "./utils";
-export { pricingTableConfig } from "./pricing-table";
+export * from "./config";
+export * from "./utils";
+export * from "./pricing-table";
+export * from "./types";
export { workspacePlans as plans } from "@openstatus/db/src/schema";
export type { WorkspacePlan } from "@openstatus/db/src/schema";
diff --git a/packages/plans/src/utils.ts b/packages/plans/src/utils.ts
index 8a51d170d..d6f057ae3 100644
--- a/packages/plans/src/utils.ts
+++ b/packages/plans/src/utils.ts
@@ -10,3 +10,7 @@ export function getLimit<T extends keyof Limits>(
) {
return allPlans[plan].limits[limit];
}
+
+export function getLimits(plan: WorkspacePlan) {
+ return allPlans[plan].limits;
+}
diff --git a/packages/ui/package.json b/packages/ui/package.json
index bb07f365d..c250116a9 100644
--- a/packages/ui/package.json
+++ b/packages/ui/package.json
@@ -29,6 +29,7 @@
"@radix-ui/react-hover-card": "1.0.7",
"@radix-ui/react-label": "2.0.2",
"@radix-ui/react-popover": "1.0.7",
+ "@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-radio-group": "1.1.3",
"@radix-ui/react-select": "2.0.0",
"@radix-ui/react-separator": "1.0.3",
diff --git a/packages/ui/src/components/progress.tsx b/packages/ui/src/components/progress.tsx
new file mode 100644
index 000000000..ac53b6b63
--- /dev/null
+++ b/packages/ui/src/components/progress.tsx
@@ -0,0 +1,28 @@
+"use client";
+
+import * as React from "react";
+import * as ProgressPrimitive from "@radix-ui/react-progress";
+
+import { cn } from "@/lib/utils";
+
+const Progress = React.forwardRef<
+ React.ElementRef<typeof ProgressPrimitive.Root>,
+ React.ComponentPropsWithoutRef<typeof ProgressPrimitive.Root>
+>(({ className, value, ...props }, ref) => (
+ <ProgressPrimitive.Root
+ ref={ref}
+ className={cn(
+ "bg-primary/20 relative h-2 w-full overflow-hidden rounded-full",
+ className,
+ )}
+ {...props}
+ >
+ <ProgressPrimitive.Indicator
+ className="bg-primary h-full w-full flex-1 transition-all"
+ style={{ transform: `translateX(-${100 - (value || 0)}%)` }}
+ />
+ </ProgressPrimitive.Root>
+));
+Progress.displayName = ProgressPrimitive.Root.displayName;
+
+export { Progress };
diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx
index 3939ff1c4..8053fbd20 100644
--- a/packages/ui/src/index.tsx
+++ b/packages/ui/src/index.tsx
@@ -19,6 +19,7 @@ export * from "./components/input-with-addons";
export * from "./components/input";
export * from "./components/label";
export * from "./components/popover";
+export * from "./components/progress";
export * from "./components/radio-group";
export * from "./components/select";
export * from "./components/separator";
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 0ee5b5897..e9a890c72 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -813,6 +813,9 @@ importers:
'@radix-ui/react-popover':
specifier: 1.0.7
+ '@radix-ui/react-progress':
+ specifier: ^1.0.3
'@radix-ui/react-radio-group':
specifier: 1.1.3
@@ -3858,6 +3861,28 @@ packages:
react-dom: 18.2.0([email protected])
dev: false
+ resolution: {integrity: sha512-5G6Om/tYSxjSeEdrb1VfKkfZfn/1IlPWd731h2RfPuSbIfNUgfqAwbKfJCg/PP6nuUCTrYzalwHSpSinoWoCag==}
+ peerDependencies:
+ '@types/react': '*'
+ '@types/react-dom': '*'
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ '@types/react-dom':
+ optional: true
+ dependencies:
+ '@babel/runtime': 7.23.2
+ '@radix-ui/react-context': 1.0.1(@types/[email protected])([email protected])
+ '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@types/react': 18.2.24
+ '@types/react-dom': 18.2.8
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-x+yELayyefNeKeTx4fjK6j99Fs6c4qKm3aY38G3swQVTN6xMpsrbigC0uHs2L//g8q4qR7qOcww8430jJmi2ag==}
peerDependencies: