Skip to content

Open-source status page, incident response and uptime monitoring

Feat/user workflow (#165)

Maximilian Kaske221c90da65a7
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx
index 9f8cd737d..8d9b61ebd 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx
@@ -8,7 +8,6 @@ import type * as z from "zod";
import type { insertMonitorSchema } from "@openstatus/db/src/schema";
-import { MonitorForm } from "@/components/forms/montitor-form";
import { LoadingAnimation } from "@/components/loading-animation";
import {
AlertDialog,
@@ -22,47 +21,20 @@ import {
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
-import { useToast } from "@/components/ui/use-toast";
import { api } from "@/trpc/client";
type Schema = z.infer<typeof insertMonitorSchema>;
export function ActionButton(props: Schema & { workspaceSlug: string }) {
const router = useRouter();
- const [dialogOpen, setDialogOpen] = React.useState(false);
const [alertOpen, setAlertOpen] = React.useState(false);
const [isPending, startTransition] = React.useTransition();
- const { toast } = useToast();
-
- async function onUpdate(values: Schema) {
- startTransition(async () => {
- try {
- await api.monitor.updateMonitor.mutate({ ...values });
- router.refresh();
- setDialogOpen(false);
- } catch {
- toast({
- title: "Something went wrong.",
- description: "If you are in the limits, please try again.",
- });
- }
- });
- }
async function onDelete() {
startTransition(async () => {
@@ -74,85 +46,53 @@ export function ActionButton(props: Schema & { workspaceSlug: string }) {
}
return (
- <Dialog open={dialogOpen} onOpenChange={(value) => setDialogOpen(value)}>
- <AlertDialog
- open={alertOpen}
- onOpenChange={(value) => setAlertOpen(value)}
- >
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- variant="ghost"
- className="data-[state=open]:bg-accent absolute right-6 top-6 h-8 w-8 p-0"
- >
- <span className="sr-only">Open menu</span>
- <MoreVertical className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DialogTrigger asChild>
- <DropdownMenuItem>Edit</DropdownMenuItem>
- </DialogTrigger>
- <Link
- href={`/app/${props.workspaceSlug}/monitors/${props.id}/data`}
- >
- <DropdownMenuItem>View data</DropdownMenuItem>
- </Link>
- <AlertDialogTrigger asChild>
- <DropdownMenuItem className="text-destructive focus:bg-destructive focus:text-background">
- Delete
- </DropdownMenuItem>
- </AlertDialogTrigger>
- </DropdownMenuContent>
- </DropdownMenu>
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
- <AlertDialogDescription>
- This action cannot be undone. This will permanently delete the
- monitor.
- </AlertDialogDescription>
- </AlertDialogHeader>
- <AlertDialogFooter>
- <AlertDialogCancel>Cancel</AlertDialogCancel>
- <AlertDialogAction
- onClick={(e) => {
- e.preventDefault();
- onDelete();
- }}
- disabled={isPending}
- className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
- >
- {!isPending ? "Delete" : <LoadingAnimation />}
- </AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
- <DialogContent className="flex max-h-screen flex-col">
- <DialogHeader>
- <DialogTitle>Update Monitor</DialogTitle>
- <DialogDescription>Change your settings.</DialogDescription>
- </DialogHeader>
- <div className="-mx-1 flex-1 overflow-y-auto px-1">
- <MonitorForm
- id="monitor-update"
- onSubmit={onUpdate}
- defaultValues={props}
- />
- </div>
- <DialogFooter>
+ <AlertDialog open={alertOpen} onOpenChange={(value) => setAlertOpen(value)}>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
<Button
- type="submit"
- form="monitor-update"
- disabled={isPending}
- onSubmit={(e) => {
+ variant="ghost"
+ className="data-[state=open]:bg-accent absolute right-6 top-6 h-8 w-8 p-0"
+ >
+ <span className="sr-only">Open menu</span>
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <Link href={`./monitors/edit?id=${props.id}`}>
+ <DropdownMenuItem>Edit</DropdownMenuItem>
+ </Link>
+ <Link href={`/app/${props.workspaceSlug}/monitors/${props.id}/data`}>
+ <DropdownMenuItem>View data</DropdownMenuItem>
+ </Link>
+ <AlertDialogTrigger asChild>
+ <DropdownMenuItem className="text-destructive focus:bg-destructive focus:text-background">
+ Delete
+ </DropdownMenuItem>
+ </AlertDialogTrigger>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
+ <AlertDialogDescription>
+ This action cannot be undone. This will permanently delete the
+ monitor.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ onClick={(e) => {
e.preventDefault();
+ onDelete();
}}
+ disabled={isPending}
+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
- {!isPending ? "Confirm" : <LoadingAnimation />}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ {!isPending ? "Delete" : <LoadingAnimation />}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
);
}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/create-form.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/create-form.tsx
deleted file mode 100644
index 2d681cb3a..000000000
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/create-form.tsx
+++ /dev/null
@@ -1,76 +0,0 @@
-"use client";
-
-import * as React from "react";
-import { useRouter } from "next/navigation";
-import type * as z from "zod";
-
-import type { insertMonitorSchema } from "@openstatus/db/src/schema";
-
-import { MonitorForm } from "@/components/forms/montitor-form";
-import { LoadingAnimation } from "@/components/loading-animation";
-import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
-import { useToast } from "@/components/ui/use-toast";
-import { api } from "@/trpc/client";
-
-type MonitorSchema = z.infer<typeof insertMonitorSchema>;
-
-interface Props {
- workspaceSlug: string;
- disabled?: boolean;
-}
-
-export function CreateForm({ workspaceSlug, disabled }: Props) {
- const router = useRouter();
- const [open, setOpen] = React.useState(false);
- const [isPending, startTransition] = React.useTransition();
- const { toast } = useToast();
-
- async function onCreate(values: MonitorSchema) {
- startTransition(async () => {
- try {
- await api.monitor.createMonitor.mutate({
- data: values,
- workspaceSlug,
- });
- router.refresh();
- setOpen(false);
- } catch {
- toast({
- title: "Something went wrong.",
- description: "If you are in the limits, please try again.",
- });
- }
- });
- }
-
- return (
- <Dialog open={open} onOpenChange={(value) => setOpen(value)}>
- <DialogTrigger asChild>
- <Button disabled={disabled}>Create</Button>
- </DialogTrigger>
- <DialogContent className="flex max-h-screen flex-col">
- <DialogHeader>
- <DialogTitle>Create Monitor</DialogTitle>
- <DialogDescription>Choose the settings.</DialogDescription>
- </DialogHeader>
- <div className="-mx-1 flex-1 overflow-y-auto px-1">
- <MonitorForm id="monitor-create" onSubmit={onCreate} />
- </div>
- <DialogFooter>
- <Button type="submit" form="monitor-create" disabled={isPending}>
- {!isPending ? "Confirm" : <LoadingAnimation />}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- );
-}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/empty-state.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/empty-state.tsx
index 189cf2a73..533aef4b0 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/empty-state.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/empty-state.tsx
@@ -1,13 +1,19 @@
+import Link from "next/link";
+
import { EmptyState as DefaultEmptyState } from "@/components/dashboard/empty-state";
-import { CreateForm } from "./create-form";
+import { Button } from "@/components/ui/button";
-export function EmptyState({ workspaceSlug }: { workspaceSlug: string }) {
+export function EmptyState() {
return (
<DefaultEmptyState
icon="activity"
title="No monitors"
description="Create your first monitor"
- action={<CreateForm {...{ workspaceSlug }} />}
+ action={
+ <Button asChild>
+ <Link href="./monitors/edit">Create</Link>
+ </Button>
+ }
/>
);
}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/loading.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/loading.tsx
new file mode 100644
index 000000000..b4dafe86f
--- /dev/null
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/loading.tsx
@@ -0,0 +1,18 @@
+import { Header } from "@/components/dashboard/header";
+import { SkeletonForm } from "@/components/forms/skeleton-form";
+import { Skeleton } from "@/components/ui/skeleton";
+
+export default function Loading() {
+ return (
+ <div className="grid gap-6 md:grid-cols-2 md:gap-8">
+ <div className="col-span-full flex w-full justify-between">
+ <Header.Skeleton>
+ <Skeleton className="h-9 w-20" />
+ </Header.Skeleton>
+ </div>
+ <div className="col-span-full">
+ <SkeletonForm />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/page.tsx
new file mode 100644
index 000000000..24322dcfc
--- /dev/null
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/page.tsx
@@ -0,0 +1,43 @@
+import { notFound } from "next/navigation";
+import * as z from "zod";
+
+import { Header } from "@/components/dashboard/header";
+import { MonitorForm } from "@/components/forms/montitor-form";
+import { api } from "@/trpc/server";
+
+/**
+ * allowed URL search params
+ */
+const searchParamsSchema = z.object({
+ id: z.coerce.number().optional(),
+});
+
+export default async function EditPage({
+ params,
+ searchParams,
+}: {
+ params: { workspaceSlug: string };
+ searchParams: { [key: string]: string | string[] | undefined };
+}) {
+ const search = searchParamsSchema.safeParse(searchParams);
+
+ if (!search.success) {
+ return notFound();
+ }
+
+ const { id } = search.data;
+
+ const monitor = id && (await api.monitor.getMonitorByID.query({ id }));
+
+ return (
+ <div className="grid gap-6 md:grid-cols-2 md:gap-8">
+ <Header title="Monitor" description="Upsert your monitor." />
+ <div className="col-span-full">
+ <MonitorForm
+ workspaceSlug={params.workspaceSlug}
+ defaultValues={monitor || undefined}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx
index 963d60c25..da687781e 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx
@@ -1,4 +1,5 @@
import * as React from "react";
+import Link from "next/link";
import { allPlans } from "@openstatus/plans";
@@ -6,10 +7,10 @@ import { Container } from "@/components/dashboard/container";
import { Header } from "@/components/dashboard/header";
import { Limit } from "@/components/dashboard/limit";
import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { api } from "@/trpc/server";
import { ActionButton } from "./_components/action-button";
-import { CreateForm } from "./_components/create-form";
import { EmptyState } from "./_components/empty-state";
const limit = allPlans.free.limits.monitors;
@@ -28,7 +29,9 @@ export default async function MonitorPage({
return (
<div className="grid gap-6 md:grid-cols-2 md:gap-8">
<Header title="Monitors" description="Overview of all your monitors.">
- <CreateForm workspaceSlug={params.workspaceSlug} disabled={isLimit} />
+ <Button asChild={!isLimit} disabled={isLimit}>
+ <Link href="./monitors/edit">Create </Link>
+ </Button>
</Header>
{Boolean(monitors?.length) ? (
monitors?.map((monitor, index) => (
@@ -70,7 +73,7 @@ export default async function MonitorPage({
</Container>
))
) : (
- <EmptyState workspaceSlug={params.workspaceSlug} />
+ <EmptyState />
)}
{isLimit ? <Limit /> : null}
</div>
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/action-button.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/action-button.tsx
index 5443ad4f0..d1cea281c 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/action-button.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/action-button.tsx
@@ -6,12 +6,8 @@ import { useRouter } from "next/navigation";
import { MoreVertical } from "lucide-react";
import type * as z from "zod";
-import type {
- allMonitorsSchema,
- insertPageSchemaWithMonitors,
-} from "@openstatus/db/src/schema";
+import type { insertPageSchemaWithMonitors } from "@openstatus/db/src/schema";
-import { StatusPageForm } from "@/components/forms/status-page-form";
import { LoadingAnimation } from "@/components/loading-animation";
import {
AlertDialog,
@@ -25,15 +21,6 @@ import {
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
import {
DropdownMenu,
DropdownMenuContent,
@@ -44,28 +31,15 @@ import { api } from "@/trpc/client";
type PageSchema = z.infer<typeof insertPageSchemaWithMonitors>;
-// allMonitors
interface ActionButtonProps {
page: PageSchema;
- allMonitors?: z.infer<typeof allMonitorsSchema>;
}
-export function ActionButton({ page, allMonitors }: ActionButtonProps) {
+export function ActionButton({ page }: ActionButtonProps) {
const router = useRouter();
- const [dialogOpen, setDialogOpen] = React.useState(false);
const [alertOpen, setAlertOpen] = React.useState(false);
const [isPending, startTransition] = React.useTransition();
- async function onUpdate({
- ...props
- }: z.infer<typeof insertPageSchemaWithMonitors>) {
- startTransition(async () => {
- await api.page.updatePage.mutate(props);
- router.refresh();
- setDialogOpen(false);
- });
- }
-
async function onDelete() {
startTransition(async () => {
if (!page.id) return;
@@ -76,94 +50,60 @@ export function ActionButton({ page, allMonitors }: ActionButtonProps) {
}
return (
- <Dialog open={dialogOpen} onOpenChange={(value) => setDialogOpen(value)}>
- <AlertDialog
- open={alertOpen}
- onOpenChange={(value) => setAlertOpen(value)}
- >
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- variant="ghost"
- className="data-[state=open]:bg-accent absolute right-6 top-6 h-8 w-8 p-0"
- >
- <span className="sr-only">Open menu</span>
- <MoreVertical className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DialogTrigger asChild>
- <DropdownMenuItem>Edit</DropdownMenuItem>
- </DialogTrigger>
- <Link
- href={
- process.env.NODE_ENV === "production"
- ? `https://${page.slug}.openstatus.dev`
- : `/status-page/${page.slug}`
- }
- target="_blank"
- >
- <DropdownMenuItem>
- {/* TODO: forward directly to subdomain */}
- View Page
- </DropdownMenuItem>
- </Link>
- <AlertDialogTrigger asChild>
- <DropdownMenuItem className="text-destructive focus:bg-destructive focus:text-background">
- Delete
- </DropdownMenuItem>
- </AlertDialogTrigger>
- </DropdownMenuContent>
- </DropdownMenu>
- <AlertDialogContent>
- <AlertDialogHeader>
- <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
- <AlertDialogDescription>
- This action cannot be undone. This will permanently delete the
- monitor.
- </AlertDialogDescription>
- </AlertDialogHeader>
- <AlertDialogFooter>
- <AlertDialogCancel>Cancel</AlertDialogCancel>
- <AlertDialogAction
- onClick={(e) => {
- e.preventDefault();
- onDelete();
- }}
- disabled={isPending}
- className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
- >
- {!isPending ? "Delete" : <LoadingAnimation />}
- </AlertDialogAction>
- </AlertDialogFooter>
- </AlertDialogContent>
- </AlertDialog>
- <DialogContent className="flex max-h-screen flex-col">
- <DialogHeader>
- <DialogTitle>Update Page</DialogTitle>
- <DialogDescription>Change your settings.</DialogDescription>
- </DialogHeader>
- <div className="overflow-y-none -mx-1 flex-1 px-1">
- <StatusPageForm
- id="status-page-update"
- onSubmit={onUpdate}
- defaultValues={page}
- allMonitors={allMonitors}
- />
- </div>
- <DialogFooter>
+ <AlertDialog open={alertOpen} onOpenChange={(value) => setAlertOpen(value)}>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
<Button
- type="submit"
- form="status-page-update"
- disabled={isPending}
- onSubmit={(e) => {
+ variant="ghost"
+ className="data-[state=open]:bg-accent absolute right-6 top-6 h-8 w-8 p-0"
+ >
+ <span className="sr-only">Open menu</span>
+ <MoreVertical className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <Link href={`./status-pages/edit?id=${page.id}`}>
+ <DropdownMenuItem>Edit</DropdownMenuItem>
+ </Link>
+ <Link
+ href={
+ process.env.NODE_ENV === "production"
+ ? `https://${page.slug}.openstatus.dev`
+ : `/status-page/${page.slug}`
+ }
+ target="_blank"
+ >
+ <DropdownMenuItem>Visit</DropdownMenuItem>
+ </Link>
+ <AlertDialogTrigger asChild>
+ <DropdownMenuItem className="text-destructive focus:bg-destructive focus:text-background">
+ Delete
+ </DropdownMenuItem>
+ </AlertDialogTrigger>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>
+ <AlertDialogDescription>
+ This action cannot be undone. This will permanently delete the
+ monitor.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ onClick={(e) => {
e.preventDefault();
+ onDelete();
}}
+ disabled={isPending}
+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
- {!isPending ? "Confirm" : <LoadingAnimation />}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
+ {!isPending ? "Delete" : <LoadingAnimation />}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
);
}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/create-form.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/create-form.tsx
deleted file mode 100644
index af8b94448..000000000
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/create-form.tsx
+++ /dev/null
@@ -1,84 +0,0 @@
-"use client";
-
-import * as React from "react";
-import { useRouter } from "next/navigation";
-import type * as z from "zod";
-
-import type {
- allMonitorsSchema,
- insertPageSchemaWithMonitors,
-} from "@openstatus/db/src/schema";
-
-import { StatusPageForm } from "@/components/forms/status-page-form";
-import { LoadingAnimation } from "@/components/loading-animation";
-import { Button } from "@/components/ui/button";
-import {
- Dialog,
- DialogContent,
- DialogDescription,
- DialogFooter,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
-} from "@/components/ui/dialog";
-import { useToast } from "@/components/ui/use-toast";
-import { api } from "@/trpc/client";
-
-interface Props {
- workspaceSlug: string;
- allMonitors?: z.infer<typeof allMonitorsSchema>;
- disabled?: boolean;
-}
-
-export function CreateForm({ workspaceSlug, allMonitors, disabled }: Props) {
- const router = useRouter();
- const [open, setOpen] = React.useState(false);
- const [isPending, startTransition] = React.useTransition();
- const { toast } = useToast();
-
- async function onCreate({
- ...props
- }: z.infer<typeof insertPageSchemaWithMonitors>) {
- startTransition(async () => {
- try {
- await api.page.createPage.mutate({
- ...props,
- workspaceSlug,
- });
- router.refresh();
- setOpen(false);
- } catch {
- toast({
- title: "Something went wrong.",
- description: "If you are in the limits, please try again.",
- });
- }
- });
- }
-
- return (
- <Dialog open={open} onOpenChange={(value) => setOpen(value)}>
- <DialogTrigger asChild>
- <Button disabled={disabled}>Create</Button>
- </DialogTrigger>
- <DialogContent className="flex max-h-screen flex-col">
- <DialogHeader>
- <DialogTitle>Create Status Page</DialogTitle>
- <DialogDescription>Choose the settings.</DialogDescription>
- </DialogHeader>
- <div className="-mx-1 flex-1 overflow-y-auto px-1">
- <StatusPageForm
- id="status-page-create"
- onSubmit={onCreate}
- allMonitors={allMonitors}
- />
- </div>
- <DialogFooter>
- <Button type="submit" form="status-page-create" disabled={isPending}>
- {!isPending ? "Confirm" : <LoadingAnimation />}
- </Button>
- </DialogFooter>
- </DialogContent>
- </Dialog>
- );
-}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/empty-state.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/empty-state.tsx
index bd65b70db..061e1cd37 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/empty-state.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/empty-state.tsx
@@ -5,13 +5,10 @@ import type { allMonitorsSchema } from "@openstatus/db/src/schema";
import { EmptyState as DefaultEmptyState } from "@/components/dashboard/empty-state";
import { Button } from "@/components/ui/button";
-import { CreateForm } from "./create-form";
export function EmptyState({
- workspaceId,
allMonitors,
}: {
- workspaceId: string;
allMonitors?: z.infer<typeof allMonitorsSchema>;
}) {
// Navigate user to monitor if they don't have one
@@ -34,7 +31,11 @@ export function EmptyState({
icon="panel-top"
title="No pages"
description="Create your first page."
- action={<CreateForm {...{ workspaceSlug: workspaceId, allMonitors }} />}
+ action={
+ <Button asChild>
+ <Link href="./status-pages/edit">Create</Link>
+ </Button>
+ }
/>
);
}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/loading.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/loading.tsx
new file mode 100644
index 000000000..b4dafe86f
--- /dev/null
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/loading.tsx
@@ -0,0 +1,18 @@
+import { Header } from "@/components/dashboard/header";
+import { SkeletonForm } from "@/components/forms/skeleton-form";
+import { Skeleton } from "@/components/ui/skeleton";
+
+export default function Loading() {
+ return (
+ <div className="grid gap-6 md:grid-cols-2 md:gap-8">
+ <div className="col-span-full flex w-full justify-between">
+ <Header.Skeleton>
+ <Skeleton className="h-9 w-20" />
+ </Header.Skeleton>
+ </div>
+ <div className="col-span-full">
+ <SkeletonForm />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/page.tsx
new file mode 100644
index 000000000..274bccaa9
--- /dev/null
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/page.tsx
@@ -0,0 +1,58 @@
+import { notFound } from "next/navigation";
+import * as z from "zod";
+
+import { Header } from "@/components/dashboard/header";
+import { StatusPageForm } from "@/components/forms/status-page-form";
+import { api } from "@/trpc/server";
+
+/**
+ * allowed URL search params
+ */
+const searchParamsSchema = z.object({
+ id: z.coerce.number().optional(),
+});
+
+export default async function EditPage({
+ params,
+ searchParams,
+}: {
+ params: { workspaceSlug: string };
+ searchParams: { [key: string]: string | string[] | undefined };
+}) {
+ const search = searchParamsSchema.safeParse(searchParams);
+
+ if (!search.success) {
+ return notFound();
+ }
+
+ const { id } = search.data;
+
+ const page = id && (await api.page.getPageByID.query({ id }));
+ const monitors = await api.monitor.getMonitorsByWorkspace.query({
+ workspaceSlug: params.workspaceSlug,
+ });
+
+ console.log(monitors, page);
+
+ return (
+ <div className="grid gap-6 md:grid-cols-2 md:gap-8">
+ <Header title="Status Page" description="Upsert your status page." />
+ <div className="col-span-full">
+ <StatusPageForm
+ allMonitors={monitors}
+ workspaceSlug={params.workspaceSlug}
+ defaultValues={
+ page
+ ? {
+ ...page,
+ monitors: page.monitorsToPages.map(
+ ({ monitor }) => monitor.id,
+ ),
+ }
+ : undefined
+ }
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/loading.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/loading.tsx
similarity index 100%
rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/loading.tsx
rename to apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/loading.tsx
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx
index c95c8a1ce..70f70a969 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx
@@ -1,4 +1,5 @@
import * as React from "react";
+import Link from "next/link";
import { allPlans } from "@openstatus/plans";
@@ -6,14 +7,17 @@ import { Container } from "@/components/dashboard/container";
import { Header } from "@/components/dashboard/header";
import { Limit } from "@/components/dashboard/limit";
import { Badge } from "@/components/ui/badge";
+import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { api } from "@/trpc/server";
import { ActionButton } from "./_components/action-button";
-import { CreateForm } from "./_components/create-form";
import { EmptyState } from "./_components/empty-state";
const limit = allPlans.free.limits["status-pages"];
+// export const revalidate = 0;
+export const dynamic = "force-dynamic";
+
export default async function Page({
params,
}: {
@@ -27,17 +31,17 @@ export default async function Page({
});
const isLimit = (pages?.length || 0) >= limit;
+ const disableButton = isLimit || !Boolean(monitors);
+
return (
<div className="grid gap-6 md:grid-cols-2 md:gap-8">
<Header
title="Status Page"
description="Overview of all your status page."
>
- <CreateForm
- workspaceSlug={params.workspaceSlug}
- allMonitors={monitors}
- disabled={isLimit || !Boolean(monitors)}
- />
+ <Button asChild={!disableButton} disabled={disableButton}>
+ <Link href="./status-pages/edit">Create</Link>
+ </Button>
</Header>
{Boolean(pages?.length) ? (
pages?.map((page, index) => (
@@ -52,7 +56,6 @@ export default async function Page({
workspaceSlug: params.workspaceSlug,
monitors: page.monitorsToPages.map(({ monitor }) => monitor.id),
}}
- allMonitors={monitors}
/>
<dl className="[&_dt]:text-muted-foreground grid gap-2 [&>*]:text-sm [&_dt]:font-light">
<div className="flex min-w-0 items-center justify-between gap-3">
@@ -81,7 +84,7 @@ export default async function Page({
</Container>
))
) : (
- <EmptyState workspaceId={params.workspaceSlug} allMonitors={monitors} />
+ <EmptyState allMonitors={monitors} />
)}
{isLimit ? <Limit /> : null}
</div>
diff --git a/apps/web/src/app/layout.tsx b/apps/web/src/app/layout.tsx
index 999398b18..c057e2a5e 100644
--- a/apps/web/src/app/layout.tsx
+++ b/apps/web/src/app/layout.tsx
@@ -47,18 +47,18 @@ export default function RootLayout({
}) {
// If you want to develop locally without Clerk, Comment the provider below
return (
- <ClerkProvider>
- <html lang="en">
- {/* TODO: remove plausible from root layout (to avoid tracking subdomains) */}
- <PlausibleProvider domain="openstatus.dev">
+ <html lang="en">
+ {/* TODO: remove plausible from root layout (to avoid tracking subdomains) */}
+ <PlausibleProvider domain="openstatus.dev">
+ <ClerkProvider>
<body className={`${inter.className} ${calSans.variable}`}>
<Background>{children}</Background>
<Toaster />
<TailwindIndicator />
</body>
- </PlausibleProvider>
- <ClientAnalytics />;
- </html>
- </ClerkProvider>
+ </ClerkProvider>
+ </PlausibleProvider>
+ <ClientAnalytics />
+ </html>
);
}
diff --git a/apps/web/src/components/forms/montitor-form.tsx b/apps/web/src/components/forms/montitor-form.tsx
index b2d1ad8f0..46194e22a 100644
--- a/apps/web/src/components/forms/montitor-form.tsx
+++ b/apps/web/src/components/forms/montitor-form.tsx
@@ -1,7 +1,9 @@
"use client";
import * as React from "react";
+import { useRouter } from "next/navigation";
import { zodResolver } from "@hookform/resolvers/zod";
+import { Check, ChevronsUpDown } from "lucide-react";
import { useForm } from "react-hook-form";
import type * as z from "zod";
@@ -11,6 +13,14 @@ import {
} from "@openstatus/db/src/schema";
import { allPlans } from "@openstatus/plans";
+import { Button } from "@/components/ui/button";
+import {
+ Command,
+ CommandEmpty,
+ CommandGroup,
+ CommandInput,
+ CommandItem,
+} from "@/components/ui/command";
import {
Form,
FormControl,
@@ -21,6 +31,11 @@ import {
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/ui/popover";
import {
Select,
SelectContent,
@@ -29,6 +44,11 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Switch } from "@/components/ui/switch";
+import { regionsDict } from "@/data/regions-dictionary";
+import { cn } from "@/lib/utils";
+import { api } from "@/trpc/client";
+import { LoadingAnimation } from "../loading-animation";
+import { useToast } from "../ui/use-toast";
const limit = allPlans.free.limits.periodicity;
const cronJobs = [
@@ -39,135 +59,234 @@ const cronJobs = [
{ value: "1h", label: "1 hour" },
] as const;
+type MonitorProps = z.infer<typeof insertMonitorSchema>;
+
interface Props {
- id: string;
- defaultValues?: z.infer<typeof insertMonitorSchema>;
- onSubmit: (values: z.infer<typeof insertMonitorSchema>) => Promise<void>;
+ defaultValues?: MonitorProps;
+ workspaceSlug: string;
}
-export function MonitorForm({ id, defaultValues, onSubmit }: Props) {
- const form = useForm<z.infer<typeof insertMonitorSchema>>({
+export function MonitorForm({ defaultValues, workspaceSlug }: Props) {
+ const form = useForm<MonitorProps>({
resolver: zodResolver(insertMonitorSchema), // too much - we should only validate the values we ask inside of the form!
defaultValues: {
url: defaultValues?.url || "",
name: defaultValues?.name || "",
description: defaultValues?.description || "",
periodicity: defaultValues?.periodicity || "30m",
- active: defaultValues?.active || true,
+ active: defaultValues?.active ?? true,
id: defaultValues?.id || undefined,
+ regions: defaultValues?.regions || [],
},
});
+ const router = useRouter();
+ const [isPending, startTransition] = React.useTransition();
+ const { toast } = useToast();
+
+ const onSubmit = ({ ...props }: MonitorProps) => {
+ startTransition(async () => {
+ try {
+ // TODO: we could use an upsertPage function instead - insert if not exist otherwise update
+ if (defaultValues) {
+ await api.monitor.updateMonitor.mutate(props);
+ } else {
+ await api.monitor.createMonitor.mutate({
+ data: props,
+ workspaceSlug,
+ });
+ }
+ router.push("./");
+ router.refresh();
+ } catch {
+ toast({
+ title: "Something went wrong.",
+ description: "If you are in the limits, please try again.",
+ });
+ }
+ });
+ };
return (
<Form {...form}>
- <form onSubmit={form.handleSubmit(onSubmit)} id={id}>
- <div className="grid w-full items-center space-y-6">
- <FormField
- control={form.control}
- name="url"
- render={({ field }) => (
- <FormItem>
- <FormLabel>URL</FormLabel>
- <FormControl>
- <Input placeholder="" {...field} />
- </FormControl>
- <FormDescription>
- Here is the URL you want to monitor.{" "}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="name"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Name</FormLabel>
- <FormControl>
- <Input placeholder="" {...field} />
- </FormControl>
- <FormDescription>
- The name of the monitor displayed on the status page.
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="description"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Description</FormLabel>
- <FormControl>
- <Input placeholder="" {...field} />
- </FormControl>
- <FormDescription>
- Provide your users with information about it.{" "}
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="active"
- render={({ field }) => (
- <FormItem className="flex flex-row items-center justify-between">
- <div className="space-y-0.5">
- <FormLabel>Active</FormLabel>
- <FormDescription>
- This will start ping your endpoint on based on the selected
- frequence.
- </FormDescription>
- </div>
+ <form
+ onSubmit={form.handleSubmit(onSubmit)}
+ className="grid w-full grid-cols-1 items-center gap-6 sm:grid-cols-6"
+ >
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-3">
+ <FormLabel>Name</FormLabel>
+ <FormControl>
+ <Input placeholder="" {...field} />
+ </FormControl>
+ <FormDescription>
+ The name of the monitor displayed on the status page.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="url"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-4">
+ <FormLabel>URL</FormLabel>
+ <FormControl>
+ <Input placeholder="" {...field} />
+ </FormControl>
+ <FormDescription>
+ Here is the URL you want to monitor.{" "}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="description"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-5">
+ <FormLabel>Description</FormLabel>
+ <FormControl>
+ <Input placeholder="" {...field} />
+ </FormControl>
+ <FormDescription>
+ Provide your users with information about it.{" "}
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="periodicity"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-3 sm:self-baseline">
+ <FormLabel>Frequency</FormLabel>
+ <Select
+ onValueChange={(value) =>
+ field.onChange(periodicityEnum.parse(value))
+ }
+ defaultValue={field.value}
+ >
<FormControl>
- <Switch
- checked={field.value || false}
- onCheckedChange={(value) => field.onChange(value)}
- />
+ <SelectTrigger>
+ <SelectValue placeholder="How often should it check your endpoint?" />
+ </SelectTrigger>
</FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="periodicity"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Frequency</FormLabel>
- <Select
- onValueChange={(value) =>
- field.onChange(periodicityEnum.parse(value))
- }
- defaultValue={field.value}
- >
+ <SelectContent>
+ {cronJobs.map(({ label, value }) => (
+ <SelectItem
+ key={value}
+ value={value}
+ disabled={!limit.includes(value)}
+ >
+ {label}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ <FormDescription>
+ Frequency of how often your endpoint will be pinged.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="regions"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-3 sm:self-baseline">
+ <FormLabel>Regions</FormLabel>
+ <Popover>
+ <PopoverTrigger asChild>
<FormControl>
- <SelectTrigger>
- <SelectValue placeholder="How often should it check your endpoint?" />
- </SelectTrigger>
+ <Button
+ variant="outline"
+ role="combobox"
+ className={cn(
+ "h-10 w-full justify-between",
+ !field.value && "text-muted-foreground",
+ )}
+ >
+ {/* This is a hotfix */}
+ {field.value?.length === 1 && field.value[0].length > 0
+ ? regionsDict[
+ field.value[0] as keyof typeof regionsDict
+ ].location
+ : "Select region"}
+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
+ </Button>
</FormControl>
- <SelectContent>
- {cronJobs.map(({ label, value }) => (
- <SelectItem
- key={value}
- value={value}
- disabled={!limit.includes(value)}
- >
- {label}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
+ </PopoverTrigger>
+ <PopoverContent className="w-full p-0">
+ <Command>
+ <CommandInput placeholder="Select a region..." />
+ <CommandEmpty>No regions found.</CommandEmpty>
+ <CommandGroup className="max-h-[150px] overflow-y-scroll">
+ {Object.keys(regionsDict).map((region) => {
+ const { code, location } =
+ regionsDict[region as keyof typeof regionsDict];
+ const isSelected = field.value?.includes(code);
+ return (
+ <CommandItem
+ value={code}
+ key={code}
+ onSelect={() => {
+ form.setValue("regions", [code]); // TODO: allow more than one to be selected in the future
+ }}
+ >
+ <Check
+ className={cn(
+ "mr-2 h-4 w-4",
+ isSelected ? "opacity-100" : "opacity-0",
+ )}
+ />
+ {location}
+ </CommandItem>
+ );
+ })}
+ </CommandGroup>
+ </Command>
+ </PopoverContent>
+ </Popover>
+ <FormDescription>
+ Select your region. Leave blank for random picked regions.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="active"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-center justify-between sm:col-span-3">
+ <div className="space-y-0.5">
+ <FormLabel>Active</FormLabel>
<FormDescription>
- Frequency of how often your endpoint will be pinged.
+ This will start ping your endpoint on based on the selected
+ frequence.
</FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
+ </div>
+ <FormControl>
+ <Switch
+ checked={field.value || false}
+ onCheckedChange={(value) => field.onChange(value)}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <div className="sm:col-span-full">
+ <Button className="w-full sm:w-auto">
+ {!isPending ? "Confirm" : <LoadingAnimation />}
+ </Button>
</div>
</form>
</Form>
diff --git a/apps/web/src/components/forms/skeleton-form.tsx b/apps/web/src/components/forms/skeleton-form.tsx
new file mode 100644
index 000000000..70c4e86f2
--- /dev/null
+++ b/apps/web/src/components/forms/skeleton-form.tsx
@@ -0,0 +1,26 @@
+import { Skeleton } from "@/components/ui/skeleton";
+
+export function SkeletonForm() {
+ return (
+ <div className="grid w-full grid-cols-1 items-center space-y-6 sm:grid-cols-6">
+ <div className="space-y-2 sm:col-span-4">
+ <Skeleton className="h-6 w-24" />
+ <Skeleton className="h-9 w-full" />
+ <Skeleton className="h-5 w-64" />
+ </div>
+ <div className="space-y-2 sm:col-span-5">
+ <Skeleton className="h-6 w-24" />
+ <Skeleton className="h-9 w-full" />
+ <Skeleton className="h-5 w-64" />
+ </div>
+ <div className="space-y-2 sm:col-span-3">
+ <Skeleton className="h-6 w-24" />
+ <Skeleton className="h-9 w-full" />
+ <Skeleton className="h-5 w-64" />
+ </div>
+ <div className="space-y-2 sm:col-span-full">
+ <Skeleton className="h-9 w-20" />
+ </div>
+ </div>
+ );
+}
diff --git a/apps/web/src/components/forms/status-page-form.tsx b/apps/web/src/components/forms/status-page-form.tsx
index ee33dd757..b707e8fcd 100644
--- a/apps/web/src/components/forms/status-page-form.tsx
+++ b/apps/web/src/components/forms/status-page-form.tsx
@@ -1,6 +1,7 @@
"use client";
import * as React from "react";
+import { useRouter } from "next/navigation";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import type * as z from "zod";
@@ -8,6 +9,8 @@ import type * as z from "zod";
import type { allMonitorsSchema } from "@openstatus/db/src/schema";
import { insertPageSchemaWithMonitors } from "@openstatus/db/src/schema";
+import { Button } from "@/components/ui/button";
+import { Checkbox } from "@/components/ui/checkbox";
import {
Form,
FormControl,
@@ -18,26 +21,24 @@ import {
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
+import { useToast } from "@/components/ui/use-toast";
import { useDebounce } from "@/hooks/use-debounce";
import { api } from "@/trpc/client";
-import { Checkbox } from "../ui/checkbox";
-import { useToast } from "../ui/use-toast";
+import { LoadingAnimation } from "../loading-animation";
// REMINDER: only use the props you need!
type Schema = z.infer<typeof insertPageSchemaWithMonitors>;
interface Props {
- id: string;
defaultValues?: Schema;
- onSubmit: (values: Schema) => Promise<void>;
+ workspaceSlug: string;
allMonitors?: z.infer<typeof allMonitorsSchema>;
}
export function StatusPageForm({
- id,
defaultValues,
- onSubmit,
+ workspaceSlug,
allMonitors,
}: Props) {
const form = useForm<Schema>({
@@ -52,6 +53,8 @@ export function StatusPageForm({
workspaceSlug: "",
},
});
+ const router = useRouter();
+ const [isPending, startTransition] = React.useTransition();
const watchSlug = form.watch("slug");
const debouncedSlug = useDebounce(watchSlug, 1000); // using debounce to not exhaust the server
const { toast } = useToast();
@@ -78,6 +81,31 @@ export function StatusPageForm({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [checkUniqueSlug]);
+ const onSubmit = async ({
+ ...props
+ }: z.infer<typeof insertPageSchemaWithMonitors>) => {
+ startTransition(async () => {
+ // TODO: we could use an upsertPage function instead - insert if not exist otherwise update
+ try {
+ if (defaultValues) {
+ await api.page.updatePage.mutate(props);
+ } else {
+ await api.page.createPage.mutate({
+ ...props,
+ workspaceSlug,
+ });
+ }
+ router.push("./");
+ router.refresh(); // this will actually revalidate the page after submission
+ } catch {
+ toast({
+ title: "Something went wrong.",
+ description: "If you are in the limits, please try again.",
+ });
+ }
+ });
+ };
+
return (
<Form {...form}>
<form
@@ -91,109 +119,117 @@ export function StatusPageForm({
description: "Please select another slug. Every slug is unique.",
});
} else {
- form.handleSubmit(onSubmit)(e);
+ if (onSubmit) {
+ form.handleSubmit(onSubmit)(e);
+ }
}
}}
- id={id}
+ className="grid w-full grid-cols-1 items-center gap-6 sm:grid-cols-6"
>
- <div className="grid w-full items-center space-y-6">
- <FormField
- control={form.control}
- name="title"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Title</FormLabel>
- <FormControl>
- <Input placeholder="" {...field} />
- </FormControl>
- <FormDescription>The title of your page.</FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="slug"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Slug</FormLabel>
- <FormControl>
- <Input placeholder="" {...field} />
- </FormControl>
- <FormDescription>
- The subdomain slug for your status page. At least 3 chars.
- </FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="description"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Description</FormLabel>
- <FormControl>
- <Input placeholder="" {...field} />
- </FormControl>
+ <FormField
+ control={form.control}
+ name="title"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-4">
+ <FormLabel>Title</FormLabel>
+ <FormControl>
+ <Input placeholder="" {...field} />
+ </FormControl>
+ <FormDescription>The title of your page.</FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="description"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-5">
+ <FormLabel>Description</FormLabel>
+ <FormControl>
+ <Input placeholder="" {...field} />
+ </FormControl>
+ <FormDescription>
+ Give your user some information about it.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="slug"
+ render={({ field }) => (
+ <FormItem className="sm:col-span-3">
+ <FormLabel>Slug</FormLabel>
+ <FormControl>
+ <Input placeholder="" {...field} />
+ </FormControl>
+ <FormDescription>
+ The subdomain for your status page. At least 3 chars.
+ </FormDescription>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="monitors"
+ render={() => (
+ <FormItem className="sm:col-span-full">
+ <div className="mb-4">
+ <FormLabel className="text-base">Monitor</FormLabel>
<FormDescription>
- Give your user some information about it.
+ Select the monitors you want to display.
</FormDescription>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="monitors"
- render={() => (
- <FormItem>
- <div className="mb-4">
- <FormLabel className="text-base">Monitor</FormLabel>
- <FormDescription>
- Select the monitors you want to display.
- </FormDescription>
- </div>
- {allMonitors?.map((item) => (
- <FormField
- key={item.id}
- control={form.control}
- name="monitors"
- render={({ field }) => {
- return (
- <FormItem
- key={item.id}
- className="flex flex-row items-start space-x-3 space-y-0"
- >
- <FormControl>
- <Checkbox
- 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,
- ),
- );
- }}
- />
- </FormControl>
+ </div>
+ {allMonitors?.map((item) => (
+ <FormField
+ key={item.id}
+ control={form.control}
+ name="monitors"
+ render={({ field }) => {
+ return (
+ <FormItem
+ key={item.id}
+ className="flex flex-row items-start space-x-3 space-y-0"
+ >
+ <FormControl>
+ <Checkbox
+ 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,
+ ),
+ );
+ }}
+ />
+ </FormControl>
+ <div className="space-y-1 leading-none">
<FormLabel className="font-normal">
{item.name}
</FormLabel>
- </FormItem>
- );
- }}
- />
- ))}
- <FormMessage />
- </FormItem>
- )}
- />
+ <FormDescription>{item.description}</FormDescription>
+ </div>
+ </FormItem>
+ );
+ }}
+ />
+ ))}
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <div className="sm:col-span-full">
+ <Button className="w-full sm:w-auto">
+ {!isPending ? "Confirm" : <LoadingAnimation />}
+ </Button>
</div>
</form>
</Form>
diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.ts
index 6e6286136..f54c19258 100644
--- a/packages/api/src/router/monitor.ts
+++ b/packages/api/src/router/monitor.ts
@@ -7,6 +7,7 @@ import {
allMonitorsSchema,
insertMonitorSchema,
monitor,
+ selectMonitorSchema,
user,
usersToWorkspaces,
workspace,
@@ -110,8 +111,8 @@ export const monitorRouter = createTRPCRouter({
.get();
if (!result || !result.users_to_workspaces) return;
-
- return currentMonitor;
+ const _monitor = selectMonitorSchema.parse(currentMonitor);
+ return _monitor;
}),
updateMonitorDescription: protectedProcedure