Skip to content

Open-source status page, incident response and uptime monitoring

refactor: forms to fit latest design changes (#678)

Maximilian Kasked1e09686af7f
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/[id]/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/[id]/edit/page.tsx
index 3cc74dae2..dae17eb59 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/[id]/edit/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/[id]/edit/page.tsx
@@ -1,4 +1,4 @@
-import { NotificationForm } from "@/components/forms/notification-form";
+import { NotificationForm } from "@/components/forms/notification/form";
import { api } from "@/trpc/server";
export default async function EditPage({
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/new/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/new/page.tsx
index 92d03c402..61179072c 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/new/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/new/page.tsx
@@ -1,7 +1,4 @@
-import { notFound } from "next/navigation";
-import * as z from "zod";
-
-import { NotificationForm } from "@/components/forms/notification-form";
+import { NotificationForm } from "@/components/forms/notification/form";
import { api } from "@/trpc/server";
export default async function EditPage({}: {
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 710791f4b..71a05eb9a 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
@@ -1,12 +1,19 @@
import { notFound } from "next/navigation";
+import { z } from "zod";
-import { StatusPageForm } from "@/components/forms/status-page-form";
+import { StatusPageForm } from "@/components/forms/status-page/form";
import { api } from "@/trpc/server";
+const searchParamsSchema = z.object({
+ section: z.string().optional().default("monitors"),
+});
+
export default async function EditPage({
params,
+ searchParams,
}: {
params: { workspaceSlug: string; id: string };
+ searchParams: { [key: string]: string | string[] | undefined };
}) {
const id = Number(params.id);
const page = await api.page.getPageById.query({ id });
@@ -16,6 +23,9 @@ export default async function EditPage({
return notFound();
}
+ // default is request
+ const search = searchParamsSchema.safeParse(searchParams);
+
return (
<StatusPageForm
allMonitors={allMonitors}
@@ -23,6 +33,7 @@ export default async function EditPage({
...page,
monitors: page.monitorsToPages.map(({ monitor }) => monitor.id),
}}
+ defaultSection={search.success ? search.data.section : undefined}
/>
);
}
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 5556e857e..ec7605c95 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
@@ -1,6 +1,6 @@
import { redirect } from "next/navigation";
-import { StatusPageForm } from "@/components/forms/status-page-form";
+import { StatusPageForm } from "@/components/forms/status-page/form";
import { api } from "@/trpc/server";
export default async function Page() {
@@ -13,6 +13,7 @@ export default async function Page() {
<StatusPageForm
allMonitors={allMonitors} // FIXME: rename to just 'monitors'
nextUrl="./" // back to the overview page
+ defaultSection="monitors"
/>
);
}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/[id]/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/[id]/edit/page.tsx
index 53b606d48..06a3a4c09 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/[id]/edit/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/[id]/edit/page.tsx
@@ -1,4 +1,4 @@
-import { StatusReportForm } from "@/components/forms/status-report-form";
+import { StatusReportForm } from "@/components/forms/status-report/form";
import { api } from "@/trpc/server";
export default async function EditPage({
@@ -31,6 +31,7 @@ export default async function EditPage({
message: "",
}
}
+ defaultSection="connect"
/>
);
}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/new/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/new/page.tsx
index 884e61be2..94d2b4e90 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/new/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/new/page.tsx
@@ -1,4 +1,4 @@
-import { StatusReportForm } from "@/components/forms/status-report-form";
+import { StatusReportForm } from "@/components/forms/status-report/form";
import { api } from "@/trpc/server";
export default async function NewPage() {
@@ -6,5 +6,12 @@ export default async function NewPage() {
const pages = await api.page.getPagesByWorkspace.query();
- return <StatusReportForm monitors={monitors} pages={pages} nextUrl={"./"} />;
+ return (
+ <StatusReportForm
+ monitors={monitors}
+ pages={pages}
+ nextUrl={"./"}
+ defaultSection="update-message"
+ />
+ );
}
diff --git a/apps/web/src/app/app/[workspaceSlug]/onboarding/page.tsx b/apps/web/src/app/app/[workspaceSlug]/onboarding/page.tsx
index f9b678302..304b5d0cc 100644
--- a/apps/web/src/app/app/[workspaceSlug]/onboarding/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/onboarding/page.tsx
@@ -9,6 +9,8 @@ import { StatusPageForm } from "@/components/forms/status-page-form";
import { api } from "@/trpc/server";
import { Description } from "./_components/description";
+// FIXME: uses legact MonitorForm and StatusPageForm
+
export default async function Onboarding({
params,
}: {
diff --git a/apps/web/src/components/dashboard/tabs.tsx b/apps/web/src/components/dashboard/tabs.tsx
index 6e2007b15..7783abc76 100644
--- a/apps/web/src/components/dashboard/tabs.tsx
+++ b/apps/web/src/components/dashboard/tabs.tsx
@@ -16,7 +16,7 @@ export function TabsList({
<>
<ShadcnTabsList
className={cn(
- "w-full justify-start rounded-none bg-transparent p-0",
+ "w-full justify-start overflow-x-auto overflow-y-hidden rounded-none bg-transparent p-0",
className,
)}
{...props}
@@ -33,7 +33,7 @@ export function TabsTrigger({
return (
<ShadcnTabsTrigger
className={cn(
- "text-muted-foreground hover:text-primary data-[state=active]:border-b-primary data-[state=active]:text-foreground relative rounded-none border-b-2 border-b-transparent bg-transparent px-4 pb-3 pt-2 shadow-none transition-none data-[state=active]:shadow-none",
+ "text-muted-foreground hover:text-primary data-[state=active]:border-b-primary data-[state=active]:text-foreground relative rounded-none border-b-4 border-b-transparent bg-transparent px-4 pb-3 pt-2 shadow-none transition-none data-[state=active]:shadow-none",
className,
)}
{...props}
diff --git a/apps/web/src/components/forms/monitor/form.tsx b/apps/web/src/components/forms/monitor/form.tsx
index 94bf76170..d27794392 100644
--- a/apps/web/src/components/forms/monitor/form.tsx
+++ b/apps/web/src/components/forms/monitor/form.tsx
@@ -13,7 +13,7 @@ import type {
WorkspacePlan,
} from "@openstatus/db/src/schema";
import { flyRegions, insertMonitorSchema } from "@openstatus/db/src/schema";
-import { Badge, Button, Form } from "@openstatus/ui";
+import { Badge, Form } from "@openstatus/ui";
import type { RegionChecker } from "@/app/play/checker/[id]/utils";
import {
@@ -22,12 +22,11 @@ import {
TabsList,
TabsTrigger,
} from "@/components/dashboard/tabs";
-import { Kbd } from "@/components/kbd";
-import { LoadingAnimation } from "@/components/loading-animation";
import { FailedPingAlertConfirmation } from "@/components/modals/failed-ping-alert-confirmation";
import { useToastAction } from "@/hooks/use-toast-action";
import { api } from "@/trpc/client";
import type { Writeable } from "@/types/utils";
+import { SaveButton } from "../shared/save-button";
import { General } from "./general";
import { SectionDanger } from "./section-danger";
import { SectionNotifications } from "./section-notifications";
@@ -78,23 +77,6 @@ export function MonitorForm({
const [pingFailed, setPingFailed] = React.useState(false);
const { toast } = useToastAction();
- React.useEffect(() => {
- const callback = (event: KeyboardEvent) => {
- // event.metaKey - pressed Command key on Macs
- // event.ctrlKey - pressed Control key on Linux or Windows
- if ((event.metaKey || event.ctrlKey) && event.key === "s") {
- event.preventDefault();
- form.handleSubmit(onSubmit)();
- }
- };
- document.addEventListener("keydown", callback);
- return () => {
- document.removeEventListener("keydown", callback);
- };
- // no need to listen to `onSubmit` changes
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [form]);
-
const handleDataUpdateOrInsertion = async (props: InsertMonitor) => {
try {
if (defaultValues) {
@@ -206,32 +188,11 @@ export function MonitorForm({
</TabsContent>
) : null}
</Tabs>
- <div className="grid gap-3 sm:justify-end">
- <div className="flex flex-col gap-6 sm:col-span-full sm:flex-row sm:justify-end">
- <Button
- className="w-full sm:w-auto"
- size="lg"
- disabled={isPending}
- >
- {!isPending ? (
- <span className="flex gap-2">
- Confirm
- <Kbd>
- <span>⌘</span>
- <span>S</span>
- </Kbd>
- </span>
- ) : (
- <LoadingAnimation />
- )}
- </Button>
- </div>
- {form.formState.isDirty ? (
- <p className="text-muted-foreground text-xs">
- You have unsaved changes
- </p>
- ) : null}
- </div>
+ <SaveButton
+ isPending={isPending}
+ isDirty={form.formState.isDirty}
+ onSubmit={form.handleSubmit(onSubmit)}
+ />
</form>
</Form>
<FailedPingAlertConfirmation
diff --git a/apps/web/src/components/forms/monitor/general.tsx b/apps/web/src/components/forms/monitor/general.tsx
index 14f084c14..6cf7a7522 100644
--- a/apps/web/src/components/forms/monitor/general.tsx
+++ b/apps/web/src/components/forms/monitor/general.tsx
@@ -15,6 +15,8 @@ import {
Switch,
} from "@openstatus/ui";
+import { SectionHeader } from "../shared/section-header";
+
interface Props {
form: UseFormReturn<InsertMonitor>;
plan: WorkspacePlan;
@@ -22,8 +24,12 @@ interface Props {
export function General({ form }: Props) {
return (
- <div className="flex w-full flex-col gap-3">
- <div className="flex items-center gap-3">
+ <div className="grid gap-4 sm:grid-cols-3 sm:gap-6">
+ <SectionHeader
+ title="Basic Information"
+ description="Be able to find your monitor easily."
+ />
+ <div className="flex w-full gap-4 sm:col-span-2">
<FormField
control={form.control}
name="name"
@@ -42,7 +48,7 @@ export function General({ form }: Props) {
control={form.control}
name="active"
render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between space-x-1 space-y-0 sm:col-span-2">
+ <FormItem className="flex flex-row items-center justify-between space-x-1 space-y-0">
<FormLabel>Active</FormLabel>
<FormControl>
<Switch
@@ -55,6 +61,7 @@ export function General({ form }: Props) {
)}
/>
</div>
+ {/* TODO: add FancyBox with "Create Tag option" once `monitor_tabs` db table is set up */}
</div>
);
}
diff --git a/apps/web/src/components/forms/monitor/request-test-button.tsx b/apps/web/src/components/forms/monitor/request-test-button.tsx
index 0b87bb345..554c61172 100644
--- a/apps/web/src/components/forms/monitor/request-test-button.tsx
+++ b/apps/web/src/components/forms/monitor/request-test-button.tsx
@@ -64,20 +64,21 @@ export function RequestTestButton({ form, pingEndpoint }: Props) {
}
});
};
+
+ const { flag } = flyRegionsDict[value as keyof typeof flyRegionsDict];
+
return (
<Dialog open={!!check} onOpenChange={() => setCheck(undefined)}>
- <div className="ring-offset-background focus-within:ring-ring group flex flex h-10 max-w-max items-center rounded-md bg-transparent text-sm focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2">
+ <div className="ring-offset-background focus-within:ring-ring group flex h-10 items-center rounded-md bg-transparent text-sm focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2">
<Select
value={value}
onValueChange={(value: MonitorFlyRegion) => setValue(value)}
>
<SelectTrigger
- className="w-16 rounded-r-none focus:ring-0"
+ className="flex-1 rounded-r-none focus:ring-0"
aria-label={value}
>
- <SelectValue>
- {flyRegionsDict[value as keyof typeof flyRegionsDict]?.flag}
- </SelectValue>
+ <SelectValue>{flag}</SelectValue>
</SelectTrigger>
<SelectContent>
{flyRegions.map((region) => {
@@ -96,7 +97,7 @@ export function RequestTestButton({ form, pingEndpoint }: Props) {
<Button
onClick={onClick}
disabled={isPending}
- className="h-full rounded-l-none focus:ring-0"
+ className="h-full flex-1 rounded-l-none focus:ring-0"
>
{isPending ? (
<LoadingAnimation />
diff --git a/apps/web/src/components/forms/monitor/section-danger.tsx b/apps/web/src/components/forms/monitor/section-danger.tsx
index 2d9ced7e9..8a21f53e9 100644
--- a/apps/web/src/components/forms/monitor/section-danger.tsx
+++ b/apps/web/src/components/forms/monitor/section-danger.tsx
@@ -55,7 +55,9 @@ export function SectionDanger({ monitorId }: Props) {
<div>
<AlertDialog open={open} onOpenChange={setOpen}>
<AlertDialogTrigger asChild>
- <Button variant="destructive">Delete</Button>
+ <Button variant="destructive" className="w-full sm:w-auto">
+ Delete
+ </Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
diff --git a/apps/web/src/components/forms/monitor/section-notifications.tsx b/apps/web/src/components/forms/monitor/section-notifications.tsx
index 8aa2294e4..cf1a71d25 100644
--- a/apps/web/src/components/forms/monitor/section-notifications.tsx
+++ b/apps/web/src/components/forms/monitor/section-notifications.tsx
@@ -27,7 +27,7 @@ import {
} from "@openstatus/ui";
import { NotificationForm } from "../notification-form";
-import { CheckboxLabel } from "./checkbox-label";
+import { CheckboxLabel } from "../shared/checkbox-label";
interface Props {
form: UseFormReturn<InsertMonitor>;
@@ -63,7 +63,7 @@ export function SectionNotifications({ form, plan, notifications }: Props) {
Select the notification channels you want to be informed.
</FormDescription>
</div>
- <div className="grid grid-cols-1 grid-rows-1 gap-6 sm:grid-cols-2 md:grid-cols-3">
+ <div className="grid grid-cols-1 grid-rows-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
{notifications?.map((item) => (
<FormField
key={item.id}
@@ -103,6 +103,9 @@ export function SectionNotifications({ form, plan, notifications }: Props) {
/>
))}
</div>
+ {!notifications || notifications.length === 0 ? (
+ <FormDescription>Missing notifications.</FormDescription>
+ ) : null}
<FormMessage />
</FormItem>
);
diff --git a/apps/web/src/components/forms/monitor/section-requests.tsx b/apps/web/src/components/forms/monitor/section-requests.tsx
index 38d162cd6..dfb9da46a 100644
--- a/apps/web/src/components/forms/monitor/section-requests.tsx
+++ b/apps/web/src/components/forms/monitor/section-requests.tsx
@@ -36,7 +36,7 @@ import {
} from "@openstatus/ui";
import type { RegionChecker } from "@/app/play/checker/[id]/utils";
-import { useToastAction } from "@/hooks/use-toast-action";
+import { SectionHeader } from "../shared/section-header";
import { RequestTestButton } from "./request-test-button";
interface Props {
@@ -79,14 +79,11 @@ export function SectionRequests({ form, pingEndpoint }: Props) {
return (
<div className="grid w-full gap-4">
- <div className="grid gap-1">
- <h4 className="text-foreground font-medium">HTTP request settings</h4>
- <p className="text-muted-foreground text-sm">
- Create your HTTP. Add custom headers, payload and test your endpoint
- before submitting.
- </p>
- </div>
- <div className="flex items-end gap-3">
+ <SectionHeader
+ title="HTTP Request Settings"
+ description="Create your HTTP. Add custom headers, payload and test your endpoint before submitting."
+ />
+ <div className="flex flex-col gap-4 sm:flex-row sm:items-end">
<FormField
control={form.control}
name="method"
@@ -101,7 +98,7 @@ export function SectionRequests({ form, pingEndpoint }: Props) {
defaultValue={field.value}
>
<FormControl>
- <SelectTrigger className="w-[120px]">
+ <SelectTrigger className="sm:w-[120px]">
<SelectValue placeholder="Select" />
</SelectTrigger>
</FormControl>
@@ -144,7 +141,7 @@ export function SectionRequests({ form, pingEndpoint }: Props) {
<div className="space-y-2 sm:col-span-full">
<FormLabel>Request Header</FormLabel>
{fields.map((field, index) => (
- <div key={field.id} className="grid grid-cols-6 gap-6">
+ <div key={field.id} className="grid grid-cols-6 gap-4">
<FormField
control={form.control}
name={`headers.${index}.key`}
diff --git a/apps/web/src/components/forms/monitor/section-scheduling.tsx b/apps/web/src/components/forms/monitor/section-scheduling.tsx
index d7234a943..4ca966487 100644
--- a/apps/web/src/components/forms/monitor/section-scheduling.tsx
+++ b/apps/web/src/components/forms/monitor/section-scheduling.tsx
@@ -20,7 +20,8 @@ import {
} from "@openstatus/ui";
import { flyRegions, flyRegionsDict } from "@openstatus/utils";
-import { CheckboxLabel } from "./checkbox-label";
+import { CheckboxLabel } from "../shared/checkbox-label";
+import { SectionHeader } from "../shared/section-header";
// TODO: centralize in a shared file!
const cronJobs = [
@@ -41,13 +42,10 @@ export function SectionScheduling({ form, plan }: Props) {
const periodicityLimit = getLimit(plan, "periodicity");
return (
<div className="grid w-full gap-4">
- <div className="grid gap-1">
- <h4 className="text-foreground font-medium">Schedule and Regions</h4>
- <p className="text-muted-foreground text-sm">
- Customize the period of time and the regions where your endpoint will
- be monitored.
- </p>
- </div>
+ <SectionHeader
+ title="Schedule and Regions"
+ description="Customize the period of time and the regions where your endpoint will be monitored."
+ />
<div className="grid sm:grid-cols-2 md:grid-cols-3">
<FormField
control={form.control}
@@ -98,7 +96,7 @@ export function SectionScheduling({ form, plan }: Props) {
Select the regions you want to monitor your endpoint from.
</FormDescription>
</div>
- <div className="grid grid-cols-1 grid-rows-1 gap-6 sm:grid-cols-2 md:grid-cols-3">
+ <div className="grid grid-cols-1 grid-rows-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
{flyRegions.map((item) => (
<FormField
key={item}
diff --git a/apps/web/src/components/forms/monitor/section-status-page.tsx b/apps/web/src/components/forms/monitor/section-status-page.tsx
index 6187e4152..3b5face58 100644
--- a/apps/web/src/components/forms/monitor/section-status-page.tsx
+++ b/apps/web/src/components/forms/monitor/section-status-page.tsx
@@ -17,7 +17,8 @@ import {
Input,
} from "@openstatus/ui";
-import { CheckboxLabel } from "./checkbox-label";
+import { CheckboxLabel } from "../shared/checkbox-label";
+import { SectionHeader } from "../shared/section-header";
interface Props {
form: UseFormReturn<InsertMonitor>;
@@ -30,18 +31,15 @@ interface Props {
export function SectionStatusPage({ form, pages }: Props) {
return (
<div className="flex w-full flex-col gap-4">
- <div className="grid gap-1">
- <h4 className="text-foreground font-medium">Status Page</h4>
- <p className="text-muted-foreground text-sm">
- Customize the informations about your monitor on the corresponding
- status page.
- </p>
- </div>
+ <SectionHeader
+ title="Status Page"
+ description="Customize the informations about your monitor on the corresponding status page."
+ />
<FormField
control={form.control}
name="description"
render={({ field }) => (
- <FormItem className="sm:col-span-2">
+ <FormItem>
<FormLabel>Description</FormLabel>
<FormControl>
<Input
@@ -68,7 +66,7 @@ export function SectionStatusPage({ form, pages }: Props) {
Select the pages where you want to display the monitor.
</FormDescription>
</div>
- <div className="grid grid-cols-1 grid-rows-1 gap-6 sm:grid-cols-2 md:grid-cols-3">
+ <div className="grid grid-cols-1 grid-rows-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
{pages?.map((item) => (
<FormField
key={item.id}
@@ -103,6 +101,9 @@ export function SectionStatusPage({ form, pages }: Props) {
/>
))}
</div>
+ {!pages || pages.length === 0 ? (
+ <FormDescription>Missing status pages.</FormDescription>
+ ) : null}
<FormMessage />
</FormItem>
);
diff --git a/apps/web/src/components/forms/notification/config.ts b/apps/web/src/components/forms/notification/config.ts
new file mode 100644
index 000000000..231feaacb
--- /dev/null
+++ b/apps/web/src/components/forms/notification/config.ts
@@ -0,0 +1,64 @@
+import type {
+ InsertNotification,
+ NotificationProvider,
+} from "@openstatus/db/src/schema";
+import { sendTestDiscordMessage } from "@openstatus/notification-discord";
+import { sendTestSlackMessage } from "@openstatus/notification-slack";
+
+export function getDefaultProviderData(defaultValues?: InsertNotification) {
+ if (!defaultValues?.provider) return ""; // FIXME: input can empty - needs to be undefined
+ return JSON.parse(defaultValues?.data || "{}")[defaultValues?.provider];
+}
+
+export function setProviderData(provider: NotificationProvider, data: string) {
+ return { [provider]: data };
+}
+
+export function getProviderMetaData(provider: NotificationProvider) {
+ switch (provider) {
+ case "email":
+ return {
+ dataType: "email",
+ placeholder: "[email protected]",
+ setupDocLink: null,
+ sendTest: null,
+ plans: ["free", "starter", "pro", "team"],
+ };
+
+ case "slack":
+ return {
+ dataType: "url",
+ placeholder: "https://hooks.slack.com/services/xxx...",
+ setupDocLink:
+ "https://api.slack.com/messaging/webhooks#getting_started",
+ sendTest: sendTestSlackMessage,
+ plans: ["free", "starter", "pro", "team"],
+ };
+
+ case "discord":
+ return {
+ dataType: "url",
+ placeholder: "https://discord.com/api/webhooks/{channelId}/xxx...",
+ setupDocLink: "https://support.discord.com/hc/en-us/articles/228383668",
+ sendTest: sendTestDiscordMessage,
+ plans: ["free", "starter", "pro", "team"],
+ };
+ case "sms":
+ return {
+ dataType: "tel",
+ placeholder: "+123456789",
+ setupDocLink: null,
+ sendTest: null,
+ plans: ["pro", "team"],
+ };
+
+ default:
+ return {
+ dataType: "url",
+ placeholder: "xxxx",
+ setupDocLink: `https://docs.openstatus.dev/integrations/${provider}`,
+ send: null,
+ plans: ["free", "starter", "pro", "team"],
+ };
+ }
+}
diff --git a/apps/web/src/components/forms/notification/form.tsx b/apps/web/src/components/forms/notification/form.tsx
new file mode 100644
index 000000000..cbd566826
--- /dev/null
+++ b/apps/web/src/components/forms/notification/form.tsx
@@ -0,0 +1,139 @@
+"use client";
+
+import { useMemo, useTransition } from "react";
+import { useRouter } from "next/navigation";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useForm } from "react-hook-form";
+
+import type {
+ InsertNotification,
+ WorkspacePlan,
+} from "@openstatus/db/src/schema";
+import { insertNotificationSchema } from "@openstatus/db/src/schema";
+import { Button, Form } from "@openstatus/ui";
+
+import { LoadingAnimation } from "@/components/loading-animation";
+import { useToastAction } from "@/hooks/use-toast-action";
+import { api } from "@/trpc/client";
+import { SaveButton } from "../shared/save-button";
+import {
+ getDefaultProviderData,
+ getProviderMetaData,
+ setProviderData,
+} from "./config";
+import { General } from "./general";
+
+interface Props {
+ defaultValues?: InsertNotification;
+ onSubmit?: () => void;
+ workspacePlan: WorkspacePlan;
+ nextUrl?: string;
+}
+
+export function NotificationForm({
+ defaultValues,
+ onSubmit: onExternalSubmit,
+ workspacePlan,
+ nextUrl,
+}: Props) {
+ const [isPending, startTransition] = useTransition();
+ const [isTestPending, startTestTransition] = useTransition();
+ const { toast } = useToastAction();
+ const router = useRouter();
+ const form = useForm<InsertNotification>({
+ resolver: zodResolver(insertNotificationSchema),
+ defaultValues: {
+ ...defaultValues,
+ name: defaultValues?.name || "",
+ data: getDefaultProviderData(defaultValues),
+ },
+ });
+ const watchProvider = form.watch("provider");
+ const watchWebhookUrl = form.watch("data");
+ const providerMetaData = useMemo(
+ () => getProviderMetaData(watchProvider),
+ [watchProvider],
+ );
+
+ async function onSubmit({ provider, data, ...rest }: InsertNotification) {
+ startTransition(async () => {
+ try {
+ if (data === "") {
+ form.setError("data", { message: "This field is required" });
+ return;
+ }
+ if (defaultValues) {
+ await api.notification.update.mutate({
+ provider,
+ data: JSON.stringify(setProviderData(provider, data)),
+ ...rest,
+ });
+ } else {
+ await api.notification.create.mutate({
+ provider,
+ data: JSON.stringify(setProviderData(provider, data)),
+ ...rest,
+ });
+ }
+ if (nextUrl) {
+ router.push(nextUrl);
+ }
+ router.refresh();
+ toast("saved");
+ } catch {
+ toast("error");
+ } finally {
+ onExternalSubmit?.();
+ }
+ });
+ }
+
+ async function sendTestWebhookPing() {
+ const webhookUrl = form.getValues("data");
+ if (!webhookUrl) return;
+ startTestTransition(async () => {
+ const isSuccessfull = await providerMetaData.sendTest?.(webhookUrl);
+ if (isSuccessfull) {
+ toast("test-success");
+ } else {
+ toast("test-error");
+ }
+ });
+ }
+
+ return (
+ <Form {...form}>
+ <form
+ onSubmit={form.handleSubmit(onSubmit)}
+ id="notification-form" // we use a form id to connect the submit button to the form (as we also have the form nested inside of `MonitorForm`)
+ className="flex flex-col gap-4"
+ >
+ <General form={form} plan={workspacePlan} />
+ <div className="flex gap-4 sm:justify-end">
+ {providerMetaData.sendTest && (
+ <Button
+ type="button"
+ variant="secondary"
+ className="w-full sm:w-auto"
+ size="lg"
+ disabled={!watchWebhookUrl || isTestPending}
+ onClick={sendTestWebhookPing}
+ >
+ {!isTestPending ? (
+ "Test Webhook"
+ ) : (
+ <LoadingAnimation variant="inverse" />
+ )}
+ </Button>
+ )}
+ <SaveButton
+ form="notification-form"
+ isPending={isPending}
+ isDirty={form.formState.isDirty}
+ onSubmit={form.handleSubmit(onSubmit)}
+ />
+ </div>
+ </form>
+ </Form>
+ );
+}
diff --git a/apps/web/src/components/forms/notification/general.tsx b/apps/web/src/components/forms/notification/general.tsx
new file mode 100644
index 000000000..4d55f0637
--- /dev/null
+++ b/apps/web/src/components/forms/notification/general.tsx
@@ -0,0 +1,145 @@
+"use client";
+
+import { useMemo } from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type {
+ InsertNotification,
+ WorkspacePlan,
+} from "@openstatus/db/src/schema";
+import {
+ notificationProvider,
+ notificationProviderSchema,
+} from "@openstatus/db/src/schema";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+ Select,
+ SelectContent,
+ SelectItem,
+ SelectTrigger,
+ SelectValue,
+} from "@openstatus/ui";
+
+import { toCapitalize } from "@/lib/utils";
+import { SectionHeader } from "../shared/section-header";
+import { getProviderMetaData } from "./config";
+
+interface Props {
+ form: UseFormReturn<InsertNotification>;
+ plan: WorkspacePlan;
+}
+
+export function General({ form, plan }: Props) {
+ const watchProvider = form.watch("provider");
+ const providerMetaData = useMemo(
+ () => getProviderMetaData(watchProvider),
+ [watchProvider],
+ );
+
+ return (
+ <div className="grid gap-4 sm:grid-cols-3 sm:gap-6">
+ <SectionHeader
+ title="Alert"
+ description="Select the notification channels you want to be informed."
+ />
+ <div className="grid gap-4 sm:col-span-2 sm:grid-cols-2">
+ <FormField
+ control={form.control}
+ name="provider"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-1 sm:self-baseline">
+ <FormLabel>Provider</FormLabel>
+ <Select
+ onValueChange={(value) =>
+ field.onChange(notificationProviderSchema.parse(value))
+ }
+ defaultValue={field.value}
+ >
+ <FormControl>
+ <SelectTrigger className="capitalize">
+ <SelectValue placeholder="Select Provider" />
+ </SelectTrigger>
+ </FormControl>
+ <SelectContent>
+ {notificationProvider.map((provider) => {
+ const isIncluded =
+ getProviderMetaData(provider).plans?.includes(plan);
+ return (
+ <SelectItem
+ key={provider}
+ value={provider}
+ className="capitalize"
+ disabled={!isIncluded}
+ >
+ {provider}
+ </SelectItem>
+ );
+ })}
+ </SelectContent>
+ </Select>
+ <FormDescription>
+ What channel/provider to send a notification.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-1 sm:self-baseline">
+ <FormLabel>Name</FormLabel>
+ <FormControl>
+ <Input placeholder="Dev Team" {...field} />
+ </FormControl>
+ <FormDescription>Define a name for the channel.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ {watchProvider && (
+ <FormField
+ control={form.control}
+ name="data"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-full">
+ {/* make the first letter capital */}
+ <div className="flex items-center justify-between">
+ <FormLabel>{toCapitalize(watchProvider)}</FormLabel>
+ </div>
+ <FormControl>
+ <Input
+ type={providerMetaData.dataType}
+ placeholder={providerMetaData.placeholder}
+ {...field}
+ disabled={!providerMetaData.plans?.includes(plan)}
+ />
+ </FormControl>
+ <FormDescription className="flex items-center justify-between">
+ The data required.
+ {providerMetaData.setupDocLink && (
+ <a
+ href={providerMetaData.setupDocLink}
+ target="_blank"
+ className="underline hover:no-underline"
+ >
+ How to setup your {toCapitalize(watchProvider)} webhook
+ </a>
+ )}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ )}
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/monitor/checkbox-label.tsx b/apps/web/src/components/forms/shared/checkbox-label.tsx
similarity index 69%
rename from apps/web/src/components/forms/monitor/checkbox-label.tsx
rename to apps/web/src/components/forms/shared/checkbox-label.tsx
index cf60d7f29..f601d51a2 100644
--- a/apps/web/src/components/forms/monitor/checkbox-label.tsx
+++ b/apps/web/src/components/forms/shared/checkbox-label.tsx
@@ -2,11 +2,14 @@ import { CheckCircle2 } from "lucide-react";
import { Checkbox, Label } from "@openstatus/ui";
+import { cn } from "@/lib/utils";
+
interface Props {
id: string;
children: React.ReactNode;
checked?: boolean;
onCheckedChange(checked: boolean): void;
+ className?: string;
}
export function CheckboxLabel({
@@ -14,6 +17,7 @@ export function CheckboxLabel({
children,
checked,
onCheckedChange,
+ className,
}: Props) {
return (
<div className="relative h-full">
@@ -25,7 +29,10 @@ export function CheckboxLabel({
/>
<Label
htmlFor={id}
- className="border-muted bg-popover hover:bg-accent hover:text-accent-foreground peer-data-[state=checked]:border-primary [&:has([data-state=checked])]:border-primary flex h-full items-center gap-1 rounded-md border-2 p-4 pr-10"
+ className={cn(
+ "border-border bg-popover hover:bg-accent hover:text-accent-foreground peer-data-[state=checked]:border-primary [&:has([data-state=checked])]:border-primary flex h-full items-center gap-1 rounded-md border p-4 pr-10",
+ className,
+ )}
>
{children}
</Label>
diff --git a/apps/web/src/components/forms/shared/save-button.tsx b/apps/web/src/components/forms/shared/save-button.tsx
new file mode 100644
index 000000000..2168a97b2
--- /dev/null
+++ b/apps/web/src/components/forms/shared/save-button.tsx
@@ -0,0 +1,62 @@
+import React from "react";
+
+import { Button } from "@openstatus/ui";
+
+import { Kbd } from "../../kbd";
+import { LoadingAnimation } from "../../loading-animation";
+
+interface Props {
+ onSubmit?: () => void;
+ isPending?: boolean;
+ isDirty?: boolean;
+ form?: string;
+}
+
+export function SaveButton({ isPending, isDirty, onSubmit, form }: Props) {
+ React.useEffect(() => {
+ const callback = (event: KeyboardEvent) => {
+ // event.metaKey - pressed Command key on Macs
+ // event.ctrlKey - pressed Control key on Linux or Windows
+ if ((event.metaKey || event.ctrlKey) && event.key === "s") {
+ event.preventDefault();
+ onSubmit?.();
+ }
+ };
+ document.addEventListener("keydown", callback);
+ return () => {
+ document.removeEventListener("keydown", callback);
+ };
+ // no need to listen to `onSubmit` changes
+ }, [onSubmit]);
+
+ return (
+ <div className="grid gap-3 sm:justify-end">
+ <div className="flex flex-col gap-6 sm:col-span-full sm:flex-row sm:justify-end">
+ <Button
+ className="w-full sm:w-auto"
+ size="lg"
+ type="submit"
+ disabled={isPending}
+ form={form}
+ >
+ {!isPending ? (
+ <span className="flex gap-2">
+ Confirm
+ <Kbd>
+ <span>⌘</span>
+ <span>S</span>
+ </Kbd>
+ </span>
+ ) : (
+ <LoadingAnimation />
+ )}
+ </Button>
+ </div>
+ {isDirty ? (
+ <p className="text-muted-foreground text-xs">
+ You have unsaved changes
+ </p>
+ ) : null}
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/shared/section-header.tsx b/apps/web/src/components/forms/shared/section-header.tsx
new file mode 100644
index 000000000..34505347a
--- /dev/null
+++ b/apps/web/src/components/forms/shared/section-header.tsx
@@ -0,0 +1,18 @@
+import { cn } from "@/lib/utils";
+
+export function SectionHeader({
+ title,
+ description,
+ className,
+}: {
+ title: string;
+ description: string;
+ className?: string;
+}) {
+ return (
+ <div className={cn("flex max-w-2xl flex-col gap-1", className)}>
+ <h4 className="text-foreground font-medium">{title}</h4>
+ <p className="text-muted-foreground text-sm">{description}</p>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/status-page/form.tsx b/apps/web/src/components/forms/status-page/form.tsx
new file mode 100644
index 000000000..912f0dc19
--- /dev/null
+++ b/apps/web/src/components/forms/status-page/form.tsx
@@ -0,0 +1,197 @@
+"use client";
+
+import * as React from "react";
+import { useCallback, useEffect, useTransition } from "react";
+import { usePathname, useRouter } from "next/navigation";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useForm } from "react-hook-form";
+
+import { insertPageSchema } from "@openstatus/db/src/schema";
+import type { InsertPage, Monitor } from "@openstatus/db/src/schema";
+import { Badge, Button, Form, useToast } from "@openstatus/ui";
+
+import {
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+} from "@/components/dashboard/tabs";
+import { useDebounce } from "@/hooks/use-debounce";
+import { useToastAction } from "@/hooks/use-toast-action";
+import useUpdateSearchParams from "@/hooks/use-update-search-params";
+import { slugify } from "@/lib/utils";
+import { api } from "@/trpc/client";
+import { SaveButton } from "../shared/save-button";
+import { General } from "./general";
+import { SectionAdvanced } from "./section-advanced";
+import { SectionMonitor } from "./section-monitor";
+
+interface Props {
+ defaultSection?: string;
+ defaultValues?: InsertPage;
+ allMonitors?: Monitor[];
+ /**
+ * gives the possibility to check all the monitors
+ */
+ checkAllMonitors?: boolean;
+ /**
+ * on submit, allows to push a url
+ */
+ nextUrl?: string;
+}
+
+export function StatusPageForm({
+ defaultSection,
+ defaultValues,
+ allMonitors,
+ checkAllMonitors,
+ nextUrl,
+}: Props) {
+ const form = useForm<InsertPage>({
+ resolver: zodResolver(insertPageSchema),
+ defaultValues: {
+ title: defaultValues?.title || "", // FIXME: you can save a page without title, causing unexpected slug behavior
+ slug: defaultValues?.slug || "",
+ description: defaultValues?.description || "",
+ workspaceId: defaultValues?.workspaceId || 0,
+ id: defaultValues?.id || 0,
+ monitors:
+ checkAllMonitors && allMonitors
+ ? allMonitors.map(({ id }) => id)
+ : defaultValues?.monitors ?? [],
+ customDomain: defaultValues?.customDomain || "",
+ icon: defaultValues?.icon || "",
+ },
+ });
+ const pathname = usePathname();
+ const router = useRouter();
+ const [isPending, startTransition] = useTransition();
+ const watchSlug = form.watch("slug");
+ const watchTitle = form.watch("title");
+ const debouncedSlug = useDebounce(watchSlug, 1000); // using debounce to not exhaust the server
+ const { toast } = useToastAction();
+ const { toast: defaultToast } = useToast();
+ const updateSearchParams = useUpdateSearchParams();
+
+ const checkUniqueSlug = useCallback(async () => {
+ const isUnique = await api.page.getSlugUniqueness.query({
+ slug: debouncedSlug,
+ });
+ return (
+ isUnique ||
+ debouncedSlug.toLowerCase() === defaultValues?.slug.toLowerCase()
+ );
+ }, [debouncedSlug, defaultValues?.slug]);
+
+ useEffect(() => {
+ async function watchSlugChanges() {
+ const isUnique = await checkUniqueSlug();
+ if (!isUnique) {
+ form.setError("slug", {
+ message: "Already taken. Please select another slug.",
+ });
+ } else {
+ form.clearErrors("slug");
+ }
+ }
+
+ void watchSlugChanges();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [checkUniqueSlug]);
+
+ useEffect(() => {
+ if (!defaultValues?.title) {
+ form.setValue("slug", slugify(watchTitle));
+ }
+ }, [watchTitle, form, defaultValues?.title]);
+
+ const onSubmit = async ({ ...props }: InsertPage) => {
+ startTransition(async () => {
+ try {
+ if (defaultValues) {
+ await api.page.update.mutate(props);
+ } else {
+ const page = await api.page.create.mutate(props);
+ const id = page?.id || null;
+ router.replace(`?${updateSearchParams({ id })}`); // to stay on same page and enable 'Advanced' tab
+ }
+
+ defaultToast({
+ title: "Saved successfully.",
+ description: "Your status page is ready to go.",
+ action: (
+ <Button variant="outline">
+ <a href={`https://${props.slug}.openstatus.dev`} target="_blank">
+ Visit
+ </a>
+ </Button>
+ ),
+ });
+ if (nextUrl) {
+ router.push(nextUrl);
+ }
+ router.refresh();
+ } catch {
+ toast("error");
+ }
+ });
+ };
+
+ function onValueChange(value: string) {
+ // REMINDER: we are not merging the searchParams here
+ // we are just setting the section to allow refreshing the page
+ const params = new URLSearchParams();
+ params.set("section", value);
+ router.push(`${pathname}?${params.toString()}`);
+ }
+
+ return (
+ <Form {...form}>
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ const isUnique = await checkUniqueSlug();
+ if (!isUnique) {
+ // the user will already have the "error" message - we include a toast as well
+ toast("unique-slug");
+ } else {
+ if (onSubmit) {
+ void form.handleSubmit(onSubmit)(e);
+ }
+ }
+ }}
+ className="grid w-full gap-6"
+ >
+ <General form={form} />
+ <Tabs
+ defaultValue={defaultSection}
+ className="w-full"
+ onValueChange={onValueChange}
+ >
+ <TabsList>
+ <TabsTrigger value="monitors">
+ Monitors{" "}
+ {defaultValues?.monitors?.length ? (
+ <Badge variant="secondary" className="ml-1">
+ {defaultValues.monitors.length}
+ </Badge>
+ ) : null}
+ </TabsTrigger>
+ <TabsTrigger value="advanced">Advanced</TabsTrigger>
+ </TabsList>
+ <TabsContent value="monitors">
+ <SectionMonitor form={form} monitors={allMonitors} />
+ </TabsContent>
+ <TabsContent value="advanced">
+ <SectionAdvanced form={form} />
+ </TabsContent>
+ </Tabs>
+ <SaveButton
+ isPending={isPending}
+ isDirty={form.formState.isDirty}
+ onSubmit={form.handleSubmit(onSubmit)}
+ />
+ </form>
+ </Form>
+ );
+}
diff --git a/apps/web/src/components/forms/status-page/general.tsx b/apps/web/src/components/forms/status-page/general.tsx
new file mode 100644
index 000000000..931525961
--- /dev/null
+++ b/apps/web/src/components/forms/status-page/general.tsx
@@ -0,0 +1,69 @@
+"use client";
+
+import * as React from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertPage } from "@openstatus/db/src/schema";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+ InputWithAddons,
+} from "@openstatus/ui";
+
+import { SectionHeader } from "../shared/section-header";
+
+interface Props {
+ form: UseFormReturn<InsertPage>;
+}
+
+export function General({ form }: Props) {
+ return (
+ <div className="grid gap-4 sm:grid-cols-3 sm:gap-6">
+ <SectionHeader
+ title="Basic information"
+ description="The public status page to update your users on service uptime."
+ />
+ <div className="grid gap-4 sm:col-span-2">
+ <FormField
+ control={form.control}
+ name="title"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Title</FormLabel>
+ <FormControl>
+ <Input placeholder="Documenso Status" {...field} />
+ </FormControl>
+ <FormDescription>The title of your page.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="slug"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Slug</FormLabel>
+ <FormControl>
+ <InputWithAddons
+ placeholder="documenso"
+ trailing={".openstatus.dev"}
+ {...field}
+ />
+ </FormControl>
+ <FormDescription>
+ The subdomain for your status page. At least 3 chars.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/status-page/section-advanced.tsx b/apps/web/src/components/forms/status-page/section-advanced.tsx
new file mode 100644
index 000000000..db8f06233
--- /dev/null
+++ b/apps/web/src/components/forms/status-page/section-advanced.tsx
@@ -0,0 +1,115 @@
+"use client";
+
+import * as React from "react";
+import { useRef } from "react";
+import Image from "next/image";
+import type { PutBlobResult } from "@vercel/blob";
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertPage } from "@openstatus/db/src/schema";
+import {
+ Button,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+} from "@openstatus/ui";
+
+import { SectionHeader } from "../shared/section-header";
+
+interface Props {
+ form: UseFormReturn<InsertPage>;
+}
+
+export function SectionAdvanced({ form }: Props) {
+ const inputFileRef = useRef<HTMLInputElement>(null);
+
+ const handleChange = async (file: FileList | null) => {
+ if (!file || file.length === 0) {
+ return;
+ }
+
+ const response = await fetch(`/api/upload?filename=${file[0].name}`, {
+ method: "POST",
+ body: file[0],
+ });
+
+ const newblob = (await response.json()) as PutBlobResult;
+ form.setValue("icon", newblob.url);
+ };
+
+ return (
+ <div className="grid w-full gap-4 md:grid-cols-3">
+ <SectionHeader
+ title="Advanced Settings"
+ description="Provide informations about what your status page is for. A favicon can be uploaded to customize your status page. It will be used as an icon on the header as well."
+ className="md:col-span-full"
+ />
+ <FormField
+ control={form.control}
+ name="description"
+ render={({ field }) => (
+ <FormItem className="md:col-span-full">
+ <FormLabel>Description</FormLabel>
+ <FormControl>
+ <Input
+ placeholder="Stay informed about our api and website health."
+ {...field}
+ />
+ </FormControl>
+ <FormDescription>
+ Provide your users informations about it.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="icon"
+ render={({ field }) => (
+ <FormItem className="col-span-full md:col-span-1">
+ <FormLabel>Favicon</FormLabel>
+ <FormControl>
+ <>
+ {!field.value && (
+ <Input
+ type="file"
+ accept="image/x-icon,image/png"
+ ref={inputFileRef}
+ onChange={(e) => handleChange(e.target.files)}
+ />
+ )}
+ {field.value && (
+ <div className="flex items-center">
+ <div className="border-border h-10 w-10 rounded-sm border p-1">
+ <Image
+ src={field.value}
+ width={64}
+ height={64}
+ alt="Favicon"
+ />
+ </div>
+ <Button
+ variant="link"
+ onClick={() => {
+ form.setValue("icon", "");
+ }}
+ >
+ Remove
+ </Button>
+ </div>
+ )}
+ </>
+ </FormControl>
+ <FormDescription>Your status page favicon</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/status-page/section-monitor.tsx b/apps/web/src/components/forms/status-page/section-monitor.tsx
new file mode 100644
index 000000000..b6243d246
--- /dev/null
+++ b/apps/web/src/components/forms/status-page/section-monitor.tsx
@@ -0,0 +1,83 @@
+"use client";
+
+import * as React from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertPage, Monitor } from "@openstatus/db/src/schema";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormMessage,
+} from "@openstatus/ui";
+
+import { CheckboxLabel } from "../shared/checkbox-label";
+import { SectionHeader } from "../shared/section-header";
+
+interface Props {
+ monitors?: Monitor[];
+ form: UseFormReturn<InsertPage>;
+}
+
+export function SectionMonitor({ monitors, form }: Props) {
+ return (
+ <div className="grid w-full gap-4">
+ <SectionHeader
+ title="Connected Monitors"
+ description="Select the monitors you want to display on your status page. Inactve monitors will not be shown."
+ />
+ <FormField
+ control={form.control}
+ name="monitors"
+ render={() => (
+ <FormItem>
+ <div className="grid grid-cols-1 grid-rows-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
+ {monitors?.map((item) => (
+ <FormField
+ key={item.id}
+ control={form.control}
+ name="monitors"
+ render={({ field }) => {
+ return (
+ <FormItem key={item.id} className="h-full w-full">
+ <FormControl className="w-full">
+ <CheckboxLabel
+ id={String(item.id)}
+ checked={field.value?.includes(item.id)}
+ onCheckedChange={(checked) => {
+ return checked
+ ? field.onChange([
+ ...(field.value || []),
+ item.id,
+ ])
+ : field.onChange(
+ field.value?.filter(
+ (value) => value !== item.id,
+ ),
+ );
+ }}
+ className="flex w-full flex-col items-start gap-2"
+ >
+ <span>{item.name}</span>
+ <span className="text-muted-foreground w-full truncate font-normal">
+ {item.url}
+ </span>
+ </CheckboxLabel>
+ </FormControl>
+ </FormItem>
+ );
+ }}
+ />
+ ))}
+ </div>
+ {!monitors || monitors.length === 0 ? (
+ <FormDescription>Missing monitors.</FormDescription>
+ ) : null}
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/status-report/form.tsx b/apps/web/src/components/forms/status-report/form.tsx
new file mode 100644
index 000000000..828b0be3d
--- /dev/null
+++ b/apps/web/src/components/forms/status-report/form.tsx
@@ -0,0 +1,148 @@
+"use client";
+
+import * as React from "react";
+import { usePathname, useRouter } from "next/navigation";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useForm } from "react-hook-form";
+
+import { insertStatusReportSchema } from "@openstatus/db/src/schema";
+import type {
+ InsertStatusReport,
+ Monitor,
+ Page,
+} from "@openstatus/db/src/schema";
+import { Form } from "@openstatus/ui";
+
+import {
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+} from "@/components/dashboard/tabs";
+import { useToastAction } from "@/hooks/use-toast-action";
+import { api } from "@/trpc/client";
+import { SaveButton } from "../shared/save-button";
+import { General } from "./general";
+import { SectionConnect } from "./section-connect";
+import { SectionUpdateMessage } from "./section-update-message";
+
+interface Props {
+ defaultSection?: string;
+ defaultValues?: InsertStatusReport;
+ monitors?: Monitor[];
+ pages?: Page[];
+ nextUrl?: string;
+}
+
+export function StatusReportForm({
+ defaultSection,
+ defaultValues,
+ monitors,
+ pages,
+ nextUrl,
+}: Props) {
+ const form = useForm<InsertStatusReport>({
+ resolver: zodResolver(insertStatusReportSchema),
+ defaultValues: defaultValues
+ ? {
+ id: defaultValues.id,
+ title: defaultValues.title,
+ status: defaultValues.status,
+ monitors: defaultValues.monitors,
+ pages: defaultValues.pages,
+ // include update on creation
+ message: defaultValues.message,
+ date: defaultValues.date,
+ }
+ : {
+ status: "investigating",
+ date: new Date(),
+ },
+ });
+ const pathname = usePathname();
+ const router = useRouter();
+ const [isPending, startTransition] = React.useTransition();
+ const { toast } = useToastAction();
+
+ const onSubmit = ({ ...props }: InsertStatusReport) => {
+ startTransition(async () => {
+ try {
+ if (defaultValues) {
+ await api.statusReport.updateStatusReport.mutate({ ...props });
+ } else {
+ const { message, date, status, ...rest } = props;
+ const statusReport = await api.statusReport.createStatusReport.mutate(
+ {
+ status,
+ message,
+ ...rest,
+ },
+ );
+ // include update on creation
+ if (statusReport?.id) {
+ await api.statusReport.createStatusReportUpdate.mutate({
+ message,
+ date,
+ status,
+ statusReportId: statusReport.id,
+ });
+ }
+ }
+ if (nextUrl) {
+ router.push(nextUrl);
+ }
+ router.refresh();
+ toast("saved");
+ } catch {
+ toast("error");
+ }
+ });
+ };
+
+ function onValueChange(value: string) {
+ // REMINDER: we are not merging the searchParams here
+ // we are just setting the section to allow refreshing the page
+ const params = new URLSearchParams();
+ params.set("section", value);
+ router.push(`${pathname}?${params.toString()}`);
+ }
+
+ return (
+ <Form {...form}>
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ form.handleSubmit(onSubmit)(e);
+ }}
+ className="grid w-full gap-6"
+ >
+ <General form={form} />
+ <Tabs
+ defaultValue={defaultSection}
+ className="w-full"
+ onValueChange={onValueChange}
+ >
+ <TabsList>
+ {!defaultValues ? (
+ <TabsTrigger value="update-message">Message</TabsTrigger>
+ ) : null}
+ <TabsTrigger value="connect">Connect</TabsTrigger>
+ </TabsList>
+ {!defaultValues ? (
+ <TabsContent value="update-message">
+ <SectionUpdateMessage form={form} />
+ </TabsContent>
+ ) : null}
+ <TabsContent value="connect">
+ <SectionConnect form={form} monitors={monitors} pages={pages} />
+ </TabsContent>
+ </Tabs>
+ <SaveButton
+ isPending={isPending}
+ isDirty={form.formState.isDirty}
+ onSubmit={form.handleSubmit(onSubmit)}
+ />
+ </form>
+ </Form>
+ );
+}
diff --git a/apps/web/src/components/forms/status-report/general.tsx b/apps/web/src/components/forms/status-report/general.tsx
new file mode 100644
index 000000000..5ddba863e
--- /dev/null
+++ b/apps/web/src/components/forms/status-report/general.tsx
@@ -0,0 +1,92 @@
+"use client";
+
+import * as React from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import {
+ statusReportStatus,
+ statusReportStatusSchema,
+} from "@openstatus/db/src/schema";
+import type { InsertStatusReport } from "@openstatus/db/src/schema";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Input,
+ RadioGroup,
+ RadioGroupItem,
+} from "@openstatus/ui";
+
+import { Icons } from "@/components/icons";
+import { statusDict } from "@/data/incidents-dictionary";
+import { SectionHeader } from "../shared/section-header";
+
+interface Props {
+ form: UseFormReturn<InsertStatusReport>;
+}
+
+export function General({ form }: Props) {
+ return (
+ <div className="grid gap-4 sm:grid-cols-3 sm:gap-6">
+ <SectionHeader
+ title="Inform"
+ description="Keep your users informed about what just happened."
+ />
+ <div className="grid gap-4 sm:col-span-2">
+ <FormField
+ control={form.control}
+ name="title"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Title</FormLabel>
+ <FormControl>
+ <Input placeholder="Downtime..." {...field} />
+ </FormControl>
+ <FormDescription>The title of your outage.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="status"
+ render={({ field }) => (
+ <FormItem className="space-y-1">
+ <FormLabel>Status</FormLabel>
+ <FormDescription>Select the current status.</FormDescription>
+ <FormMessage />
+ <RadioGroup
+ onValueChange={(value) =>
+ field.onChange(statusReportStatusSchema.parse(value))
+ } // value is a string
+ defaultValue={field.value}
+ className="grid grid-cols-2 gap-4 sm:grid-cols-4"
+ >
+ {statusReportStatus.map((status) => {
+ const { value, label, icon } = statusDict[status];
+ const Icon = Icons[icon];
+ return (
+ <FormItem key={value}>
+ <FormLabel className="[&:has([data-state=checked])>div]:border-primary [&:has([data-state=checked])>div]:text-foreground">
+ <FormControl>
+ <RadioGroupItem value={value} className="sr-only" />
+ </FormControl>
+ <div className="border-border text-muted-foreground flex w-full items-center justify-center rounded-lg border px-3 py-2 text-center text-sm">
+ <Icon className="mr-2 h-4 w-4 shrink-0" />
+ <span className="truncate">{label}</span>
+ </div>
+ </FormLabel>
+ </FormItem>
+ );
+ })}
+ </RadioGroup>
+ </FormItem>
+ )}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/status-report/section-connect.tsx b/apps/web/src/components/forms/status-report/section-connect.tsx
new file mode 100644
index 000000000..535a8db95
--- /dev/null
+++ b/apps/web/src/components/forms/status-report/section-connect.tsx
@@ -0,0 +1,143 @@
+"use client";
+
+import * as React from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type {
+ InsertStatusReport,
+ Monitor,
+ Page,
+} from "@openstatus/db/src/schema";
+import {
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@openstatus/ui";
+
+import { CheckboxLabel } from "../shared/checkbox-label";
+
+interface Props {
+ form: UseFormReturn<InsertStatusReport>;
+ pages?: Page[];
+ monitors?: Monitor[];
+}
+
+export function SectionConnect({ form, pages, monitors }: Props) {
+ return (
+ <div className="grid w-full gap-4">
+ <div className="flex flex-col gap-3">
+ <FormField
+ control={form.control}
+ name="pages"
+ render={() => (
+ <FormItem>
+ <div className="mb-4">
+ <FormLabel>Pages</FormLabel>
+ <FormDescription>
+ Select the pages that you want to refer the incident to.
+ </FormDescription>
+ </div>
+ <div className="grid grid-cols-1 grid-rows-1 gap-6 sm:grid-cols-2 md:grid-cols-3">
+ {pages?.map((item) => (
+ <FormField
+ key={item.id}
+ control={form.control}
+ name="pages"
+ render={({ field }) => {
+ return (
+ <FormItem key={item.id} className="h-full w-full">
+ <FormControl className="w-full">
+ <CheckboxLabel
+ id={String(item.id)}
+ checked={field.value?.includes(item.id)}
+ onCheckedChange={(checked) => {
+ return checked
+ ? field.onChange([
+ ...(field.value || []),
+ item.id,
+ ])
+ : field.onChange(
+ field.value?.filter(
+ (value) => value !== item.id,
+ ),
+ );
+ }}
+ >
+ {item.title}
+ </CheckboxLabel>
+ </FormControl>
+ </FormItem>
+ );
+ }}
+ />
+ ))}
+ </div>
+ {!pages || pages.length === 0 ? (
+ <FormDescription>Missing status pages.</FormDescription>
+ ) : null}
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="monitors"
+ render={() => (
+ <FormItem>
+ <div className="mb-4">
+ <FormLabel>Monitors</FormLabel>
+ {/* TODO: second phrase can be set inside of a (?) tooltip */}
+ <FormDescription>
+ Select the monitors that you want to refer the incident to. It
+ will be displayed on the status page they are attached to.
+ </FormDescription>
+ </div>
+ <div className="grid grid-cols-1 grid-rows-1 gap-6 sm:grid-cols-2 md:grid-cols-3">
+ {monitors?.map((item) => (
+ <FormField
+ key={item.id}
+ control={form.control}
+ name="monitors"
+ render={({ field }) => {
+ return (
+ <FormItem key={item.id} className="h-full w-full">
+ <FormControl className="w-full">
+ <CheckboxLabel
+ id={String(item.id)}
+ checked={field.value?.includes(item.id)}
+ onCheckedChange={(checked) => {
+ return checked
+ ? field.onChange([
+ ...(field.value || []),
+ item.id,
+ ])
+ : field.onChange(
+ field.value?.filter(
+ (value) => value !== item.id,
+ ),
+ );
+ }}
+ >
+ {item.name}
+ </CheckboxLabel>
+ </FormControl>
+ </FormItem>
+ );
+ }}
+ />
+ ))}
+ </div>
+ {!monitors || monitors.length === 0 ? (
+ <FormDescription>Missing monitors.</FormDescription>
+ ) : null}
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/status-report/section-update-message.tsx b/apps/web/src/components/forms/status-report/section-update-message.tsx
new file mode 100644
index 000000000..7ff74b0b0
--- /dev/null
+++ b/apps/web/src/components/forms/status-report/section-update-message.tsx
@@ -0,0 +1,89 @@
+"use client";
+
+import * as React from "react";
+import type { UseFormReturn } from "react-hook-form";
+
+import type { InsertStatusReport } from "@openstatus/db/src/schema";
+import {
+ DateTimePickerPopover,
+ FormControl,
+ FormDescription,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+ Tabs,
+ TabsContent,
+ TabsList,
+ TabsTrigger,
+ Textarea,
+} from "@openstatus/ui";
+
+import { Preview } from "@/components/content/preview";
+import { SectionHeader } from "../shared/section-header";
+
+interface Props {
+ form: UseFormReturn<InsertStatusReport>;
+}
+
+export function SectionUpdateMessage({ form }: Props) {
+ return (
+ <div className="grid w-full gap-4">
+ <SectionHeader
+ title="Status Update Message"
+ description="Describe the current status of the incident."
+ />
+ <FormField
+ control={form.control}
+ name="message"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-4">
+ <FormLabel>Message</FormLabel>
+ <Tabs defaultValue="write">
+ <TabsList>
+ <TabsTrigger value="write">Write</TabsTrigger>
+ <TabsTrigger value="preview">Preview</TabsTrigger>
+ </TabsList>
+ <TabsContent value="write">
+ <FormControl>
+ <Textarea
+ placeholder="We are encountering..."
+ className="h-auto w-full resize-none"
+ rows={9}
+ {...field}
+ />
+ </FormControl>
+ </TabsContent>
+ <TabsContent value="preview">
+ <Preview md={form.getValues("message")} />
+ </TabsContent>
+ </Tabs>
+ <FormDescription>
+ Tell your user what&apos;s happening. Supports markdown.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="date"
+ render={({ field }) => (
+ <FormItem className="flex flex-col sm:col-span-full">
+ <FormLabel>Date</FormLabel>
+ <DateTimePickerPopover
+ date={field.value ? new Date(field.value) : new Date()}
+ setDate={(date) => {
+ field.onChange(date);
+ }}
+ />
+ <FormDescription>
+ The date and time when the incident took place.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ );
+}