Updated
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
---
|
||||
import '../styles/global.css';
|
||||
import { Icon } from 'astro-icon/components';
|
||||
import { db } from '../db';
|
||||
import { members, organizations } from '../db/schema';
|
||||
import { eq } from 'drizzle-orm';
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
@@ -12,69 +15,148 @@ const user = Astro.locals.user;
|
||||
if (!user) {
|
||||
return Astro.redirect('/login');
|
||||
}
|
||||
|
||||
// Get user's team memberships
|
||||
const userMemberships = await db.select({
|
||||
membership: members,
|
||||
organization: organizations,
|
||||
})
|
||||
.from(members)
|
||||
.innerJoin(organizations, eq(members.organizationId, organizations.id))
|
||||
.where(eq(members.userId, user.id))
|
||||
.all();
|
||||
|
||||
// Get current team from cookie or use first membership
|
||||
const currentTeamId = Astro.cookies.get('currentTeamId')?.value || userMemberships[0]?.organization.id;
|
||||
const currentTeam = userMemberships.find(m => m.organization.id === currentTeamId);
|
||||
---
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en" data-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="description" content="Zamaan Dashboard" />
|
||||
<meta name="description" content="Chronus Dashboard" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>{title}</title>
|
||||
</head>
|
||||
<body class="bg-base-100 text-base-content">
|
||||
<body class="bg-gradient-to-br from-base-100 via-base-200 to-base-100">
|
||||
<div class="drawer lg:drawer-open">
|
||||
<input id="my-drawer-2" type="checkbox" class="drawer-toggle" />
|
||||
<div class="drawer-content flex flex-col">
|
||||
<!-- Navbar -->
|
||||
<div class="w-full navbar bg-base-100 border-b border-base-200 lg:hidden">
|
||||
<div class="navbar bg-base-100 sticky top-0 z-50 lg:hidden border-b border-base-300">
|
||||
<div class="flex-none lg:hidden">
|
||||
<label for="my-drawer-2" aria-label="open sidebar" class="btn btn-square btn-ghost">
|
||||
<Icon name="heroicons:bars-3" class="w-6 h-6" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex-1 px-2 mx-2">Zamaan</div>
|
||||
<div class="flex-1 px-2">
|
||||
<span class="text-xl font-bold bg-gradient-to-r from-primary to-secondary bg-clip-text text-transparent">Chronus</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Page content here -->
|
||||
<main class="p-6">
|
||||
<main class="p-6 md:p-8">
|
||||
<slot />
|
||||
</main>
|
||||
</div>
|
||||
<div class="drawer-side">
|
||||
<div class="drawer-side z-50">
|
||||
<label for="my-drawer-2" aria-label="close sidebar" class="drawer-overlay"></label>
|
||||
<ul class="menu p-4 w-80 min-h-full bg-base-300 text-base-content">
|
||||
<ul class="menu bg-base-200 min-h-full w-80 p-4">
|
||||
<!-- Sidebar content here -->
|
||||
<li class="mb-4">
|
||||
<a href="/dashboard" class="text-xl font-bold px-2">Zamaan</a>
|
||||
<li class="mb-6">
|
||||
<a href="/dashboard" class="text-2xl font-bold bg-gradient-to-r from-primary to-secondary bg-clip-text text-transparent pointer-events-none">Chronus</a>
|
||||
</li>
|
||||
<li><a href="/dashboard">Dashboard</a></li>
|
||||
<li><a href="/dashboard/tracker">Time Tracker</a></li>
|
||||
<li><a href="/dashboard/reports">Reports</a></li>
|
||||
<li><a href="/dashboard/clients">Clients</a></li>
|
||||
<li><a href="/dashboard/team">Team</a></li>
|
||||
|
||||
{/* Team Switcher */}
|
||||
{userMemberships.length > 0 && (
|
||||
<li class="mb-4">
|
||||
<div class="form-control">
|
||||
<select
|
||||
class="select select-bordered w-full font-semibold"
|
||||
id="team-switcher"
|
||||
onchange="document.cookie = 'currentTeamId=' + this.value + '; path=/'; window.location.reload();"
|
||||
>
|
||||
{userMemberships.map(({ membership, organization }) => (
|
||||
<option
|
||||
value={organization.id}
|
||||
selected={organization.id === currentTeamId}
|
||||
>
|
||||
{organization.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</li>
|
||||
)}
|
||||
|
||||
{userMemberships.length === 0 && (
|
||||
<li class="mb-4">
|
||||
<a href="/dashboard/organizations/new" class="btn btn-primary btn-sm">
|
||||
<Icon name="heroicons:plus" class="w-4 h-4" />
|
||||
Create Team
|
||||
</a>
|
||||
</li>
|
||||
)}
|
||||
|
||||
<div class="divider my-2"></div>
|
||||
|
||||
<li><a href="/dashboard">
|
||||
<Icon name="heroicons:home" class="w-5 h-5" />
|
||||
Dashboard
|
||||
</a></li>
|
||||
<li><a href="/dashboard/tracker">
|
||||
<Icon name="heroicons:clock" class="w-5 h-5" />
|
||||
Time Tracker
|
||||
</a></li>
|
||||
<li><a href="/dashboard/reports">
|
||||
<Icon name="heroicons:chart-bar" class="w-5 h-5" />
|
||||
Reports
|
||||
</a></li>
|
||||
<li><a href="/dashboard/clients">
|
||||
<Icon name="heroicons:building-office" class="w-5 h-5" />
|
||||
Clients
|
||||
</a></li>
|
||||
<li><a href="/dashboard/team">
|
||||
<Icon name="heroicons:user-group" class="w-5 h-5" />
|
||||
Team
|
||||
</a></li>
|
||||
|
||||
{user.isSiteAdmin && (
|
||||
<>
|
||||
<div class="divider"></div>
|
||||
<li><a href="/admin" class="font-semibold">⚙️ Site Admin</a></li>
|
||||
<li><a href="/admin" class="font-semibold">
|
||||
<Icon name="heroicons:cog-6-tooth" class="w-5 h-5" />
|
||||
Site Admin
|
||||
</a></li>
|
||||
</>
|
||||
)}
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<li>
|
||||
<div class="flex items-center gap-2">
|
||||
<a href="/dashboard/settings" class="flex items-center gap-3 bg-base-100 hover:bg-base-300 rounded-lg p-3">
|
||||
<div class="avatar placeholder">
|
||||
<div class="bg-neutral text-neutral-content rounded-full w-8">
|
||||
<span class="text-xs">{user.name.charAt(0)}</span>
|
||||
<div class="bg-gradient-to-br from-primary via-secondary to-accent text-primary-content rounded-full w-10 ring ring-primary ring-offset-base-100 ring-offset-2">
|
||||
<span class="text-sm font-bold">{user.name.charAt(0).toUpperCase()}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span>{user.name}</span>
|
||||
</div>
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="font-semibold text-sm truncate">{user.name}</div>
|
||||
<div class="text-xs text-base-content/60 truncate">{user.email}</div>
|
||||
</div>
|
||||
<Icon name="heroicons:chevron-right" class="w-4 h-4 opacity-50" />
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<form action="/api/auth/logout" method="POST">
|
||||
<button type="submit">Logout</button>
|
||||
<button type="submit" class="w-full text-error hover:bg-error/10">
|
||||
<Icon name="heroicons:arrow-right-on-rectangle" class="w-5 h-5" />
|
||||
Logout
|
||||
</button>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user