feat: dashboard overhaul, chargeability reports, dispo import enhancements, UI polish
Dashboard: expanded chargeability widget, resource/project table widgets with sorting and filters, stat cards with formatMoney integration. Chargeability: new report client with filtering, chargeability-bookings use case, updated dashboard overview logic. Dispo import: TBD project handling, parse-dispo-matrix improvements, stage-dispo-projects resource value scores, new tests. Estimates: CommercialTermsEditor component, commercial-terms engine module, expanded estimate schemas and types. UI: AppShell navigation updates, timeline filter/toolbar enhancements, role management improvements, signin page redesign, Tailwind/globals polish, SystemSettings SMTP section, anonymization support. Tests: new router tests (anonymization, chargeability, effort-rule, entitlement, estimate, experience-multiplier, notification, resource, staffing, vacation). Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
@@ -2,18 +2,71 @@
|
||||
|
||||
import { useMemo, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import type { AppRouter } from "@planarchy/api/router";
|
||||
import { EstimateStatus, type EstimateVersionStatus } from "@planarchy/shared";
|
||||
import type { inferRouterOutputs } from "@trpc/server";
|
||||
import { clsx } from "clsx";
|
||||
import { EstimateWizard } from "~/components/estimates/EstimateWizard.js";
|
||||
import { usePermissions } from "~/hooks/usePermissions.js";
|
||||
import { formatDateLong, formatMoney } from "~/lib/format.js";
|
||||
import { trpc } from "~/lib/trpc/client.js";
|
||||
|
||||
type RouterOutput = inferRouterOutputs<AppRouter>;
|
||||
type EstimateListItem = RouterOutput["estimate"]["list"][number];
|
||||
type EstimateDetail = RouterOutput["estimate"]["getById"];
|
||||
type EstimateMetric = {
|
||||
id: string;
|
||||
key: string;
|
||||
label: string;
|
||||
valueDecimal: number;
|
||||
valueCents: number | null;
|
||||
currency: string | null;
|
||||
};
|
||||
|
||||
type EstimateScopeItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string | null;
|
||||
scopeType: string;
|
||||
};
|
||||
|
||||
type EstimateDemandLine = {
|
||||
id: string;
|
||||
name: string;
|
||||
hours: number;
|
||||
costTotalCents: number;
|
||||
priceTotalCents: number;
|
||||
currency: string;
|
||||
chapter: string | null;
|
||||
};
|
||||
|
||||
type EstimateVersion = {
|
||||
versionNumber: number;
|
||||
label: string | null;
|
||||
status: EstimateVersionStatus;
|
||||
notes: string | null;
|
||||
metrics: EstimateMetric[];
|
||||
scopeItems: EstimateScopeItem[];
|
||||
demandLines: EstimateDemandLine[];
|
||||
};
|
||||
|
||||
type EstimateProjectRef = {
|
||||
shortCode: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
type EstimateListItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
status: EstimateStatus;
|
||||
opportunityId: string | null;
|
||||
updatedAt: Date | string;
|
||||
project: EstimateProjectRef | null;
|
||||
versions: Array<Pick<EstimateVersion, "versionNumber" | "status">>;
|
||||
};
|
||||
|
||||
type EstimateDetail = {
|
||||
id: string;
|
||||
name: string;
|
||||
status: EstimateStatus;
|
||||
project: EstimateProjectRef | null;
|
||||
versions: EstimateVersion[];
|
||||
};
|
||||
|
||||
const STATUS_STYLES: Record<EstimateStatus, string> = {
|
||||
DRAFT: "bg-slate-100 text-slate-700",
|
||||
@@ -30,7 +83,7 @@ const VERSION_STYLES: Record<EstimateVersionStatus, string> = {
|
||||
SUPERSEDED: "bg-zinc-200 text-zinc-700",
|
||||
};
|
||||
|
||||
function formatMetricValue(metric: EstimateDetail["versions"][number]["metrics"][number]) {
|
||||
function formatMetricValue(metric: EstimateMetric) {
|
||||
if (metric.valueCents != null) {
|
||||
return formatMoney(metric.valueCents, metric.currency ?? "EUR");
|
||||
}
|
||||
@@ -42,7 +95,13 @@ function formatMetricValue(metric: EstimateDetail["versions"][number]["metrics"]
|
||||
|
||||
function getLatestVersion(estimate: EstimateDetail | null | undefined) {
|
||||
if (!estimate) return null;
|
||||
return [...estimate.versions].sort((left, right) => right.versionNumber - left.versionNumber)[0] ?? null;
|
||||
let latest = estimate.versions[0] ?? null;
|
||||
for (const version of estimate.versions) {
|
||||
if (!latest || version.versionNumber > latest.versionNumber) {
|
||||
latest = version;
|
||||
}
|
||||
}
|
||||
return latest;
|
||||
}
|
||||
|
||||
function EstimateDetailPanel({
|
||||
@@ -58,16 +117,27 @@ function EstimateDetailPanel({
|
||||
const latestMetrics = latestVersion?.metrics ?? [];
|
||||
|
||||
return (
|
||||
<aside className="rounded-3xl border border-gray-200 bg-white p-5 shadow-sm">
|
||||
<aside className="app-surface h-full p-5">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-gray-400">Estimate detail</p>
|
||||
<h2 className="mt-2 text-xl font-semibold text-gray-900">{estimate.name}</h2>
|
||||
<p className="mt-1 text-sm text-gray-500">
|
||||
{estimate.project ? `${estimate.project.shortCode} - ${estimate.project.name}` : "Standalone estimate"}
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-gray-400">
|
||||
Estimate detail
|
||||
</p>
|
||||
<h2 className="mt-2 text-xl font-semibold text-gray-900 dark:text-gray-50">
|
||||
{estimate.name}
|
||||
</h2>
|
||||
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400">
|
||||
{estimate.project
|
||||
? `${estimate.project.shortCode} - ${estimate.project.name}`
|
||||
: "Standalone estimate"}
|
||||
</p>
|
||||
</div>
|
||||
<span className={clsx("rounded-full px-3 py-1 text-xs font-semibold", STATUS_STYLES[estimate.status])}>
|
||||
<span
|
||||
className={clsx(
|
||||
"rounded-full px-3 py-1 text-xs font-semibold",
|
||||
STATUS_STYLES[estimate.status],
|
||||
)}
|
||||
>
|
||||
{estimate.status.replace("_", " ")}
|
||||
</span>
|
||||
</div>
|
||||
@@ -84,7 +154,7 @@ function EstimateDetailPanel({
|
||||
type="button"
|
||||
disabled={cloning}
|
||||
onClick={() => onClone(estimate.id)}
|
||||
className="inline-flex items-center justify-center rounded-2xl border border-gray-200 bg-white px-4 py-2 text-sm font-semibold text-gray-700 transition hover:border-gray-300 hover:bg-gray-50 disabled:opacity-50"
|
||||
className="inline-flex items-center justify-center rounded-2xl border border-gray-200 bg-white px-4 py-2 text-sm font-semibold text-gray-700 transition hover:border-gray-300 hover:bg-gray-50 disabled:opacity-50 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-200 dark:hover:bg-gray-800"
|
||||
>
|
||||
{cloning ? "Cloning..." : "Clone"}
|
||||
</button>
|
||||
@@ -98,7 +168,12 @@ function EstimateDetailPanel({
|
||||
Version {latestVersion.versionNumber}
|
||||
{latestVersion.label ? ` - ${latestVersion.label}` : ""}
|
||||
</span>
|
||||
<span className={clsx("rounded-full px-2 py-0.5 text-xs font-medium", VERSION_STYLES[latestVersion.status])}>
|
||||
<span
|
||||
className={clsx(
|
||||
"rounded-full px-2 py-0.5 text-xs font-medium",
|
||||
VERSION_STYLES[latestVersion.status],
|
||||
)}
|
||||
>
|
||||
{latestVersion.status}
|
||||
</span>
|
||||
</div>
|
||||
@@ -106,25 +181,32 @@ function EstimateDetailPanel({
|
||||
{latestMetrics.length > 0 && (
|
||||
<div className="mt-5 grid gap-3 sm:grid-cols-2">
|
||||
{latestMetrics.map((metric) => (
|
||||
<div key={metric.id} className="rounded-2xl border border-gray-100 bg-gray-50 px-4 py-3">
|
||||
<div
|
||||
key={metric.id}
|
||||
className="rounded-2xl border border-gray-100 bg-gray-50 px-4 py-3 dark:border-gray-800 dark:bg-gray-900/70"
|
||||
>
|
||||
<p className="text-xs uppercase tracking-wide text-gray-400">{metric.label}</p>
|
||||
<p className="mt-1 text-lg font-semibold text-gray-900">{formatMetricValue(metric)}</p>
|
||||
<p className="mt-1 text-lg font-semibold text-gray-900 dark:text-gray-100">
|
||||
{formatMetricValue(metric)}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{latestVersion.notes && (
|
||||
<div className="mt-5 rounded-2xl border border-gray-100 bg-gray-50 p-4">
|
||||
<div className="mt-5 rounded-2xl border border-gray-100 bg-gray-50 p-4 dark:border-gray-800 dark:bg-gray-900/70">
|
||||
<p className="text-xs uppercase tracking-wide text-gray-400">Version notes</p>
|
||||
<p className="mt-2 text-sm text-gray-700">{latestVersion.notes}</p>
|
||||
<p className="mt-2 text-sm text-gray-700 dark:text-gray-200">{latestVersion.notes}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-5 grid gap-5 xl:grid-cols-2">
|
||||
<section>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold text-gray-900">Scope items</h3>
|
||||
<h3 className="text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
Scope items
|
||||
</h3>
|
||||
<span className="text-xs text-gray-400">{latestVersion.scopeItems.length}</span>
|
||||
</div>
|
||||
<div className="mt-3 space-y-2">
|
||||
@@ -134,12 +216,19 @@ function EstimateDetailPanel({
|
||||
</p>
|
||||
) : (
|
||||
latestVersion.scopeItems.map((item) => (
|
||||
<div key={item.id} className="rounded-2xl border border-gray-100 px-4 py-3">
|
||||
<div
|
||||
key={item.id}
|
||||
className="rounded-2xl border border-gray-100 px-4 py-3 dark:border-gray-800"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<p className="font-medium text-gray-900">{item.name}</p>
|
||||
<p className="font-medium text-gray-900 dark:text-gray-100">{item.name}</p>
|
||||
<span className="text-xs text-gray-400">{item.scopeType}</span>
|
||||
</div>
|
||||
{item.description && <p className="mt-1 text-sm text-gray-600">{item.description}</p>}
|
||||
{item.description && (
|
||||
<p className="mt-1 text-sm text-gray-600 dark:text-gray-300">
|
||||
{item.description}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
@@ -148,7 +237,9 @@ function EstimateDetailPanel({
|
||||
|
||||
<section>
|
||||
<div className="flex items-center justify-between">
|
||||
<h3 className="text-sm font-semibold text-gray-900">Demand lines</h3>
|
||||
<h3 className="text-sm font-semibold text-gray-900 dark:text-gray-100">
|
||||
Demand lines
|
||||
</h3>
|
||||
<span className="text-xs text-gray-400">{latestVersion.demandLines.length}</span>
|
||||
</div>
|
||||
<div className="mt-3 space-y-2">
|
||||
@@ -158,12 +249,17 @@ function EstimateDetailPanel({
|
||||
</p>
|
||||
) : (
|
||||
latestVersion.demandLines.map((line) => (
|
||||
<div key={line.id} className="rounded-2xl border border-gray-100 px-4 py-3">
|
||||
<div
|
||||
key={line.id}
|
||||
className="rounded-2xl border border-gray-100 px-4 py-3 dark:border-gray-800"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<p className="font-medium text-gray-900">{line.name}</p>
|
||||
<p className="text-sm font-medium text-gray-600">{line.hours.toFixed(1)} h</p>
|
||||
<p className="font-medium text-gray-900 dark:text-gray-100">{line.name}</p>
|
||||
<p className="text-sm font-medium text-gray-600 dark:text-gray-300">
|
||||
{line.hours.toFixed(1)} h
|
||||
</p>
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap gap-2 text-xs text-gray-500">
|
||||
<div className="mt-2 flex flex-wrap gap-2 text-xs text-gray-500 dark:text-gray-400">
|
||||
<span>{formatMoney(line.costTotalCents, line.currency)} cost</span>
|
||||
<span>{formatMoney(line.priceTotalCents, line.currency)} sell</span>
|
||||
{line.chapter && <span>{line.chapter}</span>}
|
||||
@@ -204,14 +300,21 @@ function EstimateCard({
|
||||
disabled={!canInspect}
|
||||
className={clsx(
|
||||
"w-full rounded-3xl border p-5 text-left transition",
|
||||
active ? "border-brand-500 bg-brand-50 shadow-sm" : "border-gray-200 bg-white hover:border-gray-300 hover:shadow-sm",
|
||||
active
|
||||
? "border-brand-500 bg-brand-50 shadow-sm dark:bg-brand-950/30"
|
||||
: "border-gray-200 bg-white hover:border-gray-300 hover:shadow-sm dark:border-gray-800 dark:bg-gray-950 dark:hover:border-gray-700",
|
||||
!canInspect && "cursor-default",
|
||||
)}
|
||||
>
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className={clsx("rounded-full px-2.5 py-1 text-xs font-semibold", STATUS_STYLES[estimate.status])}>
|
||||
<span
|
||||
className={clsx(
|
||||
"rounded-full px-2.5 py-1 text-xs font-semibold",
|
||||
STATUS_STYLES[estimate.status],
|
||||
)}
|
||||
>
|
||||
{estimate.status.replace("_", " ")}
|
||||
</span>
|
||||
{estimate.project && (
|
||||
@@ -220,13 +323,20 @@ function EstimateCard({
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<h3 className="mt-3 text-lg font-semibold text-gray-900">{estimate.name}</h3>
|
||||
<p className="mt-1 text-sm text-gray-500">
|
||||
<h3 className="mt-3 text-lg font-semibold text-gray-900 dark:text-gray-50">
|
||||
{estimate.name}
|
||||
</h3>
|
||||
<p className="mt-1 text-sm text-gray-500 dark:text-gray-400">
|
||||
{estimate.project ? estimate.project.name : "No linked project"}
|
||||
</p>
|
||||
</div>
|
||||
{latestVersion && (
|
||||
<span className={clsx("rounded-full px-2.5 py-1 text-xs font-medium", VERSION_STYLES[latestVersion.status])}>
|
||||
<span
|
||||
className={clsx(
|
||||
"rounded-full px-2.5 py-1 text-xs font-medium",
|
||||
VERSION_STYLES[latestVersion.status],
|
||||
)}
|
||||
>
|
||||
v{latestVersion.versionNumber}
|
||||
</span>
|
||||
)}
|
||||
@@ -235,16 +345,20 @@ function EstimateCard({
|
||||
<div className="mt-5 grid gap-3 sm:grid-cols-2">
|
||||
<div>
|
||||
<p className="text-xs uppercase tracking-wide text-gray-400">Opportunity</p>
|
||||
<p className="mt-1 text-sm text-gray-700">{estimate.opportunityId ?? "Not set"}</p>
|
||||
<p className="mt-1 text-sm text-gray-700 dark:text-gray-200">
|
||||
{estimate.opportunityId ?? "Not set"}
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-xs uppercase tracking-wide text-gray-400">Updated</p>
|
||||
<p className="mt-1 text-sm text-gray-700">{formatDateLong(estimate.updatedAt)}</p>
|
||||
<p className="mt-1 text-sm text-gray-700 dark:text-gray-200">
|
||||
{formatDateLong(estimate.updatedAt)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{!canInspect && (
|
||||
<p className="mt-4 text-xs text-gray-400">
|
||||
<p className="mt-4 text-xs text-gray-400 dark:text-gray-500">
|
||||
Detailed financial breakdown is limited to manager and controller roles.
|
||||
</p>
|
||||
)}
|
||||
@@ -283,23 +397,28 @@ export function EstimatesClient() {
|
||||
},
|
||||
);
|
||||
|
||||
const estimates = listQuery.data ?? [];
|
||||
const estimates = (listQuery.data ?? []) as unknown as EstimateListItem[];
|
||||
|
||||
const selectedEstimate = useMemo(() => {
|
||||
if (!canViewCosts) return null;
|
||||
return detailQuery.data ?? null;
|
||||
return (detailQuery.data ?? null) as unknown as EstimateDetail | null;
|
||||
}, [canViewCosts, detailQuery.data]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="space-y-6">
|
||||
<div className="rounded-[28px] border border-gray-200 bg-gradient-to-br from-white via-white to-brand-50 p-6 shadow-sm">
|
||||
<div className="app-page space-y-6">
|
||||
<div className="app-surface-strong overflow-hidden bg-gradient-to-br from-white via-white to-brand-50 p-6 dark:from-gray-950 dark:via-gray-950 dark:to-brand-950/40">
|
||||
<div className="flex flex-col gap-5 lg:flex-row lg:items-end lg:justify-between">
|
||||
<div>
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.24em] text-brand-600">Estimating</p>
|
||||
<h1 className="mt-2 text-3xl font-semibold text-gray-900">Browser-native estimate workspace</h1>
|
||||
<p className="mt-2 max-w-3xl text-sm text-gray-600">
|
||||
Build structured estimates from live projects, resources, and role data instead of maintaining a disconnected spreadsheet.
|
||||
<p className="text-xs font-semibold uppercase tracking-[0.24em] text-brand-600">
|
||||
Estimating
|
||||
</p>
|
||||
<h1 className="mt-2 font-display text-3xl font-semibold text-gray-900 dark:text-gray-50">
|
||||
Browser-native estimate workspace
|
||||
</h1>
|
||||
<p className="mt-2 max-w-3xl text-sm text-gray-600 dark:text-gray-300">
|
||||
Build structured estimates from live projects, resources, and role data instead of
|
||||
maintaining a disconnected spreadsheet.
|
||||
</p>
|
||||
</div>
|
||||
{canEdit && (
|
||||
@@ -319,12 +438,12 @@ export function EstimatesClient() {
|
||||
value={search}
|
||||
onChange={(event) => setSearch(event.target.value)}
|
||||
placeholder="Search by estimate or opportunity"
|
||||
className="w-full rounded-2xl border border-gray-300 bg-white px-4 py-3 text-sm text-gray-900 outline-none ring-0 transition focus:border-brand-500 focus:ring-2 focus:ring-brand-100"
|
||||
className="app-input rounded-2xl px-4 py-3"
|
||||
/>
|
||||
<select
|
||||
value={status}
|
||||
onChange={(event) => setStatus(event.target.value as EstimateStatus | "")}
|
||||
className="w-full rounded-2xl border border-gray-300 bg-white px-4 py-3 text-sm text-gray-900 outline-none transition focus:border-brand-500 focus:ring-2 focus:ring-brand-100"
|
||||
className="app-select w-full rounded-2xl px-4 py-3"
|
||||
>
|
||||
<option value="">All statuses</option>
|
||||
{Object.values(EstimateStatus).map((value) => (
|
||||
@@ -337,13 +456,15 @@ export function EstimatesClient() {
|
||||
</div>
|
||||
|
||||
{listQuery.isLoading ? (
|
||||
<div className="rounded-3xl border border-dashed border-gray-200 bg-white px-6 py-14 text-center text-sm text-gray-400">
|
||||
<div className="app-surface-strong border-dashed px-6 py-14 text-center text-sm text-gray-400">
|
||||
Loading estimates...
|
||||
</div>
|
||||
) : estimates.length === 0 ? (
|
||||
<div className="rounded-3xl border border-dashed border-gray-200 bg-white px-6 py-14 text-center">
|
||||
<p className="text-base font-medium text-gray-700">No estimates yet</p>
|
||||
<p className="mt-2 text-sm text-gray-400">
|
||||
<div className="app-surface-strong border-dashed px-6 py-14 text-center">
|
||||
<p className="text-base font-medium text-gray-700 dark:text-gray-100">
|
||||
No estimates yet
|
||||
</p>
|
||||
<p className="mt-2 text-sm text-gray-400 dark:text-gray-500">
|
||||
Start with the wizard to create a connected estimate from Planarchy data.
|
||||
</p>
|
||||
</div>
|
||||
@@ -358,7 +479,9 @@ export function EstimatesClient() {
|
||||
canInspect={canViewCosts}
|
||||
onSelect={() => {
|
||||
if (!canViewCosts) return;
|
||||
setSelectedEstimateId((current) => (current === estimate.id ? current : estimate.id));
|
||||
setSelectedEstimateId((current) =>
|
||||
current === estimate.id ? current : estimate.id,
|
||||
);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
@@ -369,15 +492,21 @@ export function EstimatesClient() {
|
||||
selectedEstimate ? (
|
||||
<EstimateDetailPanel
|
||||
estimate={selectedEstimate}
|
||||
{...(canEdit ? { onClone: (id: string) => cloneMutation.mutate({ sourceEstimateId: id }), cloning: cloneMutation.isPending } : {})}
|
||||
{...(canEdit
|
||||
? {
|
||||
onClone: (id: string) => cloneMutation.mutate({ sourceEstimateId: id }),
|
||||
cloning: cloneMutation.isPending,
|
||||
}
|
||||
: {})}
|
||||
/>
|
||||
) : (
|
||||
<div className="rounded-3xl border border-dashed border-gray-200 bg-white px-6 py-14 text-center text-sm text-gray-400">
|
||||
Select an estimate to inspect the current version, demand lines, and summary metrics.
|
||||
<div className="app-surface-strong border-dashed px-6 py-14 text-center text-sm text-gray-400">
|
||||
Select an estimate to inspect the current version, demand lines, and summary
|
||||
metrics.
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<div className="rounded-3xl border border-dashed border-gray-200 bg-white px-6 py-14 text-center text-sm text-gray-400">
|
||||
<div className="app-surface-strong border-dashed px-6 py-14 text-center text-sm text-gray-400">
|
||||
Your role can access the estimate list, but not the detailed financial breakdown.
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user