feat(db): mesh data model — meshes, members, invites, audit log
- pgSchema "mesh" with 4 tables isolating the peer mesh domain - Enums: visibility, transport, tier, role - audit_log is metadata-only (E2E encryption enforced at broker/client) - Cascade on mesh delete, soft-delete via archivedAt/revokedAt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
176
apps/web/src/modules/common/layout/dashboard/action-bar.tsx
Normal file
176
apps/web/src/modules/common/layout/dashboard/action-bar.tsx
Normal file
@@ -0,0 +1,176 @@
|
||||
"use client";
|
||||
|
||||
import { usePathname } from "next/navigation";
|
||||
import { Fragment } from "react";
|
||||
import * as z from "zod";
|
||||
|
||||
import { isKey, useTranslation } from "@turbostarter/i18n";
|
||||
import {
|
||||
Breadcrumb,
|
||||
BreadcrumbItem,
|
||||
BreadcrumbLink,
|
||||
BreadcrumbList,
|
||||
BreadcrumbPage,
|
||||
BreadcrumbSeparator,
|
||||
} from "@turbostarter/ui-web/breadcrumb";
|
||||
import { buttonVariants } from "@turbostarter/ui-web/button";
|
||||
import { Icons } from "@turbostarter/ui-web/icons";
|
||||
import { Separator } from "@turbostarter/ui-web/separator";
|
||||
import { SidebarTrigger } from "@turbostarter/ui-web/sidebar";
|
||||
|
||||
import { pathsConfig } from "~/config/paths";
|
||||
import { TurboLink } from "~/modules/common/turbo-link";
|
||||
|
||||
const ROOT_KEY = "home";
|
||||
|
||||
const indexSchema = z.object({
|
||||
index: z.string(),
|
||||
});
|
||||
|
||||
const hasIndex = (value: unknown): value is z.infer<typeof indexSchema> => {
|
||||
return indexSchema.safeParse(value).success;
|
||||
};
|
||||
|
||||
const getDisplayKey = (rawKey: string, hasPrevious: boolean) => {
|
||||
if (rawKey === "index") return hasPrevious ? null : ROOT_KEY;
|
||||
return rawKey;
|
||||
};
|
||||
const isSkippedKey = (key: string) => ["user", "organization"].includes(key);
|
||||
|
||||
const addCrumb = (
|
||||
trail: { key: string; path?: string }[],
|
||||
rawKey: string,
|
||||
path?: string,
|
||||
) => {
|
||||
const displayKey = getDisplayKey(rawKey, trail.length > 0);
|
||||
if (!displayKey || isSkippedKey(rawKey)) return trail;
|
||||
return [...trail, { key: displayKey, path }];
|
||||
};
|
||||
|
||||
const getPath = (
|
||||
obj: unknown,
|
||||
target: string,
|
||||
current: { key: string; path?: string }[] = [],
|
||||
): { key: string; path?: string }[] | null => {
|
||||
if (!obj || typeof obj !== "object") return null;
|
||||
|
||||
for (const [rawKey, value] of Object.entries(
|
||||
obj as Record<string, unknown>,
|
||||
)) {
|
||||
if (typeof value === "string") {
|
||||
if (value === target) return addCrumb(current, rawKey, value);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof value === "function") {
|
||||
const candidates = target.split("/").filter(Boolean);
|
||||
for (const candidate of candidates) {
|
||||
try {
|
||||
const result = (value as (arg: string) => unknown)(candidate);
|
||||
if (typeof result === "string") {
|
||||
if (result === target) return addCrumb(current, rawKey, result);
|
||||
} else if (result && typeof result === "object") {
|
||||
const parentPath = addCrumb(
|
||||
current,
|
||||
rawKey,
|
||||
hasIndex(result) ? result.index : undefined,
|
||||
);
|
||||
const found = getPath(result, target, parentPath);
|
||||
if (found) return found;
|
||||
}
|
||||
} catch {
|
||||
// Ignore callable errors and continue trying other candidates
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value && typeof value === "object") {
|
||||
const parentPath = addCrumb(
|
||||
current,
|
||||
rawKey,
|
||||
hasIndex(value) ? value.index : undefined,
|
||||
);
|
||||
const found = getPath(value, target, parentPath);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const DashboardActionBar = () => {
|
||||
const { t, i18n } = useTranslation("common");
|
||||
const pathname = usePathname();
|
||||
|
||||
const rawPath = getPath(pathsConfig, pathname);
|
||||
const path =
|
||||
rawPath?.length === 1 ? [{ ...rawPath[0], key: ROOT_KEY }] : rawPath;
|
||||
|
||||
const last = path?.at(-1);
|
||||
|
||||
return (
|
||||
<header className="flex h-16 shrink-0 items-center justify-between gap-2 px-4 transition-[width,height] ease-linear md:px-6 lg:px-7">
|
||||
<div className="flex items-center gap-2 pr-4">
|
||||
<SidebarTrigger className="-ml-1" />
|
||||
{path ? (
|
||||
<>
|
||||
<Separator orientation="vertical" className="mr-2 h-4" />
|
||||
<Breadcrumb>
|
||||
<BreadcrumbList>
|
||||
{path.length > 1 &&
|
||||
path.slice(1, -1).map((item, index, array) => (
|
||||
<Fragment key={item.key}>
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbLink asChild>
|
||||
<TurboLink href={item.path ?? "#"}>
|
||||
{isKey(item.key, i18n, "common")
|
||||
? t(item.key)
|
||||
: item.key}
|
||||
</TurboLink>
|
||||
</BreadcrumbLink>
|
||||
</BreadcrumbItem>
|
||||
{index < array.length - 1 && <BreadcrumbSeparator />}
|
||||
</Fragment>
|
||||
))}
|
||||
|
||||
{last && (
|
||||
<>
|
||||
{path.length > 2 && <BreadcrumbSeparator />}
|
||||
<BreadcrumbItem>
|
||||
<BreadcrumbPage>
|
||||
{isKey(last.key, i18n, "common")
|
||||
? t(last.key)
|
||||
: last.key}
|
||||
</BreadcrumbPage>
|
||||
</BreadcrumbItem>
|
||||
</>
|
||||
)}
|
||||
</BreadcrumbList>
|
||||
</Breadcrumb>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="text-muted-foreground flex items-center gap-2">
|
||||
<a
|
||||
href="https://github.com/turbostarter"
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
className={buttonVariants({ variant: "ghost", size: "icon" })}
|
||||
>
|
||||
<Icons.Github className="size-5" />
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://discord.gg/KjpK2uk3JP"
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
className={buttonVariants({ variant: "ghost", size: "icon" })}
|
||||
>
|
||||
<Icons.Discord className="size-5" />
|
||||
</a>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
};
|
||||
40
apps/web/src/modules/common/layout/dashboard/header.tsx
Normal file
40
apps/web/src/modules/common/layout/dashboard/header.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { cn } from "@turbostarter/ui";
|
||||
|
||||
export const DashboardHeader = ({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"header">) => {
|
||||
return (
|
||||
<header
|
||||
className={cn(
|
||||
"flex w-full flex-wrap items-center justify-between gap-4 py-2 md:gap-6 lg:gap-10",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const DashboardHeaderTitle = ({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"h1">) => {
|
||||
return (
|
||||
<h1
|
||||
className={cn("text-3xl font-bold tracking-tighter", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const DashboardHeaderDescription = ({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"p">) => {
|
||||
return (
|
||||
<p
|
||||
className={cn("text-muted-foreground text-sm text-pretty", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
17
apps/web/src/modules/common/layout/dashboard/inset.tsx
Normal file
17
apps/web/src/modules/common/layout/dashboard/inset.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
"use client";
|
||||
|
||||
import { SidebarInset } from "@turbostarter/ui-web/sidebar";
|
||||
|
||||
import { DashboardActionBar } from "./action-bar";
|
||||
import { ScrollContainer } from "./scroll-container";
|
||||
|
||||
export const DashboardInset = ({ children }: { children: React.ReactNode }) => {
|
||||
return (
|
||||
<SidebarInset className="relative flex h-dvh flex-col sm:h-[calc(100dvh-1rem)]">
|
||||
<DashboardActionBar />
|
||||
<ScrollContainer>
|
||||
{children}
|
||||
</ScrollContainer>
|
||||
</SidebarInset>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { cn } from "@turbostarter/ui";
|
||||
|
||||
interface ScrollContainerProps {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function ScrollContainer({ children, className }: ScrollContainerProps) {
|
||||
const scrollRef = useRef<HTMLDivElement>(null);
|
||||
const [_canScrollUp, setCanScrollUp] = useState(false);
|
||||
const [_canScrollDown, setCanScrollDown] = useState(false);
|
||||
|
||||
const updateScrollState = useCallback(() => {
|
||||
const el = scrollRef.current;
|
||||
if (!el) return;
|
||||
|
||||
const { scrollTop, scrollHeight, clientHeight } = el;
|
||||
setCanScrollUp(scrollTop > 1);
|
||||
setCanScrollDown(scrollTop + clientHeight < scrollHeight - 1);
|
||||
}, []);
|
||||
|
||||
// Check on mount, resize, and content changes
|
||||
useEffect(() => {
|
||||
const el = scrollRef.current;
|
||||
if (!el) return;
|
||||
|
||||
// Initial check
|
||||
updateScrollState();
|
||||
|
||||
// Watch for size changes
|
||||
const observer = new ResizeObserver(updateScrollState);
|
||||
observer.observe(el);
|
||||
|
||||
// Also observe children for content changes
|
||||
const mutationObserver = new MutationObserver(updateScrollState);
|
||||
mutationObserver.observe(el, { childList: true, subtree: true });
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
mutationObserver.disconnect();
|
||||
};
|
||||
}, [updateScrollState]);
|
||||
|
||||
return (
|
||||
<div className={cn("relative flex-1 overflow-hidden", className)}>
|
||||
{/* Scroll content - shadows removed, handled by individual components */}
|
||||
<div
|
||||
ref={scrollRef}
|
||||
onScroll={updateScrollState}
|
||||
className="h-full overflow-auto"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
135
apps/web/src/modules/common/layout/dashboard/settings-card.tsx
Normal file
135
apps/web/src/modules/common/layout/dashboard/settings-card.tsx
Normal file
@@ -0,0 +1,135 @@
|
||||
import { cva } from "class-variance-authority";
|
||||
import * as React from "react";
|
||||
import { createContext, useContext } from "react";
|
||||
|
||||
import { cn } from "@turbostarter/ui";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardFooter,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@turbostarter/ui-web/card";
|
||||
|
||||
import type { VariantProps } from "class-variance-authority";
|
||||
|
||||
const settingsCardVariant = cva("bg-background h-fit w-full overflow-hidden", {
|
||||
variants: {
|
||||
variant: {
|
||||
default: "dark:border-input",
|
||||
destructive: "border-destructive/25",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
});
|
||||
|
||||
const SettingsCardContext = createContext<
|
||||
{
|
||||
disabled: boolean;
|
||||
} & VariantProps<typeof settingsCardVariant>
|
||||
>({
|
||||
disabled: false,
|
||||
variant: "default",
|
||||
});
|
||||
|
||||
const SettingsCard = ({
|
||||
className,
|
||||
variant,
|
||||
disabled = false,
|
||||
...props
|
||||
}: React.ComponentProps<typeof Card> &
|
||||
VariantProps<typeof settingsCardVariant> & { disabled?: boolean }) => (
|
||||
<SettingsCardContext.Provider value={{ disabled, variant }}>
|
||||
<Card
|
||||
className={cn(
|
||||
settingsCardVariant({ variant: disabled ? "default" : variant }),
|
||||
"pb-0",
|
||||
{
|
||||
"text-muted-foreground cursor-not-allowed": disabled,
|
||||
},
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</SettingsCardContext.Provider>
|
||||
);
|
||||
|
||||
const SettingsCardHeader = CardHeader;
|
||||
|
||||
const SettingsCardTitle = ({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CardTitle>) => (
|
||||
<CardTitle className={cn("text-xl", className)} {...props} />
|
||||
);
|
||||
|
||||
const SettingsCardDescription = ({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CardDescription>) => {
|
||||
const { disabled } = useContext(SettingsCardContext);
|
||||
|
||||
return (
|
||||
<CardDescription
|
||||
className={cn(
|
||||
"pb-1.5 text-sm",
|
||||
{
|
||||
"text-foreground": !disabled,
|
||||
},
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const SettingsCardContent = ({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CardContent>) => {
|
||||
return <CardContent className={cn("-mt-4", className)} {...props} />;
|
||||
};
|
||||
|
||||
const settingsCardFooterVariant = cva(
|
||||
"flex min-h-14 cursor-auto justify-between gap-10 border-t py-3 text-sm leading-tight [.border-t]:pt-3",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-accent text-muted-foreground dark:bg-accent/75",
|
||||
destructive:
|
||||
"border-t-destructive/25 bg-destructive/15 dark:bg-destructive/20 border-t",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
const SettingsCardFooter = ({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof CardFooter>) => {
|
||||
const { variant, disabled } = useContext(SettingsCardContext);
|
||||
return (
|
||||
<CardFooter
|
||||
className={cn(
|
||||
settingsCardFooterVariant({ variant: disabled ? "default" : variant }),
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export {
|
||||
SettingsCard,
|
||||
SettingsCardHeader,
|
||||
SettingsCardContent,
|
||||
SettingsCardFooter,
|
||||
SettingsCardTitle,
|
||||
SettingsCardDescription,
|
||||
};
|
||||
@@ -0,0 +1,54 @@
|
||||
"use client";
|
||||
|
||||
import { useParams, usePathname } from "next/navigation";
|
||||
import { memo } from "react";
|
||||
|
||||
import { SidebarMenuButton, useSidebar } from "@turbostarter/ui-web/sidebar";
|
||||
|
||||
import { pathsConfig } from "~/config/paths";
|
||||
import { TurboLink } from "~/modules/common/turbo-link";
|
||||
|
||||
interface SidebarLinkProps
|
||||
extends React.ComponentProps<typeof SidebarMenuButton> {
|
||||
href: string;
|
||||
}
|
||||
|
||||
export const SidebarLink = memo<SidebarLinkProps>(
|
||||
({ href, children, ...props }) => {
|
||||
const { setOpenMobile } = useSidebar();
|
||||
|
||||
const pathname = usePathname();
|
||||
const params = useParams();
|
||||
|
||||
const normalizedPathname = pathname.replace(
|
||||
`/${params.locale?.toString()}`,
|
||||
"",
|
||||
);
|
||||
|
||||
return (
|
||||
<SidebarMenuButton
|
||||
asChild
|
||||
isActive={
|
||||
[
|
||||
pathsConfig.admin.index,
|
||||
pathsConfig.dashboard.user.index,
|
||||
...(params.organization
|
||||
? [
|
||||
pathsConfig.dashboard.organization(
|
||||
params.organization.toString(),
|
||||
).index,
|
||||
]
|
||||
: []),
|
||||
].includes(href)
|
||||
? normalizedPathname === href
|
||||
: normalizedPathname.startsWith(href)
|
||||
}
|
||||
{...props}
|
||||
>
|
||||
<TurboLink href={href} onClick={() => setOpenMobile(false)}>
|
||||
{children}
|
||||
</TurboLink>
|
||||
</SidebarMenuButton>
|
||||
);
|
||||
},
|
||||
);
|
||||
117
apps/web/src/modules/common/layout/dashboard/sidebar.tsx
Normal file
117
apps/web/src/modules/common/layout/dashboard/sidebar.tsx
Normal file
@@ -0,0 +1,117 @@
|
||||
import { memo } from "react";
|
||||
|
||||
import { isKey } from "@turbostarter/i18n";
|
||||
import { getTranslation } from "@turbostarter/i18n/server";
|
||||
import { Icons } from "@turbostarter/ui-web/icons";
|
||||
import {
|
||||
SidebarGroup,
|
||||
SidebarGroupContent,
|
||||
SidebarGroupLabel,
|
||||
SidebarMenuItem,
|
||||
SidebarRail,
|
||||
} from "@turbostarter/ui-web/sidebar";
|
||||
import { SidebarMenu } from "@turbostarter/ui-web/sidebar";
|
||||
import {
|
||||
SidebarContent,
|
||||
SidebarFooter,
|
||||
SidebarHeader,
|
||||
} from "@turbostarter/ui-web/sidebar";
|
||||
import { Sidebar } from "@turbostarter/ui-web/sidebar";
|
||||
|
||||
import { pathsConfig } from "~/config/paths";
|
||||
import { AccountSwitcher } from "~/modules/organization/account-switcher";
|
||||
import { UserNavigation } from "~/modules/user/user-navigation";
|
||||
|
||||
import { SidebarLink } from "./sidebar-link";
|
||||
|
||||
import type { User } from "@turbostarter/auth";
|
||||
import type { Icon } from "@turbostarter/ui-web/icons";
|
||||
|
||||
interface DashboardSidebarProps {
|
||||
readonly user: User;
|
||||
readonly menu: {
|
||||
label: string;
|
||||
items: {
|
||||
title: string;
|
||||
href: string;
|
||||
icon: Icon;
|
||||
}[];
|
||||
}[];
|
||||
}
|
||||
|
||||
export const DashboardSidebar = memo<DashboardSidebarProps>(
|
||||
async ({ user, menu }) => {
|
||||
const { t, i18n } = await getTranslation({ ns: "common" });
|
||||
|
||||
return (
|
||||
<Sidebar
|
||||
variant="inset"
|
||||
className="top-(--banner-height) h-[calc(100svh-var(--banner-height))]"
|
||||
>
|
||||
<SidebarHeader>
|
||||
<AccountSwitcher user={user} />
|
||||
</SidebarHeader>
|
||||
<SidebarContent>
|
||||
{menu.map((group) => (
|
||||
<SidebarGroup key={group.label}>
|
||||
<SidebarGroupLabel className="uppercase">
|
||||
{isKey(group.label, i18n, "common")
|
||||
? t(group.label)
|
||||
: group.label}
|
||||
</SidebarGroupLabel>
|
||||
<SidebarMenu>
|
||||
{group.items.map((item) => {
|
||||
const title = isKey(item.title, i18n, "common")
|
||||
? t(item.title)
|
||||
: item.title;
|
||||
return (
|
||||
<SidebarMenuItem key={item.href}>
|
||||
<SidebarLink href={item.href} tooltip={title}>
|
||||
<item.icon />
|
||||
<span>{title}</span>
|
||||
</SidebarLink>
|
||||
</SidebarMenuItem>
|
||||
);
|
||||
})}
|
||||
</SidebarMenu>
|
||||
</SidebarGroup>
|
||||
))}
|
||||
|
||||
<SidebarGroup className="mt-auto">
|
||||
<SidebarGroupContent>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<SidebarLink
|
||||
href={pathsConfig.marketing.contact}
|
||||
tooltip={t("support")}
|
||||
>
|
||||
<Icons.LifeBuoy />
|
||||
<span>{t("support")}</span>
|
||||
</SidebarLink>
|
||||
</SidebarMenuItem>
|
||||
|
||||
<SidebarMenuItem>
|
||||
<SidebarLink
|
||||
href={pathsConfig.marketing.contact}
|
||||
tooltip={t("feedback")}
|
||||
>
|
||||
<Icons.MessageCircle />
|
||||
<span>{t("feedback")}</span>
|
||||
</SidebarLink>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarGroupContent>
|
||||
</SidebarGroup>
|
||||
</SidebarContent>
|
||||
<SidebarFooter>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<UserNavigation user={user} />
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
</SidebarFooter>
|
||||
<SidebarRail />
|
||||
</Sidebar>
|
||||
);
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user