@voyantjs/legal-ui 0.30.7 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/components/contract-detail-page.d.ts +16 -0
- package/dist/components/contract-detail-page.d.ts.map +1 -0
- package/dist/components/contract-detail-page.js +106 -0
- package/dist/components/contracts-page.d.ts +14 -0
- package/dist/components/contracts-page.d.ts.map +1 -0
- package/dist/components/contracts-page.js +72 -0
- package/dist/components/number-series-page.d.ts +13 -0
- package/dist/components/number-series-page.d.ts.map +1 -0
- package/dist/components/number-series-page.js +37 -0
- package/dist/components/policies-page.d.ts +13 -0
- package/dist/components/policies-page.d.ts.map +1 -0
- package/dist/components/policies-page.js +60 -0
- package/dist/components/policy-detail-page.d.ts +23 -0
- package/dist/components/policy-detail-page.d.ts.map +1 -0
- package/dist/components/policy-detail-page.js +153 -0
- package/dist/components/template-detail-page.d.ts +10 -0
- package/dist/components/template-detail-page.d.ts.map +1 -0
- package/dist/components/template-detail-page.js +84 -0
- package/dist/components/templates-page.d.ts +22 -0
- package/dist/components/templates-page.d.ts.map +1 -0
- package/dist/components/templates-page.js +98 -0
- package/dist/i18n/en.d.ts +262 -0
- package/dist/i18n/en.d.ts.map +1 -1
- package/dist/i18n/en.js +262 -0
- package/dist/i18n/index.d.ts +2 -1
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +1 -0
- package/dist/i18n/messages.d.ts +234 -0
- package/dist/i18n/messages.d.ts.map +1 -1
- package/dist/i18n/messages.js +20 -0
- package/dist/i18n/provider.d.ts +524 -0
- package/dist/i18n/provider.d.ts.map +1 -1
- package/dist/i18n/ro.d.ts +262 -0
- package/dist/i18n/ro.d.ts.map +1 -1
- package/dist/i18n/ro.js +262 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -25,7 +25,3 @@ import { legalUiRo } from "@voyantjs/legal-ui/i18n/ro"
|
|
|
25
25
|
|
|
26
26
|
English-only apps should import only `./i18n/en`. Bilingual apps can import
|
|
27
27
|
`./i18n/en` and `./i18n/ro`.
|
|
28
|
-
|
|
29
|
-
## Not included (registry-only)
|
|
30
|
-
|
|
31
|
-
Some components couple to TanStack Router or template-local helpers and remain available only via the shadcn registry: `contract-detail-page`, `contracts-page`, `policies-page`, `policy-detail-page`, `template-detail-page`, `templates-page`. Import via `npx shadcn add @voyant/<component>` and customize per-project.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type LegalContractAttachmentRecord, type LegalContractRecord } from "@voyantjs/legal-react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
export interface ContractDetailPageProps {
|
|
4
|
+
id: string;
|
|
5
|
+
onBackToContracts?: () => void;
|
|
6
|
+
renderContractDialog?: (props: ContractDetailDialogRenderProps) => ReactNode;
|
|
7
|
+
getAttachmentDownloadHref?: (attachment: LegalContractAttachmentRecord) => string;
|
|
8
|
+
}
|
|
9
|
+
export interface ContractDetailDialogRenderProps {
|
|
10
|
+
open: boolean;
|
|
11
|
+
onOpenChange: (open: boolean) => void;
|
|
12
|
+
contract: LegalContractRecord;
|
|
13
|
+
onSuccess: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare function ContractDetailPage({ id, onBackToContracts, renderContractDialog, getAttachmentDownloadHref, }: ContractDetailPageProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=contract-detail-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-detail-page.d.ts","sourceRoot":"","sources":["../../src/components/contract-detail-page.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,6BAA6B,EAClC,KAAK,mBAAmB,EAMzB,MAAM,uBAAuB,CAAA;AAW9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAqBtC,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAA;IACV,iBAAiB,CAAC,EAAE,MAAM,IAAI,CAAA;IAC9B,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,+BAA+B,KAAK,SAAS,CAAA;IAC5E,yBAAyB,CAAC,EAAE,CAAC,UAAU,EAAE,6BAA6B,KAAK,MAAM,CAAA;CAClF;AAED,MAAM,WAAW,+BAA+B;IAC9C,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,SAAS,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,EAAE,EACF,iBAAiB,EACjB,oBAAoB,EACpB,yBAAyB,GAC1B,EAAE,uBAAuB,2CA0TzB"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { formatMessage } from "@voyantjs/i18n";
|
|
4
|
+
import { useLegalContract, useLegalContractAttachmentMutation, useLegalContractAttachments, useLegalContractMutation, useLegalContractSignatures, } from "@voyantjs/legal-react";
|
|
5
|
+
import { Badge, Button, Card, CardContent, CardHeader, CardTitle } from "@voyantjs/ui/components";
|
|
6
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@voyantjs/ui/components/table";
|
|
7
|
+
import { ArrowLeft, ExternalLink, FileText, Pencil, Plus, Trash2 } from "lucide-react";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
import { useLegalUiI18nOrDefault, useLegalUiMessagesOrDefault } from "../i18n/index.js";
|
|
10
|
+
import { AttachmentDialog } from "./attachment-dialog.js";
|
|
11
|
+
import { SignatureDialog } from "./signature-dialog.js";
|
|
12
|
+
const statusVariant = {
|
|
13
|
+
draft: "outline",
|
|
14
|
+
issued: "secondary",
|
|
15
|
+
sent: "secondary",
|
|
16
|
+
signed: "default",
|
|
17
|
+
executed: "default",
|
|
18
|
+
expired: "destructive",
|
|
19
|
+
void: "destructive",
|
|
20
|
+
};
|
|
21
|
+
export function ContractDetailPage({ id, onBackToContracts, renderContractDialog, getAttachmentDownloadHref, }) {
|
|
22
|
+
const queryClient = useQueryClient();
|
|
23
|
+
const i18n = useLegalUiI18nOrDefault();
|
|
24
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
25
|
+
const f = messages.contractDetailPage;
|
|
26
|
+
const { remove, issue, voidContract } = useLegalContractMutation();
|
|
27
|
+
const { remove: removeAttachment } = useLegalContractAttachmentMutation();
|
|
28
|
+
const [editOpen, setEditOpen] = useState(false);
|
|
29
|
+
const [signOpen, setSignOpen] = useState(false);
|
|
30
|
+
const [attachOpen, setAttachOpen] = useState(false);
|
|
31
|
+
const [editingAttachment, setEditingAttachment] = useState();
|
|
32
|
+
const { data: contract, isPending } = useLegalContract(id);
|
|
33
|
+
const { data: signatures, refetch: refetchSignatures } = useLegalContractSignatures({
|
|
34
|
+
contractId: id,
|
|
35
|
+
});
|
|
36
|
+
const { data: attachments, refetch: refetchAttachments } = useLegalContractAttachments({
|
|
37
|
+
contractId: id,
|
|
38
|
+
});
|
|
39
|
+
if (isPending) {
|
|
40
|
+
return (_jsx("div", { className: "flex flex-col gap-6 p-6", children: _jsx("div", { className: "rounded-md border border-dashed p-8 text-center", children: _jsx("p", { className: "text-sm text-muted-foreground", children: messages.common.loading }) }) }));
|
|
41
|
+
}
|
|
42
|
+
if (!contract) {
|
|
43
|
+
return (_jsxs("div", { className: "flex flex-col items-center justify-center gap-4 py-12", children: [_jsx("p", { className: "text-muted-foreground", children: f.notFound }), onBackToContracts ? (_jsx(Button, { variant: "outline", onClick: onBackToContracts, children: f.backToContracts })) : null] }));
|
|
44
|
+
}
|
|
45
|
+
const status = contract.status;
|
|
46
|
+
const canAddSignature = status === "issued" || status === "sent" || status === "signed";
|
|
47
|
+
return (_jsxs("div", { className: "flex flex-col gap-6 p-6", children: [_jsxs("div", { className: "flex items-center gap-4", children: [onBackToContracts ? (_jsx(Button, { variant: "ghost", size: "icon", onClick: onBackToContracts, children: _jsx(ArrowLeft, { className: "size-4", "aria-hidden": "true" }) })) : null, _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: contract.title }), _jsxs("div", { className: "mt-1 flex flex-wrap items-center gap-2", children: [_jsx(Badge, { variant: "outline", children: messages.common.contractScopeLabels[contract.scope] ?? contract.scope }), _jsx(Badge, { variant: statusVariant[status] ?? "secondary", children: messages.common.contractStatusLabels[status] ?? status }), contract.contractNumber ? (_jsx("span", { className: "font-mono text-xs text-muted-foreground", children: contract.contractNumber })) : null] })] }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [status === "draft" ? (_jsx(Button, { size: "sm", onClick: () => issue.mutate(id), disabled: issue.isPending, children: f.actions.issue })) : null, status !== "void" ? (_jsx(Button, { size: "sm", variant: "destructive", onClick: () => {
|
|
48
|
+
if (confirm(f.voidConfirm)) {
|
|
49
|
+
voidContract.mutate(id);
|
|
50
|
+
}
|
|
51
|
+
}, disabled: voidContract.isPending, children: f.actions.void })) : null, renderContractDialog ? (_jsxs(Button, { variant: "outline", size: "sm", onClick: () => setEditOpen(true), children: [_jsx(Pencil, { className: "mr-2 size-4", "aria-hidden": "true" }), messages.common.edit] })) : null, status === "draft" ? (_jsxs(Button, { variant: "destructive", size: "sm", onClick: () => {
|
|
52
|
+
if (confirm(formatMessage(f.deleteConfirm, { title: contract.title }))) {
|
|
53
|
+
remove.mutate(id, { onSuccess: () => onBackToContracts?.() });
|
|
54
|
+
}
|
|
55
|
+
}, disabled: remove.isPending, children: [_jsx(Trash2, { className: "mr-2 size-4", "aria-hidden": "true" }), messages.common.delete] })) : null] })] }), _jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: f.sections.details }) }), _jsxs(CardContent, { className: "grid gap-3 text-sm", children: [_jsx(DetailRow, { label: f.fields.language, children: contract.language }), contract.templateVersionId ? (_jsx(DetailRow, { label: f.fields.templateVersion, children: _jsx("span", { className: "font-mono text-xs", children: contract.templateVersionId }) })) : null, contract.seriesId ? (_jsx(DetailRow, { label: f.fields.series, children: _jsx("span", { className: "font-mono text-xs", children: contract.seriesId }) })) : null, contract.expiresAt ? (_jsx(DetailRow, { label: f.fields.expires, children: i18n.formatDate(contract.expiresAt) })) : null, _jsxs("div", { className: "mt-2 border-t pt-3", children: [_jsx(DetailRow, { label: f.fields.created, children: i18n.formatDate(contract.createdAt) }), _jsx(DetailRow, { label: f.fields.updated, children: i18n.formatDate(contract.updatedAt) })] })] })] }), _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: f.sections.parties }) }), _jsxs(CardContent, { className: "grid gap-3 text-sm", children: [contract.personId ? (_jsx(DetailRow, { label: f.fields.person, children: _jsx("span", { className: "font-mono text-xs", children: contract.personId }) })) : null, contract.organizationId ? (_jsx(DetailRow, { label: f.fields.organization, children: _jsx("span", { className: "font-mono text-xs", children: contract.organizationId }) })) : null, contract.supplierId ? (_jsx(DetailRow, { label: f.fields.supplier, children: _jsx("span", { className: "font-mono text-xs", children: contract.supplierId }) })) : null, contract.channelId ? (_jsx(DetailRow, { label: f.fields.channel, children: _jsx("span", { className: "font-mono text-xs", children: contract.channelId }) })) : null, !contract.personId &&
|
|
56
|
+
!contract.organizationId &&
|
|
57
|
+
!contract.supplierId &&
|
|
58
|
+
!contract.channelId ? (_jsx("p", { className: "text-muted-foreground", children: f.empty.noParties })) : null] })] })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between", children: [_jsx(CardTitle, { children: f.sections.signatures }), canAddSignature ? (_jsxs(Button, { size: "sm", onClick: () => setSignOpen(true), children: [_jsx(Plus, { className: "mr-2 size-4", "aria-hidden": "true" }), f.actions.addSignature] })) : null] }), _jsx(CardContent, { children: !signatures || signatures.length === 0 ? (_jsx("p", { className: "py-4 text-center text-sm text-muted-foreground", children: f.empty.noSignatures })) : (_jsx("div", { className: "rounded border bg-background", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: f.fields.name }), _jsx(TableHead, { children: f.fields.email }), _jsx(TableHead, { children: f.fields.role }), _jsx(TableHead, { children: f.fields.method }), _jsx(TableHead, { children: f.fields.signedAt })] }) }), _jsx(TableBody, { children: signatures.map((signature) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: signature.signerName }), _jsx(TableCell, { children: signature.signerEmail ?? messages.common.noResultsDash }), _jsx(TableCell, { children: signature.signerRole ?? messages.common.noResultsDash }), _jsx(TableCell, { children: signature.method }), _jsx(TableCell, { children: i18n.formatDateTime(signature.signedAt) })] }, signature.id))) })] }) })) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between", children: [_jsx(CardTitle, { children: f.sections.attachments }), _jsxs(Button, { size: "sm", onClick: () => {
|
|
59
|
+
setEditingAttachment(undefined);
|
|
60
|
+
setAttachOpen(true);
|
|
61
|
+
}, children: [_jsx(Plus, { className: "mr-2 size-4", "aria-hidden": "true" }), f.actions.addAttachment] })] }), _jsx(CardContent, { children: !attachments || attachments.length === 0 ? (_jsx("p", { className: "py-4 text-center text-sm text-muted-foreground", children: f.empty.noAttachments })) : (_jsx("div", { className: "rounded border bg-background", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: f.fields.name }), _jsx(TableHead, { children: f.fields.kind }), _jsx(TableHead, { children: f.fields.mimeType }), _jsx(TableHead, { children: f.fields.size }), _jsx(TableHead, { className: "w-16" })] }) }), _jsx(TableBody, { children: attachments.map((attachment) => (_jsx(AttachmentRow, { attachment: attachment, downloadHref: getAttachmentDownloadHref?.(attachment), onEdit: () => {
|
|
62
|
+
setEditingAttachment(attachment);
|
|
63
|
+
setAttachOpen(true);
|
|
64
|
+
}, onDelete: () => {
|
|
65
|
+
if (confirm(f.deleteAttachmentConfirm)) {
|
|
66
|
+
removeAttachment.mutate({ contractId: id, id: attachment.id });
|
|
67
|
+
}
|
|
68
|
+
} }, attachment.id))) })] }) })) })] }), renderContractDialog?.({
|
|
69
|
+
open: editOpen,
|
|
70
|
+
onOpenChange: setEditOpen,
|
|
71
|
+
contract,
|
|
72
|
+
onSuccess: () => {
|
|
73
|
+
setEditOpen(false);
|
|
74
|
+
void queryClient.invalidateQueries();
|
|
75
|
+
},
|
|
76
|
+
}), _jsx(SignatureDialog, { open: signOpen, onOpenChange: setSignOpen, contractId: id, onSuccess: () => {
|
|
77
|
+
setSignOpen(false);
|
|
78
|
+
void refetchSignatures();
|
|
79
|
+
void queryClient.invalidateQueries();
|
|
80
|
+
} }), _jsx(AttachmentDialog, { open: attachOpen, onOpenChange: setAttachOpen, contractId: id, attachment: editingAttachment, onSuccess: () => {
|
|
81
|
+
setAttachOpen(false);
|
|
82
|
+
setEditingAttachment(undefined);
|
|
83
|
+
void refetchAttachments();
|
|
84
|
+
} })] }));
|
|
85
|
+
}
|
|
86
|
+
function DetailRow({ label, children }) {
|
|
87
|
+
return (_jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [label, ":"] }), " ", _jsx("span", { children: children })] }));
|
|
88
|
+
}
|
|
89
|
+
function AttachmentRow({ attachment, downloadHref, onEdit, onDelete, }) {
|
|
90
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
91
|
+
const f = messages.contractDetailPage;
|
|
92
|
+
return (_jsxs(TableRow, { children: [_jsx(TableCell, { children: downloadHref ? (_jsxs("a", { href: downloadHref, target: "_blank", rel: "noopener noreferrer", className: "inline-flex items-center gap-1.5 hover:underline", children: [_jsx(FileText, { className: "size-3.5 shrink-0 opacity-60", "aria-hidden": "true" }), _jsx("span", { className: "truncate", children: attachment.name }), _jsx(ExternalLink, { className: "size-3 opacity-60", "aria-hidden": "true" })] })) : (_jsx("span", { children: attachment.name })) }), _jsx(TableCell, { children: attachment.kind }), _jsx(TableCell, { children: attachment.mimeType ?? messages.common.noResultsDash }), _jsx(TableCell, { children: attachment.fileSize != null
|
|
93
|
+
? formatBytes(attachment.fileSize, {
|
|
94
|
+
bytes: f.units.bytes,
|
|
95
|
+
kilobytes: f.units.kilobytes,
|
|
96
|
+
megabytes: f.units.megabytes,
|
|
97
|
+
})
|
|
98
|
+
: messages.common.noResultsDash }), _jsx(TableCell, { children: _jsxs("div", { className: "flex items-center gap-1", children: [_jsx("button", { type: "button", onClick: onEdit, className: "text-muted-foreground hover:text-foreground", children: _jsx(Pencil, { className: "size-3", "aria-hidden": "true" }) }), _jsx("button", { type: "button", onClick: onDelete, className: "text-muted-foreground hover:text-destructive", children: _jsx(Trash2, { className: "size-3", "aria-hidden": "true" }) })] }) })] }));
|
|
99
|
+
}
|
|
100
|
+
function formatBytes(bytes, units) {
|
|
101
|
+
if (bytes < 1024)
|
|
102
|
+
return `${bytes} ${units.bytes}`;
|
|
103
|
+
if (bytes < 1024 * 1024)
|
|
104
|
+
return `${Math.round(bytes / 1024)} ${units.kilobytes}`;
|
|
105
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} ${units.megabytes}`;
|
|
106
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface ContractDialogRenderProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onOpenChange: (open: boolean) => void;
|
|
5
|
+
onSuccess: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface ContractsPageProps {
|
|
8
|
+
className?: string;
|
|
9
|
+
onOpenContract?: (contractId: string) => void;
|
|
10
|
+
renderContractDialog?: (props: ContractDialogRenderProps) => ReactNode;
|
|
11
|
+
renderPersonCell?: (personId: string | null) => ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export declare function ContractsPage({ className, onOpenContract, renderContractDialog, renderPersonCell, }?: ContractsPageProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=contracts-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contracts-page.d.ts","sourceRoot":"","sources":["../../src/components/contracts-page.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAoBtC,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,SAAS,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7C,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE,yBAAyB,KAAK,SAAS,CAAA;IACtE,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,KAAK,SAAS,CAAA;CAC1D;AAED,wBAAgB,aAAa,CAAC,EAC5B,SAAS,EACT,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GACjB,GAAE,kBAAuB,2CA8LzB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { formatMessage } from "@voyantjs/i18n";
|
|
3
|
+
import { useLegalContracts } from "@voyantjs/legal-react";
|
|
4
|
+
import { Badge, Button, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@voyantjs/ui/components";
|
|
5
|
+
import { Skeleton } from "@voyantjs/ui/components/skeleton";
|
|
6
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@voyantjs/ui/components/table";
|
|
7
|
+
import { cn } from "@voyantjs/ui/lib/utils";
|
|
8
|
+
import { Plus, Search } from "lucide-react";
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import { useLegalUiI18nOrDefault, useLegalUiMessagesOrDefault } from "../i18n/index.js";
|
|
11
|
+
import { legalContractScopes, legalContractStatuses } from "../i18n/messages.js";
|
|
12
|
+
const PAGE_SIZE = 25;
|
|
13
|
+
const SCOPE_ALL = "__all__";
|
|
14
|
+
const STATUS_ALL = "__all__";
|
|
15
|
+
const statusVariant = {
|
|
16
|
+
draft: "outline",
|
|
17
|
+
issued: "secondary",
|
|
18
|
+
sent: "secondary",
|
|
19
|
+
signed: "default",
|
|
20
|
+
executed: "default",
|
|
21
|
+
expired: "destructive",
|
|
22
|
+
void: "destructive",
|
|
23
|
+
};
|
|
24
|
+
export function ContractsPage({ className, onOpenContract, renderContractDialog, renderPersonCell, } = {}) {
|
|
25
|
+
const i18n = useLegalUiI18nOrDefault();
|
|
26
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
27
|
+
const f = messages.contractsPage;
|
|
28
|
+
const [search, setSearch] = useState("");
|
|
29
|
+
const [scope, setScope] = useState(SCOPE_ALL);
|
|
30
|
+
const [status, setStatus] = useState(STATUS_ALL);
|
|
31
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
32
|
+
const [pageIndex, setPageIndex] = useState(0);
|
|
33
|
+
const { data, isPending, isFetching, isError, refetch } = useLegalContracts({
|
|
34
|
+
search,
|
|
35
|
+
scope: scope === SCOPE_ALL ? "all" : scope,
|
|
36
|
+
status: status === STATUS_ALL ? "all" : status,
|
|
37
|
+
limit: PAGE_SIZE,
|
|
38
|
+
offset: pageIndex * PAGE_SIZE,
|
|
39
|
+
});
|
|
40
|
+
const contracts = data?.data ?? [];
|
|
41
|
+
const total = data?.total ?? 0;
|
|
42
|
+
const page = pageIndex + 1;
|
|
43
|
+
const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE));
|
|
44
|
+
const showSkeleton = isPending || (isFetching && contracts.length === 0);
|
|
45
|
+
const resetPage = () => setPageIndex(0);
|
|
46
|
+
return (_jsxs("div", { className: cn("flex flex-col gap-6 p-6", className), children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: f.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: f.description })] }), renderContractDialog ? (_jsxs(Button, { onClick: () => setDialogOpen(true), children: [_jsx(Plus, { className: "mr-2 size-4", "aria-hidden": "true" }), f.create] })) : null] }), _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsxs("div", { className: "relative min-w-[14rem] max-w-sm flex-1", children: [_jsx(Label, { htmlFor: "contracts-search", className: "sr-only", children: f.searchPlaceholder }), _jsx(Search, { className: "absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground", "aria-hidden": "true" }), _jsx(Input, { id: "contracts-search", placeholder: f.searchPlaceholder, value: search, onChange: (event) => {
|
|
47
|
+
setSearch(event.target.value);
|
|
48
|
+
resetPage();
|
|
49
|
+
}, className: "pl-9" })] }), _jsxs(Select, { value: scope, onValueChange: (value) => {
|
|
50
|
+
setScope(value ?? SCOPE_ALL);
|
|
51
|
+
resetPage();
|
|
52
|
+
}, children: [_jsx(SelectTrigger, { className: "w-[12.5rem]", children: _jsx(SelectValue, { placeholder: f.filters.scope }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: SCOPE_ALL, children: f.filters.allScopes }), legalContractScopes.map((value) => (_jsx(SelectItem, { value: value, children: messages.common.contractScopeLabels[value] }, value)))] })] }), _jsxs(Select, { value: status, onValueChange: (value) => {
|
|
53
|
+
setStatus(value ?? STATUS_ALL);
|
|
54
|
+
resetPage();
|
|
55
|
+
}, children: [_jsx(SelectTrigger, { className: "w-[12.5rem]", children: _jsx(SelectValue, { placeholder: f.filters.status }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: STATUS_ALL, children: f.filters.allStatuses }), legalContractStatuses.map((value) => (_jsx(SelectItem, { value: value, children: messages.common.contractStatusLabels[value] }, value)))] })] })] }), _jsx("div", { className: "rounded-md border", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: f.columns.number }), _jsx(TableHead, { children: f.columns.title }), _jsx(TableHead, { children: f.columns.scope }), _jsx(TableHead, { children: f.columns.status }), _jsx(TableHead, { children: f.columns.person }), _jsx(TableHead, { children: f.columns.created })] }) }), _jsx(TableBody, { children: showSkeleton ? (_jsx(ContractRowSkeleton, { rows: 6 })) : isError ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 6, className: "h-24 text-center text-sm text-destructive", children: f.loadFailed }) })) : contracts.length === 0 ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 6, className: "h-24 text-center text-sm text-muted-foreground", children: f.empty }) })) : (contracts.map((contract) => (_jsxs(TableRow, { onClick: () => onOpenContract?.(contract.id), className: cn(onOpenContract && "cursor-pointer"), children: [_jsx(TableCell, { className: "font-mono text-xs", children: contract.contractNumber ?? messages.common.noResultsDash }), _jsx(TableCell, { className: "font-medium", children: contract.title }), _jsx(TableCell, { children: _jsx(Badge, { variant: "outline", children: messages.common.contractScopeLabels[contract.scope] ?? contract.scope }) }), _jsx(TableCell, { children: _jsx(Badge, { variant: statusVariant[contract.status] ?? "secondary", children: messages.common.contractStatusLabels[contract.status] }) }), _jsx(TableCell, { children: renderPersonCell ? (renderPersonCell(contract.personId)) : (_jsx("span", { className: "font-mono text-xs", children: contract.personId ?? messages.common.noResultsDash })) }), _jsx(TableCell, { children: i18n.formatDate(contract.createdAt) })] }, contract.id)))) })] }) }), _jsx(PaginationBar, { shown: contracts.length, total: total, page: page, pageCount: pageCount, onPrevious: () => setPageIndex((prev) => Math.max(0, prev - 1)), onNext: () => setPageIndex((prev) => prev + 1), canGoBack: pageIndex > 0, canGoForward: (pageIndex + 1) * PAGE_SIZE < total }), renderContractDialog?.({
|
|
56
|
+
open: dialogOpen,
|
|
57
|
+
onOpenChange: setDialogOpen,
|
|
58
|
+
onSuccess: () => {
|
|
59
|
+
setDialogOpen(false);
|
|
60
|
+
setPageIndex(0);
|
|
61
|
+
void refetch();
|
|
62
|
+
},
|
|
63
|
+
})] }));
|
|
64
|
+
}
|
|
65
|
+
function PaginationBar({ shown, total, page, pageCount, onPrevious, onNext, canGoBack, canGoForward, }) {
|
|
66
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
67
|
+
const f = messages.contractsPage.pagination;
|
|
68
|
+
return (_jsxs("div", { className: "flex items-center justify-between text-sm text-muted-foreground", children: [_jsx("span", { children: formatMessage(f.showing, { count: shown, total }) }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", disabled: !canGoBack, onClick: onPrevious, children: f.previous }), _jsx("span", { children: formatMessage(f.page, { page, pageCount }) }), _jsx(Button, { variant: "outline", size: "sm", disabled: !canGoForward, onClick: onNext, children: f.next })] })] }));
|
|
69
|
+
}
|
|
70
|
+
function ContractRowSkeleton({ rows }) {
|
|
71
|
+
return (_jsx(_Fragment, { children: Array.from({ length: rows }).map((_, index) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-24" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-40" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-5 w-24 rounded-full" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-5 w-20 rounded-full" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-28" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-24" }) })] }, `contract-skeleton-${index}`))) }));
|
|
72
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type LegalContractNumberSeriesRecord } from "@voyantjs/legal-react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
export interface NumberSeriesDialogRenderProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onOpenChange: (open: boolean) => void;
|
|
6
|
+
series?: LegalContractNumberSeriesRecord;
|
|
7
|
+
onSuccess: () => void;
|
|
8
|
+
}
|
|
9
|
+
export interface NumberSeriesPageProps {
|
|
10
|
+
renderNumberSeriesDialog?: (props: NumberSeriesDialogRenderProps) => ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare function NumberSeriesPage({ renderNumberSeriesDialog }?: NumberSeriesPageProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=number-series-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-series-page.d.ts","sourceRoot":"","sources":["../../src/components/number-series-page.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,+BAA+B,EAGrC,MAAM,uBAAuB,CAAA;AAG9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAKtC,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,MAAM,CAAC,EAAE,+BAA+B,CAAA;IACxC,SAAS,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,qBAAqB;IACpC,wBAAwB,CAAC,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,SAAS,CAAA;CAC/E;AAED,wBAAgB,gBAAgB,CAAC,EAAE,wBAAwB,EAAE,GAAE,qBAA0B,2CA2HxF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { formatMessage } from "@voyantjs/i18n";
|
|
3
|
+
import { useLegalContractNumberSeries, useLegalContractNumberSeriesMutation, } from "@voyantjs/legal-react";
|
|
4
|
+
import { Badge, Button } from "@voyantjs/ui/components";
|
|
5
|
+
import { Loader2, Pencil, Plus, Trash2 } from "lucide-react";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { useLegalUiMessagesOrDefault } from "../i18n/index.js";
|
|
8
|
+
export function NumberSeriesPage({ renderNumberSeriesDialog } = {}) {
|
|
9
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
10
|
+
const page = messages.numberSeriesPage;
|
|
11
|
+
const common = messages.common;
|
|
12
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
13
|
+
const [editingSeries, setEditingSeries] = useState();
|
|
14
|
+
const { remove } = useLegalContractNumberSeriesMutation();
|
|
15
|
+
const { data, isPending, refetch } = useLegalContractNumberSeries();
|
|
16
|
+
const rows = data?.data ?? [];
|
|
17
|
+
return (_jsxs("div", { className: "flex flex-col gap-6 p-6", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: page.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: page.description })] }), renderNumberSeriesDialog ? (_jsxs(Button, { onClick: () => {
|
|
18
|
+
setEditingSeries(undefined);
|
|
19
|
+
setDialogOpen(true);
|
|
20
|
+
}, children: [_jsx(Plus, { className: "mr-2 h-4 w-4" }), page.actions.create] })) : null] }), isPending ? (_jsx("div", { className: "flex items-center justify-center py-12", children: _jsx(Loader2, { className: "h-6 w-6 animate-spin text-muted-foreground" }) })) : null, !isPending && rows.length === 0 ? (_jsx("div", { className: "rounded-md border border-dashed p-8 text-center", children: _jsx("p", { className: "text-sm text-muted-foreground", children: page.empty }) })) : null, !isPending && rows.length > 0 ? (_jsx("div", { className: "rounded border bg-background", children: _jsxs("table", { className: "w-full text-sm", children: [_jsx("thead", { children: _jsxs("tr", { className: "border-b text-muted-foreground", children: [_jsx("th", { className: "p-3 text-left font-medium", children: page.columns.name }), _jsx("th", { className: "p-3 text-left font-medium", children: page.columns.prefix }), _jsx("th", { className: "p-3 text-left font-medium", children: page.columns.separator }), _jsx("th", { className: "p-3 text-left font-medium", children: page.columns.pad }), _jsx("th", { className: "p-3 text-left font-medium", children: page.columns.current }), _jsx("th", { className: "p-3 text-left font-medium", children: page.columns.reset }), _jsx("th", { className: "p-3 text-left font-medium", children: page.columns.scope }), _jsx("th", { className: "p-3 text-left font-medium", children: page.columns.status }), _jsx("th", { className: "w-20 p-3" })] }) }), _jsx("tbody", { children: rows.map((series) => (_jsxs("tr", { className: "border-b last:border-b-0", children: [_jsx("td", { className: "p-3", children: series.name }), _jsx("td", { className: "p-3 font-mono", children: series.prefix }), _jsx("td", { className: "p-3 font-mono", children: series.separator || common.none }), _jsx("td", { className: "p-3", children: series.padLength }), _jsx("td", { className: "p-3 font-mono", children: series.currentSequence }), _jsx("td", { className: "p-3 capitalize", children: series.resetStrategy }), _jsx("td", { className: "p-3", children: _jsx(Badge, { variant: "outline", className: "capitalize", children: series.scope }) }), _jsx("td", { className: "p-3", children: _jsx(Badge, { variant: series.active ? "default" : "secondary", children: series.active ? page.active : page.inactive }) }), _jsx("td", { className: "p-3", children: _jsxs("div", { className: "flex items-center gap-1", children: [renderNumberSeriesDialog ? (_jsx("button", { type: "button", onClick: () => {
|
|
21
|
+
setEditingSeries(series);
|
|
22
|
+
setDialogOpen(true);
|
|
23
|
+
}, className: "text-muted-foreground hover:text-foreground", children: _jsx(Pencil, { className: "h-3.5 w-3.5" }) })) : null, _jsx("button", { type: "button", onClick: () => {
|
|
24
|
+
if (confirm(formatMessage(page.deleteConfirm, { name: series.name }))) {
|
|
25
|
+
remove.mutate(series.id, { onSuccess: () => void refetch() });
|
|
26
|
+
}
|
|
27
|
+
}, className: "text-muted-foreground hover:text-destructive", children: _jsx(Trash2, { className: "h-3.5 w-3.5" }) })] }) })] }, series.id))) })] }) })) : null, renderNumberSeriesDialog?.({
|
|
28
|
+
open: dialogOpen,
|
|
29
|
+
onOpenChange: setDialogOpen,
|
|
30
|
+
series: editingSeries,
|
|
31
|
+
onSuccess: () => {
|
|
32
|
+
setDialogOpen(false);
|
|
33
|
+
setEditingSeries(undefined);
|
|
34
|
+
void refetch();
|
|
35
|
+
},
|
|
36
|
+
})] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export interface PolicyDialogRenderProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onOpenChange: (open: boolean) => void;
|
|
5
|
+
onSuccess: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface PoliciesPageProps {
|
|
8
|
+
className?: string;
|
|
9
|
+
onOpenPolicy?: (policyId: string) => void;
|
|
10
|
+
renderPolicyDialog?: (props: PolicyDialogRenderProps) => ReactNode;
|
|
11
|
+
}
|
|
12
|
+
export declare function PoliciesPage({ className, onOpenPolicy, renderPolicyDialog, }?: PoliciesPageProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=policies-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policies-page.d.ts","sourceRoot":"","sources":["../../src/components/policies-page.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAStC,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,SAAS,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,SAAS,CAAA;CACnE;AAED,wBAAgB,YAAY,CAAC,EAC3B,SAAS,EACT,YAAY,EACZ,kBAAkB,GACnB,GAAE,iBAAsB,2CAmJxB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { formatMessage } from "@voyantjs/i18n";
|
|
3
|
+
import { useLegalPolicies } from "@voyantjs/legal-react";
|
|
4
|
+
import { Badge, Button, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@voyantjs/ui/components";
|
|
5
|
+
import { Skeleton } from "@voyantjs/ui/components/skeleton";
|
|
6
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@voyantjs/ui/components/table";
|
|
7
|
+
import { cn } from "@voyantjs/ui/lib/utils";
|
|
8
|
+
import { Plus, Search } from "lucide-react";
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
import { useLegalUiI18nOrDefault, useLegalUiMessagesOrDefault } from "../i18n/index.js";
|
|
11
|
+
import { legalPolicyKinds } from "../i18n/messages.js";
|
|
12
|
+
const PAGE_SIZE = 25;
|
|
13
|
+
const KIND_ALL = "__all__";
|
|
14
|
+
export function PoliciesPage({ className, onOpenPolicy, renderPolicyDialog, } = {}) {
|
|
15
|
+
const i18n = useLegalUiI18nOrDefault();
|
|
16
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
17
|
+
const f = messages.policiesPage;
|
|
18
|
+
const [search, setSearch] = useState("");
|
|
19
|
+
const [kind, setKind] = useState(KIND_ALL);
|
|
20
|
+
const [dialogOpen, setDialogOpen] = useState(false);
|
|
21
|
+
const [pageIndex, setPageIndex] = useState(0);
|
|
22
|
+
const { data, isPending, isFetching, isError, refetch } = useLegalPolicies({
|
|
23
|
+
search,
|
|
24
|
+
kind: kind === KIND_ALL ? "all" : kind,
|
|
25
|
+
limit: PAGE_SIZE,
|
|
26
|
+
offset: pageIndex * PAGE_SIZE,
|
|
27
|
+
});
|
|
28
|
+
const policies = data?.data ?? [];
|
|
29
|
+
const total = data?.total ?? 0;
|
|
30
|
+
const page = pageIndex + 1;
|
|
31
|
+
const pageCount = Math.max(1, Math.ceil(total / PAGE_SIZE));
|
|
32
|
+
const showSkeleton = isPending || (isFetching && policies.length === 0);
|
|
33
|
+
const resetPage = () => setPageIndex(0);
|
|
34
|
+
return (_jsxs("div", { className: cn("flex flex-col gap-6 p-6", className), children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: f.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: f.description })] }), renderPolicyDialog ? (_jsxs(Button, { onClick: () => setDialogOpen(true), children: [_jsx(Plus, { className: "mr-2 size-4", "aria-hidden": "true" }), f.create] })) : null] }), _jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [_jsxs("div", { className: "relative min-w-[14rem] max-w-sm flex-1", children: [_jsx(Label, { htmlFor: "policies-search", className: "sr-only", children: f.searchPlaceholder }), _jsx(Search, { className: "absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground", "aria-hidden": "true" }), _jsx(Input, { id: "policies-search", placeholder: f.searchPlaceholder, value: search, onChange: (event) => {
|
|
35
|
+
setSearch(event.target.value);
|
|
36
|
+
resetPage();
|
|
37
|
+
}, className: "pl-9" })] }), _jsxs(Select, { value: kind, onValueChange: (value) => {
|
|
38
|
+
setKind(value ?? KIND_ALL);
|
|
39
|
+
resetPage();
|
|
40
|
+
}, children: [_jsx(SelectTrigger, { className: "w-[12.5rem]", children: _jsx(SelectValue, { placeholder: f.columns.kind }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: KIND_ALL, children: f.allKinds }), legalPolicyKinds.map((value) => (_jsx(SelectItem, { value: value, children: messages.common.policyKindLabels[value] }, value)))] })] })] }), _jsx("div", { className: "rounded-md border", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: f.columns.name }), _jsx(TableHead, { children: f.columns.slug }), _jsx(TableHead, { children: f.columns.kind }), _jsx(TableHead, { children: f.columns.language }), _jsx(TableHead, { children: f.columns.created })] }) }), _jsx(TableBody, { children: showSkeleton ? (_jsx(PolicyRowSkeleton, { rows: 6 })) : isError ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 5, className: "h-24 text-center text-sm text-destructive", children: f.loadFailed }) })) : policies.length === 0 ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 5, className: "h-24 text-center text-sm text-muted-foreground", children: f.empty }) })) : (policies.map((policy) => (_jsx(PolicyRow, { policy: policy, created: i18n.formatDate(policy.createdAt), kindLabel: messages.common.policyKindLabels[policy.kind] ?? policy.kind, onOpenPolicy: onOpenPolicy }, policy.id)))) })] }) }), _jsx(PaginationBar, { shown: policies.length, total: total, page: page, pageCount: pageCount, onPrevious: () => setPageIndex((prev) => Math.max(0, prev - 1)), onNext: () => setPageIndex((prev) => prev + 1), canGoBack: pageIndex > 0, canGoForward: (pageIndex + 1) * PAGE_SIZE < total }), renderPolicyDialog?.({
|
|
41
|
+
open: dialogOpen,
|
|
42
|
+
onOpenChange: setDialogOpen,
|
|
43
|
+
onSuccess: () => {
|
|
44
|
+
setDialogOpen(false);
|
|
45
|
+
setPageIndex(0);
|
|
46
|
+
void refetch();
|
|
47
|
+
},
|
|
48
|
+
})] }));
|
|
49
|
+
}
|
|
50
|
+
function PolicyRow({ policy, created, kindLabel, onOpenPolicy, }) {
|
|
51
|
+
return (_jsxs(TableRow, { onClick: () => onOpenPolicy?.(policy.id), className: cn(onOpenPolicy && "cursor-pointer"), children: [_jsx(TableCell, { className: "font-medium", children: policy.name }), _jsx(TableCell, { className: "font-mono text-xs", children: policy.slug }), _jsx(TableCell, { children: _jsx(Badge, { variant: "outline", children: kindLabel }) }), _jsx(TableCell, { children: policy.language }), _jsx(TableCell, { children: created })] }));
|
|
52
|
+
}
|
|
53
|
+
function PaginationBar({ shown, total, page, pageCount, onPrevious, onNext, canGoBack, canGoForward, }) {
|
|
54
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
55
|
+
const f = messages.policiesPage.pagination;
|
|
56
|
+
return (_jsxs("div", { className: "flex items-center justify-between text-sm text-muted-foreground", children: [_jsx("span", { children: formatMessage(f.showing, { count: shown, total }) }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", disabled: !canGoBack, onClick: onPrevious, children: f.previous }), _jsx("span", { children: formatMessage(f.page, { page, pageCount }) }), _jsx(Button, { variant: "outline", size: "sm", disabled: !canGoForward, onClick: onNext, children: f.next })] })] }));
|
|
57
|
+
}
|
|
58
|
+
function PolicyRowSkeleton({ rows }) {
|
|
59
|
+
return (_jsx(_Fragment, { children: Array.from({ length: rows }).map((_, index) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-40" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-32" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-5 w-28 rounded-full" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-12" }) }), _jsx(TableCell, { children: _jsx(Skeleton, { className: "h-4 w-24" }) })] }, `policy-skeleton-${index}`))) }));
|
|
60
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type LegalPolicyAssignmentRecord, type LegalPolicyRecord } from "@voyantjs/legal-react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
export interface PolicyDetailPageProps {
|
|
4
|
+
id: string;
|
|
5
|
+
onBackToPolicies?: () => void;
|
|
6
|
+
renderPolicyDialog?: (props: PolicyDetailDialogRenderProps) => ReactNode;
|
|
7
|
+
renderPolicyAssignmentDialog?: (props: PolicyAssignmentDialogRenderProps) => ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export interface PolicyDetailDialogRenderProps {
|
|
10
|
+
open: boolean;
|
|
11
|
+
onOpenChange: (open: boolean) => void;
|
|
12
|
+
policy: LegalPolicyRecord;
|
|
13
|
+
onSuccess: () => void;
|
|
14
|
+
}
|
|
15
|
+
export interface PolicyAssignmentDialogRenderProps {
|
|
16
|
+
open: boolean;
|
|
17
|
+
onOpenChange: (open: boolean) => void;
|
|
18
|
+
policyId: string;
|
|
19
|
+
assignment?: LegalPolicyAssignmentRecord;
|
|
20
|
+
onSuccess: () => void;
|
|
21
|
+
}
|
|
22
|
+
export declare function PolicyDetailPage({ id, onBackToPolicies, renderPolicyDialog, renderPolicyAssignmentDialog, }: PolicyDetailPageProps): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
//# sourceMappingURL=policy-detail-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy-detail-page.d.ts","sourceRoot":"","sources":["../../src/components/policy-detail-page.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,2BAA2B,EAChC,KAAK,iBAAiB,EAWvB,MAAM,uBAAuB,CAAA;AAW9B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAatC,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAA;IAC7B,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,6BAA6B,KAAK,SAAS,CAAA;IACxE,4BAA4B,CAAC,EAAE,CAAC,KAAK,EAAE,iCAAiC,KAAK,SAAS,CAAA;CACvF;AAED,MAAM,WAAW,6BAA6B;IAC5C,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,MAAM,EAAE,iBAAiB,CAAA;IACzB,SAAS,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,2BAA2B,CAAA;IACxC,SAAS,EAAE,MAAM,IAAI,CAAA;CACtB;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,EAAE,EACF,gBAAgB,EAChB,kBAAkB,EAClB,4BAA4B,GAC7B,EAAE,qBAAqB,2CAoSvB"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { formatMessage } from "@voyantjs/i18n";
|
|
4
|
+
import { useLegalPolicy, useLegalPolicyAcceptances, useLegalPolicyAssignmentMutation, useLegalPolicyAssignments, useLegalPolicyMutation, useLegalPolicyRuleMutation, useLegalPolicyRules, useLegalPolicyVersionMutation, useLegalPolicyVersions, } from "@voyantjs/legal-react";
|
|
5
|
+
import { Badge, Button, Card, CardContent, CardHeader, CardTitle } from "@voyantjs/ui/components";
|
|
6
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@voyantjs/ui/components/table";
|
|
7
|
+
import { ArrowLeft, ChevronDown, ChevronRight, Pencil, Plus, Trash2 } from "lucide-react";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
import { useLegalUiI18nOrDefault, useLegalUiMessagesOrDefault } from "../i18n/index.js";
|
|
10
|
+
import { PolicyRuleDialog } from "./policy-rule-dialog.js";
|
|
11
|
+
import { PolicyVersionDialog } from "./policy-version-dialog.js";
|
|
12
|
+
const versionStatusVariant = {
|
|
13
|
+
draft: "outline",
|
|
14
|
+
published: "default",
|
|
15
|
+
retired: "secondary",
|
|
16
|
+
};
|
|
17
|
+
export function PolicyDetailPage({ id, onBackToPolicies, renderPolicyDialog, renderPolicyAssignmentDialog, }) {
|
|
18
|
+
const queryClient = useQueryClient();
|
|
19
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
20
|
+
const f = messages.policyDetailPage;
|
|
21
|
+
const { remove } = useLegalPolicyMutation();
|
|
22
|
+
const { publish, retire } = useLegalPolicyVersionMutation();
|
|
23
|
+
const { remove: removeAssignment } = useLegalPolicyAssignmentMutation();
|
|
24
|
+
const [editOpen, setEditOpen] = useState(false);
|
|
25
|
+
const [versionDialogOpen, setVersionDialogOpen] = useState(false);
|
|
26
|
+
const [editingVersion, setEditingVersion] = useState();
|
|
27
|
+
const [expandedVersionId, setExpandedVersionId] = useState(null);
|
|
28
|
+
const [ruleDialogOpen, setRuleDialogOpen] = useState(false);
|
|
29
|
+
const [ruleDialogVersionId, setRuleDialogVersionId] = useState("");
|
|
30
|
+
const [editingRule, setEditingRule] = useState();
|
|
31
|
+
const [assignmentDialogOpen, setAssignmentDialogOpen] = useState(false);
|
|
32
|
+
const [editingAssignment, setEditingAssignment] = useState();
|
|
33
|
+
const { data: policy, isPending } = useLegalPolicy(id);
|
|
34
|
+
const { data: versionsData, refetch: refetchVersions } = useLegalPolicyVersions({ policyId: id });
|
|
35
|
+
const { data: assignmentsData, refetch: refetchAssignments } = useLegalPolicyAssignments({
|
|
36
|
+
policyId: id,
|
|
37
|
+
});
|
|
38
|
+
const { data: acceptancesData } = useLegalPolicyAcceptances({ limit: 50, offset: 0 });
|
|
39
|
+
const assignments = assignmentsData?.data ?? [];
|
|
40
|
+
const acceptances = acceptancesData?.data ?? [];
|
|
41
|
+
if (isPending) {
|
|
42
|
+
return (_jsx("div", { className: "flex flex-col gap-6 p-6", children: _jsx("div", { className: "rounded-md border border-dashed p-8 text-center", children: _jsx("p", { className: "text-sm text-muted-foreground", children: messages.common.loading }) }) }));
|
|
43
|
+
}
|
|
44
|
+
if (!policy) {
|
|
45
|
+
return (_jsxs("div", { className: "flex flex-col items-center justify-center gap-4 py-12", children: [_jsx("p", { className: "text-muted-foreground", children: f.notFound }), onBackToPolicies ? (_jsx(Button, { variant: "outline", onClick: onBackToPolicies, children: f.backToPolicies })) : null] }));
|
|
46
|
+
}
|
|
47
|
+
return (_jsxs("div", { className: "flex flex-col gap-6 p-6", children: [_jsxs("div", { className: "flex items-center gap-4", children: [onBackToPolicies ? (_jsx(Button, { variant: "ghost", size: "icon", onClick: onBackToPolicies, children: _jsx(ArrowLeft, { className: "size-4", "aria-hidden": "true" }) })) : null, _jsxs("div", { className: "min-w-0 flex-1", children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: policy.name }), _jsxs("div", { className: "mt-1 flex flex-wrap items-center gap-2", children: [_jsx(Badge, { variant: "outline", children: messages.common.policyKindLabels[policy.kind] ?? policy.kind }), _jsx("span", { className: "font-mono text-xs text-muted-foreground", children: policy.slug })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [renderPolicyDialog ? (_jsxs(Button, { variant: "outline", onClick: () => setEditOpen(true), children: [_jsx(Pencil, { className: "mr-2 size-4", "aria-hidden": "true" }), messages.common.edit] })) : null, _jsxs(Button, { variant: "destructive", onClick: () => {
|
|
48
|
+
if (confirm(formatMessage(f.deleteConfirm, { name: policy.name }))) {
|
|
49
|
+
remove.mutate(id, { onSuccess: () => onBackToPolicies?.() });
|
|
50
|
+
}
|
|
51
|
+
}, disabled: remove.isPending, children: [_jsx(Trash2, { className: "mr-2 size-4", "aria-hidden": "true" }), messages.common.delete] })] })] }), policy.description ? (_jsx(Card, { children: _jsx(CardContent, { className: "pt-6", children: _jsx("p", { className: "text-sm", children: policy.description }) }) })) : null, _jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between", children: [_jsx(CardTitle, { children: f.sections.versions }), _jsxs(Button, { size: "sm", onClick: () => {
|
|
52
|
+
setEditingVersion(undefined);
|
|
53
|
+
setVersionDialogOpen(true);
|
|
54
|
+
}, children: [_jsx(Plus, { className: "mr-2 size-4", "aria-hidden": "true" }), f.actions.newVersion] })] }), _jsxs(CardContent, { children: [!versionsData || versionsData.length === 0 ? (_jsx("p", { className: "py-4 text-center text-sm text-muted-foreground", children: f.empty.noVersions })) : null, _jsx("div", { className: "flex flex-col gap-2", children: versionsData?.map((version) => (_jsx(PolicyVersionRow, { version: version, expanded: expandedVersionId === version.id, onToggle: () => setExpandedVersionId(expandedVersionId === version.id ? null : version.id), onEdit: () => {
|
|
55
|
+
setEditingVersion(version);
|
|
56
|
+
setVersionDialogOpen(true);
|
|
57
|
+
}, onPublish: () => publish.mutate(version.id), onRetire: () => retire.mutate(version.id), onAddRule: () => {
|
|
58
|
+
setRuleDialogVersionId(version.id);
|
|
59
|
+
setEditingRule(undefined);
|
|
60
|
+
setRuleDialogOpen(true);
|
|
61
|
+
}, onEditRule: (rule) => {
|
|
62
|
+
setRuleDialogVersionId(version.id);
|
|
63
|
+
setEditingRule(rule);
|
|
64
|
+
setRuleDialogOpen(true);
|
|
65
|
+
} }, version.id))) })] })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center justify-between", children: [_jsx(CardTitle, { children: f.sections.assignments }), renderPolicyAssignmentDialog ? (_jsxs(Button, { size: "sm", onClick: () => {
|
|
66
|
+
setEditingAssignment(undefined);
|
|
67
|
+
setAssignmentDialogOpen(true);
|
|
68
|
+
}, children: [_jsx(Plus, { className: "mr-2 size-4", "aria-hidden": "true" }), f.actions.addAssignment] })) : null] }), _jsxs(CardContent, { children: [assignments.length === 0 ? (_jsx("p", { className: "py-4 text-center text-sm text-muted-foreground", children: f.empty.noAssignments })) : null, assignments.length > 0 ? (_jsx("div", { className: "rounded border bg-background", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: f.fields.scope }), _jsx(TableHead, { children: f.fields.targetId }), _jsx(TableHead, { children: f.fields.priority }), _jsx(TableHead, { children: f.fields.valid }), _jsx(TableHead, { className: "w-16" })] }) }), _jsx(TableBody, { children: assignments.map((assignment) => (_jsx(AssignmentRow, { assignment: assignment, onEdit: renderPolicyAssignmentDialog
|
|
69
|
+
? () => {
|
|
70
|
+
setEditingAssignment(assignment);
|
|
71
|
+
setAssignmentDialogOpen(true);
|
|
72
|
+
}
|
|
73
|
+
: undefined, onDelete: () => {
|
|
74
|
+
if (confirm(f.deleteAssignmentConfirm)) {
|
|
75
|
+
removeAssignment.mutate({ policyId: id, id: assignment.id });
|
|
76
|
+
}
|
|
77
|
+
} }, assignment.id))) })] }) })) : null] })] }), _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: f.sections.acceptances }) }), _jsxs(CardContent, { children: [acceptances.length === 0 ? (_jsx("p", { className: "py-4 text-center text-sm text-muted-foreground", children: f.empty.noAcceptances })) : null, acceptances.length > 0 ? (_jsx("div", { className: "rounded border bg-background", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: f.fields.versionId }), _jsx(TableHead, { children: f.fields.personId }), _jsx(TableHead, { children: f.fields.bookingId }), _jsx(TableHead, { children: f.fields.method }), _jsx(TableHead, { children: f.fields.acceptedAt })] }) }), _jsx(TableBody, { children: acceptances.map((acceptance) => (_jsx(AcceptanceRow, { acceptance: acceptance }, acceptance.id))) })] }) })) : null] })] }), renderPolicyDialog?.({
|
|
78
|
+
open: editOpen,
|
|
79
|
+
onOpenChange: setEditOpen,
|
|
80
|
+
policy,
|
|
81
|
+
onSuccess: () => {
|
|
82
|
+
setEditOpen(false);
|
|
83
|
+
void queryClient.invalidateQueries();
|
|
84
|
+
},
|
|
85
|
+
}), _jsx(PolicyVersionDialog, { open: versionDialogOpen, onOpenChange: setVersionDialogOpen, policyId: id, version: editingVersion, onSuccess: () => {
|
|
86
|
+
setVersionDialogOpen(false);
|
|
87
|
+
setEditingVersion(undefined);
|
|
88
|
+
void refetchVersions();
|
|
89
|
+
} }), ruleDialogVersionId ? (_jsx(PolicyRuleDialog, { open: ruleDialogOpen, onOpenChange: setRuleDialogOpen, versionId: ruleDialogVersionId, rule: editingRule, onSuccess: () => {
|
|
90
|
+
setRuleDialogOpen(false);
|
|
91
|
+
setEditingRule(undefined);
|
|
92
|
+
void queryClient.invalidateQueries();
|
|
93
|
+
} })) : null, renderPolicyAssignmentDialog?.({
|
|
94
|
+
open: assignmentDialogOpen,
|
|
95
|
+
onOpenChange: setAssignmentDialogOpen,
|
|
96
|
+
policyId: id,
|
|
97
|
+
assignment: editingAssignment,
|
|
98
|
+
onSuccess: () => {
|
|
99
|
+
setAssignmentDialogOpen(false);
|
|
100
|
+
setEditingAssignment(undefined);
|
|
101
|
+
void refetchAssignments();
|
|
102
|
+
},
|
|
103
|
+
})] }));
|
|
104
|
+
}
|
|
105
|
+
function PolicyVersionRow({ version, expanded, onToggle, onEdit, onPublish, onRetire, onAddRule, onEditRule, }) {
|
|
106
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
107
|
+
const f = messages.policyDetailPage;
|
|
108
|
+
const { remove } = useLegalPolicyRuleMutation();
|
|
109
|
+
const { data: rulesData } = useLegalPolicyRules({
|
|
110
|
+
versionId: version.id,
|
|
111
|
+
enabled: expanded,
|
|
112
|
+
});
|
|
113
|
+
return (_jsxs("div", { className: "rounded-md border", children: [_jsxs("div", { className: "flex items-center gap-3 p-3", children: [_jsx("button", { type: "button", onClick: onToggle, className: "text-muted-foreground hover:text-foreground", children: expanded ? (_jsx(ChevronDown, { className: "size-4", "aria-hidden": "true" })) : (_jsx(ChevronRight, { className: "size-4", "aria-hidden": "true" })) }), _jsx("div", { className: "flex-1", children: _jsxs("div", { className: "flex items-center gap-2", children: [_jsxs("span", { className: "text-sm font-medium", children: ["v", version.version] }), _jsx(Badge, { variant: versionStatusVariant[version.status] ?? "secondary", children: f.versionStatusLabels[version.status] ?? version.status }), _jsx("span", { className: "text-sm text-muted-foreground", children: version.title })] }) }), _jsxs("div", { className: "flex items-center gap-1", children: [version.status === "draft" ? (_jsx(Button, { variant: "outline", size: "sm", onClick: onPublish, children: f.actions.publish })) : null, version.status === "published" ? (_jsx(Button, { variant: "outline", size: "sm", onClick: onRetire, children: f.actions.retire })) : null, version.status === "draft" ? (_jsx(Button, { variant: "ghost", size: "sm", onClick: onEdit, children: _jsx(Pencil, { className: "size-3.5", "aria-hidden": "true" }) })) : null] })] }), expanded ? (_jsxs("div", { className: "border-t bg-muted/30 p-3", children: [version.body ? (_jsxs("div", { className: "mb-4 rounded border bg-background p-3", children: [_jsx("p", { className: "mb-2 text-xs font-medium uppercase text-muted-foreground", children: f.sections.body }), version.body.trim().startsWith("<") ? (_jsx("div", { className: "prose prose-invert max-w-none text-sm [&_h1]:text-xl [&_h2]:text-lg [&_h3]:text-base [&_p]:my-2",
|
|
114
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: Policy version body is trusted admin-authored HTML rendered for preview.
|
|
115
|
+
dangerouslySetInnerHTML: { __html: version.body } })) : (_jsx("pre", { className: "whitespace-pre-wrap text-sm", children: version.body }))] })) : null, _jsxs("div", { className: "mb-2 flex items-center justify-between", children: [_jsx("p", { className: "text-xs font-medium uppercase text-muted-foreground", children: f.sections.rules }), _jsxs(Button, { variant: "outline", size: "sm", onClick: onAddRule, children: [_jsx(Plus, { className: "mr-1 size-3", "aria-hidden": "true" }), f.actions.addRule] })] }), !rulesData || rulesData.length === 0 ? (_jsx("p", { className: "py-2 text-center text-xs text-muted-foreground", children: f.empty.noRules })) : null, rulesData && rulesData.length > 0 ? (_jsx("div", { className: "rounded border bg-background", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: f.fields.sort }), _jsx(TableHead, { children: f.fields.type }), _jsx(TableHead, { children: f.fields.label }), _jsx(TableHead, { children: f.fields.days }), _jsx(TableHead, { children: f.fields.refund }), _jsx(TableHead, { children: f.fields.refundType }), _jsx(TableHead, { className: "w-16" })] }) }), _jsx(TableBody, { children: rulesData
|
|
116
|
+
.slice()
|
|
117
|
+
.sort((a, b) => a.sortOrder - b.sortOrder)
|
|
118
|
+
.map((rule) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-mono", children: rule.sortOrder }), _jsx(TableCell, { children: messages.policyRuleDialog.ruleTypeLabels[rule.ruleType] ?? rule.ruleType }), _jsx(TableCell, { children: rule.label ?? messages.common.noResultsDash }), _jsx(TableCell, { children: rule.daysBeforeDeparture ?? messages.common.noResultsDash }), _jsx(TableCell, { children: formatRuleRefund(rule) }), _jsx(TableCell, { children: rule.refundType
|
|
119
|
+
? (messages.policyRuleDialog.refundTypeLabels[rule.refundType] ?? rule.refundType)
|
|
120
|
+
: messages.common.noResultsDash }), _jsx(TableCell, { children: _jsxs("div", { className: "flex items-center gap-1", children: [_jsx("button", { type: "button", onClick: () => onEditRule(rule), className: "text-muted-foreground hover:text-foreground", children: _jsx(Pencil, { className: "size-3", "aria-hidden": "true" }) }), _jsx("button", { type: "button", onClick: () => {
|
|
121
|
+
if (confirm(f.deleteRuleConfirm)) {
|
|
122
|
+
remove.mutate({ versionId: version.id, id: rule.id });
|
|
123
|
+
}
|
|
124
|
+
}, className: "text-muted-foreground hover:text-destructive", children: _jsx(Trash2, { className: "size-3", "aria-hidden": "true" }) })] }) })] }, rule.id))) })] }) })) : null] })) : null] }));
|
|
125
|
+
}
|
|
126
|
+
function AssignmentRow({ assignment, onEdit, onDelete, }) {
|
|
127
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
128
|
+
const f = messages.policyDetailPage;
|
|
129
|
+
return (_jsxs(TableRow, { children: [_jsx(TableCell, { children: f.assignmentScopeLabels[assignment.scope] ?? assignment.scope }), _jsx(TableCell, { className: "font-mono text-xs", children: getAssignmentTargetId(assignment) }), _jsx(TableCell, { children: assignment.priority }), _jsx(TableCell, { className: "text-xs", children: assignment.validFrom || assignment.validTo
|
|
130
|
+
? `${assignment.validFrom ?? "..."} - ${assignment.validTo ?? "..."}`
|
|
131
|
+
: f.always }), _jsx(TableCell, { children: _jsxs("div", { className: "flex items-center gap-1", children: [onEdit ? (_jsx("button", { type: "button", onClick: onEdit, className: "text-muted-foreground hover:text-foreground", children: _jsx(Pencil, { className: "size-3", "aria-hidden": "true" }) })) : null, _jsx("button", { type: "button", onClick: onDelete, className: "text-muted-foreground hover:text-destructive", children: _jsx(Trash2, { className: "size-3", "aria-hidden": "true" }) })] }) })] }));
|
|
132
|
+
}
|
|
133
|
+
function AcceptanceRow({ acceptance }) {
|
|
134
|
+
const i18n = useLegalUiI18nOrDefault();
|
|
135
|
+
const messages = useLegalUiMessagesOrDefault();
|
|
136
|
+
return (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-mono text-xs", children: acceptance.policyVersionId }), _jsx(TableCell, { className: "font-mono text-xs", children: acceptance.personId ?? messages.common.noResultsDash }), _jsx(TableCell, { className: "font-mono text-xs", children: acceptance.bookingId ?? messages.common.noResultsDash }), _jsx(TableCell, { children: acceptance.method.replace(/_/g, " ") }), _jsx(TableCell, { children: i18n.formatDateTime(acceptance.acceptedAt) })] }));
|
|
137
|
+
}
|
|
138
|
+
function getAssignmentTargetId(assignment) {
|
|
139
|
+
return (assignment.productId ||
|
|
140
|
+
assignment.channelId ||
|
|
141
|
+
assignment.supplierId ||
|
|
142
|
+
assignment.marketId ||
|
|
143
|
+
assignment.organizationId ||
|
|
144
|
+
"-");
|
|
145
|
+
}
|
|
146
|
+
function formatRuleRefund(rule) {
|
|
147
|
+
if (rule.refundPercent != null)
|
|
148
|
+
return `${(rule.refundPercent / 100).toFixed(2)}%`;
|
|
149
|
+
if (rule.flatAmountCents != null) {
|
|
150
|
+
return `${(rule.flatAmountCents / 100).toFixed(2)} ${rule.currency ?? ""}`;
|
|
151
|
+
}
|
|
152
|
+
return "-";
|
|
153
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { TemplateDialogRenderProps, TemplateVersionDialogRenderProps } from "./templates-page.js";
|
|
3
|
+
export interface TemplateDetailPageProps {
|
|
4
|
+
id: string;
|
|
5
|
+
onBackToTemplates?: () => void;
|
|
6
|
+
renderTemplateDialog?: (props: TemplateDialogRenderProps) => ReactNode;
|
|
7
|
+
renderTemplateVersionDialog?: (props: TemplateVersionDialogRenderProps) => ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function TemplateDetailPage({ id, onBackToTemplates, renderTemplateDialog, renderTemplateVersionDialog, }: TemplateDetailPageProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
//# sourceMappingURL=template-detail-page.d.ts.map
|