@voyantjs/distribution-react 0.106.0 → 0.107.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.
Files changed (66) hide show
  1. package/README.md +56 -10
  2. package/dist/components/booking-link-detail-page.d.ts +10 -0
  3. package/dist/components/booking-link-detail-page.d.ts.map +1 -0
  4. package/dist/components/booking-link-detail-page.js +51 -0
  5. package/dist/components/channel-detail-page.d.ts +12 -0
  6. package/dist/components/channel-detail-page.d.ts.map +1 -0
  7. package/dist/components/channel-detail-page.js +41 -0
  8. package/dist/components/channel-sync-page.d.ts +8 -0
  9. package/dist/components/channel-sync-page.d.ts.map +1 -0
  10. package/dist/components/channel-sync-page.js +257 -0
  11. package/dist/components/channels-page.d.ts +6 -0
  12. package/dist/components/channels-page.d.ts.map +1 -0
  13. package/dist/components/channels-page.js +132 -0
  14. package/dist/components/commission-rule-detail-page.d.ts +10 -0
  15. package/dist/components/commission-rule-detail-page.d.ts.map +1 -0
  16. package/dist/components/commission-rule-detail-page.js +57 -0
  17. package/dist/components/contract-detail-page.d.ts +10 -0
  18. package/dist/components/contract-detail-page.d.ts.map +1 -0
  19. package/dist/components/contract-detail-page.js +64 -0
  20. package/dist/components/distribution-overview.d.ts +19 -0
  21. package/dist/components/distribution-overview.d.ts.map +1 -0
  22. package/dist/components/distribution-overview.js +13 -0
  23. package/dist/components/distribution-page.d.ts +26 -0
  24. package/dist/components/distribution-page.d.ts.map +1 -0
  25. package/dist/components/distribution-page.js +190 -0
  26. package/dist/components/distribution-section-header.d.ts +7 -0
  27. package/dist/components/distribution-section-header.d.ts.map +1 -0
  28. package/dist/components/distribution-section-header.js +6 -0
  29. package/dist/components/distribution-shared.d.ts +32 -0
  30. package/dist/components/distribution-shared.d.ts.map +1 -0
  31. package/dist/components/distribution-shared.js +246 -0
  32. package/dist/components/distribution-tabs-primary.d.ts +57 -0
  33. package/dist/components/distribution-tabs-primary.d.ts.map +1 -0
  34. package/dist/components/distribution-tabs-primary.js +89 -0
  35. package/dist/components/distribution-tabs-secondary.d.ts +58 -0
  36. package/dist/components/distribution-tabs-secondary.d.ts.map +1 -0
  37. package/dist/components/distribution-tabs-secondary.js +89 -0
  38. package/dist/components/mapping-detail-page.d.ts +10 -0
  39. package/dist/components/mapping-detail-page.d.ts.map +1 -0
  40. package/dist/components/mapping-detail-page.js +51 -0
  41. package/dist/components/webhook-event-detail-page.d.ts +9 -0
  42. package/dist/components/webhook-event-detail-page.d.ts.map +1 -0
  43. package/dist/components/webhook-event-detail-page.js +46 -0
  44. package/dist/i18n/en.d.ts +592 -0
  45. package/dist/i18n/en.d.ts.map +1 -0
  46. package/dist/i18n/en.js +561 -0
  47. package/dist/i18n/index.d.ts +5 -0
  48. package/dist/i18n/index.d.ts.map +1 -0
  49. package/dist/i18n/index.js +3 -0
  50. package/dist/i18n/messages.d.ts +409 -0
  51. package/dist/i18n/messages.d.ts.map +1 -0
  52. package/dist/i18n/messages.js +1 -0
  53. package/dist/i18n/provider.d.ts +1207 -0
  54. package/dist/i18n/provider.d.ts.map +1 -0
  55. package/dist/i18n/provider.js +44 -0
  56. package/dist/i18n/ro.d.ts +592 -0
  57. package/dist/i18n/ro.d.ts.map +1 -0
  58. package/dist/i18n/ro.js +561 -0
  59. package/dist/i18n/utils.d.ts +4 -0
  60. package/dist/i18n/utils.d.ts.map +1 -0
  61. package/dist/i18n/utils.js +8 -0
  62. package/dist/ui.d.ts +16 -0
  63. package/dist/ui.d.ts.map +1 -0
  64. package/dist/ui.js +14 -0
  65. package/package.json +53 -9
  66. package/src/styles.css +11 -0
@@ -0,0 +1,132 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { Badge, Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Sheet, SheetBody, SheetContent, SheetFooter, SheetHeader, SheetTitle, } from "@voyantjs/ui/components";
4
+ import { cn } from "@voyantjs/ui/lib/utils";
5
+ import { Loader2, MoreHorizontal, Pencil, Plus, Trash2 } from "lucide-react";
6
+ import { useEffect, useState } from "react";
7
+ import { useDistributionUiI18nOrDefault } from "../i18n/index.js";
8
+ import { useChannelMutation, useChannels, } from "../index.js";
9
+ const PAGE_SIZE = 25;
10
+ const defaultFormValues = {
11
+ name: "",
12
+ kind: "direct",
13
+ status: "active",
14
+ website: "",
15
+ contactName: "",
16
+ contactEmail: "",
17
+ };
18
+ export function ChannelsPage({ className, pageSize = PAGE_SIZE } = {}) {
19
+ const { messages } = useDistributionUiI18nOrDefault();
20
+ const page = messages.settings.channelsPage;
21
+ const [sheetOpen, setSheetOpen] = useState(false);
22
+ const [editing, setEditing] = useState();
23
+ const [pageIndex, setPageIndex] = useState(0);
24
+ const { data, isPending, refetch } = useChannels({
25
+ limit: pageSize,
26
+ offset: pageIndex * pageSize,
27
+ });
28
+ const { remove } = useChannelMutation();
29
+ const channels = data?.data ?? [];
30
+ const total = data?.total ?? 0;
31
+ const pageCount = Math.max(1, Math.ceil(total / pageSize));
32
+ return (_jsxs("div", { "data-slot": "channels-page", className: cn("flex flex-col gap-6 p-6", className), children: [_jsxs("div", { className: "flex items-center justify-between gap-4", children: [_jsxs("div", { children: [_jsx("h2", { className: "text-lg font-semibold tracking-tight", children: page.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: page.description })] }), _jsxs(Button, { size: "sm", onClick: () => {
33
+ setEditing(undefined);
34
+ setSheetOpen(true);
35
+ }, children: [_jsx(Plus, { className: "mr-1.5 h-3.5 w-3.5" }), page.addChannel] })] }), isPending ? (_jsx(ChannelsListSkeleton, {})) : (_jsx("div", { className: "rounded-lg border bg-card text-card-foreground shadow-sm", children: channels.length === 0 ? (_jsx("p", { className: "py-12 text-center text-sm text-muted-foreground", children: page.empty })) : (_jsx("div", { className: "flex flex-col divide-y", children: channels.map((channel) => (_jsxs("div", { className: "flex items-center justify-between px-6 py-3", children: [_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "text-sm font-medium", children: channel.name }), _jsx(Badge, { variant: "outline", className: "text-xs", children: messages.common.channelKindLabels[channel.kind] }), channel.status !== "active" ? (_jsx(Badge, { variant: "secondary", className: "text-xs", children: messages.common.channelStatusLabels[channel.status] })) : null] }), _jsxs("div", { className: "flex flex-wrap gap-3 text-xs text-muted-foreground", children: [channel.website ? _jsx("span", { children: channel.website }) : null, channel.contactName ? _jsx("span", { children: channel.contactName }) : null, channel.contactEmail ? _jsx("span", { children: channel.contactEmail }) : null] })] }), _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { asChild: true, children: _jsx(Button, { variant: "ghost", size: "icon", className: "h-8 w-8 text-muted-foreground", children: _jsx(MoreHorizontal, { className: "h-4 w-4" }) }) }), _jsxs(DropdownMenuContent, { align: "end", children: [_jsxs(DropdownMenuItem, { onClick: () => {
36
+ setEditing(channel);
37
+ setSheetOpen(true);
38
+ }, children: [_jsx(Pencil, { className: "h-4 w-4" }), page.edit] }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { variant: "destructive", disabled: remove.isPending, onClick: () => {
39
+ if (window.confirm(page.deleteConfirm)) {
40
+ void remove.mutateAsync(channel.id).then(() => refetch());
41
+ }
42
+ }, children: [_jsx(Trash2, { className: "h-4 w-4" }), page.delete] })] })] })] }, channel.id))) })) })), _jsxs("div", { className: "flex items-center justify-between gap-4 text-sm text-muted-foreground", children: [_jsx("span", { children: page.paginationShowing
43
+ .replace("{count}", String(channels.length))
44
+ .replace("{total}", String(total)) }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", disabled: pageIndex === 0, onClick: () => setPageIndex((current) => Math.max(0, current - 1)), children: page.paginationPrevious }), _jsx("span", { children: page.paginationPage
45
+ .replace("{page}", String(pageIndex + 1))
46
+ .replace("{pageCount}", String(pageCount)) }), _jsx(Button, { variant: "outline", size: "sm", disabled: (pageIndex + 1) * pageSize >= total, onClick: () => setPageIndex((current) => current + 1), children: page.paginationNext })] })] }), _jsx(ChannelSheet, { open: sheetOpen, onOpenChange: setSheetOpen, channel: editing, onSuccess: () => {
47
+ setSheetOpen(false);
48
+ setEditing(undefined);
49
+ void refetch();
50
+ } })] }));
51
+ }
52
+ function ChannelSheet({ open, onOpenChange, channel, onSuccess, }) {
53
+ const { messages } = useDistributionUiI18nOrDefault();
54
+ const page = messages.settings.channelsPage;
55
+ const isEditing = !!channel;
56
+ const { create, update } = useChannelMutation();
57
+ const [values, setValues] = useState(defaultFormValues);
58
+ const [errors, setErrors] = useState({});
59
+ const channelKinds = Object.entries(messages.common.channelKindLabels).map(([value, label]) => ({
60
+ value: value,
61
+ label,
62
+ }));
63
+ useEffect(() => {
64
+ if (open && channel) {
65
+ setValues({
66
+ name: channel.name,
67
+ kind: channel.kind,
68
+ status: channel.status,
69
+ website: channel.website ?? "",
70
+ contactName: channel.contactName ?? "",
71
+ contactEmail: channel.contactEmail ?? "",
72
+ });
73
+ setErrors({});
74
+ }
75
+ else if (open) {
76
+ setValues(defaultFormValues);
77
+ setErrors({});
78
+ }
79
+ }, [open, channel]);
80
+ const isSubmitting = create.isPending || update.isPending;
81
+ const setValue = (key, value) => setValues((current) => ({ ...current, [key]: value }));
82
+ const onSubmit = async (event) => {
83
+ event.preventDefault();
84
+ const nextErrors = validateChannelForm(values, page);
85
+ setErrors(nextErrors);
86
+ if (Object.keys(nextErrors).length > 0)
87
+ return;
88
+ const payload = {
89
+ name: values.name.trim(),
90
+ kind: values.kind,
91
+ status: values.status,
92
+ website: normalizeOptional(values.website),
93
+ contactName: normalizeOptional(values.contactName),
94
+ contactEmail: normalizeOptional(values.contactEmail),
95
+ };
96
+ if (isEditing) {
97
+ await update.mutateAsync({ id: channel.id, input: payload });
98
+ }
99
+ else {
100
+ await create.mutateAsync(payload);
101
+ }
102
+ onSuccess();
103
+ };
104
+ return (_jsx(Sheet, { open: open, onOpenChange: onOpenChange, children: _jsxs(SheetContent, { side: "right", size: "lg", children: [_jsx(SheetHeader, { children: _jsx(SheetTitle, { children: isEditing ? page.editSheetTitle : page.newSheetTitle }) }), _jsxs("form", { onSubmit: onSubmit, className: "flex flex-1 flex-col overflow-hidden", children: [_jsxs(SheetBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: page.nameLabel }), _jsx(Input, { value: values.name, onChange: (event) => setValue("name", event.target.value), placeholder: page.namePlaceholder, autoFocus: true }), errors.name ? _jsx("p", { className: "text-xs text-destructive", children: errors.name }) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: page.kindLabel }), _jsxs(Select, { items: channelKinds, value: values.kind, onValueChange: (value) => setValue("kind", value), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: channelKinds.map((kind) => (_jsx(SelectItem, { value: kind.value, children: kind.label }, kind.value))) })] })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: page.statusLabel }), _jsxs(Select, { value: values.status, onValueChange: (value) => setValue("status", value), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: Object.entries(messages.common.channelStatusLabels).map(([value, label]) => (_jsx(SelectItem, { value: value, children: label }, value))) })] })] })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: page.websiteLabel }), _jsx(Input, { value: values.website, onChange: (event) => setValue("website", event.target.value), placeholder: page.websitePlaceholder }), errors.website ? _jsx("p", { className: "text-xs text-destructive", children: errors.website }) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: page.primaryContactLabel }), _jsx(Input, { value: values.contactName, onChange: (event) => setValue("contactName", event.target.value), placeholder: page.primaryContactPlaceholder })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: page.contactEmailLabel }), _jsx(Input, { value: values.contactEmail, onChange: (event) => setValue("contactEmail", event.target.value), placeholder: page.contactEmailPlaceholder }), errors.contactEmail ? (_jsx("p", { className: "text-xs text-destructive", children: errors.contactEmail })) : null] })] })] }), _jsxs(SheetFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => onOpenChange(false), children: messages.common.cancel }), _jsxs(Button, { type: "submit", size: "sm", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing ? page.saveChanges : page.createChannel] })] })] })] }) }));
105
+ }
106
+ function ChannelsListSkeleton() {
107
+ const rows = ["first", "second", "third", "fourth", "fifth"];
108
+ return (_jsx("div", { className: "rounded-lg border bg-card text-card-foreground shadow-sm", children: rows.map((row) => (_jsxs("div", { className: "flex items-center justify-between border-b px-6 py-3 last:border-b-0", children: [_jsxs("div", { className: "space-y-2", children: [_jsx("div", { className: "h-4 w-44 rounded bg-muted" }), _jsx("div", { className: "h-3 w-64 rounded bg-muted" })] }), _jsx("div", { className: "h-8 w-8 rounded bg-muted" })] }, row))) }));
109
+ }
110
+ function validateChannelForm(values, page) {
111
+ const errors = {};
112
+ if (!values.name.trim())
113
+ errors.name = page.validationNameRequired;
114
+ if (values.name.length > 255)
115
+ errors.name = page.validationNameRequired;
116
+ if (values.website.trim()) {
117
+ try {
118
+ new URL(values.website.trim());
119
+ }
120
+ catch {
121
+ errors.website = page.validationInvalidUrl;
122
+ }
123
+ }
124
+ if (values.contactEmail.trim() && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(values.contactEmail)) {
125
+ errors.contactEmail = page.validationInvalidEmail;
126
+ }
127
+ return errors;
128
+ }
129
+ function normalizeOptional(value) {
130
+ const trimmed = value.trim();
131
+ return trimmed.length > 0 ? trimmed : null;
132
+ }
@@ -0,0 +1,10 @@
1
+ export interface CommissionRuleDetailPageProps {
2
+ id: string;
3
+ className?: string;
4
+ onBack?: () => void;
5
+ onDeleted?: () => void;
6
+ onContractOpen?: (contractId: string) => void;
7
+ onProductOpen?: (productId: string) => void;
8
+ }
9
+ export declare function CommissionRuleDetailPage({ id, className, onBack, onDeleted, onContractOpen, onProductOpen, }: CommissionRuleDetailPageProps): import("react/jsx-runtime").JSX.Element;
10
+ //# sourceMappingURL=commission-rule-detail-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commission-rule-detail-page.d.ts","sourceRoot":"","sources":["../../src/components/commission-rule-detail-page.tsx"],"names":[],"mappings":"AAyBA,MAAM,WAAW,6BAA6B;IAC5C,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7C,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;CAC5C;AAID,wBAAgB,wBAAwB,CAAC,EACvC,EAAE,EACF,SAAS,EACT,MAAa,EACb,SAAgB,EAChB,cAAqB,EACrB,aAAoB,GACrB,EAAE,6BAA6B,2CAgK/B"}
@@ -0,0 +1,57 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
+ import { Badge, Button, Card, CardContent, CardHeader, CardTitle, ConfirmActionButton, } from "@voyantjs/ui/components";
4
+ import { cn } from "@voyantjs/ui/lib/utils";
5
+ import { ArrowLeft, DollarSign, Loader2, Package } from "lucide-react";
6
+ import { useDistributionUiI18nOrDefault } from "../i18n/index.js";
7
+ import { distributionQueryKeys, fetchWithValidation, getChannelQueryOptions, getCommissionRuleQueryOptions, getContractQueryOptions, getProductQueryOptions, successEnvelope, useVoyantDistributionContext, } from "../index.js";
8
+ import { formatDistributionDate, formatDistributionDateTime } from "./distribution-shared.js";
9
+ const noop = () => { };
10
+ export function CommissionRuleDetailPage({ id, className, onBack = noop, onDeleted = noop, onContractOpen = noop, onProductOpen = noop, }) {
11
+ const i18n = useDistributionUiI18nOrDefault();
12
+ const { messages } = i18n;
13
+ const detail = messages.details.commissionRule;
14
+ const client = useVoyantDistributionContext();
15
+ const queryClient = useQueryClient();
16
+ const ruleQuery = useQuery({
17
+ ...getCommissionRuleQueryOptions(client, id),
18
+ select: (result) => result.data,
19
+ });
20
+ const rule = ruleQuery.data;
21
+ const contractQuery = useQuery({
22
+ ...getContractQueryOptions(client, rule?.contractId),
23
+ select: (result) => result.data,
24
+ enabled: Boolean(rule?.contractId),
25
+ });
26
+ const contract = contractQuery.data;
27
+ const channelQuery = useQuery({
28
+ ...getChannelQueryOptions(client, contract?.channelId),
29
+ select: (result) => result.data,
30
+ enabled: Boolean(contract?.channelId),
31
+ });
32
+ const productQuery = useQuery({
33
+ ...getProductQueryOptions(client, rule?.productId),
34
+ select: (result) => result.data,
35
+ enabled: Boolean(rule?.productId),
36
+ });
37
+ const remove = useMutation({
38
+ mutationFn: () => fetchWithValidation(`/v1/distribution/commission-rules/${id}`, successEnvelope, client, {
39
+ method: "DELETE", // i18n-literal-ok HTTP method
40
+ }),
41
+ onSuccess: () => {
42
+ void queryClient.invalidateQueries({ queryKey: distributionQueryKeys.commissionRules() });
43
+ queryClient.removeQueries({ queryKey: distributionQueryKeys.commissionRule(id) });
44
+ onDeleted();
45
+ onBack();
46
+ },
47
+ });
48
+ if (ruleQuery.isPending) {
49
+ return (_jsx("div", { className: "flex items-center justify-center py-12", children: _jsx(Loader2, { className: "h-6 w-6 animate-spin text-muted-foreground" }) }));
50
+ }
51
+ if (!rule) {
52
+ return (_jsxs("div", { className: "flex flex-col items-center justify-center gap-4 py-12", children: [_jsx("p", { className: "text-muted-foreground", children: detail.notFound }), _jsx(Button, { variant: "outline", onClick: onBack, children: messages.common.backToDistribution })] }));
53
+ }
54
+ return (_jsxs("div", { "data-slot": "commission-rule-detail-page", className: cn("flex flex-col gap-6 p-6", className), children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx(Button, { variant: "ghost", size: "icon", onClick: onBack, children: _jsx(ArrowLeft, { className: "h-4 w-4" }) }), _jsxs("div", { className: "flex-1", children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: detail.title }), _jsxs("div", { className: "mt-1 flex items-center gap-2", children: [_jsx(Badge, { variant: "outline", children: messages.common.commissionScopeLabels[rule.scope] }), _jsx(Badge, { variant: "secondary", children: messages.common.commissionTypeLabels[rule.commissionType] })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsxs(Button, { variant: "outline", onClick: () => onContractOpen(rule.contractId), children: [_jsx(DollarSign, { className: "mr-2 h-4 w-4" }), detail.openContract] }), rule.productId ? (_jsxs(Button, { variant: "outline", onClick: () => onProductOpen(rule.productId), children: [_jsx(Package, { className: "mr-2 h-4 w-4" }), detail.openProduct] })) : null, _jsx(ConfirmActionButton, { buttonLabel: detail.deleteButton, confirmLabel: detail.deleteButton, title: detail.deleteConfirm, description: detail.deleteDescription, variant: "destructive", confirmVariant: "destructive", disabled: remove.isPending, onConfirm: async () => {
55
+ await remove.mutateAsync();
56
+ } })] })] }), _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: detail.sections.details }) }), _jsxs(CardContent, { className: "grid gap-3 text-sm md:grid-cols-2", children: [_jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [messages.common.contractLabel, ":"] }), " ", _jsx("span", { children: contract?.id ?? rule.contractId })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [messages.common.channelLabel, ":"] }), " ", _jsx("span", { children: channelQuery.data?.name ?? contract?.channelId ?? messages.common.none })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [messages.common.productLabel, ":"] }), " ", _jsx("span", { children: productQuery.data?.name ?? rule.productId ?? messages.common.none })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.amount, ":"] }), " ", _jsx("span", { children: rule.amountCents ?? messages.common.none })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.basisPoints, ":"] }), " ", _jsx("span", { children: rule.percentBasisPoints ?? messages.common.none })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.externalRate, ":"] }), " ", _jsx("span", { children: rule.externalRateId ?? messages.common.none })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.externalCategory, ":"] }), " ", _jsx("span", { children: rule.externalCategoryId ?? messages.common.none })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.valid, ":"] }), " ", _jsxs("span", { children: [rule.validFrom ? formatDistributionDate(rule.validFrom, i18n) : messages.common.none, " to ", rule.validTo ? formatDistributionDate(rule.validTo, i18n) : messages.common.none] })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [messages.common.createdLabel, ":"] }), " ", _jsx("span", { children: formatDistributionDateTime(rule.createdAt, i18n) })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [messages.common.updatedLabel, ":"] }), " ", _jsx("span", { children: formatDistributionDateTime(rule.updatedAt, i18n) })] })] })] })] }));
57
+ }
@@ -0,0 +1,10 @@
1
+ export interface ContractDetailPageProps {
2
+ id: string;
3
+ className?: string;
4
+ onBack?: () => void;
5
+ onDeleted?: () => void;
6
+ onChannelOpen?: (channelId: string) => void;
7
+ onCommissionRuleOpen?: (commissionRuleId: string) => void;
8
+ }
9
+ export declare function ContractDetailPage({ id, className, onBack, onDeleted, onChannelOpen, onCommissionRuleOpen, }: ContractDetailPageProps): import("react/jsx-runtime").JSX.Element;
10
+ //# 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":"AA+BA,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,oBAAoB,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAA;CAC1D;AAID,wBAAgB,kBAAkB,CAAC,EACjC,EAAE,EACF,SAAS,EACT,MAAa,EACb,SAAgB,EAChB,aAAoB,EACpB,oBAA2B,GAC5B,EAAE,uBAAuB,2CAqNzB"}
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
3
+ import { Badge, Button, Card, CardContent, CardHeader, CardTitle, ConfirmActionButton, } from "@voyantjs/ui/components";
4
+ import { cn } from "@voyantjs/ui/lib/utils";
5
+ import { ArrowLeft, DollarSign, Loader2 } from "lucide-react";
6
+ import { useDistributionUiI18nOrDefault } from "../i18n/index.js";
7
+ import { distributionQueryKeys, fetchWithValidation, getChannelQueryOptions, getCommissionRulesQueryOptions, getContractQueryOptions, getProductsQueryOptions, getSupplierQueryOptions, successEnvelope, useVoyantDistributionContext, } from "../index.js";
8
+ import { formatDistributionDate, formatDistributionDateTime, getContractStatusLabel, getPaymentOwnerLabel, } from "./distribution-shared.js";
9
+ const noop = () => { };
10
+ export function ContractDetailPage({ id, className, onBack = noop, onDeleted = noop, onChannelOpen = noop, onCommissionRuleOpen = noop, }) {
11
+ const i18n = useDistributionUiI18nOrDefault();
12
+ const { messages } = i18n;
13
+ const detail = messages.details.contract;
14
+ const client = useVoyantDistributionContext();
15
+ const queryClient = useQueryClient();
16
+ const contractQuery = useQuery({
17
+ ...getContractQueryOptions(client, id),
18
+ select: (result) => result.data,
19
+ });
20
+ const contract = contractQuery.data;
21
+ const channelQuery = useQuery({
22
+ ...getChannelQueryOptions(client, contract?.channelId),
23
+ select: (result) => result.data,
24
+ enabled: Boolean(contract?.channelId),
25
+ });
26
+ const supplierQuery = useQuery({
27
+ ...getSupplierQueryOptions(client, contract?.supplierId),
28
+ select: (result) => result.data,
29
+ enabled: Boolean(contract?.supplierId),
30
+ });
31
+ const commissionRulesQuery = useQuery({
32
+ ...getCommissionRulesQueryOptions(client, { contractId: id }),
33
+ enabled: Boolean(id),
34
+ });
35
+ const productsQuery = useQuery(getProductsQueryOptions(client, { limit: 50, offset: 0 }));
36
+ const remove = useMutation({
37
+ mutationFn: () => fetchWithValidation(`/v1/distribution/contracts/${id}`, successEnvelope, client, {
38
+ method: "DELETE", // i18n-literal-ok HTTP method
39
+ }),
40
+ onSuccess: () => {
41
+ void queryClient.invalidateQueries({ queryKey: distributionQueryKeys.contracts() });
42
+ void queryClient.invalidateQueries({ queryKey: distributionQueryKeys.commissionRules() });
43
+ queryClient.removeQueries({ queryKey: distributionQueryKeys.contract(id) });
44
+ onDeleted();
45
+ onBack();
46
+ },
47
+ });
48
+ if (contractQuery.isPending) {
49
+ return (_jsx("div", { className: "flex items-center justify-center py-12", children: _jsx(Loader2, { className: "h-6 w-6 animate-spin text-muted-foreground" }) }));
50
+ }
51
+ if (!contract) {
52
+ return (_jsxs("div", { className: "flex flex-col items-center justify-center gap-4 py-12", children: [_jsx("p", { className: "text-muted-foreground", children: detail.notFound }), _jsx(Button, { variant: "outline", onClick: onBack, children: messages.common.backToDistribution })] }));
53
+ }
54
+ const productsById = new Map((productsQuery.data?.data ?? []).map((product) => [product.id, product]));
55
+ return (_jsxs("div", { "data-slot": "contract-detail-page", className: cn("flex flex-col gap-6 p-6", className), children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx(Button, { variant: "ghost", size: "icon", onClick: onBack, children: _jsx(ArrowLeft, { className: "h-4 w-4" }) }), _jsxs("div", { className: "flex-1", children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: detail.title }), _jsxs("div", { className: "mt-1 flex items-center gap-2", children: [_jsx(Badge, { variant: "outline", children: getContractStatusLabel(contract.status, messages) }), _jsx(Badge, { variant: "secondary", children: formatDistributionDate(contract.startsAt, i18n) })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Button, { variant: "outline", onClick: () => onChannelOpen(contract.channelId), children: detail.openChannel }), _jsx(ConfirmActionButton, { buttonLabel: detail.deleteButton, confirmLabel: detail.deleteButton, title: detail.deleteConfirm, description: detail.deleteDescription, variant: "destructive", confirmVariant: "destructive", disabled: remove.isPending, onConfirm: async () => {
56
+ await remove.mutateAsync();
57
+ } })] })] }), _jsxs("div", { className: "grid gap-6 md:grid-cols-2", children: [_jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: detail.sections.details }) }), _jsxs(CardContent, { className: "grid gap-3 text-sm", children: [_jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [messages.common.channelLabel, ":"] }), " ", _jsx("span", { children: channelQuery.data?.name ?? contract.channelId })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.supplier, ":"] }), " ", _jsx("span", { children: supplierQuery.data?.name ?? contract.supplierId ?? messages.common.none })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.endsAt, ":"] }), " ", _jsx("span", { children: contract.endsAt
58
+ ? formatDistributionDate(contract.endsAt, i18n)
59
+ : messages.common.openEnded })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.paymentOwner, ":"] }), " ", _jsx("span", { children: getPaymentOwnerLabel(contract.paymentOwner, messages) })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [detail.labels.cancellationOwner, ":"] }), " ", _jsx("span", { children: messages.common.cancellationOwnerLabels[contract.cancellationOwner] })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [messages.common.createdLabel, ":"] }), " ", _jsx("span", { children: formatDistributionDateTime(contract.createdAt, i18n) })] }), _jsxs("div", { children: [_jsxs("span", { className: "text-muted-foreground", children: [messages.common.updatedLabel, ":"] }), " ", _jsx("span", { children: formatDistributionDateTime(contract.updatedAt, i18n) })] })] })] }), _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: detail.sections.notes }) }), _jsxs(CardContent, { className: "grid gap-4 text-sm", children: [_jsxs("div", { children: [_jsx("div", { className: "mb-1 text-muted-foreground", children: detail.labels.settlementTerms }), _jsx("div", { className: "whitespace-pre-wrap", children: contract.settlementTerms ?? messages.common.none })] }), _jsxs("div", { children: [_jsx("div", { className: "mb-1 text-muted-foreground", children: detail.labels.notes }), _jsx("div", { className: "whitespace-pre-wrap", children: contract.notes ?? messages.common.none })] })] })] })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "flex flex-row items-center gap-2", children: [_jsx(DollarSign, { className: "h-4 w-4" }), _jsx(CardTitle, { children: detail.sections.commissionRules })] }), _jsx(CardContent, { className: "space-y-3 text-sm", children: (commissionRulesQuery.data?.data.length ?? 0) === 0 ? (_jsx("p", { className: "text-muted-foreground", children: detail.empty.commissionRules })) : (commissionRulesQuery.data?.data.map((rule) => (_jsxs("button", { type: "button", className: "block w-full rounded-md border p-3 text-left hover:bg-muted/40", onClick: () => onCommissionRuleOpen(rule.id), children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Badge, { variant: "outline", children: messages.common.commissionScopeLabels[rule.scope] }), _jsx(Badge, { variant: "secondary", children: messages.common.commissionTypeLabels[rule.commissionType] })] }), _jsxs("div", { className: "mt-2 text-muted-foreground", children: [messages.common.productLabel, ":", " ", productsById.get(rule.productId ?? "")?.name ??
60
+ rule.productId ??
61
+ messages.common.none] }), _jsxs("div", { className: "text-muted-foreground", children: [detail.labels.amount, ": ", rule.amountCents ?? messages.common.none, " - ", detail.labels.basisPoints, ": ", rule.percentBasisPoints ?? messages.common.none] }), _jsxs("div", { className: "text-muted-foreground", children: [detail.labels.rate, ": ", rule.externalRateId ?? messages.common.none, " - ", detail.labels.category, ": ", rule.externalCategoryId ?? messages.common.none] }), _jsxs("div", { className: "text-muted-foreground", children: [detail.labels.valid, ":", " ", rule.validFrom
62
+ ? formatDistributionDate(rule.validFrom, i18n)
63
+ : messages.common.none, " to ", rule.validTo ? formatDistributionDate(rule.validTo, i18n) : messages.common.none] })] }, rule.id)))) })] })] }));
64
+ }
@@ -0,0 +1,19 @@
1
+ import type { ChannelContractRow, ChannelProductMappingRow, ChannelRow, ChannelWebhookEventRow, SupplierOption } from "./distribution-shared.js";
2
+ export declare function DistributionOverview({ channels, suppliers, filteredChannels, filteredContracts, filteredMappings, syncQueue, contractsNeedingReview, search, setSearch, channelFilter, setChannelFilter, hasFilters, onClearFilters, onOpenWebhookEvent, onOpenContract, }: {
3
+ channels: ChannelRow[];
4
+ suppliers: SupplierOption[];
5
+ filteredChannels: ChannelRow[];
6
+ filteredContracts: ChannelContractRow[];
7
+ filteredMappings: ChannelProductMappingRow[];
8
+ syncQueue: ChannelWebhookEventRow[];
9
+ contractsNeedingReview: ChannelContractRow[];
10
+ search: string;
11
+ setSearch: (value: string) => void;
12
+ channelFilter: string;
13
+ setChannelFilter: (value: string) => void;
14
+ hasFilters: boolean;
15
+ onClearFilters: () => void;
16
+ onOpenWebhookEvent: (eventId: string) => void;
17
+ onOpenContract: (contractId: string) => void;
18
+ }): import("react/jsx-runtime").JSX.Element;
19
+ //# sourceMappingURL=distribution-overview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distribution-overview.d.ts","sourceRoot":"","sources":["../../src/components/distribution-overview.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EACV,kBAAkB,EAClB,wBAAwB,EACxB,UAAU,EACV,sBAAsB,EACtB,cAAc,EACf,MAAM,0BAA0B,CAAA;AASjC,wBAAgB,oBAAoB,CAAC,EACnC,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,SAAS,EACT,sBAAsB,EACtB,MAAM,EACN,SAAS,EACT,aAAa,EACb,gBAAgB,EAChB,UAAU,EACV,cAAc,EACd,kBAAkB,EAClB,cAAc,GACf,EAAE;IACD,QAAQ,EAAE,UAAU,EAAE,CAAA;IACtB,SAAS,EAAE,cAAc,EAAE,CAAA;IAC3B,gBAAgB,EAAE,UAAU,EAAE,CAAA;IAC9B,iBAAiB,EAAE,kBAAkB,EAAE,CAAA;IACvC,gBAAgB,EAAE,wBAAwB,EAAE,CAAA;IAC5C,SAAS,EAAE,sBAAsB,EAAE,CAAA;IACnC,sBAAsB,EAAE,kBAAkB,EAAE,CAAA;IAC5C,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,aAAa,EAAE,MAAM,CAAA;IACrB,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,UAAU,EAAE,OAAO,CAAA;IACnB,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7C,cAAc,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;CAC7C,2CAoIA"}
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Button, Card, CardContent, CardHeader, CardTitle, Input, OverviewMetric, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@voyantjs/ui/components";
3
+ import { DollarSign, ExternalLink, Link2, Search, Webhook } from "lucide-react";
4
+ import { useDistributionUiI18nOrDefault } from "../i18n/index.js";
5
+ import { formatDistributionDate, formatDistributionDateTime, getContractStatusLabel, getWebhookStatusLabel, labelById, } from "./distribution-shared.js";
6
+ export function DistributionOverview({ channels, suppliers, filteredChannels, filteredContracts, filteredMappings, syncQueue, contractsNeedingReview, search, setSearch, channelFilter, setChannelFilter, hasFilters, onClearFilters, onOpenWebhookEvent, onOpenContract, }) {
7
+ const activeChannelsCount = filteredChannels.filter((channel) => channel.status === "active").length;
8
+ const activeContractsCount = filteredContracts.filter((contract) => contract.status === "active").length;
9
+ const activeMappingsCount = filteredMappings.filter((mapping) => mapping.active).length;
10
+ const i18n = useDistributionUiI18nOrDefault();
11
+ const { messages } = i18n;
12
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { className: "grid gap-4 md:grid-cols-2 xl:grid-cols-4", children: [_jsx(OverviewMetric, { title: messages.overview.metrics.activeChannels.title, value: activeChannelsCount, description: messages.overview.metrics.activeChannels.description, icon: Link2 }), _jsx(OverviewMetric, { title: messages.overview.metrics.activeContracts.title, value: activeContractsCount, description: messages.overview.metrics.activeContracts.description, icon: DollarSign }), _jsx(OverviewMetric, { title: messages.overview.metrics.activeMappings.title, value: activeMappingsCount, description: messages.overview.metrics.activeMappings.description, icon: ExternalLink }), _jsx(OverviewMetric, { title: messages.overview.metrics.syncQueue.title, value: syncQueue.length, description: messages.overview.metrics.syncQueue.description, icon: Webhook })] }), _jsxs("div", { className: "grid gap-4 xl:grid-cols-2", children: [_jsxs(Card, { size: "sm", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: messages.overview.webhookQueue.title }) }), _jsx(CardContent, { className: "space-y-3 text-sm", children: syncQueue.length === 0 ? (_jsx("p", { className: "text-muted-foreground", children: messages.overview.webhookQueue.empty })) : (syncQueue.slice(0, 4).map((event) => (_jsxs("button", { type: "button", className: "block w-full rounded-md border p-3 text-left hover:bg-muted/40", onClick: () => onOpenWebhookEvent(event.id), children: [_jsxs("div", { className: "font-medium", children: [labelById(channels, event.channelId), " \u00B7 ", event.eventType] }), _jsxs("div", { className: "text-muted-foreground", children: [getWebhookStatusLabel(event.status, messages), " \u00B7 ", messages.common.received, " ", formatDistributionDateTime(event.receivedAt, i18n)] })] }, event.id)))) })] }), _jsxs(Card, { size: "sm", children: [_jsx(CardHeader, { children: _jsx(CardTitle, { children: messages.overview.contractsToReview.title }) }), _jsx(CardContent, { className: "space-y-3 text-sm", children: contractsNeedingReview.length === 0 ? (_jsx("p", { className: "text-muted-foreground", children: messages.overview.contractsToReview.empty })) : (contractsNeedingReview.slice(0, 4).map((contract) => (_jsxs("button", { type: "button", className: "block w-full rounded-md border p-3 text-left hover:bg-muted/40", onClick: () => onOpenContract(contract.id), children: [_jsxs("div", { className: "font-medium", children: [labelById(channels, contract.channelId), " \u00B7", " ", formatDistributionDate(contract.startsAt, i18n)] }), _jsxs("div", { className: "text-muted-foreground", children: [getContractStatusLabel(contract.status, messages), " \u00B7 ", messages.common.supplier, " ", labelById(suppliers, contract.supplierId)] })] }, contract.id)))) })] })] }), _jsxs("div", { className: "flex flex-col gap-3 md:flex-row md:items-center md:justify-between", children: [_jsxs("div", { className: "flex flex-1 flex-col gap-3 md:flex-row md:items-center", children: [_jsxs("div", { className: "relative w-full max-w-sm", children: [_jsx(Search, { className: "absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }), _jsx(Input, { placeholder: messages.common.searchPlaceholder, value: search, onChange: (event) => setSearch(event.target.value), className: "pl-9" })] }), _jsxs(Select, { value: channelFilter, onValueChange: (value) => setChannelFilter(value ?? "all"), children: [_jsx(SelectTrigger, { className: "w-full md:w-64", children: _jsx(SelectValue, { placeholder: messages.overview.filters.allChannelsPlaceholder }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "all", children: messages.common.allChannels }), channels.map((channel) => (_jsx(SelectItem, { value: channel.id, children: channel.name }, channel.id)))] })] })] }), hasFilters ? (_jsx(Button, { variant: "outline", onClick: onClearFilters, children: messages.common.clearFilters })) : null] })] }));
13
+ }
@@ -0,0 +1,26 @@
1
+ import type { BatchMutationResponse, ChannelBookingLinkRow, ChannelCommissionRuleRow, ChannelContractRow, ChannelProductMappingRow, ChannelRow, ChannelWebhookEventRow } from "./distribution-shared.js";
2
+ export interface DistributionPageProps {
3
+ className?: string;
4
+ onChannelOpen?: (channelId: string) => void;
5
+ onContractOpen?: (contractId: string) => void;
6
+ onCommissionRuleOpen?: (commissionRuleId: string) => void;
7
+ onMappingOpen?: (mappingId: string) => void;
8
+ onBookingLinkOpen?: (bookingLinkId: string) => void;
9
+ onWebhookEventOpen?: (webhookEventId: string) => void;
10
+ onChannelCreate?: () => void;
11
+ onContractCreate?: () => void;
12
+ onCommissionRuleCreate?: () => void;
13
+ onMappingCreate?: () => void;
14
+ onBookingLinkCreate?: () => void;
15
+ onWebhookEventCreate?: () => void;
16
+ onChannelEdit?: (channel: ChannelRow) => void;
17
+ onContractEdit?: (contract: ChannelContractRow) => void;
18
+ onCommissionRuleEdit?: (commissionRule: ChannelCommissionRuleRow) => void;
19
+ onMappingEdit?: (mapping: ChannelProductMappingRow) => void;
20
+ onBookingLinkEdit?: (bookingLink: ChannelBookingLinkRow) => void;
21
+ onWebhookEventEdit?: (webhookEvent: ChannelWebhookEventRow) => void;
22
+ onBulkSuccess?: (message: string, result: BatchMutationResponse) => void;
23
+ onBulkError?: (message: string, error: unknown, result?: BatchMutationResponse) => void;
24
+ }
25
+ export declare function DistributionPage({ className, onChannelOpen, onContractOpen, onCommissionRuleOpen, onMappingOpen, onBookingLinkOpen, onWebhookEventOpen, onChannelCreate, onContractCreate, onCommissionRuleCreate, onMappingCreate, onBookingLinkCreate, onWebhookEventCreate, onChannelEdit, onContractEdit, onCommissionRuleEdit, onMappingEdit, onBookingLinkEdit, onWebhookEventEdit, onBulkSuccess, onBulkError, }?: DistributionPageProps): import("react/jsx-runtime").JSX.Element;
26
+ //# sourceMappingURL=distribution-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distribution-page.d.ts","sourceRoot":"","sources":["../../src/components/distribution-page.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACrB,wBAAwB,EACxB,kBAAkB,EAClB,wBAAwB,EACxB,UAAU,EACV,sBAAsB,EACvB,MAAM,0BAA0B,CAAA;AAyBjC,MAAM,WAAW,qBAAqB;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,cAAc,CAAC,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7C,oBAAoB,CAAC,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAA;IACzD,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAA;IAC3C,iBAAiB,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAA;IACnD,kBAAkB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAA;IACrD,eAAe,CAAC,EAAE,MAAM,IAAI,CAAA;IAC5B,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAA;IAC7B,sBAAsB,CAAC,EAAE,MAAM,IAAI,CAAA;IACnC,eAAe,CAAC,EAAE,MAAM,IAAI,CAAA;IAC5B,mBAAmB,CAAC,EAAE,MAAM,IAAI,CAAA;IAChC,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAA;IACjC,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,IAAI,CAAA;IAC7C,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,kBAAkB,KAAK,IAAI,CAAA;IACvD,oBAAoB,CAAC,EAAE,CAAC,cAAc,EAAE,wBAAwB,KAAK,IAAI,CAAA;IACzE,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,IAAI,CAAA;IAC3D,iBAAiB,CAAC,EAAE,CAAC,WAAW,EAAE,qBAAqB,KAAK,IAAI,CAAA;IAChE,kBAAkB,CAAC,EAAE,CAAC,YAAY,EAAE,sBAAsB,KAAK,IAAI,CAAA;IACnE,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAA;IACxE,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAA;CACxF;AAID,wBAAgB,gBAAgB,CAAC,EAC/B,SAAS,EACT,aAAoB,EACpB,cAAqB,EACrB,oBAA2B,EAC3B,aAAoB,EACpB,iBAAwB,EACxB,kBAAyB,EACzB,eAAsB,EACtB,gBAAuB,EACvB,sBAA6B,EAC7B,eAAsB,EACtB,mBAA0B,EAC1B,oBAA2B,EAC3B,aAAoB,EACpB,cAAqB,EACrB,oBAA2B,EAC3B,aAAoB,EACpB,iBAAwB,EACxB,kBAAyB,EACzB,aAAa,EACb,WAAW,GACZ,GAAE,qBAA0B,2CA6V5B"}
@@ -0,0 +1,190 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Tabs, TabsList, TabsTrigger } from "@voyantjs/ui/components/tabs";
3
+ import { cn } from "@voyantjs/ui/lib/utils";
4
+ import { Loader2 } from "lucide-react";
5
+ import { useState } from "react";
6
+ import { useDistributionUiI18nOrDefault } from "../i18n/index.js";
7
+ import { formatDistributionCount, formatDistributionSummary } from "../i18n/utils.js";
8
+ import { useBookingLinks, useBookings, useChannels, useCommissionRules, useContracts, useMappings, useProducts, useSuppliers, useVoyantDistributionContext, useWebhookEvents, } from "../index.js";
9
+ import { DistributionOverview } from "./distribution-overview.js";
10
+ import { labelById } from "./distribution-shared.js";
11
+ import { DistributionChannelsTab, DistributionCommissionsTab, DistributionContractsTab, } from "./distribution-tabs-primary.js";
12
+ import { DistributionBookingLinksTab, DistributionMappingsTab, DistributionWebhooksTab, } from "./distribution-tabs-secondary.js";
13
+ const noop = () => { };
14
+ export function DistributionPage({ className, onChannelOpen = noop, onContractOpen = noop, onCommissionRuleOpen = noop, onMappingOpen = noop, onBookingLinkOpen = noop, onWebhookEventOpen = noop, onChannelCreate = noop, onContractCreate = noop, onCommissionRuleCreate = noop, onMappingCreate = noop, onBookingLinkCreate = noop, onWebhookEventCreate = noop, onChannelEdit = noop, onContractEdit = noop, onCommissionRuleEdit = noop, onMappingEdit = noop, onBookingLinkEdit = noop, onWebhookEventEdit = noop, onBulkSuccess, onBulkError, } = {}) {
15
+ const client = useVoyantDistributionContext();
16
+ const i18n = useDistributionUiI18nOrDefault();
17
+ const { messages } = i18n;
18
+ const [search, setSearch] = useState("");
19
+ const [channelFilter, setChannelFilter] = useState("all");
20
+ const [bulkActionTarget, setBulkActionTarget] = useState(null);
21
+ const [channelSelection, setChannelSelection] = useState({});
22
+ const [contractSelection, setContractSelection] = useState({});
23
+ const [commissionSelection, setCommissionSelection] = useState({});
24
+ const [mappingSelection, setMappingSelection] = useState({});
25
+ const [bookingLinkSelection, setBookingLinkSelection] = useState({});
26
+ const [webhookSelection, setWebhookSelection] = useState({});
27
+ const suppliersQuery = useSuppliers();
28
+ const productsQuery = useProducts();
29
+ const bookingsQuery = useBookings();
30
+ const channelsQuery = useChannels();
31
+ const contractsQuery = useContracts();
32
+ const commissionRulesQuery = useCommissionRules();
33
+ const mappingsQuery = useMappings();
34
+ const bookingLinksQuery = useBookingLinks();
35
+ const webhookEventsQuery = useWebhookEvents();
36
+ const suppliers = suppliersQuery.data?.data ?? [];
37
+ const products = productsQuery.data?.data ?? [];
38
+ const bookings = bookingsQuery.data?.data ?? [];
39
+ const channels = channelsQuery.data?.data ?? [];
40
+ const contracts = contractsQuery.data?.data ?? [];
41
+ const commissionRules = commissionRulesQuery.data?.data ?? [];
42
+ const mappings = mappingsQuery.data?.data ?? [];
43
+ const bookingLinks = bookingLinksQuery.data?.data ?? [];
44
+ const webhookEvents = webhookEventsQuery.data?.data ?? [];
45
+ const contractsById = new Map(contracts.map((contract) => [contract.id, contract]));
46
+ const normalizedSearch = search.trim().toLowerCase();
47
+ const matchesSearch = (...values) => !normalizedSearch ||
48
+ values.some((value) => String(value ?? "")
49
+ .toLowerCase()
50
+ .includes(normalizedSearch));
51
+ const matchesChannel = (id) => channelFilter === "all" || id === channelFilter;
52
+ const filteredChannels = channels.filter((channel) => matchesChannel(channel.id) &&
53
+ matchesSearch(channel.name, channel.kind, channel.status, channel.website, channel.contactName, channel.contactEmail));
54
+ const filteredContracts = contracts.filter((contract) => matchesChannel(contract.channelId) &&
55
+ matchesSearch(labelById(channels, contract.channelId), labelById(suppliers, contract.supplierId), contract.status, contract.paymentOwner, contract.startsAt, contract.endsAt, contract.settlementTerms, contract.notes));
56
+ const filteredCommissionRules = commissionRules.filter((rule) => {
57
+ const contract = contractsById.get(rule.contractId);
58
+ return (matchesChannel(contract?.channelId) &&
59
+ matchesSearch(rule.contractId, labelById(products, rule.productId), rule.scope, rule.commissionType, rule.amountCents, rule.percentBasisPoints, rule.externalRateId, rule.externalCategoryId));
60
+ });
61
+ const filteredMappings = mappings.filter((mapping) => matchesChannel(mapping.channelId) &&
62
+ matchesSearch(labelById(channels, mapping.channelId), labelById(products, mapping.productId), mapping.externalProductId, mapping.externalRateId, mapping.externalCategoryId));
63
+ const filteredBookingLinks = bookingLinks.filter((bookingLink) => matchesChannel(bookingLink.channelId) &&
64
+ matchesSearch(labelById(channels, bookingLink.channelId), labelById(bookings, bookingLink.bookingId), bookingLink.externalBookingId, bookingLink.externalReference, bookingLink.externalStatus));
65
+ const filteredWebhookEvents = webhookEvents.filter((event) => matchesChannel(event.channelId) &&
66
+ matchesSearch(labelById(channels, event.channelId), event.eventType, event.externalEventId, event.status, event.errorMessage));
67
+ const syncQueue = filteredWebhookEvents.filter((event) => event.status === "pending" || event.status === "failed");
68
+ const contractsNeedingReview = filteredContracts.filter((contract) => contract.status !== "active");
69
+ const hasFilters = search.length > 0 || channelFilter !== "all";
70
+ const isLoading = suppliersQuery.isPending ||
71
+ productsQuery.isPending ||
72
+ bookingsQuery.isPending ||
73
+ channelsQuery.isPending ||
74
+ contractsQuery.isPending ||
75
+ commissionRulesQuery.isPending ||
76
+ mappingsQuery.isPending ||
77
+ bookingLinksQuery.isPending ||
78
+ webhookEventsQuery.isPending;
79
+ const refreshAll = async () => {
80
+ await Promise.all([
81
+ channelsQuery.refetch(),
82
+ contractsQuery.refetch(),
83
+ commissionRulesQuery.refetch(),
84
+ mappingsQuery.refetch(),
85
+ bookingLinksQuery.refetch(),
86
+ webhookEventsQuery.refetch(),
87
+ ]);
88
+ };
89
+ const handleBulkUpdate = async ({ ids, endpoint, target, noun, payload, successVerb, clearSelection, }) => {
90
+ if (ids.length === 0)
91
+ return;
92
+ setBulkActionTarget(target);
93
+ try {
94
+ const result = await postBatch(client, `${endpoint}/batch-update`, {
95
+ ids,
96
+ patch: payload,
97
+ });
98
+ await refreshAll();
99
+ clearSelection();
100
+ const countLabel = formatDistributionCount(messages, noun, result.succeeded);
101
+ const totalLabel = formatDistributionCount(messages, noun, result.total);
102
+ const message = formatDistributionSummary(messages.common.resultSummary, {
103
+ verb: successVerb,
104
+ countLabel: result.failed.length === 0 ? countLabel : `${result.succeeded} of ${totalLabel}`,
105
+ });
106
+ if (result.failed.length === 0) {
107
+ onBulkSuccess?.(message, result);
108
+ }
109
+ else {
110
+ onBulkError?.(message, undefined, result);
111
+ }
112
+ }
113
+ catch (error) {
114
+ onBulkError?.(error instanceof Error ? error.message : String(error), error);
115
+ }
116
+ finally {
117
+ setBulkActionTarget(null);
118
+ }
119
+ };
120
+ const handleBulkDelete = async ({ ids, endpoint, target, noun, clearSelection, }) => {
121
+ if (ids.length === 0)
122
+ return;
123
+ setBulkActionTarget(target);
124
+ try {
125
+ const result = await postBatch(client, `${endpoint}/batch-delete`, { ids });
126
+ await refreshAll();
127
+ clearSelection();
128
+ const countLabel = formatDistributionCount(messages, noun, result.succeeded);
129
+ const totalLabel = formatDistributionCount(messages, noun, result.total);
130
+ const message = formatDistributionSummary(messages.common.deleteSummary, {
131
+ countLabel: result.failed.length === 0 ? countLabel : `${result.succeeded} of ${totalLabel}`,
132
+ });
133
+ if (result.failed.length === 0) {
134
+ onBulkSuccess?.(message, result);
135
+ }
136
+ else {
137
+ onBulkError?.(message, undefined, result);
138
+ }
139
+ }
140
+ catch (error) {
141
+ onBulkError?.(error instanceof Error ? error.message : String(error), error);
142
+ }
143
+ finally {
144
+ setBulkActionTarget(null);
145
+ }
146
+ };
147
+ return (_jsxs("div", { "data-slot": "distribution-page", className: cn("flex flex-col gap-6 p-6", className), children: [_jsxs("div", { children: [_jsx("h1", { className: "text-2xl font-bold tracking-tight", children: messages.page.title }), _jsx("p", { className: "text-sm text-muted-foreground", children: messages.page.description })] }), isLoading ? (_jsx("div", { className: "flex items-center justify-center py-16", children: _jsx(Loader2, { className: "h-6 w-6 animate-spin text-muted-foreground" }) })) : (_jsxs(_Fragment, { children: [_jsx(DistributionOverview, { channels: channels, suppliers: suppliers, filteredChannels: filteredChannels, filteredContracts: filteredContracts, filteredMappings: filteredMappings, syncQueue: syncQueue, contractsNeedingReview: contractsNeedingReview, search: search, setSearch: setSearch, channelFilter: channelFilter, setChannelFilter: setChannelFilter, hasFilters: hasFilters, onClearFilters: () => {
148
+ setSearch("");
149
+ setChannelFilter("all");
150
+ }, onOpenWebhookEvent: onWebhookEventOpen, onOpenContract: onContractOpen }), _jsxs(Tabs, { defaultValue: "channels", children: [_jsxs(TabsList, { variant: "line", children: [_jsx(TabsTrigger, { value: "channels", children: messages.page.tabs.channels }), _jsx(TabsTrigger, { value: "contracts", children: messages.page.tabs.contracts }), _jsx(TabsTrigger, { value: "commissions", children: messages.page.tabs.commissions }), _jsx(TabsTrigger, { value: "mappings", children: messages.page.tabs.mappings }), _jsx(TabsTrigger, { value: "booking-links", children: messages.page.tabs.bookingLinks }), _jsx(TabsTrigger, { value: "webhooks", children: messages.page.tabs.webhooks })] }), _jsx(DistributionChannelsTab, { filteredChannels: filteredChannels, channelSelection: channelSelection, setChannelSelection: setChannelSelection, bulkActionTarget: bulkActionTarget, handleBulkUpdate: handleBulkUpdate, handleBulkDelete: handleBulkDelete, onCreate: onChannelCreate, onOpenRoute: onChannelOpen, onEdit: onChannelEdit }), _jsx(DistributionContractsTab, { channels: channels, suppliers: suppliers, filteredContracts: filteredContracts, contractSelection: contractSelection, setContractSelection: setContractSelection, bulkActionTarget: bulkActionTarget, handleBulkUpdate: handleBulkUpdate, handleBulkDelete: handleBulkDelete, onCreate: onContractCreate, onOpenRoute: onContractOpen, onEdit: onContractEdit }), _jsx(DistributionCommissionsTab, { contracts: contracts, products: products, filteredCommissionRules: filteredCommissionRules, commissionSelection: commissionSelection, setCommissionSelection: setCommissionSelection, bulkActionTarget: bulkActionTarget, handleBulkDelete: handleBulkDelete, onCreate: onCommissionRuleCreate, onOpenRoute: onCommissionRuleOpen, onEdit: onCommissionRuleEdit }), _jsx(DistributionMappingsTab, { channels: channels, products: products, filteredMappings: filteredMappings, mappingSelection: mappingSelection, setMappingSelection: setMappingSelection, bulkActionTarget: bulkActionTarget, handleBulkUpdate: handleBulkUpdate, handleBulkDelete: handleBulkDelete, onCreate: onMappingCreate, onOpenRoute: onMappingOpen, onEdit: onMappingEdit }), _jsx(DistributionBookingLinksTab, { channels: channels, bookings: bookings, filteredBookingLinks: filteredBookingLinks, bookingLinkSelection: bookingLinkSelection, setBookingLinkSelection: setBookingLinkSelection, bulkActionTarget: bulkActionTarget, handleBulkDelete: handleBulkDelete, onCreate: onBookingLinkCreate, onOpenRoute: onBookingLinkOpen, onEdit: onBookingLinkEdit }), _jsx(DistributionWebhooksTab, { channels: channels, filteredWebhookEvents: filteredWebhookEvents, webhookSelection: webhookSelection, setWebhookSelection: setWebhookSelection, bulkActionTarget: bulkActionTarget, handleBulkUpdate: handleBulkUpdate, handleBulkDelete: handleBulkDelete, onCreate: onWebhookEventCreate, onOpenRoute: onWebhookEventOpen, onEdit: onWebhookEventEdit })] })] }))] }));
151
+ }
152
+ async function postBatch(client, path, body) {
153
+ const response = await client.fetcher(joinUrl(client.baseUrl, path), {
154
+ method: "POST",
155
+ headers: { "Content-Type": "application/json" },
156
+ body: JSON.stringify(body),
157
+ });
158
+ const responseBody = await safeJson(response);
159
+ if (!response.ok) {
160
+ throw new Error(extractErrorMessage(response.status, response.statusText, responseBody));
161
+ }
162
+ return responseBody;
163
+ }
164
+ async function safeJson(response) {
165
+ const text = await response.text();
166
+ if (!text)
167
+ return undefined;
168
+ try {
169
+ return JSON.parse(text);
170
+ }
171
+ catch {
172
+ return text;
173
+ }
174
+ }
175
+ function extractErrorMessage(status, statusText, body) {
176
+ if (typeof body === "object" && body !== null && "error" in body) {
177
+ const error = body.error;
178
+ if (typeof error === "string")
179
+ return error;
180
+ if (typeof error === "object" && error !== null && "message" in error) {
181
+ return String(error.message);
182
+ }
183
+ }
184
+ return `Voyant API error: ${status} ${statusText}`;
185
+ }
186
+ function joinUrl(baseUrl, path) {
187
+ const trimmedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
188
+ const trimmedPath = path.startsWith("/") ? path : `/${path}`;
189
+ return `${trimmedBase}${trimmedPath}`;
190
+ }
@@ -0,0 +1,7 @@
1
+ export declare function SectionHeader({ title, description, actionLabel, onAction, }: {
2
+ title: string;
3
+ description: string;
4
+ actionLabel: string;
5
+ onAction: () => void;
6
+ }): import("react/jsx-runtime").JSX.Element;
7
+ //# sourceMappingURL=distribution-section-header.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distribution-section-header.d.ts","sourceRoot":"","sources":["../../src/components/distribution-section-header.tsx"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,WAAW,EACX,WAAW,EACX,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB,2CAaA"}
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button } from "@voyantjs/ui/components";
3
+ import { Plus } from "lucide-react";
4
+ export function SectionHeader({ title, description, actionLabel, onAction, }) {
5
+ return (_jsxs("div", { className: "flex items-center justify-between gap-4", children: [_jsxs("div", { children: [_jsx("h2", { className: "text-lg font-semibold", children: title }), _jsx("p", { className: "text-sm text-muted-foreground", children: description })] }), _jsxs(Button, { onClick: onAction, children: [_jsx(Plus, { className: "mr-2 h-4 w-4" }), actionLabel] })] }));
6
+ }