Skip to content

Open-source status page, incident response and uptime monitoring

fix: missing plan on page creation

mxkaske689b3999e900
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/edit/page.tsx
index 382527110..9ce4ccbcd 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/edit/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/edit/page.tsx
@@ -35,7 +35,7 @@ export default async function EditPage({
monitors: page.monitorsToPages.map(({ monitor }) => monitor.id),
}}
defaultSection={search.success ? search.data.section : undefined}
- plan={workspace?.plan}
+ plan={workspace.plan}
workspaceSlug={params.workspaceSlug}
/>
);
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/layout.tsx
index 28040033e..ee99e1a9d 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/layout.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/[id]/layout.tsx
@@ -3,6 +3,7 @@ import { notFound } from "next/navigation";
import { Button } from "@openstatus/ui";
+import { getBaseUrl } from "@/app/status-page/[domain]/utils";
import { Header } from "@/components/dashboard/header";
import AppPageWithSidebarLayout from "@/components/layout/app-page-with-sidebar-layout";
import { api } from "@/trpc/server";
@@ -33,12 +34,10 @@ export default async function Layout({
<Button variant="outline" asChild>
<Link
target="_blank"
- href={
- process.env.NODE_ENV === "development"
- ? `http://localhost:3000/status-page/${page.slug}`
- : // TODO: add custom domain support
- `https://${page.slug}.openstatus.dev`
- }
+ href={getBaseUrl({
+ slug: page.slug,
+ customDomain: page.customDomain,
+ })}
>
Visit
</Link>
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/new/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/new/page.tsx
index 5d39ecd3a..21eec07a0 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/new/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/new/page.tsx
@@ -10,6 +10,7 @@ export default async function Page({
}) {
const allMonitors = await api.monitor.getMonitorsByWorkspace.query();
const isLimitReached = await api.page.isPageLimitReached.query();
+ const workspace = await api.workspace.getWorkspace.query();
if (isLimitReached) return redirect("./");
@@ -19,6 +20,7 @@ export default async function Page({
nextUrl="./" // back to the overview page
defaultSection="monitors"
workspaceSlug={params.workspaceSlug}
+ plan={workspace.plan}
/>
);
}
diff --git a/apps/web/src/app/status-page/[domain]/utils.tsx b/apps/web/src/app/status-page/[domain]/utils.tsx
index ebedbaa17..92dc8a8b3 100644
--- a/apps/web/src/app/status-page/[domain]/utils.tsx
+++ b/apps/web/src/app/status-page/[domain]/utils.tsx
@@ -12,3 +12,19 @@ export function setPrefixUrl(value: string, params: { domain: string }) {
export function createProtectedCookieKey(value: string) {
return `secured-${value}`;
}
+
+export function getBaseUrl({
+ slug,
+ customDomain,
+}: {
+ slug: string;
+ customDomain?: string;
+}) {
+ if (process.env.NODE_ENV === "development") {
+ return `http://localhost:3000/status-page/${slug}`;
+ }
+ if (customDomain) {
+ return `https://${customDomain}`;
+ }
+ return `https://${slug}.openstatus.dev`;
+}
diff --git a/apps/web/src/components/billing/pro-feature-hover-card.tsx b/apps/web/src/components/billing/pro-feature-hover-card.tsx
index 3c95945d3..6b47353f2 100644
--- a/apps/web/src/components/billing/pro-feature-hover-card.tsx
+++ b/apps/web/src/components/billing/pro-feature-hover-card.tsx
@@ -19,13 +19,13 @@ export function ProFeatureHoverCard({
workspaceSlug,
}: {
children: React.ReactNode;
- plan?: WorkspacePlan;
+ plan: WorkspacePlan;
minRequiredPlan: WorkspacePlan;
workspaceSlug: string;
}) {
console.log({ workspaceSlug, plan, minRequiredPlan });
const [open, setOpen] = useState(false);
- const shouldUpgrade = upgradePlan(plan || "free", minRequiredPlan);
+ const shouldUpgrade = upgradePlan(plan, minRequiredPlan);
if (!shouldUpgrade) return children;
diff --git a/apps/web/src/components/forms/status-page/form.tsx b/apps/web/src/components/forms/status-page/form.tsx
index 1f67d8ded..82eeb3dd2 100644
--- a/apps/web/src/components/forms/status-page/form.tsx
+++ b/apps/web/src/components/forms/status-page/form.tsx
@@ -43,7 +43,7 @@ interface Props {
* on submit, allows to push a url
*/
nextUrl?: string;
- plan?: WorkspacePlan;
+ plan: WorkspacePlan;
workspaceSlug: string;
}
diff --git a/apps/web/src/components/forms/status-page/section-visibility.tsx b/apps/web/src/components/forms/status-page/section-visibility.tsx
index b8ef42be4..b43c0c296 100644
--- a/apps/web/src/components/forms/status-page/section-visibility.tsx
+++ b/apps/web/src/components/forms/status-page/section-visibility.tsx
@@ -17,13 +17,14 @@ import {
Input,
} from "@openstatus/ui";
+import { getBaseUrl } from "@/app/status-page/[domain]/utils";
import { ProFeatureHoverCard } from "@/components/billing/pro-feature-hover-card";
import { CopyToClipboardButton } from "@/components/dashboard/copy-to-clipboard-button";
import { SectionHeader } from "../shared/section-header";
interface Props {
form: UseFormReturn<InsertPage>;
- plan?: WorkspacePlan;
+ plan: WorkspacePlan;
workspaceSlug: string;
}
@@ -31,19 +32,13 @@ export function SectionVisibility({ form, plan, workspaceSlug }: Props) {
const watchPasswordProtected = form.watch("passwordProtected");
const watchPassword = form.watch("password");
- const getBaseUrl = () => {
- if (process.env.NODE_ENV === "development") {
- return `http://localhost:3000/status-page/${form.getValues("slug")}`;
- }
- if (form.getValues("customDomain") !== "") {
- return `https://${form.getValues("customDomain")}`;
- }
- return `https://${form.getValues("slug")}.openstatus.dev`;
- };
+ const baseUrl = getBaseUrl({
+ slug: form.getValues("slug"),
+ customDomain: form.getValues("customDomain"),
+ });
+ const link = `${baseUrl}?authorize=${watchPassword}`;
- const link = `${getBaseUrl()}?authorize=${watchPassword}`;
-
- const hasFreePlan = !plan || plan === "free" ? true : false;
+ const hasFreePlan = plan === "free";
return (
<div className="grid w-full gap-4 md:grid-cols-2">