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 { useState } from 'react';
|
2026-03-26 12:06:18 +01:00
|
|
|
import { useParams } from 'next/navigation';
|
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 { Plus, Download, FileText, FileSpreadsheet } from 'lucide-react';
|
|
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from '@/components/ui/dropdown-menu';
|
|
|
|
|
import { DataTable } from '@/components/shared/data-table';
|
|
|
|
|
import { FilterBar } from '@/components/shared/filter-bar';
|
|
|
|
|
import { PageHeader } from '@/components/shared/page-header';
|
|
|
|
|
import { EmptyState } from '@/components/shared/empty-state';
|
|
|
|
|
import { TableSkeleton } from '@/components/shared/loading-skeleton';
|
|
|
|
|
import { ArchiveConfirmDialog } from '@/components/shared/archive-confirm-dialog';
|
|
|
|
|
import { PermissionGate } from '@/components/shared/permission-gate';
|
|
|
|
|
import { ExpenseFormDialog } from '@/components/expenses/expense-form-dialog';
|
feat(mobile): mobile cards for yachts, companies, berths, invoices, expenses
Five new <EntityCard> files using the shared <ListCard> shell, wired
into each list page's <DataTable> via cardRender. Desktop view
(lg+) is unchanged.
- YachtCard: Ship icon, owner subtitle (User/Building2 icon by
ownerType), dimensions in meters preferred, hull #,
status pill. No accent bar (status is free-text).
- CompanyCard: Building2 icon, legalName subtitle, country (MapPin)
+ tax id (Hash) meta, member/yacht count line.
- BerthCard: Anchor icon, area subtitle (MapPin), dimensions
meta, status pill. Status-encoded accent bar
(emerald=available, amber=under_offer, slate=sold).
- InvoiceCard: FileText icon, client subtitle, due date (Calendar)
meta, prominent currency-formatted amount. Status
accent bar (emerald=paid, orange=overdue, ...).
- ExpenseCard: Receipt icon, category subtitle, expense date meta,
prominent amount, payment-status pill, "Possible
duplicate" pill when duplicateOf is set. Accent bar
by paymentStatus, overridden to amber when flagged
as duplicate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 15:34:04 +02:00
|
|
|
import { ExpenseCard } from '@/components/expenses/expense-card';
|
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 { expenseFilterDefinitions } from '@/components/expenses/expense-filters';
|
|
|
|
|
import { getExpenseColumns, type ExpenseRow } from '@/components/expenses/expense-columns';
|
2026-05-12 14:50:58 +02:00
|
|
|
import { useCreateFromUrl } from '@/hooks/use-create-from-url';
|
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 { usePaginatedQuery } from '@/hooks/use-paginated-query';
|
|
|
|
|
import { useRealtimeInvalidation } from '@/hooks/use-realtime-invalidation';
|
|
|
|
|
import { apiFetch } from '@/lib/api/client';
|
|
|
|
|
|
|
|
|
|
export default function ExpensesPage() {
|
|
|
|
|
const params = useParams<{ portSlug: string }>();
|
|
|
|
|
const portSlug = params?.portSlug ?? '';
|
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
|
|
|
|
const [createOpen, setCreateOpen] = useState(false);
|
2026-05-12 14:50:58 +02:00
|
|
|
useCreateFromUrl(() => setCreateOpen(true));
|
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 [editExpense, setEditExpense] = useState<ExpenseRow | null>(null);
|
|
|
|
|
const [archiveExpense, setArchiveExpense] = useState<ExpenseRow | null>(null);
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
data,
|
|
|
|
|
pagination,
|
|
|
|
|
isLoading,
|
|
|
|
|
isFetching,
|
|
|
|
|
sort,
|
|
|
|
|
setSort,
|
|
|
|
|
setPage,
|
|
|
|
|
setPageSize,
|
|
|
|
|
filters,
|
|
|
|
|
setFilter,
|
|
|
|
|
clearFilters,
|
|
|
|
|
} = usePaginatedQuery<ExpenseRow>({
|
|
|
|
|
queryKey: ['expenses'],
|
|
|
|
|
endpoint: '/api/v1/expenses',
|
|
|
|
|
filterDefinitions: expenseFilterDefinitions,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useRealtimeInvalidation({
|
|
|
|
|
'expense:created': [['expenses']],
|
|
|
|
|
'expense:updated': [['expenses']],
|
|
|
|
|
'expense:archived': [['expenses']],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const archiveMutation = useMutation({
|
feat(mobile): mobile cards for yachts, companies, berths, invoices, expenses
Five new <EntityCard> files using the shared <ListCard> shell, wired
into each list page's <DataTable> via cardRender. Desktop view
(lg+) is unchanged.
- YachtCard: Ship icon, owner subtitle (User/Building2 icon by
ownerType), dimensions in meters preferred, hull #,
status pill. No accent bar (status is free-text).
- CompanyCard: Building2 icon, legalName subtitle, country (MapPin)
+ tax id (Hash) meta, member/yacht count line.
- BerthCard: Anchor icon, area subtitle (MapPin), dimensions
meta, status pill. Status-encoded accent bar
(emerald=available, amber=under_offer, slate=sold).
- InvoiceCard: FileText icon, client subtitle, due date (Calendar)
meta, prominent currency-formatted amount. Status
accent bar (emerald=paid, orange=overdue, ...).
- ExpenseCard: Receipt icon, category subtitle, expense date meta,
prominent amount, payment-status pill, "Possible
duplicate" pill when duplicateOf is set. Accent bar
by paymentStatus, overridden to amber when flagged
as duplicate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 15:34:04 +02:00
|
|
|
mutationFn: (id: string) => apiFetch(`/api/v1/expenses/${id}`, { method: 'DELETE' }),
|
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
|
|
|
onSuccess: () => {
|
|
|
|
|
queryClient.invalidateQueries({ queryKey: ['expenses'] });
|
|
|
|
|
setArchiveExpense(null);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function handleExport(type: 'csv' | 'pdf') {
|
|
|
|
|
const res = await fetch(`/api/v1/expenses/export/${type}`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify(filters),
|
|
|
|
|
credentials: 'include',
|
|
|
|
|
});
|
|
|
|
|
if (!res.ok) return;
|
|
|
|
|
const blob = await res.blob();
|
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
|
|
|
const a = document.createElement('a');
|
|
|
|
|
a.href = url;
|
|
|
|
|
a.download = `expenses.${type}`;
|
|
|
|
|
a.click();
|
|
|
|
|
URL.revokeObjectURL(url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const columns = getExpenseColumns({
|
|
|
|
|
portSlug,
|
|
|
|
|
onEdit: (expense) => setEditExpense(expense),
|
|
|
|
|
onArchive: (expense) => setArchiveExpense(expense),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<PageHeader
|
|
|
|
|
title="Expenses"
|
|
|
|
|
description="Track and manage port expenses"
|
|
|
|
|
actions={
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<PermissionGate resource="expenses" action="view">
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<Button variant="outline" size="sm">
|
|
|
|
|
<Download className="mr-1.5 h-4 w-4" />
|
|
|
|
|
Export
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent align="end">
|
|
|
|
|
<DropdownMenuItem onClick={() => handleExport('csv')}>
|
|
|
|
|
<FileSpreadsheet className="mr-2 h-4 w-4" />
|
|
|
|
|
Export CSV
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
<DropdownMenuItem onClick={() => handleExport('pdf')}>
|
|
|
|
|
<FileText className="mr-2 h-4 w-4" />
|
|
|
|
|
Export PDF
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
</PermissionGate>
|
|
|
|
|
|
|
|
|
|
<PermissionGate resource="expenses" action="create">
|
|
|
|
|
<Button size="sm" onClick={() => setCreateOpen(true)}>
|
|
|
|
|
<Plus className="mr-1.5 h-4 w-4" />
|
|
|
|
|
New Expense
|
|
|
|
|
</Button>
|
|
|
|
|
</PermissionGate>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<FilterBar
|
|
|
|
|
filters={expenseFilterDefinitions}
|
|
|
|
|
values={filters}
|
|
|
|
|
onChange={setFilter}
|
|
|
|
|
onClear={clearFilters}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{isLoading ? (
|
|
|
|
|
<TableSkeleton />
|
|
|
|
|
) : (
|
|
|
|
|
<DataTable
|
|
|
|
|
columns={columns}
|
|
|
|
|
data={data}
|
|
|
|
|
pagination={pagination}
|
|
|
|
|
onPaginationChange={(p, ps) => {
|
|
|
|
|
setPage(p);
|
|
|
|
|
setPageSize(ps);
|
|
|
|
|
}}
|
|
|
|
|
sort={sort}
|
|
|
|
|
onSortChange={setSort}
|
|
|
|
|
isLoading={isFetching && !isLoading}
|
|
|
|
|
getRowId={(row) => row.id}
|
feat(mobile): mobile cards for yachts, companies, berths, invoices, expenses
Five new <EntityCard> files using the shared <ListCard> shell, wired
into each list page's <DataTable> via cardRender. Desktop view
(lg+) is unchanged.
- YachtCard: Ship icon, owner subtitle (User/Building2 icon by
ownerType), dimensions in meters preferred, hull #,
status pill. No accent bar (status is free-text).
- CompanyCard: Building2 icon, legalName subtitle, country (MapPin)
+ tax id (Hash) meta, member/yacht count line.
- BerthCard: Anchor icon, area subtitle (MapPin), dimensions
meta, status pill. Status-encoded accent bar
(emerald=available, amber=under_offer, slate=sold).
- InvoiceCard: FileText icon, client subtitle, due date (Calendar)
meta, prominent currency-formatted amount. Status
accent bar (emerald=paid, orange=overdue, ...).
- ExpenseCard: Receipt icon, category subtitle, expense date meta,
prominent amount, payment-status pill, "Possible
duplicate" pill when duplicateOf is set. Accent bar
by paymentStatus, overridden to amber when flagged
as duplicate.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 15:34:04 +02:00
|
|
|
cardRender={(row) => (
|
|
|
|
|
<ExpenseCard
|
|
|
|
|
expense={row.original}
|
|
|
|
|
portSlug={portSlug}
|
|
|
|
|
onEdit={setEditExpense}
|
|
|
|
|
onArchive={setArchiveExpense}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
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
|
|
|
emptyState={
|
|
|
|
|
<EmptyState
|
|
|
|
|
title="No expenses found"
|
|
|
|
|
description="Get started by adding your first expense."
|
|
|
|
|
action={{ label: 'New Expense', onClick: () => setCreateOpen(true) }}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<ExpenseFormDialog open={createOpen} onOpenChange={setCreateOpen} />
|
|
|
|
|
|
|
|
|
|
{editExpense && (
|
|
|
|
|
<ExpenseFormDialog
|
|
|
|
|
open={!!editExpense}
|
|
|
|
|
onOpenChange={(open) => !open && setEditExpense(null)}
|
|
|
|
|
expense={editExpense}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<ArchiveConfirmDialog
|
|
|
|
|
open={!!archiveExpense}
|
|
|
|
|
onOpenChange={(open) => !open && setArchiveExpense(null)}
|
|
|
|
|
entityName={archiveExpense?.establishmentName ?? 'this expense'}
|
|
|
|
|
entityType="Expense"
|
|
|
|
|
isArchived={false}
|
|
|
|
|
onConfirm={() => archiveExpense && archiveMutation.mutate(archiveExpense.id)}
|
|
|
|
|
isLoading={archiveMutation.isPending}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|