mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-02-13 21:35:44 +01:00
fix: resolve Prettier markdown code block parsing errors
- Fix syntax errors in skills markdown files (.github/skills, .opencode/skills) - Change typescript to tsx for code blocks with JSX - Replace ellipsis (...) in array examples with valid syntax - Separate CSS from TypeScript into distinct code blocks - Convert JavaScript object examples to valid JSON in docs - Fix enum definitions with proper comma separation
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import type { PlatformUserRole } from "@prisma/client";
|
||||
import type { UserRole } from "@prisma/client";
|
||||
import {
|
||||
Activity,
|
||||
BarChart3,
|
||||
@@ -31,6 +31,7 @@ import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { ThemeToggle } from "@/components/ui/theme-toggle";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
import { authClient } from "@/lib/auth/client";
|
||||
|
||||
interface Company {
|
||||
id: string;
|
||||
@@ -52,51 +53,74 @@ interface DashboardData {
|
||||
};
|
||||
}
|
||||
|
||||
interface PlatformSession {
|
||||
user: {
|
||||
id: string;
|
||||
email: string;
|
||||
name?: string;
|
||||
isPlatformUser: boolean;
|
||||
platformRole: PlatformUserRole;
|
||||
};
|
||||
interface PlatformUserData {
|
||||
id: string;
|
||||
email: string;
|
||||
name: string | null;
|
||||
role: UserRole;
|
||||
}
|
||||
|
||||
// Custom hook for platform session
|
||||
function usePlatformSession() {
|
||||
const [session, setSession] = useState<PlatformSession | null>(null);
|
||||
const [status, setStatus] = useState<
|
||||
"loading" | "authenticated" | "unauthenticated"
|
||||
>("loading");
|
||||
// Platform roles for checking
|
||||
const PLATFORM_ROLES: UserRole[] = [
|
||||
"PLATFORM_SUPER_ADMIN",
|
||||
"PLATFORM_ADMIN",
|
||||
"PLATFORM_SUPPORT",
|
||||
];
|
||||
|
||||
function isPlatformRole(role: UserRole): boolean {
|
||||
return PLATFORM_ROLES.includes(role);
|
||||
}
|
||||
|
||||
// Custom hook for platform user data
|
||||
function usePlatformUser() {
|
||||
const { data: sessionData, isPending } = authClient.useSession();
|
||||
const [platformUser, setPlatformUser] = useState<PlatformUserData | null>(
|
||||
null
|
||||
);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchSession = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/platform/auth/session");
|
||||
const sessionData = await response.json();
|
||||
if (isPending) return;
|
||||
|
||||
if (sessionData?.user?.isPlatformUser) {
|
||||
setSession(sessionData);
|
||||
setStatus("authenticated");
|
||||
if (!sessionData?.session) {
|
||||
setPlatformUser(null);
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fetch user data from our API to get role
|
||||
const fetchUser = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/auth/me");
|
||||
if (response.ok) {
|
||||
const userData = await response.json();
|
||||
if (isPlatformRole(userData.role)) {
|
||||
setPlatformUser(userData);
|
||||
} else {
|
||||
setPlatformUser(null);
|
||||
}
|
||||
} else {
|
||||
setSession(null);
|
||||
setStatus("unauthenticated");
|
||||
setPlatformUser(null);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Platform session fetch error:", error);
|
||||
setSession(null);
|
||||
setStatus("unauthenticated");
|
||||
} catch {
|
||||
setPlatformUser(null);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchSession();
|
||||
}, []);
|
||||
fetchUser();
|
||||
}, [sessionData, isPending]);
|
||||
|
||||
return { data: session, status };
|
||||
return {
|
||||
user: platformUser,
|
||||
isLoading: isPending || isLoading,
|
||||
isAuthenticated: !!platformUser,
|
||||
};
|
||||
}
|
||||
|
||||
export default function PlatformDashboard() {
|
||||
const { data: session, status } = usePlatformSession();
|
||||
const { user, isLoading: userLoading, isAuthenticated } = usePlatformUser();
|
||||
const router = useRouter();
|
||||
const { toast } = useToast();
|
||||
const [dashboardData, setDashboardData] = useState<DashboardData | null>(
|
||||
@@ -115,7 +139,6 @@ export default function PlatformDashboard() {
|
||||
csvPassword: "",
|
||||
adminEmail: "",
|
||||
adminName: "",
|
||||
adminPassword: "",
|
||||
maxUsers: 10,
|
||||
});
|
||||
|
||||
@@ -125,7 +148,6 @@ export default function PlatformDashboard() {
|
||||
const csvPasswordId = useId();
|
||||
const adminNameId = useId();
|
||||
const adminEmailId = useId();
|
||||
const adminPasswordId = useId();
|
||||
const maxUsersId = useId();
|
||||
|
||||
const fetchDashboardData = useCallback(async () => {
|
||||
@@ -143,15 +165,15 @@ export default function PlatformDashboard() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (status === "loading") return;
|
||||
if (userLoading) return;
|
||||
|
||||
if (status === "unauthenticated" || !session?.user?.isPlatformUser) {
|
||||
if (!isAuthenticated) {
|
||||
router.push("/platform/login");
|
||||
return;
|
||||
}
|
||||
|
||||
fetchDashboardData();
|
||||
}, [session, status, router, fetchDashboardData]);
|
||||
}, [userLoading, isAuthenticated, router, fetchDashboardData]);
|
||||
|
||||
const copyToClipboard = async (text: string, type: "email" | "password") => {
|
||||
try {
|
||||
@@ -211,14 +233,12 @@ export default function PlatformDashboard() {
|
||||
csvPassword: "",
|
||||
adminEmail: "",
|
||||
adminName: "",
|
||||
adminPassword: "",
|
||||
maxUsers: 10,
|
||||
});
|
||||
|
||||
fetchDashboardData(); // Refresh the list
|
||||
fetchDashboardData();
|
||||
|
||||
// Show success message with copyable credentials
|
||||
if (result.generatedPassword) {
|
||||
if (result.adminUser) {
|
||||
toast({
|
||||
title: "Company Created Successfully!",
|
||||
description: (
|
||||
@@ -251,34 +271,36 @@ export default function PlatformDashboard() {
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex items-center justify-between bg-muted p-2 rounded">
|
||||
<div className="flex-1">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Admin Password:
|
||||
</p>
|
||||
<p className="font-mono text-sm">
|
||||
{result.generatedPassword}
|
||||
</p>
|
||||
{result.inviteLink && (
|
||||
<div className="flex items-center justify-between bg-muted p-2 rounded">
|
||||
<div className="flex-1">
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Invite Link:
|
||||
</p>
|
||||
<p className="font-mono text-sm truncate">
|
||||
{result.inviteLink}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() =>
|
||||
copyToClipboard(result.inviteLink, "password")
|
||||
}
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
{copiedPassword ? (
|
||||
<Check className="h-3 w-3" />
|
||||
) : (
|
||||
<Copy className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
onClick={() =>
|
||||
copyToClipboard(result.generatedPassword, "password")
|
||||
}
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
{copiedPassword ? (
|
||||
<Check className="h-3 w-3" />
|
||||
) : (
|
||||
<Copy className="h-3 w-3" />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
duration: 15000, // Longer duration for credentials
|
||||
duration: 15000,
|
||||
});
|
||||
} else {
|
||||
toast({
|
||||
@@ -317,7 +339,7 @@ export default function PlatformDashboard() {
|
||||
}
|
||||
};
|
||||
|
||||
if (status === "loading" || isLoading) {
|
||||
if (userLoading || isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<div className="text-center">Loading platform dashboard...</div>
|
||||
@@ -325,7 +347,7 @@ export default function PlatformDashboard() {
|
||||
);
|
||||
}
|
||||
|
||||
if (status === "unauthenticated" || !session?.user?.isPlatformUser) {
|
||||
if (!isAuthenticated || !user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -352,13 +374,12 @@ export default function PlatformDashboard() {
|
||||
Platform Dashboard
|
||||
</h1>
|
||||
<p className="text-sm text-gray-500 dark:text-gray-400">
|
||||
Welcome back, {session.user.name || session.user.email}
|
||||
Welcome back, {user.name || user.email}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-4 items-center">
|
||||
<ThemeToggle />
|
||||
|
||||
{/* Search Filter */}
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4" />
|
||||
<Input
|
||||
@@ -378,7 +399,6 @@ export default function PlatformDashboard() {
|
||||
</div>
|
||||
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
{/* Stats Overview */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-6 mb-8">
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
@@ -430,7 +450,6 @@ export default function PlatformDashboard() {
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Companies List */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center justify-between">
|
||||
@@ -550,21 +569,6 @@ export default function PlatformDashboard() {
|
||||
placeholder="admin@acme.com"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={adminPasswordId}>Admin Password</Label>
|
||||
<Input
|
||||
id={adminPasswordId}
|
||||
type="password"
|
||||
value={newCompanyData.adminPassword}
|
||||
onChange={(e) =>
|
||||
setNewCompanyData((prev) => ({
|
||||
...prev,
|
||||
adminPassword: e.target.value,
|
||||
}))
|
||||
}
|
||||
placeholder="Leave empty to auto-generate"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor={maxUsersId}>Max Users</Label>
|
||||
<Input
|
||||
|
||||
Reference in New Issue
Block a user