Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
|
|
import { apiFetch } from '@/lib/api/client';
|
2026-05-04 22:54:55 +02:00
|
|
|
import { useUIStore } from '@/stores/ui-store';
|
2026-04-28 12:09:59 +02:00
|
|
|
import { KPITile } from '@/components/ui/kpi-tile';
|
|
|
|
|
import { Skeleton } from '@/components/ui/skeleton';
|
2026-05-09 04:24:46 +02:00
|
|
|
import { formatCurrency } from '@/lib/utils/currency';
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
import { WidgetErrorBoundary } from './widget-error-boundary';
|
|
|
|
|
|
|
|
|
|
interface KpiData {
|
|
|
|
|
totalClients: number;
|
|
|
|
|
activeInterests: number;
|
|
|
|
|
pipelineValueUsd: number;
|
|
|
|
|
occupancyRate: number;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-09 04:24:46 +02:00
|
|
|
const formatUsd = (value: number) => formatCurrency(value, 'USD', { maxFractionDigits: 0 });
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
|
|
|
|
|
function formatPercent(value: number): string {
|
|
|
|
|
return `${value.toFixed(1)}%`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 12:09:59 +02:00
|
|
|
function KpiTileSkeleton() {
|
|
|
|
|
return (
|
2026-05-03 16:15:20 +02:00
|
|
|
<div className="relative overflow-hidden rounded-xl border border-border bg-card p-3 shadow-sm sm:p-5">
|
2026-04-28 12:24:14 +02:00
|
|
|
<div className="absolute inset-x-0 top-0 h-1 bg-muted" aria-hidden />
|
2026-05-03 16:15:20 +02:00
|
|
|
<Skeleton className="h-3 w-20" />
|
|
|
|
|
<Skeleton className="mt-2 h-6 w-24 sm:mt-3 sm:h-7" />
|
2026-04-28 12:09:59 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
export function KpiCards() {
|
2026-05-04 22:54:55 +02:00
|
|
|
// Keying on currentPortId ensures React Query treats a port-resolved fetch
|
|
|
|
|
// as a different query than the one that fires on first paint when the
|
|
|
|
|
// store hasn't yet hydrated. Without this, an early null-port fetch could
|
|
|
|
|
// cache an error and display "-" indefinitely until the staleTime expires.
|
|
|
|
|
const portId = useUIStore((s) => s.currentPortId);
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
const { data, isLoading, isError } = useQuery<KpiData>({
|
2026-05-04 22:54:55 +02:00
|
|
|
queryKey: ['dashboard', 'kpis', portId],
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
queryFn: () => apiFetch<KpiData>('/api/v1/dashboard/kpis'),
|
|
|
|
|
staleTime: 60_000,
|
|
|
|
|
retry: 2,
|
2026-05-04 22:54:55 +02:00
|
|
|
// Avoid running until we have a port id - gates against the early
|
|
|
|
|
// unauth/no-port window where the API would return zeroes/errors.
|
|
|
|
|
enabled: !!portId,
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2026-04-28 12:09:59 +02:00
|
|
|
<KpiTileSkeleton />
|
|
|
|
|
<KpiTileSkeleton />
|
|
|
|
|
<KpiTileSkeleton />
|
|
|
|
|
<KpiTileSkeleton />
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 12:09:59 +02:00
|
|
|
const kpis: Array<{
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
accent: 'brand' | 'success' | 'warning' | 'mint' | 'teal' | 'purple';
|
|
|
|
|
}> = [
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
{
|
|
|
|
|
label: 'Total Clients',
|
2026-05-04 22:54:55 +02:00
|
|
|
value: isError ? '-' : String(data?.totalClients ?? 0),
|
2026-04-28 12:09:59 +02:00
|
|
|
accent: 'brand',
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Active Interests',
|
2026-05-04 22:54:55 +02:00
|
|
|
value: isError ? '-' : String(data?.activeInterests ?? 0),
|
2026-04-28 12:09:59 +02:00
|
|
|
accent: 'teal',
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Pipeline Value',
|
2026-05-09 04:24:46 +02:00
|
|
|
value: isError ? '-' : formatUsd(data?.pipelineValueUsd ?? 0),
|
2026-04-28 12:09:59 +02:00
|
|
|
accent: 'success',
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Occupancy Rate',
|
2026-05-04 22:54:55 +02:00
|
|
|
value: isError ? '-' : formatPercent(data?.occupancyRate ?? 0),
|
2026-04-28 12:09:59 +02:00
|
|
|
accent: 'purple',
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2026-04-28 12:09:59 +02:00
|
|
|
{kpis.map(({ label, value, accent }) => (
|
|
|
|
|
<KPITile key={label} title={label} value={value} accent={accent} />
|
Initial commit: Port Nimara CRM (Layers 0-4)
Full CRM rebuild with Next.js 15, TypeScript, Tailwind, Drizzle ORM,
PostgreSQL, Redis, BullMQ, MinIO, and Socket.io. Includes 461 source
files covering clients, berths, interests/pipeline, documents/EOI,
expenses/invoices, email, notifications, dashboard, admin, and
client portal. CI/CD via Gitea Actions with Docker builds.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 11:52:51 +01:00
|
|
|
))}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function KpiCardsWithBoundary() {
|
|
|
|
|
return (
|
|
|
|
|
<WidgetErrorBoundary>
|
|
|
|
|
<KpiCards />
|
|
|
|
|
</WidgetErrorBoundary>
|
|
|
|
|
);
|
|
|
|
|
}
|