Skip to content

Open-source status page, incident response and uptime monitoring

feat: create dialog form example (#43)

Maximilian Kaskec6c4d741348d
diff --git a/README.md b/README.md
index c132807ba..ad95f6de9 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,10 @@ email at [[email protected]](mailto:[email protected]) <br/> or <br/>
- [Next.js](https://nextjs.org/)
- [Tailwind CSS](https://tailwindcss.com/)
- [shadcn/ui](https://ui.shadcn.com/)
+- [tinybird](http://tinybird.co/)
+- [planetscale](http://planetscale.com/)
+- [drizzle](https://orm.drizzle.team/)
+- [clerk](https://clerk.com/)
## Getting Started
@@ -75,6 +79,14 @@ email at [[email protected]](mailto:[email protected]) <br/> or <br/>
5. Open [http://localhost:3000](http://localhost:3000) with your browser to see
the result.
+For [clerk](https://clerk.com), you will need to create a webhook endpoint. To
+access the link via ngrok (free), after login, append `/api/webhook/clerk` to
+the link you get after entering:
+
+```
+$ ngrok http 3000
+```
+
## Roadmap
Coming soon
diff --git a/apps/web/package.json b/apps/web/package.json
index 1de3eb2e3..c2ffb056c 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -18,6 +18,7 @@
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-hover-card": "^1.0.6",
+ "@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-select": "^1.2.2",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.4",
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceId]/loading.tsx b/apps/web/src/app/app/(dashboard)/[workspaceId]/loading.tsx
index 3c4e9f583..42b107881 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceId]/loading.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceId]/loading.tsx
@@ -1,10 +1,15 @@
import { Container } from "@/components/dashboard/container";
import { Header } from "@/components/dashboard/header";
+import { Skeleton } from "@/components/ui/skeleton";
export default function Loading() {
return (
<div className="grid gap-6 md:grid-cols-2 md:gap-8">
- <Header.Skeleton />
+ <div className="col-span-full flex w-full justify-between">
+ <Header.Skeleton>
+ <Skeleton className="h-9 w-20" />
+ </Header.Skeleton>
+ </div>
<Container.Skeleton />
<Container.Skeleton />
<Container.Skeleton />
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceId]/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceId]/page.tsx
index d2ba99d10..b8d44a328 100644
--- a/apps/web/src/app/app/(dashboard)/[workspaceId]/page.tsx
+++ b/apps/web/src/app/app/(dashboard)/[workspaceId]/page.tsx
@@ -2,13 +2,20 @@ import * as React from "react";
import { Container } from "@/components/dashboard/container";
import { Header } from "@/components/dashboard/header";
+import { DialogForm } from "@/components/forms/dialog-form";
+import { Button } from "@/components/ui/button";
import { wait } from "@/lib/utils";
export default async function DashboardPage() {
await wait(1000);
return (
<div className="grid gap-6 md:grid-cols-2 md:gap-8">
- <Header title="Dashboard" description="Overview of all your websites" />
+ <div className="col-span-full flex w-full justify-between">
+ <Header title="Dashboard" description="Overview of all your websites">
+ {/* <Button>Create</Button> */}
+ <DialogForm />
+ </Header>
+ </div>
<Container title="Hello"></Container>
<Container title="World"></Container>
</div>
diff --git a/apps/web/src/app/app/(dashboard)/layout.tsx b/apps/web/src/app/app/(dashboard)/layout.tsx
index d846263e8..047a71baf 100644
--- a/apps/web/src/app/app/(dashboard)/layout.tsx
+++ b/apps/web/src/app/app/(dashboard)/layout.tsx
@@ -18,6 +18,7 @@ export default function AppLayout({ children }: { children: React.ReactNode }) {
</Shell>
<main className="z-10 flex w-full flex-1 flex-col items-start justify-center">
<Shell className="relative flex-1">
+ {/* The `top-4` is represented in Shell with a `py-4` class */}
<nav className="absolute right-4 top-4 block md:hidden">
<AppMenu />
</nav>
diff --git a/apps/web/src/components/dashboard/header.tsx b/apps/web/src/components/dashboard/header.tsx
index 2cd44f697..d07c572f9 100644
--- a/apps/web/src/components/dashboard/header.tsx
+++ b/apps/web/src/components/dashboard/header.tsx
@@ -6,22 +6,36 @@ interface HeaderProps extends React.HTMLAttributes<HTMLDivElement> {
description?: string | null;
}
-function Header({ title, description, className }: HeaderProps) {
+/**
+ * use `children` to include a Button e.g.
+ */
+function Header({ title, description, className, children }: HeaderProps) {
return (
- <div className={cn("col-span-full grid gap-1", className)}>
- <h1 className="font-cal text-3xl">{title}</h1>
- {description ? (
- <p className="text-muted-foreground">{description}</p>
- ) : null}
+ <div
+ className={cn(
+ "col-span-full mr-12 flex w-full justify-between md:mr-0",
+ className,
+ )}
+ >
+ <div className="grid w-full gap-1">
+ <h1 className="font-cal text-3xl">{title}</h1>
+ {description ? (
+ <p className="text-muted-foreground">{description}</p>
+ ) : null}
+ </div>
+ {children}
</div>
);
}
-function HeaderSkeleton() {
+function HeaderSkeleton({ children }: { children?: React.ReactNode }) {
return (
- <div className="col-span-full grid gap-3">
- <Skeleton className="h-8 w-[200px]" />
- <Skeleton className="h-4 w-[300px]" />
+ <div className="col-span-full mr-12 flex w-full justify-between md:mr-0">
+ <div className="grid w-full gap-3">
+ <Skeleton className="h-8 w-full max-w-[200px]" />
+ <Skeleton className="h-4 w-full max-w-[300px]" />
+ </div>
+ {children}
</div>
);
}
diff --git a/apps/web/src/components/dashboard/shell.tsx b/apps/web/src/components/dashboard/shell.tsx
index f9bae6320..c32b8a64a 100644
--- a/apps/web/src/components/dashboard/shell.tsx
+++ b/apps/web/src/components/dashboard/shell.tsx
@@ -6,7 +6,7 @@ function Shell({ children, className }: ShellProps) {
return (
<div
className={cn(
- "border-border w-full rounded-lg border p-3 backdrop-blur-[2px] md:p-6",
+ "border-border w-full rounded-lg border px-3 py-4 backdrop-blur-[2px] md:p-6",
className,
)}
>
diff --git a/apps/web/src/components/forms/dialog-form.tsx b/apps/web/src/components/forms/dialog-form.tsx
new file mode 100644
index 000000000..2b0719421
--- /dev/null
+++ b/apps/web/src/components/forms/dialog-form.tsx
@@ -0,0 +1,71 @@
+"use client";
+
+import * as React from "react";
+import { Loader2 } from "lucide-react";
+
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from "@/components/ui/dialog";
+import { wait } from "@/lib/utils";
+import { Button } from "../ui/button";
+import { Input } from "../ui/input";
+import { Label } from "../ui/label";
+
+// EXAMPLE
+export function DialogForm() {
+ const [saving, setSaving] = React.useState(false);
+ const [open, setOpen] = React.useState(false);
+
+ // either like that or with a user action
+ async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
+ e.preventDefault();
+ setSaving(true);
+ const data = Object.fromEntries(new FormData(e.currentTarget));
+
+ console.log(data); // { url: "" }
+ await wait(1500);
+ // save data
+
+ setOpen(false);
+ setSaving(false);
+ }
+
+ return (
+ <Dialog open={open} onOpenChange={(value) => setOpen(value)}>
+ <DialogTrigger asChild>
+ <Button>Create</Button>
+ </DialogTrigger>
+ <DialogContent>
+ <DialogHeader>
+ <DialogTitle>Create Monitor</DialogTitle>
+ <DialogDescription>
+ Type an URL that you want to ping periodically.
+ </DialogDescription>
+ </DialogHeader>
+ <form onSubmit={handleSubmit} id="monitor">
+ <div className="grid w-full items-center gap-1.5">
+ <Label htmlFor="url">Link</Label>
+ <Input
+ id="url"
+ name="url"
+ type="url"
+ placeholder="https://"
+ required
+ />
+ </div>
+ </form>
+ <DialogFooter>
+ <Button type="submit" form="monitor" disabled={saving}>
+ {!saving ? "Confirm" : <Loader2 className="h-4 w-4 animate-spin" />}
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/apps/web/src/components/layout/app-menu.tsx b/apps/web/src/components/layout/app-menu.tsx
index b25ad804e..a2b5e2f22 100644
--- a/apps/web/src/components/layout/app-menu.tsx
+++ b/apps/web/src/components/layout/app-menu.tsx
@@ -8,12 +8,10 @@ import { Button } from "../ui/button";
import {
Sheet,
SheetContent,
- SheetDescription,
SheetHeader,
SheetTitle,
SheetTrigger,
} from "../ui/sheet";
-// your navigation
import { AppSidebar } from "./app-sidebar";
export function AppMenu() {
@@ -35,9 +33,7 @@ export function AppMenu() {
<SheetContent>
<SheetHeader>
<SheetTitle className="text-left">Navigation</SheetTitle>
- <SheetDescription>
- <AppSidebar /> {/* is here */}
- </SheetDescription>
+ <AppSidebar />
</SheetHeader>
</SheetContent>
</Sheet>
diff --git a/apps/web/src/components/layout/app-sidebar.tsx b/apps/web/src/components/layout/app-sidebar.tsx
index 332dab944..4303ac86c 100644
--- a/apps/web/src/components/layout/app-sidebar.tsx
+++ b/apps/web/src/components/layout/app-sidebar.tsx
@@ -7,13 +7,6 @@ import { pagesConfig } from "@/config/pages";
import { cn } from "@/lib/utils";
import { Icons } from "../icons";
-type PageConfig = {
- title: string;
- href: string;
- icon: string;
- disabled: boolean;
-};
-
export function AppSidebar() {
const pathname = usePathname();
const params = useParams();
diff --git a/apps/web/src/components/ui/label.tsx b/apps/web/src/components/ui/label.tsx
new file mode 100644
index 000000000..590c4e7a4
--- /dev/null
+++ b/apps/web/src/components/ui/label.tsx
@@ -0,0 +1,28 @@
+// THIS IS **NOT** a shadcn ui component. TBD if we want to keep `import/consistent-type-specifier-style`
+// https://ui.shadcn.com/docs/components/label
+
+"use client";
+
+import * as React from "react";
+import { cva } from "class-variance-authority";
+import type { VariantProps } from "class-variance-authority";
+
+import { cn } from "@/lib/utils";
+
+const labelVariants = cva(
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
+);
+
+export interface LabelProps
+ extends React.LabelHTMLAttributes<HTMLLabelElement>,
+ VariantProps<typeof labelVariants> {}
+
+const Label = React.forwardRef<HTMLLabelElement, LabelProps>(
+ ({ className, ...props }, ref) => (
+ <label ref={ref} className={cn(labelVariants(), className)} {...props} />
+ ),
+);
+
+Label.displayName = "Label";
+
+export { Label };
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 35d0ce59d..f6d5be3ab 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -62,6 +62,9 @@ importers:
'@radix-ui/react-hover-card':
specifier: ^1.0.6
+ '@radix-ui/react-label':
+ specifier: ^2.0.2
'@radix-ui/react-select':
specifier: ^1.2.2
@@ -2023,6 +2026,27 @@ packages:
react: 18.2.0
dev: false
+ resolution: {integrity: sha512-N5ehvlM7qoTLx7nWPodsPYPgMzA5WM8zZChQg8nyFJKnDO5WHdba1vv5/H6IO5LtJMfD2Q3wh1qHFGNtK0w3bQ==}
+ peerDependencies:
+ '@types/react': '*'
+ '@types/react-dom': '*'
+ react: ^16.8 || ^17.0 || ^18.0
+ react-dom: ^16.8 || ^17.0 || ^18.0
+ peerDependenciesMeta:
+ '@types/react':
+ optional: true
+ '@types/react-dom':
+ optional: true
+ dependencies:
+ '@babel/runtime': 7.22.5
+ '@radix-ui/react-primitive': 1.0.3(@types/[email protected])(@types/[email protected])([email protected])([email protected])
+ '@types/react': 18.2.12
+ '@types/react-dom': 18.2.5
+ react: 18.2.0
+ react-dom: 18.2.0([email protected])
+ dev: false
+
resolution: {integrity: sha512-Gw4f9pwdH+w5w+49k0gLjN0PfRDHvxmAgG16AbyJZ7zhwZ6PBHKtWohvnSwfusfnK3L68dpBREHpVkj8wEM7ZA==}
peerDependencies: