init
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
|
||||
type NavItem = { label: string; href: string };
|
||||
|
||||
const MAIN: NavItem[] = [
|
||||
{ label: "Overview", href: "/" },
|
||||
{ label: "Trend", href: "/trend" },
|
||||
];
|
||||
|
||||
const ADMIN: NavItem[] = [
|
||||
{ label: "Cost Registration", href: "/cost-registration" },
|
||||
{ label: "Cost Item Creation", href: "/cost-item-creation" },
|
||||
{ label: "Year Creation", href: "/year-creation" },
|
||||
];
|
||||
|
||||
export default function Sidebar({ isAdmin }: { isAdmin: boolean }) {
|
||||
const pathname = usePathname();
|
||||
|
||||
const renderLink = (item: NavItem) => {
|
||||
const active = pathname === item.href;
|
||||
return (
|
||||
<Link
|
||||
key={item.href}
|
||||
href={item.href}
|
||||
className={`block rounded-md px-3 py-2 text-sm font-medium transition-colors ${
|
||||
active
|
||||
? "bg-[#3B82F6] text-white"
|
||||
: "text-gray-700 hover:bg-gray-100"
|
||||
}`}
|
||||
>
|
||||
{item.label}
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<aside className="flex w-60 shrink-0 flex-col border-r border-[#E5E7EB] bg-white">
|
||||
<div className="flex h-14 items-center px-6 text-base font-semibold text-[#111827]">
|
||||
IT Cost
|
||||
</div>
|
||||
<nav className="flex flex-col gap-1 px-3 py-4">
|
||||
{MAIN.map(renderLink)}
|
||||
{isAdmin && (
|
||||
<>
|
||||
<div className="mt-6 mb-1 px-3 text-xs font-semibold uppercase tracking-wide text-[#6B7280]">
|
||||
Admin
|
||||
</div>
|
||||
{ADMIN.map(renderLink)}
|
||||
</>
|
||||
)}
|
||||
</nav>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { auth, signIn, signOut } from "@/auth";
|
||||
|
||||
export default async function TopNav() {
|
||||
const session = await auth();
|
||||
const user = session?.user;
|
||||
|
||||
return (
|
||||
<header className="flex h-14 items-center justify-between bg-[#111827] px-6 text-white">
|
||||
<span className="text-lg font-semibold">Global IT Cost Dashboard</span>
|
||||
{user ? (
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm text-white/80">{user.name ?? user.email}</span>
|
||||
<form
|
||||
action={async () => {
|
||||
"use server";
|
||||
await signOut({ redirectTo: "/" });
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
) : (
|
||||
<form
|
||||
action={async () => {
|
||||
"use server";
|
||||
await signIn("microsoft-entra-id");
|
||||
}}
|
||||
>
|
||||
<button
|
||||
type="submit"
|
||||
className="rounded-md bg-white/10 px-4 py-1.5 text-sm font-medium hover:bg-white/20"
|
||||
>
|
||||
Login
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import {
|
||||
LineChart,
|
||||
Line,
|
||||
XAxis,
|
||||
YAxis,
|
||||
CartesianGrid,
|
||||
Tooltip,
|
||||
Legend,
|
||||
ResponsiveContainer,
|
||||
} from "recharts";
|
||||
import { formatCurrency } from "@/lib/format";
|
||||
|
||||
export type Series = {
|
||||
years: number[];
|
||||
lines: { key: string; values: number[] }[];
|
||||
};
|
||||
|
||||
// Total is blue + emphasized; regions/items cycle through this palette.
|
||||
const TOTAL_COLOR = "#3B82F6";
|
||||
const PALETTE = [
|
||||
"#10B981", // green
|
||||
"#F59E0B", // amber
|
||||
"#EF4444", // red
|
||||
"#8B5CF6", // purple
|
||||
"#06B6D4", // cyan
|
||||
"#EC4899", // pink
|
||||
"#84CC16", // lime
|
||||
];
|
||||
|
||||
export default function TrendChart({ series }: { series: Series }) {
|
||||
// Which single line is isolated (null = show all).
|
||||
const [isolated, setIsolated] = useState<string | null>(null);
|
||||
|
||||
const data = useMemo(() => {
|
||||
return series.years.map((year, i) => {
|
||||
const row: Record<string, number | string> = { year };
|
||||
for (const line of series.lines) row[line.key] = line.values[i] ?? 0;
|
||||
return row;
|
||||
});
|
||||
}, [series]);
|
||||
|
||||
const colorFor = (key: string, idx: number) =>
|
||||
key === "Total" ? TOTAL_COLOR : PALETTE[(idx - 1) % PALETTE.length];
|
||||
|
||||
// Click a legend entry to isolate that line; click it again to restore all.
|
||||
const handleLegendClick = (o: { value?: unknown; dataKey?: unknown }) => {
|
||||
const key =
|
||||
typeof o?.dataKey === "string"
|
||||
? o.dataKey
|
||||
: typeof o?.value === "string"
|
||||
? o.value
|
||||
: "";
|
||||
if (!key) return;
|
||||
setIsolated((cur) => (cur === key ? null : key));
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="h-[420px] w-full">
|
||||
<ResponsiveContainer width="100%" height="100%">
|
||||
<LineChart data={data} margin={{ top: 16, right: 24, bottom: 8, left: 8 }}>
|
||||
<CartesianGrid stroke="#EDEFF2" vertical={false} />
|
||||
<XAxis
|
||||
dataKey="year"
|
||||
tick={{ fill: "#6B7280", fontSize: 12 }}
|
||||
axisLine={{ stroke: "#E5E7EB" }}
|
||||
tickLine={false}
|
||||
/>
|
||||
<YAxis
|
||||
tick={{ fill: "#6B7280", fontSize: 12 }}
|
||||
axisLine={{ stroke: "#E5E7EB" }}
|
||||
tickLine={false}
|
||||
tickFormatter={(v: number) => formatCurrency(v)}
|
||||
width={80}
|
||||
/>
|
||||
<Tooltip
|
||||
formatter={(v: number) => formatCurrency(v)}
|
||||
contentStyle={{
|
||||
borderRadius: 8,
|
||||
border: "1px solid #E5E7EB",
|
||||
fontSize: 12,
|
||||
}}
|
||||
/>
|
||||
<Legend
|
||||
onClick={handleLegendClick}
|
||||
wrapperStyle={{ cursor: "pointer", fontSize: 12 }}
|
||||
/>
|
||||
{series.lines.map((line, idx) => {
|
||||
const hidden = isolated !== null && isolated !== line.key;
|
||||
return (
|
||||
<Line
|
||||
key={line.key}
|
||||
type="monotone"
|
||||
dataKey={line.key}
|
||||
stroke={colorFor(line.key, idx)}
|
||||
strokeWidth={line.key === "Total" ? 3 : 2}
|
||||
dot={{ r: 3 }}
|
||||
activeDot={{ r: 5 }}
|
||||
hide={hidden}
|
||||
isAnimationActive={false}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
</div>
|
||||
<p className="mt-3 text-xs text-[#6B7280]">
|
||||
Tip: click a name in the legend to isolate that line; click it again to
|
||||
show all.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
export default function Card({
|
||||
title,
|
||||
children,
|
||||
className = "",
|
||||
}: {
|
||||
title?: string;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<div
|
||||
className={`rounded-lg border border-[#E5E7EB] bg-white ${className}`}
|
||||
>
|
||||
{title && (
|
||||
<div className="border-b border-[#E5E7EB] px-5 py-3.5 text-sm font-semibold text-[#111827]">
|
||||
{title}
|
||||
</div>
|
||||
)}
|
||||
<div className="p-5">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export default function FilterBar({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<div className="mb-6 flex flex-wrap items-end gap-6 rounded-lg border border-[#E5E7EB] bg-white p-4">
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
"use client";
|
||||
|
||||
type Option = { value: string; label: string };
|
||||
|
||||
export default function Select({
|
||||
label,
|
||||
value,
|
||||
onChange,
|
||||
options,
|
||||
placeholder,
|
||||
className = "",
|
||||
}: {
|
||||
label?: string;
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
options: (Option | string)[];
|
||||
placeholder?: string;
|
||||
className?: string;
|
||||
}) {
|
||||
const normalized: Option[] = options.map((o) =>
|
||||
typeof o === "string" ? { value: o, label: o } : o
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={`flex flex-col gap-1.5 ${className}`}>
|
||||
{label && (
|
||||
<span className="text-xs font-medium text-[#6B7280]">{label}</span>
|
||||
)}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
className="w-full appearance-none rounded-lg border border-[#E5E7EB] bg-white px-3 py-2.5 pr-9 text-sm text-[#111827] outline-none focus:border-[#3B82F6]"
|
||||
>
|
||||
{placeholder && (
|
||||
<option value="" disabled>
|
||||
{placeholder}
|
||||
</option>
|
||||
)}
|
||||
{normalized.map((o) => (
|
||||
<option key={o.value} value={o.value}>
|
||||
{o.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<svg
|
||||
className="pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[#6B7280]"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
d="M5.23 7.21a.75.75 0 011.06.02L10 10.94l3.71-3.71a.75.75 0 111.06 1.06l-4.24 4.24a.75.75 0 01-1.06 0L5.21 8.29a.75.75 0 01.02-1.08z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user