Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: invite members to workspace (#503)
Maximilian Kaske0e12f6e6bb59
diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/team/page.tsx b/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/team/page.tsxdeleted file mode 100644index f79e3bd2d..000000000--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/team/page.tsx+++ /dev/null@@ -1,27 +0,0 @@-import { AlertTriangle } from "lucide-react";--import { Alert, AlertDescription, AlertTitle } from "@openstatus/ui";--import { columns } from "@/components/data-table/user/columns";-import { DataTable } from "@/components/data-table/user/data-table";-import { api } from "@/trpc/server";--export default async function TeamPage() {- const workspace = await api.workspace.getWorkspace.query();- const users = await api.workspace.getWorkspaceUsers.query();-- return (- <div className="flex flex-col gap-4">- <Alert>- <AlertTriangle className="h-4 w-4" />- <AlertTitle>Team</AlertTitle>- <AlertDescription>- {workspace.plan === "free"- ? "Please upgrade to invite more team members."- : "Please contact us to invite more team members. We are working on a self-service solution."}- </AlertDescription>- </Alert>- <DataTable data={users} columns={columns} />- </div>- );-}diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/integrations/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/integrations/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/integrations/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/integrations/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/vercel/configure/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/integrations/vercel/configure/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/integrations/vercel/configure/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/integrations/vercel/configure/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/layout.tsxsimilarity index 79%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/layout.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/layout.tsxindex 6c8dd4079..4a1728946 100644--- a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/layout.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/layout.tsx@@ -6,6 +6,7 @@ import { AppHeader } from "@/components/layout/app-header";import { AppMenu } from "@/components/layout/app-menu";import { AppSidebar } from "@/components/layout/app-sidebar";import { api } from "@/trpc/server";+import { WorkspaceClientCookie } from "../worskpace-client-cookie";// TODO: make the container min-h-screen and the footer below!export default async function AppLayout({@@ -15,8 +16,12 @@ export default async function AppLayout({children: React.ReactNode;params: { workspaceSlug: string };}) {- const workspace = await api.workspace.getWorkspace.query();- if (!workspace) return notFound(); // TODO: discuss if we should move to middleware+ const { workspaceSlug } = params;+ const workspaces = await api.workspace.getUserWorkspaces.query();++ if (workspaces.length === 0) return notFound();+ if (workspaces.find((w) => w.slug === workspaceSlug) === undefined)+ return notFound();return (<div className="container relative mx-auto flex min-h-screen w-full flex-col items-center justify-center gap-6 p-4 lg:p-8">@@ -36,6 +41,7 @@ export default async function AppLayout({</Shell></main></div>+ <WorkspaceClientCookie {...{ workspaceSlug }} /></div>);}diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/_components/chart-wrapper.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/chart-wrapper.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/_components/chart-wrapper.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/chart-wrapper.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/_components/chart.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/chart.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/_components/chart.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/chart.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/_components/date-picker-preset.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/date-picker-preset.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/_components/date-picker-preset.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/date-picker-preset.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/utils.ts b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/utils.tssimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/[id]/data/utils.tsrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/utils.tsdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/_components/action-button.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/action-button.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/_components/action-button.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/empty-state.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/_components/empty-state.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/_components/empty-state.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/_components/empty-state.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/edit/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/edit/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/edit/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/edit/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/edit/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/monitors/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/_components/empty-state.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/_components/empty-state.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/_components/empty-state.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/_components/empty-state.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/edit/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/edit/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/edit/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/edit/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/edit/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/edit/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/edit/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/notifications/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/notifications/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/actions.ts b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/actions.tssimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/actions.tsrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/actions.tsdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/card.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/card.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/card.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/card.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/create-form.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/create-form.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/create-form.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/create-form.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/revoke-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/revoke-button.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/revoke-button.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/revoke-button.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/submit-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/submit-button.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/_components/submit-button.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/_components/submit-button.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/api-token/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/api-token/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/billing/_components/customer-portal-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/customer-portal-button.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/billing/_components/customer-portal-button.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/customer-portal-button.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/billing/_components/plan.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/plan.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/billing/_components/plan.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/_components/plan.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/billing/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/billing/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/billing/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/general/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/general/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/general/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/layout.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/layout.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/layout.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/settings/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/page.tsxdiff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/_components/invite-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/_components/invite-button.tsxnew file mode 100644index 000000000..320702ff5--- /dev/null+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/_components/invite-button.tsx@@ -0,0 +1,110 @@+"use client";++import { useState, useTransition } 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";++import { insertInvitationSchema } from "@openstatus/db/src/schema";+import {+ Button,+ Dialog,+ DialogContent,+ DialogDescription,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+ Form,+ FormControl,+ FormDescription,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+ Input,+} from "@openstatus/ui";++import { LoadingAnimation } from "@/components/loading-animation";+import { useToastAction } from "@/hooks/use-toast-action";+import { wait } from "@/lib/utils";+import { api } from "@/trpc/client";++const schema = insertInvitationSchema.pick({ email: true });+type Schema = z.infer<typeof schema>;++export function InviteButton({+ defaultValues,+ disabled,+}: {+ defaultValues?: Schema;+ disabled?: boolean;+}) {+ const [open, setOpen] = useState(false);+ const form = useForm<Schema>({+ resolver: zodResolver(schema),+ defaultValues,+ });+ const router = useRouter();+ const [isPending, startTransition] = useTransition();+ const { toast } = useToastAction();++ async function onSubmit(data: Schema) {+ startTransition(async () => {+ try {+ wait(2000);+ api.invitation.create.mutate(data);+ toast("saved");+ router.refresh();+ } catch {+ toast("error");+ } finally {+ setOpen(false);+ }+ });+ }++ return (+ <Dialog open={open} onOpenChange={setOpen}>+ <DialogTrigger asChild>+ <Button onClick={() => setOpen((v) => !v)} disabled={disabled}>Invite Member</Button>+ </DialogTrigger>+ <DialogContent>+ <DialogHeader>+ <DialogTitle>Invite your team members!</DialogTitle>+ <DialogDescription>+ They will receive an email invite to join your workspace.+ </DialogDescription>+ </DialogHeader>+ <Form {...form}>+ <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="email"+ render={({ field }) => (+ <FormItem className="sm:col-span-5">+ <FormLabel>Email</FormLabel>+ <FormControl>+ <Input {...field} />+ </FormControl>+ <FormDescription>+ We will send an invite to this email address.+ </FormDescription>+ <FormMessage />+ </FormItem>+ )}+ />+ <div className="sm:col-span-full">+ <Button className="w-full sm:w-auto" size="lg">+ {!isPending ? "Confirm" : <LoadingAnimation />}+ </Button>+ </div>+ </form>+ </Form>+ </DialogContent>+ </Dialog>+ );+}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/page.tsxnew file mode 100644index 000000000..b27a9e0f7--- /dev/null+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/settings/team/page.tsx@@ -0,0 +1,53 @@+import { AlertTriangle } from "lucide-react";++import { allPlans } from "@openstatus/plans";+import {+ Alert,+ AlertDescription,+ AlertTitle,+ ButtonWithDisableTooltip,+} from "@openstatus/ui";++import { columns as invitationColumns } from "@/components/data-table/invitation/columns";+import { DataTable as InvitationDataTable } from "@/components/data-table/invitation/data-table";+import { columns as userColumns } from "@/components/data-table/user/columns";+import { DataTable as UserDataTable } from "@/components/data-table/user/data-table";+import { api } from "@/trpc/server";+import { InviteButton } from "./_components/invite-button";++export default async function TeamPage() {+ const workspace = await api.workspace.getWorkspace.query();+ const invitations = await api.invitation.getWorkspaceOpenInvitations.query();+ const users = await api.workspace.getWorkspaceUsers.query();++ const isLimit =+ invitations.length + users.length >=+ allPlans[workspace.plan || "free"].limits.members;++ const isFreePlan = workspace.plan === "free";++ return (+ <div className="flex flex-col gap-4">+ {isFreePlan ? (+ <Alert>+ <AlertTriangle className="h-4 w-4" />+ <AlertTitle>Team</AlertTitle>+ <AlertDescription>+ Please upgrade to invite more team members.+ </AlertDescription>+ </Alert>+ ) : null}+ {/* TODO: only show if isAdmin */}+ <div className="flex justify-end">+ <InviteButton disabled={isLimit} />+ </div>+ <UserDataTable+ data={users.map(({ role, user }) => ({ role, ...user }))}+ columns={userColumns}+ />+ {invitations.length > 0 ? (+ <InvitationDataTable data={invitations} columns={invitationColumns} />+ ) : null}+ </div>+ );+}diff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/action-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/_components/action-button.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/action-button.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/_components/action-button.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/empty-state.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/_components/empty-state.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/_components/empty-state.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/_components/empty-state.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/_components/pro-feature-alert.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/edit/_components/pro-feature-alert.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/_components/pro-feature-alert.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/edit/_components/pro-feature-alert.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/edit/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/edit/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/edit/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/edit/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/edit/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-pages/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-pages/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/action-button.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/_components/action-button.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/action-button.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/_components/action-button.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/delete-status-update.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/_components/delete-status-update.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/delete-status-update.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/_components/delete-status-update.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/empty-state.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/_components/empty-state.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/empty-state.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/_components/empty-state.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/edit/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/edit/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/edit/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/edit/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/edit/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/update/edit/loading.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/loading.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/update/edit/loading.tsxdiff --git a/apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/update/edit/page.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/[workspaceSlug]/status-reports/update/edit/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/(dashboard)/status-reports/update/edit/page.tsxdiff --git a/apps/web/src/app/app/(dashboard)/onboarding/_components/description.tsx b/apps/web/src/app/app/[workspaceSlug]/onboarding/_components/description.tsxsimilarity index 100%rename from apps/web/src/app/app/(dashboard)/onboarding/_components/description.tsxrename to apps/web/src/app/app/[workspaceSlug]/onboarding/_components/description.tsxdiff --git a/apps/web/src/app/app/[workspaceSlug]/onboarding/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/onboarding/layout.tsxnew file mode 100644index 000000000..a56f82c11--- /dev/null+++ b/apps/web/src/app/app/[workspaceSlug]/onboarding/layout.tsx@@ -0,0 +1,27 @@+import * as React from "react";++import { Shell } from "@/components/dashboard/shell";+import { AppHeader } from "@/components/layout/app-header";+import { WorkspaceClientCookie } from "../worskpace-client-cookie";++// TODO: make the container min-h-screen and the footer below!+export default async function AppLayout({+ params,+ children,+}: {+ params: { workspaceSlug: string };+ children: React.ReactNode;+}) {+ const { workspaceSlug } = params;+ return (+ <div className="container relative mx-auto flex min-h-screen w-full flex-col items-center justify-center gap-6 p-4 lg:p-8">+ <AppHeader />+ <div className="flex w-full flex-1 gap-6 lg:gap-8">+ <main className="z-10 flex w-full flex-1 flex-col items-start justify-center">+ <Shell className="relative flex-1">{children}</Shell>+ </main>+ </div>+ <WorkspaceClientCookie {...{ workspaceSlug }} />+ </div>+ );+}diff --git a/apps/web/src/app/app/(dashboard)/onboarding/page.tsx b/apps/web/src/app/app/[workspaceSlug]/onboarding/page.tsxsimilarity index 86%rename from apps/web/src/app/app/(dashboard)/onboarding/page.tsxrename to apps/web/src/app/app/[workspaceSlug]/onboarding/page.tsxindex 07bf09974..65dac307d 100644--- a/apps/web/src/app/app/(dashboard)/onboarding/page.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/onboarding/page.tsx@@ -15,35 +15,24 @@ import { Description } from "./_components/description";*/const searchParamsSchema = z.object({id: z.coerce.number().optional(), // monitorId- workspaceSlug: z.string().optional(),});export default async function Onboarding({+ params,searchParams,}: {+ params: { workspaceSlug: string };searchParams: { [key: string]: string | string[] | undefined };}) {const search = searchParamsSchema.safeParse(searchParams);+ const { workspaceSlug } = params;if (!search.success) {return notFound();}// Instead of having the workspaceSlug in the search params, we can get it from the auth user- const { workspaceSlug, id: monitorId } = search.data;-- if (!workspaceSlug) {- return (- <div className="flex flex-col gap-3">- <p className="text-lg">Waiting for Slug </p>- <div>- <Button variant="outline" asChild>- <Link href="/app">Retry</Link>- </Button>- </div>- </div>- );- }+ const { id: monitorId } = search.data;const allMonitors = await api.monitor.getMonitorsByWorkspace.query();diff --git a/apps/web/src/app/app/[workspaceSlug]/worskpace-client-cookie.ts b/apps/web/src/app/app/[workspaceSlug]/worskpace-client-cookie.tsnew file mode 100644index 000000000..98a5eeeaa--- /dev/null+++ b/apps/web/src/app/app/[workspaceSlug]/worskpace-client-cookie.ts@@ -0,0 +1,22 @@+"use client";++import { useEffect } from "react";++/**+ * ISSUE: using the `middleware` to add a server httpOnly cookie doesn't work+ * req.nextUrl.pathname.startsWith("/app") is not true on the server as we are using the /api/trpc endpoint+ * to mutate our database. For some reasons, querying the database works fine.+ */++export function WorkspaceClientCookie({+ workspaceSlug,+}: {+ workspaceSlug: string;+}) {+ useEffect(() => {+ if (document) {+ document.cookie = `workspace-slug=${workspaceSlug}; path=/`;+ }+ }, [workspaceSlug]);+ return null;+}diff --git a/apps/web/src/app/app/(dashboard)/onboarding/layout.tsx b/apps/web/src/app/app/invite/layout.tsxsimilarity index 91%rename from apps/web/src/app/app/(dashboard)/onboarding/layout.tsxrename to apps/web/src/app/app/invite/layout.tsxindex 619d63f92..e4485cc58 100644--- a/apps/web/src/app/app/(dashboard)/onboarding/layout.tsx+++ b/apps/web/src/app/app/invite/layout.tsx@@ -3,7 +3,6 @@ import * as React from "react";import { Shell } from "@/components/dashboard/shell";import { AppHeader } from "@/components/layout/app-header";-// TODO: make the container min-h-screen and the footer below!export default async function AppLayout({children,}: {diff --git a/apps/web/src/app/app/invite/page.tsx b/apps/web/src/app/app/invite/page.tsxnew file mode 100644index 000000000..7eb6a8eb2--- /dev/null+++ b/apps/web/src/app/app/invite/page.tsx@@ -0,0 +1,34 @@+import Link from "next/link";+import { z } from "zod";++import { Button } from "@openstatus/ui";++import { api } from "@/trpc/server";++/**+ * allowed URL search params+ */+const searchParamsSchema = z.object({+ token: z.string(),+});++export default async function InvitePage({+ searchParams,+}: {+ searchParams: { [key: string]: string | string[] | undefined };+}) {+ const search = searchParamsSchema.safeParse(searchParams);++ const message = search.success+ ? await api.invitation.acceptInvitation.mutate({ token: search.data.token })+ : "Invalid token";++ return (+ <div className="flex h-full flex-1 flex-col items-center justify-center gap-4">+ <p className="text-muted-foreground text-lg">{message}</p>+ <Button>+ <Link href="/app">Dashboard</Link>+ </Button>+ </div>+ );+}diff --git a/apps/web/src/components/data-table/invitation/columns.tsx b/apps/web/src/components/data-table/invitation/columns.tsxnew file mode 100644index 000000000..a2691a751--- /dev/null+++ b/apps/web/src/components/data-table/invitation/columns.tsx@@ -0,0 +1,47 @@+"use client";++import type { ColumnDef } from "@tanstack/react-table";++import type { Invitation, WorkspaceRole } from "@openstatus/db/src/schema";+import { Badge } from "@openstatus/ui";++import { formatDate } from "@/lib/utils";+import { DataTableRowActions } from "./data-table-row-actions";++// TODO: add total number of monitors++export const columns: ColumnDef<Invitation>[] = [+ {+ accessorKey: "email",+ header: "Email",+ },+ {+ accessorKey: "role",+ header: "Role",+ cell: ({ row }) => {+ const role = row.getValue("role") as WorkspaceRole;+ return (+ <Badge variant={role === "member" ? "outline" : "default"}>+ {row.getValue("role")}+ </Badge>+ );+ },+ },+ {+ accessorKey: "expiresAt",+ header: "Expires at",+ cell: ({ row }) => {+ return <span>{formatDate(row.getValue("expiresAt"))}</span>;+ },+ },+ {+ id: "actions",+ cell: ({ row }) => {+ return (+ <div className="text-right">+ <DataTableRowActions row={row} />+ </div>+ );+ },+ },+];diff --git a/apps/web/src/components/data-table/invitation/data-table-row-actions.tsx b/apps/web/src/components/data-table/invitation/data-table-row-actions.tsxnew file mode 100644index 000000000..30add013d--- /dev/null+++ b/apps/web/src/components/data-table/invitation/data-table-row-actions.tsx@@ -0,0 +1,83 @@+"use client";++import * as React from "react";+import { useRouter } from "next/navigation";+import type { Row } from "@tanstack/react-table";++import { selectInvitationSchema } from "@openstatus/db/src/schema";+import {+ AlertDialog,+ AlertDialogAction,+ AlertDialogCancel,+ AlertDialogContent,+ AlertDialogDescription,+ AlertDialogFooter,+ AlertDialogHeader,+ AlertDialogTitle,+ AlertDialogTrigger,+ Button,+} from "@openstatus/ui";++import { LoadingAnimation } from "@/components/loading-animation";+import { useToastAction } from "@/hooks/use-toast-action";+import { api } from "@/trpc/client";++interface DataTableRowActionsProps<TData> {+ row: Row<TData>;+}++export function DataTableRowActions<TData>({+ row,+}: DataTableRowActionsProps<TData>) {+ const invitation = selectInvitationSchema.parse(row.original);+ const router = useRouter();+ const { toast } = useToastAction();+ const [alertOpen, setAlertOpen] = React.useState(false);+ const [isPending, startTransition] = React.useTransition();++ async function onRevoke() {+ startTransition(async () => {+ try {+ if (!invitation.id) return;+ await api.invitation.delete.mutate({ id: invitation.id });+ toast("deleted");+ router.refresh();+ setAlertOpen(false);+ } catch {+ toast("error");+ }+ });+ }++ return (+ <AlertDialog open={alertOpen} onOpenChange={(value) => setAlertOpen(value)}>+ <AlertDialogTrigger asChild>+ <Button variant="outline" size="sm">+ Revoke+ </Button>+ </AlertDialogTrigger>+ <AlertDialogContent>+ <AlertDialogHeader>+ <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>+ <AlertDialogDescription>+ The invitation will be revoked and the user will no longer be able+ to join the workspace.+ </AlertDialogDescription>+ </AlertDialogHeader>+ <AlertDialogFooter>+ <AlertDialogCancel>Cancel</AlertDialogCancel>+ <AlertDialogAction+ onClick={(e) => {+ e.preventDefault();+ onRevoke();+ }}+ disabled={isPending}+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"+ >+ {!isPending ? "Revoke" : <LoadingAnimation />}+ </AlertDialogAction>+ </AlertDialogFooter>+ </AlertDialogContent>+ </AlertDialog>+ );+}diff --git a/apps/web/src/components/data-table/invitation/data-table.tsx b/apps/web/src/components/data-table/invitation/data-table.tsxnew file mode 100644index 000000000..bbe2814b4--- /dev/null+++ b/apps/web/src/components/data-table/invitation/data-table.tsx@@ -0,0 +1,81 @@+"use client";++import * as React from "react";+import type { ColumnDef } from "@tanstack/react-table";+import {+ flexRender,+ getCoreRowModel,+ useReactTable,+} from "@tanstack/react-table";++import {+ Table,+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+} from "@openstatus/ui";++interface DataTableProps<TData, TValue> {+ columns: ColumnDef<TData, TValue>[];+ data: TData[];+}++export function DataTable<TData, TValue>({+ columns,+ data,+}: DataTableProps<TData, TValue>) {+ const table = useReactTable({+ data,+ columns,+ getCoreRowModel: getCoreRowModel(),+ });++ return (+ <div className="rounded-md border">+ <Table>+ <TableHeader className="bg-muted/50">+ {table.getHeaderGroups().map((headerGroup) => (+ <TableRow key={headerGroup.id} className="hover:bg-transparent">+ {headerGroup.headers.map((header) => {+ return (+ <TableHead key={header.id}>+ {header.isPlaceholder+ ? null+ : flexRender(+ header.column.columnDef.header,+ header.getContext(),+ )}+ </TableHead>+ );+ })}+ </TableRow>+ ))}+ </TableHeader>+ <TableBody>+ {table.getRowModel().rows?.length ? (+ table.getRowModel().rows.map((row) => (+ <TableRow+ key={row.id}+ data-state={row.getIsSelected() && "selected"}+ >+ {row.getVisibleCells().map((cell) => (+ <TableCell key={cell.id}>+ {flexRender(cell.column.columnDef.cell, cell.getContext())}+ </TableCell>+ ))}+ </TableRow>+ ))+ ) : (+ <TableRow>+ <TableCell colSpan={columns.length} className="h-24 text-center">+ No results.+ </TableCell>+ </TableRow>+ )}+ </TableBody>+ </Table>+ </div>+ );+}diff --git a/apps/web/src/components/data-table/user/columns.tsx b/apps/web/src/components/data-table/user/columns.tsxindex cf9a400c8..747f472a7 100644--- a/apps/web/src/components/data-table/user/columns.tsx+++ b/apps/web/src/components/data-table/user/columns.tsx@@ -2,14 +2,15 @@import type { ColumnDef } from "@tanstack/react-table";-import type { User } from "@openstatus/db/src/schema";+import type { User, WorkspaceRole } from "@openstatus/db/src/schema";+import { Badge } from "@openstatus/ui";import { formatDate } from "@/lib/utils";import { DataTableRowActions } from "./data-table-row-actions";// TODO: add total number of monitors-export const columns: ColumnDef<User>[] = [+export const columns: ColumnDef<User & { role: WorkspaceRole }>[] = [{accessorKey: "email",header: "Email",@@ -24,6 +25,18 @@ export const columns: ColumnDef<User>[] = [);},},+ {+ accessorKey: "role",+ header: "Role",+ cell: ({ row }) => {+ const role = row.getValue("role") as WorkspaceRole;+ return (+ <Badge variant={role === "member" ? "outline" : "default"}>+ {row.getValue("role")}+ </Badge>+ );+ },+ },{accessorKey: "createdAt",header: "Created",diff --git a/apps/web/src/components/layout/app-sidebar.tsx b/apps/web/src/components/layout/app-sidebar.tsxindex b16b215d6..ac0c48581 100644--- a/apps/web/src/components/layout/app-sidebar.tsx+++ b/apps/web/src/components/layout/app-sidebar.tsx@@ -3,10 +3,13 @@import Link from "next/link";import { useParams, usePathname } from "next/navigation";+import type { Workspace } from "@openstatus/db/src/schema";+import { pagesConfig } from "@/config/pages";import { cn } from "@/lib/utils";import { ProBanner } from "../billing/pro-banner";import { Icons } from "../icons";+import { SelectWorkspace } from "../workspace/select-workspace";export function AppSidebar() {const pathname = usePathname();@@ -41,17 +44,7 @@ export function AppSidebar() {<ProBanner /></li><li className="w-full">- <Link- href={`/app/${params?.workspaceSlug}/settings`}- className={cn(- "hover:bg-muted/50 hover:text-foreground text-muted-foreground group flex w-full min-w-[200px] items-center rounded-md border border-transparent px-3 py-1",- pathname?.startsWith(`/app/${params?.workspaceSlug}/settings`) &&- "bg-muted/50 border-border text-foreground",- )}- >- <Icons.cog className={cn("mr-2 h-4 w-4")} />- Settings- </Link>+ <SelectWorkspace /></li></ul></div>diff --git a/apps/web/src/components/status-update/events.tsx b/apps/web/src/components/status-update/events.tsxindex 44aa8339b..a2739faf0 100644--- a/apps/web/src/components/status-update/events.tsx+++ b/apps/web/src/components/status-update/events.tsx@@ -14,7 +14,7 @@ import {TooltipTrigger,} from "@openstatus/ui";-import { DeleteStatusReportUpdateButtonIcon } from "@/app/app/(dashboard)/[workspaceSlug]/status-reports/_components/delete-status-update";+import { DeleteStatusReportUpdateButtonIcon } from "@/app/app/[workspaceSlug]/(dashboard)/status-reports/_components/delete-status-update";import { Icons } from "@/components/icons";import { statusDict } from "@/data/incidents-dictionary";import { useProcessor } from "@/hooks/use-preprocessor";diff --git a/apps/web/src/components/workspace/select-workspace.tsx b/apps/web/src/components/workspace/select-workspace.tsxnew file mode 100644index 000000000..6e0446af9--- /dev/null+++ b/apps/web/src/components/workspace/select-workspace.tsx@@ -0,0 +1,85 @@+"use client";++import * as React from "react";+import Link from "next/link";+import { usePathname } from "next/navigation";+import { Check, ChevronsUpDown, Plus } from "lucide-react";++import type { Workspace } from "@openstatus/db/src/schema";+import {+ Button,+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+ Skeleton,+} from "@openstatus/ui";++import { api } from "@/trpc/client";++export function SelectWorkspace() {+ const [workspaces, setWorkspaces] = React.useState<Workspace[]>([]);+ const [active, setActive] = React.useState<string>();+ const pathname = usePathname();++ React.useEffect(() => {+ if (pathname?.split("/")?.[2] && workspaces.length > 0) {+ setActive(pathname?.split("/")?.[2]);+ }+ }, [pathname, workspaces]);++ React.useEffect(() => {+ // REMINDER: avoid prop drilling to get data from the layout.tsx component. instead use client trpc+ async function fetchWorkspaces() {+ const _workspaces = await api.workspace.getUserWorkspaces.query();+ setWorkspaces(_workspaces);+ }+ fetchWorkspaces();+ }, []);++ return (+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <Button+ variant="outline"+ className="flex w-full items-center justify-between"+ >+ {active ? <span>{active}</span> : <Skeleton className="h-5 w-full" />}+ <ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent className="w-[var(--radix-dropdown-menu-trigger-width)]">+ <DropdownMenuLabel>Workspaces</DropdownMenuLabel>+ <DropdownMenuSeparator />+ {workspaces.map((workspace) => (+ <DropdownMenuItem+ key={workspace.id}+ onClick={() => {+ if (workspace.slug !== active) {+ window.location.href = `/app/${workspace.slug}/monitors`;+ }+ }}+ className="justify-between"+ >+ {workspace.slug}+ {active === workspace.slug ? (+ <Check className="ml-2 h-4 w-4" />+ ) : null}+ </DropdownMenuItem>+ ))}+ <DropdownMenuSeparator />+ <DropdownMenuItem asChild>+ <Link+ href={`/app/${active}/settings/team`}+ className="flex items-center justify-between"+ >+ Invite Members+ <Plus className="ml-2 h-4 w-4" />+ </Link>+ </DropdownMenuItem>+ </DropdownMenuContent>+ </DropdownMenu>+ );+}diff --git a/apps/web/src/config/pages.ts b/apps/web/src/config/pages.tsindex b2424e20b..244cea170 100644--- a/apps/web/src/config/pages.ts+++ b/apps/web/src/config/pages.ts@@ -34,6 +34,12 @@ export const pagesConfig: Page[] = [href: "/notifications",icon: "bell",},+ {+ title: "Settings",+ description: "Your workspace settings",+ href: "/settings",+ icon: "cog",+ },// {// title: "Integrations",// description: "Where you can see all the integrations.",diff --git a/apps/web/src/middleware.ts b/apps/web/src/middleware.tsindex b169067c8..9dce17b3f 100644--- a/apps/web/src/middleware.ts+++ b/apps/web/src/middleware.ts@@ -83,7 +83,7 @@ export default authMiddleware({"/status-page/(.*)","/incidents", // used when trying subdomain slug via status.documenso.com/incidents],- ignoredRoutes: ["/api/og", "/discord", "github", "/status-page/(.*)"], // FIXME: we should check the `publicRoutes`+ ignoredRoutes: ["/api/og", "/discord", "/github", "/status-page/(.*)"], // FIXME: we should check the `publicRoutes`beforeAuth: before,debug: false,async afterAuth(auth, req) {@@ -126,7 +126,7 @@ export default authMiddleware({if (!firstMonitor) {console.log(`>>> Redirecting to onboarding`);const onboarding = new URL(- `/app/onboarding?workspaceSlug=${currentWorkspace.slug}`,+ `/app/${currentWorkspace.slug}/onboarding`,req.url,);return NextResponse.redirect(onboarding);@@ -148,6 +148,14 @@ export default authMiddleware({console.log("redirecting to onboarding");return;}++ if (auth.userId && req.nextUrl.pathname.startsWith("/app")) {+ const workspaceSlug = req.nextUrl.pathname.split("/")?.[2];+ // overrides the document.cookie set on the client+ if (workspaceSlug) req.cookies.set("workspace-slug", workspaceSlug);+ }++ // TODO: removeif (auth.userId &&req.nextUrl.pathname === "/app/integrations/vercel/configure"diff --git a/packages/api/src/analytics.ts b/packages/api/src/analytics.tsindex ae2807276..72e0db21c 100644--- a/packages/api/src/analytics.ts+++ b/packages/api/src/analytics.ts@@ -45,3 +45,5 @@ export async function trackNewNotification(}export async function trackNewStatusReport() {}++export async function trackNewInvitation() {}diff --git a/packages/api/src/edge.ts b/packages/api/src/edge.tsindex 99943b122..54c0ffb16 100644--- a/packages/api/src/edge.ts+++ b/packages/api/src/edge.ts@@ -1,5 +1,6 @@import { domainRouter } from "./router/domain";import { integrationRouter } from "./router/integration";+import { invitationRouter } from "./router/invitation";import { monitorRouter } from "./router/monitor";import { notificationRouter } from "./router/notification";import { pageRouter } from "./router/page";@@ -18,4 +19,5 @@ export const edgeRouter = createTRPCRouter({integration: integrationRouter,user: userRouter,notification: notificationRouter,+ invitation: invitationRouter});diff --git a/packages/api/src/router/clerk/webhook.ts b/packages/api/src/router/clerk/webhook.tsindex d9cc8e118..5d6e42a1a 100644--- a/packages/api/src/router/clerk/webhook.ts+++ b/packages/api/src/router/clerk/webhook.ts@@ -62,6 +62,7 @@ export const webhookRouter = createTRPCRouter({.values({userId: userResult.id,workspaceId: workspaceResult.id,+ role: "owner",}).returning().get();diff --git a/packages/api/src/router/invitation.ts b/packages/api/src/router/invitation.tsnew file mode 100644index 000000000..12bc9659b--- /dev/null+++ b/packages/api/src/router/invitation.ts@@ -0,0 +1,166 @@+import { TRPCError } from "@trpc/server";+import { z } from "zod";++import { and, eq, gte, isNull } from "@openstatus/db";+import {+ insertInvitationSchema,+ invitation,+ user,+ usersToWorkspaces,+} from "@openstatus/db/src/schema";+import { allPlans } from "@openstatus/plans";++import { trackNewInvitation } from "../analytics";+import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc";++export const invitationRouter = createTRPCRouter({+ create: protectedProcedure+ .input(insertInvitationSchema.pick({ email: true }))+ .mutation(async (opts) => {+ const { email } = opts.input;++ const membersLimit = allPlans[opts.ctx.workspace.plan].limits.members;++ const usersToWorkspacesNumbers = (+ await opts.ctx.db.query.usersToWorkspaces.findMany({+ where: eq(usersToWorkspaces.workspaceId, opts.ctx.workspace.id),+ })+ ).length;++ const openInvitationsNumbers = (+ await opts.ctx.db.query.invitation.findMany({+ where: and(+ eq(invitation.workspaceId, opts.ctx.workspace.id),+ gte(invitation.expiresAt, new Date()),+ isNull(invitation.acceptedAt),+ ),+ })+ ).length;++ // the user has reached the limits+ if (usersToWorkspacesNumbers + openInvitationsNumbers >= membersLimit) {+ throw new TRPCError({+ code: "FORBIDDEN",+ message: "You reached your member limits.",+ });+ }++ const expiresAt = new Date();+ expiresAt.setDate(expiresAt.getDate() + 7);++ const token = crypto.randomUUID();++ await fetch("https://api.resend.com/emails", {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ Authorization: `Bearer ${process.env.RESEND_API_KEY}`,+ },+ body: JSON.stringify({+ to: email,+ from: "Maximilian Kaske <[email protected]>",+ subject: `You have been invited to join OpenStatus.dev`,+ html: `<p>Click here to join the workspace: <a href='https://openstatus.dev/app/invite?token=${token}'>accept invitation</a></p>`,+ }),+ });++ const _invitation = await opts.ctx.db+ .insert(invitation)+ .values({ email, expiresAt, token, workspaceId: opts.ctx.workspace.id })+ .returning()+ .get();++ // TODO:+ await trackNewInvitation();++ return _invitation;+ }),++ delete: protectedProcedure+ .input(z.object({ id: z.number() }))+ .mutation(async (opts) => {+ await opts.ctx.db+ .delete(invitation)+ .where(+ and(+ eq(invitation.id, opts.input.id),+ eq(invitation.workspaceId, opts.ctx.workspace.id),+ ),+ )+ .run();+ }),++ getWorkspaceOpenInvitations: protectedProcedure.query(async (opts) => {+ const _invitations = await opts.ctx.db.query.invitation.findMany({+ where: and(+ eq(invitation.workspaceId, opts.ctx.workspace.id),+ gte(invitation.expiresAt, new Date()),+ isNull(invitation.acceptedAt),+ ),+ });+ return _invitations;+ }),++ getInvitationByToken: protectedProcedure+ .input(z.object({ token: z.string() }))+ .query(async (opts) => {+ const _invitation = await opts.ctx.db.query.invitation.findFirst({+ where: and(eq(invitation.token, opts.input.token)),+ with: {+ workspace: true,+ },+ });+ return _invitation;+ }),++ /**+ * REMINDER: we are not using a protected procedure here of the `/app/invite` url+ * instead of `/app/workspace-slug/invite` as the user is not allowed to it yet.+ * We validate the auth token in the `acceptInvitation` procedure+ */+ acceptInvitation: publicProcedure+ .input(z.object({ token: z.string() }))+ .mutation(async (opts) => {+ const _invitation = await opts.ctx.db.query.invitation.findFirst({+ where: and(+ eq(invitation.token, opts.input.token),+ isNull(invitation.acceptedAt),+ ),+ with: {+ workspace: true,+ },+ });++ const _user = await opts.ctx.db.query.user.findFirst({+ where: eq(user.tenantId, opts.ctx.auth?.userId || ""),+ });++ if (!_user) return "Invalid user";++ if (!_invitation) return "Invalid invitation token";++ if (_invitation.email !== _user.email)+ return "You are not invited to this workspace";++ if (_invitation.expiresAt.getTime() < new Date().getTime()) {+ return "Invitation expired";+ }++ await opts.ctx.db+ .update(invitation)+ .set({ acceptedAt: new Date() })+ .where(eq(invitation.id, _invitation.id))+ .run();++ await opts.ctx.db+ .insert(usersToWorkspaces)+ .values({+ userId: _user.id,+ workspaceId: _invitation.workspaceId,+ role: _invitation.role,+ })+ .run();++ return "Invitation accepted";+ }),+});diff --git a/packages/api/src/router/user.ts b/packages/api/src/router/user.tsindex d9ddc871f..b7df97ab4 100644--- a/packages/api/src/router/user.ts+++ b/packages/api/src/router/user.ts@@ -1,3 +1,5 @@+import { z } from "zod";+import { eq } from "@openstatus/db";import { user } from "@openstatus/db/src/schema";diff --git a/packages/api/src/router/workspace.ts b/packages/api/src/router/workspace.tsindex 754ace987..0dffe74ba 100644--- a/packages/api/src/router/workspace.ts+++ b/packages/api/src/router/workspace.ts@@ -33,6 +33,19 @@ export const workspaceRouter = createTRPCRouter({return selectWorkspaceSchema.parse(result);}),+ getUserWorkspaces: protectedProcedure.query(async (opts) => {+ const result = await opts.ctx.db.query.usersToWorkspaces.findMany({+ where: eq(usersToWorkspaces.userId, opts.ctx.user.id),+ with: {+ workspace: true,+ },+ });++ return selectWorkspaceSchema+ .array()+ .parse(result.map(({ workspace }) => workspace));+ }),+getWorkspaceUsers: protectedProcedure.query(async (opts) => {// const result = await opts.ctx.db// .select()@@ -48,7 +61,7 @@ export const workspaceRouter = createTRPCRouter({},where: eq(usersToWorkspaces.workspaceId, opts.ctx.workspace.id),});- return result.map(({ user }) => user);+ return result;}),createWorkspace: protectedProcedurediff --git a/packages/api/src/trpc.ts b/packages/api/src/trpc.tsindex 50344882e..983ff6ab9 100644--- a/packages/api/src/trpc.ts+++ b/packages/api/src/trpc.ts@@ -118,33 +118,63 @@ const enforceUserIsAuthed = t.middleware(async ({ ctx, next }) => {throw new TRPCError({ code: "UNAUTHORIZED" });}+ // /**+ // * Attach `user` and `workspace` | `activeWorkspace` infos to context by+ // * comparing the `user.tenantId` to clerk's `auth.userId`+ // */+ const userAndWorkspace = await db.query.user.findFirst({+ where: eq(schema.user.tenantId, ctx.auth.userId),+ with: {+ usersToWorkspaces: {+ with: {+ workspace: true,+ },+ },+ },+ });++ const { usersToWorkspaces, ...userProps } = userAndWorkspace || {};+/**- * Attach `user` and `workspace` infos to context by- * comparing the `user.tenantId` to clerk's `auth.userId`+ * We need to include the active "workspace-slug" cookie in the request found in the+ * `/app/[workspaceSlug]/.../`routes. We pass them either via middleware if it's a+ * server request or via the client cookie, set via `<WorspaceClientCookie />`+ * if it's a client request.+ *+ * REMINDER: We only need the client cookie because of client side mutations.*/- const query = await db- .select()- .from(schema.user)- .innerJoin(- schema.usersToWorkspaces,- eq(schema.usersToWorkspaces.userId, schema.user.id),- )- .innerJoin(- schema.workspace,- eq(schema.workspace.id, schema.usersToWorkspaces.workspaceId),- )- .where(eq(schema.user.tenantId, ctx.auth.userId))- .get();-- const workspace = schema.selectWorkspaceSchema.parse(query?.workspace);- const user = schema.selectUserSchema.parse(query?.user);-- if (!workspace && !user) {- throw new TRPCError({ code: "UNAUTHORIZED" });+ const workspaceSlug = ctx.req?.cookies.get("workspace-slug")?.value;++ // if (!workspaceSlug) {+ // throw new TRPCError({+ // code: "UNAUTHORIZED",+ // message: "Workspace Slug Not Found",+ // });+ // }++ const activeWorkspace = usersToWorkspaces?.find(({ workspace }) => {+ // If there is a workspace slug in the cookie, use it to find the workspace+ if (workspaceSlug) return workspace.slug === workspaceSlug;+ return true;+ })?.workspace;++ if (!activeWorkspace) {+ throw new TRPCError({+ code: "UNAUTHORIZED",+ message: "Workspace Not Found",+ });+ }++ if (!userProps) {+ throw new TRPCError({ code: "UNAUTHORIZED", message: "User Not Found" });}+ const user = schema.selectUserSchema.parse(userProps);+ const workspace = schema.selectWorkspaceSchema.parse(activeWorkspace);+return next({ctx: {+ ...ctx,auth: {...ctx.auth,userId: ctx.auth.userId,diff --git a/packages/db/drizzle/0012_tan_magma.sql b/packages/db/drizzle/0012_tan_magma.sqlnew file mode 100644index 000000000..703c19d1c--- /dev/null+++ b/packages/db/drizzle/0012_tan_magma.sql@@ -0,0 +1,12 @@+CREATE TABLE `invitation` (+ `id` integer PRIMARY KEY NOT NULL,+ `email` text NOT NULL,+ `role` text DEFAULT 'member' NOT NULL,+ `workspace_id` integer NOT NULL,+ `token` text NOT NULL,+ `expires_at` integer NOT NULL,+ `created_at` integer DEFAULT (strftime('%s', 'now')),+ `accepted_at` integer+);+--> statement-breakpoint+ALTER TABLE users_to_workspaces ADD `role` text DEFAULT 'owner' NOT NULL;\ No newline at end of filediff --git a/packages/db/drizzle/meta/0012_snapshot.json b/packages/db/drizzle/meta/0012_snapshot.jsonnew file mode 100644index 000000000..0732e5000--- /dev/null+++ b/packages/db/drizzle/meta/0012_snapshot.json@@ -0,0 +1,1169 @@+{+ "version": "5",+ "dialect": "sqlite",+ "id": "b5c53ce9-981d-4a7c-a0da-c82e517fc0a3",+ "prevId": "21a5d3a2-6aab-4f67-8385-19d905e1a232",+ "tables": {+ "status_report_to_monitors": {+ "name": "status_report_to_monitors",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status_report_id": {+ "name": "status_report_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_report_to_monitors_monitor_id_monitor_id_fk": {+ "name": "status_report_to_monitors_monitor_id_monitor_id_fk",+ "tableFrom": "status_report_to_monitors",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "status_report_to_monitors_status_report_id_status_report_id_fk": {+ "name": "status_report_to_monitors_status_report_id_status_report_id_fk",+ "tableFrom": "status_report_to_monitors",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "status_report_to_monitors_monitor_id_status_report_id_pk": {+ "columns": [+ "monitor_id",+ "status_report_id"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "status_reports_to_pages": {+ "name": "status_reports_to_pages",+ "columns": {+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status_report_id": {+ "name": "status_report_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_reports_to_pages_page_id_page_id_fk": {+ "name": "status_reports_to_pages_page_id_page_id_fk",+ "tableFrom": "status_reports_to_pages",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "status_reports_to_pages_status_report_id_status_report_id_fk": {+ "name": "status_reports_to_pages_status_report_id_status_report_id_fk",+ "tableFrom": "status_reports_to_pages",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "status_reports_to_pages_page_id_status_report_id_pk": {+ "columns": [+ "page_id",+ "status_report_id"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "status_report": {+ "name": "status_report",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_report_workspace_id_workspace_id_fk": {+ "name": "status_report_workspace_id_workspace_id_fk",+ "tableFrom": "status_report",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "status_report_update": {+ "name": "status_report_update",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "status": {+ "name": "status",+ "type": "text(4)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "date": {+ "name": "date",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "message": {+ "name": "message",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "status_report_id": {+ "name": "status_report_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "status_report_update_status_report_id_status_report_id_fk": {+ "name": "status_report_update_status_report_id_status_report_id_fk",+ "tableFrom": "status_report_update",+ "tableTo": "status_report",+ "columnsFrom": [+ "status_report_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "integration": {+ "name": "integration",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "credential": {+ "name": "credential",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "external_id": {+ "name": "external_id",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "data": {+ "name": "data",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "integration_workspace_id_workspace_id_fk": {+ "name": "integration_workspace_id_workspace_id_fk",+ "tableFrom": "integration",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "page": {+ "name": "page",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "title": {+ "name": "title",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "icon": {+ "name": "icon",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "slug": {+ "name": "slug",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "custom_domain": {+ "name": "custom_domain",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "published": {+ "name": "published",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "page_slug_unique": {+ "name": "page_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {+ "page_workspace_id_workspace_id_fk": {+ "name": "page_workspace_id_workspace_id_fk",+ "tableFrom": "page",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "monitor": {+ "name": "monitor",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "job_type": {+ "name": "job_type",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'other'"+ },+ "periodicity": {+ "name": "periodicity",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'other'"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'active'"+ },+ "active": {+ "name": "active",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": false+ },+ "regions": {+ "name": "regions",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "url": {+ "name": "url",+ "type": "text(2048)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "description": {+ "name": "description",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "headers": {+ "name": "headers",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "body": {+ "name": "body",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "method": {+ "name": "method",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'GET'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitor_workspace_id_workspace_id_fk": {+ "name": "monitor_workspace_id_workspace_id_fk",+ "tableFrom": "monitor",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "monitors_to_pages": {+ "name": "monitors_to_pages",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "page_id": {+ "name": "page_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "monitors_to_pages_monitor_id_monitor_id_fk": {+ "name": "monitors_to_pages_monitor_id_monitor_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "monitors_to_pages_page_id_page_id_fk": {+ "name": "monitors_to_pages_page_id_page_id_fk",+ "tableFrom": "monitors_to_pages",+ "tableTo": "page",+ "columnsFrom": [+ "page_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitors_to_pages_monitor_id_page_id_pk": {+ "columns": [+ "monitor_id",+ "page_id"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "user": {+ "name": "user",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "tenant_id": {+ "name": "tenant_id",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "first_name": {+ "name": "first_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "last_name": {+ "name": "last_name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "photo_url": {+ "name": "photo_url",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "''"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "user_tenant_id_unique": {+ "name": "user_tenant_id_unique",+ "columns": [+ "tenant_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "users_to_workspaces": {+ "name": "users_to_workspaces",+ "columns": {+ "user_id": {+ "name": "user_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'member'"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "users_to_workspaces_user_id_user_id_fk": {+ "name": "users_to_workspaces_user_id_user_id_fk",+ "tableFrom": "users_to_workspaces",+ "tableTo": "user",+ "columnsFrom": [+ "user_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ },+ "users_to_workspaces_workspace_id_workspace_id_fk": {+ "name": "users_to_workspaces_workspace_id_workspace_id_fk",+ "tableFrom": "users_to_workspaces",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "users_to_workspaces_user_id_workspace_id_pk": {+ "columns": [+ "user_id",+ "workspace_id"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "workspace": {+ "name": "workspace",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "slug": {+ "name": "slug",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "stripe_id": {+ "name": "stripe_id",+ "type": "text(256)",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "subscription_id": {+ "name": "subscription_id",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "plan": {+ "name": "plan",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "ends_at": {+ "name": "ends_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "paid_until": {+ "name": "paid_until",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "workspace_slug_unique": {+ "name": "workspace_slug_unique",+ "columns": [+ "slug"+ ],+ "isUnique": true+ },+ "workspace_stripe_id_unique": {+ "name": "workspace_stripe_id_unique",+ "columns": [+ "stripe_id"+ ],+ "isUnique": true+ }+ },+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "notification": {+ "name": "notification",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "name": {+ "name": "name",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "provider": {+ "name": "provider",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "data": {+ "name": "data",+ "type": "text",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "'{}'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {},+ "foreignKeys": {+ "notification_workspace_id_workspace_id_fk": {+ "name": "notification_workspace_id_workspace_id_fk",+ "tableFrom": "notification",+ "tableTo": "workspace",+ "columnsFrom": [+ "workspace_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "no action",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ },+ "notifications_to_monitors": {+ "name": "notifications_to_monitors",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "notification_id": {+ "name": "notification_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {+ "notifications_to_monitors_monitor_id_monitor_id_fk": {+ "name": "notifications_to_monitors_monitor_id_monitor_id_fk",+ "tableFrom": "notifications_to_monitors",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ },+ "notifications_to_monitors_notification_id_notification_id_fk": {+ "name": "notifications_to_monitors_notification_id_notification_id_fk",+ "tableFrom": "notifications_to_monitors",+ "tableTo": "notification",+ "columnsFrom": [+ "notification_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "notifications_to_monitors_monitor_id_notification_id_pk": {+ "columns": [+ "monitor_id",+ "notification_id"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "monitor_status": {+ "name": "monitor_status",+ "columns": {+ "monitor_id": {+ "name": "monitor_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "region": {+ "name": "region",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "''"+ },+ "status": {+ "name": "status",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'active'"+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "updated_at": {+ "name": "updated_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ }+ },+ "indexes": {+ "monitor_status_idx": {+ "name": "monitor_status_idx",+ "columns": [+ "monitor_id",+ "region"+ ],+ "isUnique": false+ }+ },+ "foreignKeys": {+ "monitor_status_monitor_id_monitor_id_fk": {+ "name": "monitor_status_monitor_id_monitor_id_fk",+ "tableFrom": "monitor_status",+ "tableTo": "monitor",+ "columnsFrom": [+ "monitor_id"+ ],+ "columnsTo": [+ "id"+ ],+ "onDelete": "cascade",+ "onUpdate": "no action"+ }+ },+ "compositePrimaryKeys": {+ "monitor_status_monitor_id_region_pk": {+ "columns": [+ "monitor_id",+ "region"+ ]+ }+ },+ "uniqueConstraints": {}+ },+ "invitation": {+ "name": "invitation",+ "columns": {+ "id": {+ "name": "id",+ "type": "integer",+ "primaryKey": true,+ "notNull": true,+ "autoincrement": false+ },+ "email": {+ "name": "email",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "role": {+ "name": "role",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false,+ "default": "'member'"+ },+ "workspace_id": {+ "name": "workspace_id",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "token": {+ "name": "token",+ "type": "text",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "expires_at": {+ "name": "expires_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": true,+ "autoincrement": false+ },+ "created_at": {+ "name": "created_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false,+ "default": "(strftime('%s', 'now'))"+ },+ "accepted_at": {+ "name": "accepted_at",+ "type": "integer",+ "primaryKey": false,+ "notNull": false,+ "autoincrement": false+ }+ },+ "indexes": {},+ "foreignKeys": {},+ "compositePrimaryKeys": {},+ "uniqueConstraints": {}+ }+ },+ "enums": {},+ "_meta": {+ "schemas": {},+ "tables": {},+ "columns": {}+ }+}\ No newline at end of filediff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.jsonindex fc6ef345c..5868d9d11 100644--- a/packages/db/drizzle/meta/_journal.json+++ b/packages/db/drizzle/meta/_journal.json@@ -85,6 +85,13 @@"when": 1701100570578,"tag": "0011_bright_jazinda","breakpoints": true+ },+ {+ "idx": 12,+ "version": "5",+ "when": 1701713135829,+ "tag": "0012_tan_magma",+ "breakpoints": true}]-}+}\ No newline at end of filediff --git a/packages/db/src/schema/index.ts b/packages/db/src/schema/index.tsindex 0a96d55ce..97ed69175 100644--- a/packages/db/src/schema/index.ts+++ b/packages/db/src/schema/index.ts@@ -7,3 +7,4 @@ export * from "./workspaces";export * from "./shared";export * from "./notifications";export * from "./monitor_status";+export * from "./invitations";diff --git a/packages/db/src/schema/invitations/index.ts b/packages/db/src/schema/invitations/index.tsnew file mode 100644index 000000000..f119ca093--- /dev/null+++ b/packages/db/src/schema/invitations/index.ts@@ -0,0 +1,2 @@+export * from "./invitation";+export * from "./validation";diff --git a/packages/db/src/schema/invitations/invitation.ts b/packages/db/src/schema/invitations/invitation.tsnew file mode 100644index 000000000..ca4a08a20--- /dev/null+++ b/packages/db/src/schema/invitations/invitation.ts@@ -0,0 +1,24 @@+import { relations, sql } from "drizzle-orm";+import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";++import { workspace, workspaceRole } from "../workspaces";++export const invitation = sqliteTable("invitation", {+ id: integer("id").primaryKey(),+ email: text("email").notNull(),+ role: text("role", { enum: workspaceRole }).notNull().default("member"),+ workspaceId: integer("workspace_id").notNull(),+ token: text("token").notNull(),+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),+ createdAt: integer("created_at", { mode: "timestamp" }).default(+ sql`(strftime('%s', 'now'))`,+ ),+ acceptedAt: integer("accepted_at", { mode: "timestamp" }),+});++export const invitationRelations = relations(invitation, ({ one }) => ({+ workspace: one(workspace, {+ fields: [invitation.workspaceId],+ references: [workspace.id],+ }),+}));diff --git a/packages/db/src/schema/invitations/validation.ts b/packages/db/src/schema/invitations/validation.tsnew file mode 100644index 000000000..340f00173--- /dev/null+++ b/packages/db/src/schema/invitations/validation.ts@@ -0,0 +1,13 @@+import { createInsertSchema, createSelectSchema } from "drizzle-zod";+import { z } from "zod";++import { invitation } from "./invitation";++export const insertInvitationSchema = createInsertSchema(invitation, {+ email: z.string().email(),+});++export const selectInvitationSchema = createSelectSchema(invitation);++export type InsertInvitation = z.infer<typeof insertInvitationSchema>;+export type Invitation = z.infer<typeof selectInvitationSchema>;diff --git a/packages/db/src/schema/users/user.ts b/packages/db/src/schema/users/user.tsindex 5b10f39e2..9cf5aeccd 100644--- a/packages/db/src/schema/users/user.ts+++ b/packages/db/src/schema/users/user.ts@@ -6,7 +6,7 @@ import {text,} from "drizzle-orm/sqlite-core";-import { workspace } from "../workspaces";+import { workspace, workspaceRole } from "../workspaces";export const user = sqliteTable("user", {id: integer("id").primaryKey(),@@ -38,6 +38,7 @@ export const usersToWorkspaces = sqliteTable(workspaceId: integer("workspace_id").notNull().references(() => workspace.id),+ role: text("role", { enum: workspaceRole }).notNull().default("member"),},(t) => ({pk: primaryKey(t.userId, t.workspaceId),diff --git a/packages/db/src/schema/workspaces/constants.ts b/packages/db/src/schema/workspaces/constants.tsindex 650c6c9b5..2d7b13f49 100644--- a/packages/db/src/schema/workspaces/constants.ts+++ b/packages/db/src/schema/workspaces/constants.ts@@ -1 +1,2 @@export const workspacePlans = ["free", "pro"] as const;+export const workspaceRole = ["owner", "admin", "member"] as const;diff --git a/packages/db/src/schema/workspaces/validation.ts b/packages/db/src/schema/workspaces/validation.tsindex a102ac8de..0b247ba74 100644--- a/packages/db/src/schema/workspaces/validation.ts+++ b/packages/db/src/schema/workspaces/validation.ts@@ -1,10 +1,11 @@import { createSelectSchema } from "drizzle-zod";import { z } from "zod";-import { workspacePlans } from "./constants";+import { workspacePlans, workspaceRole } from "./constants";import { workspace } from "./workspace";export const workspacePlanSchema = z.enum(workspacePlans);+export const workspaceRoleSchema = z.enum(workspaceRole);export const selectWorkspaceSchema = createSelectSchema(workspace).extend({plan: z@@ -18,3 +19,4 @@ export const insertWorkspaceSchema = createSelectSchema(workspace);export type Workspace = z.infer<typeof selectWorkspaceSchema>;export type WorkspacePlan = z.infer<typeof workspacePlanSchema>;+export type WorkspaceRole = z.infer<typeof workspaceRoleSchema>;diff --git a/packages/plans/index.ts b/packages/plans/index.tsindex c70800cba..246832881 100644--- a/packages/plans/index.ts+++ b/packages/plans/index.ts@@ -5,6 +5,7 @@ export type Plan = {monitors: number;"status-pages": number;periodicity: Partial<MonitorPeriodicity>[];+ members: number;};};@@ -14,6 +15,7 @@ export const allPlans: Record<"free" | "pro", Plan> = {monitors: 5,"status-pages": 1,periodicity: ["10m", "30m", "1h"],+ members: 1,},},pro: {@@ -21,6 +23,7 @@ export const allPlans: Record<"free" | "pro", Plan> = {monitors: 20,"status-pages": 5,periodicity: ["1m", "5m", "10m", "30m", "1h"],+ members: 5,},},};