@voyantjs/distribution-ui 0.30.6 → 0.31.0

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 (53) hide show
  1. package/README.md +9 -1
  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 +242 -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-page.d.ts +26 -0
  21. package/dist/components/distribution-page.d.ts.map +1 -0
  22. package/dist/components/distribution-page.js +190 -0
  23. package/dist/components/distribution-tabs-primary.d.ts +57 -0
  24. package/dist/components/distribution-tabs-primary.d.ts.map +1 -0
  25. package/dist/components/distribution-tabs-primary.js +89 -0
  26. package/dist/components/distribution-tabs-secondary.d.ts +58 -0
  27. package/dist/components/distribution-tabs-secondary.d.ts.map +1 -0
  28. package/dist/components/distribution-tabs-secondary.js +89 -0
  29. package/dist/components/mapping-detail-page.d.ts +10 -0
  30. package/dist/components/mapping-detail-page.d.ts.map +1 -0
  31. package/dist/components/mapping-detail-page.js +51 -0
  32. package/dist/components/webhook-event-detail-page.d.ts +9 -0
  33. package/dist/components/webhook-event-detail-page.d.ts.map +1 -0
  34. package/dist/components/webhook-event-detail-page.js +46 -0
  35. package/dist/i18n/en.d.ts +381 -0
  36. package/dist/i18n/en.d.ts.map +1 -1
  37. package/dist/i18n/en.js +363 -0
  38. package/dist/i18n/index.d.ts +1 -1
  39. package/dist/i18n/index.d.ts.map +1 -1
  40. package/dist/i18n/messages.d.ts +244 -0
  41. package/dist/i18n/messages.d.ts.map +1 -1
  42. package/dist/i18n/provider.d.ts +762 -0
  43. package/dist/i18n/provider.d.ts.map +1 -1
  44. package/dist/i18n/ro.d.ts +381 -0
  45. package/dist/i18n/ro.d.ts.map +1 -1
  46. package/dist/i18n/ro.js +363 -0
  47. package/dist/i18n/utils.d.ts +4 -0
  48. package/dist/i18n/utils.d.ts.map +1 -0
  49. package/dist/i18n/utils.js +8 -0
  50. package/dist/index.d.ts +12 -1
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +11 -0
  53. package/package.json +7 -7
@@ -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 { distributionQueryKeys, fetchWithValidation, getChannelQueryOptions, getCommissionRuleQueryOptions, getContractQueryOptions, getProductQueryOptions, successEnvelope, useVoyantDistributionContext, } from "@voyantjs/distribution-react";
4
+ import { Badge, Button, Card, CardContent, CardHeader, CardTitle, ConfirmActionButton, } from "@voyantjs/ui/components";
5
+ import { cn } from "@voyantjs/ui/lib/utils";
6
+ import { ArrowLeft, DollarSign, Loader2, Package } from "lucide-react";
7
+ import { useDistributionUiI18nOrDefault } from "../i18n/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",
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":"AAgCA,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 { distributionQueryKeys, fetchWithValidation, getChannelQueryOptions, getCommissionRulesQueryOptions, getContractQueryOptions, getProductsQueryOptions, getSupplierQueryOptions, successEnvelope, useVoyantDistributionContext, } from "@voyantjs/distribution-react";
4
+ import { Badge, Button, Card, CardContent, CardHeader, CardTitle, ConfirmActionButton, } from "@voyantjs/ui/components";
5
+ import { cn } from "@voyantjs/ui/lib/utils";
6
+ import { ArrowLeft, DollarSign, Loader2 } from "lucide-react";
7
+ import { useDistributionUiI18nOrDefault } from "../i18n/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",
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,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":"AAsBA,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 { useBookingLinks, useBookings, useChannels, useCommissionRules, useContracts, useMappings, useProducts, useSuppliers, useVoyantDistributionContext, useWebhookEvents, } from "@voyantjs/distribution-react";
3
+ import { Tabs, TabsList, TabsTrigger } from "@voyantjs/ui/components/tabs";
4
+ import { cn } from "@voyantjs/ui/lib/utils";
5
+ import { Loader2 } from "lucide-react";
6
+ import { useState } from "react";
7
+ import { useDistributionUiI18nOrDefault } from "../i18n/index.js";
8
+ import { formatDistributionCount, formatDistributionSummary } from "../i18n/utils.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,57 @@
1
+ import type { OnChangeFn, RowSelectionState } from "@tanstack/react-table";
2
+ import type { DistributionEntity } from "../i18n/messages.js";
3
+ import type { ChannelCommissionRuleRow, ChannelContractRow, ChannelRow, ProductOption, SupplierOption } from "./distribution-shared.js";
4
+ type BulkFn = (args: {
5
+ ids: string[];
6
+ endpoint: string;
7
+ target: string;
8
+ noun: DistributionEntity;
9
+ payload: Record<string, unknown>;
10
+ successVerb: string;
11
+ clearSelection: () => void;
12
+ }) => Promise<void>;
13
+ type DeleteFn = (args: {
14
+ ids: string[];
15
+ endpoint: string;
16
+ target: string;
17
+ noun: DistributionEntity;
18
+ clearSelection: () => void;
19
+ }) => Promise<void>;
20
+ export declare function DistributionChannelsTab(props: {
21
+ filteredChannels: ChannelRow[];
22
+ channelSelection: RowSelectionState;
23
+ setChannelSelection: OnChangeFn<RowSelectionState>;
24
+ bulkActionTarget: string | null;
25
+ handleBulkUpdate: BulkFn;
26
+ handleBulkDelete: DeleteFn;
27
+ onCreate: () => void;
28
+ onOpenRoute: (channelId: string) => void;
29
+ onEdit: (row: ChannelRow) => void;
30
+ }): import("react/jsx-runtime").JSX.Element;
31
+ export declare function DistributionContractsTab(props: {
32
+ channels: ChannelRow[];
33
+ suppliers: SupplierOption[];
34
+ filteredContracts: ChannelContractRow[];
35
+ contractSelection: RowSelectionState;
36
+ setContractSelection: OnChangeFn<RowSelectionState>;
37
+ bulkActionTarget: string | null;
38
+ handleBulkUpdate: BulkFn;
39
+ handleBulkDelete: DeleteFn;
40
+ onCreate: () => void;
41
+ onOpenRoute: (contractId: string) => void;
42
+ onEdit: (row: ChannelContractRow) => void;
43
+ }): import("react/jsx-runtime").JSX.Element;
44
+ export declare function DistributionCommissionsTab(props: {
45
+ contracts: ChannelContractRow[];
46
+ products: ProductOption[];
47
+ filteredCommissionRules: ChannelCommissionRuleRow[];
48
+ commissionSelection: RowSelectionState;
49
+ setCommissionSelection: OnChangeFn<RowSelectionState>;
50
+ bulkActionTarget: string | null;
51
+ handleBulkDelete: DeleteFn;
52
+ onCreate: () => void;
53
+ onOpenRoute: (commissionRuleId: string) => void;
54
+ onEdit: (row: ChannelCommissionRuleRow) => void;
55
+ }): import("react/jsx-runtime").JSX.Element;
56
+ export {};
57
+ //# sourceMappingURL=distribution-tabs-primary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distribution-tabs-primary.d.ts","sourceRoot":"","sources":["../../src/components/distribution-tabs-primary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,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K,IAAI,CAAA;CAClC,2CAkGA;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,QAAQ,EAAE,UAAU,EAAE,CAAA;IACtB,SAAS,EAAE,cAAc,EAAE,CAAA;IAC3B,iBAAiB,EAAE,kBAAkB,EAAE,CAAA;IACvC,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,oBAAoB,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAA;IACnD,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,QAAQ,CAAA;IAC1B,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,WAAW,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAA;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,kBAAkB,KAAK,IAAI,CAAA;CAC1C,2CAkGA;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IAChD,SAAS,EAAE,kBAAkB,EAAE,CAAA;IAC/B,QAAQ,EAAE,aAAa,EAAE,CAAA;IACzB,uBAAuB,EAAE,wBAAwB,EAAE,CAAA;IACnD,mBAAmB,EAAE,iBAAiB,CAAA;IACtC,sBAAsB,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAA;IACrD,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;IAC/B,gBAAgB,EAAE,QAAQ,CAAA;IAC1B,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,WAAW,EAAE,CAAC,gBAAgB,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/C,MAAM,EAAE,CAAC,GAAG,EAAE,wBAAwB,KAAK,IAAI,CAAA;CAChD,2CAgEA"}
@@ -0,0 +1,89 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { formatMessage } from "@voyantjs/i18n";
3
+ import { ConfirmActionButton, SelectionActionBar } from "@voyantjs/ui/components";
4
+ import { DataTable } from "@voyantjs/ui/components/data-table";
5
+ import { TabsContent } from "@voyantjs/ui/components/tabs";
6
+ import { useDistributionUiI18nOrDefault } from "../i18n/index.js";
7
+ import { formatDistributionCount, formatDistributionSummary } from "../i18n/utils.js";
8
+ import { SectionHeader } from "./distribution-section-header.js";
9
+ import { channelColumns, commissionColumns, contractColumns } from "./distribution-shared.js";
10
+ function getSelectionSummary(count, template) {
11
+ return formatDistributionSummary(template, { count });
12
+ }
13
+ export function DistributionChannelsTab(props) {
14
+ const i18n = useDistributionUiI18nOrDefault();
15
+ const { messages } = i18n;
16
+ const tab = messages.tabs.channels;
17
+ return (_jsxs(TabsContent, { value: "channels", className: "space-y-4", children: [_jsx(SectionHeader, { title: tab.title, description: tab.description, actionLabel: tab.actionLabel, onAction: props.onCreate }), _jsx(DataTable, { columns: channelColumns(props.onOpenRoute, i18n), data: props.filteredChannels, emptyMessage: tab.empty, enableRowSelection: true, getRowId: (row) => row.id, rowSelection: props.channelSelection, onRowSelectionChange: props.setChannelSelection, renderSelectionActions: ({ selectedRows, clearSelection }) => {
18
+ const countLabel = formatDistributionCount(messages, "channel", selectedRows.length);
19
+ return (_jsxs(SelectionActionBar, { selectedCount: selectedRows.length, onClear: clearSelection, selectionSummary: getSelectionSummary(selectedRows.length, messages.common.selectionSummary), clearLabel: messages.common.clearSelection, children: [_jsx(ConfirmActionButton, { buttonLabel: tab.actions.activate.button, confirmLabel: tab.actions.activate.confirm, cancelLabel: messages.common.cancel, title: formatMessage(tab.actions.activate.title, { countLabel }), description: tab.actions.activate.description, disabled: props.bulkActionTarget === "channels-activate", onConfirm: () => props.handleBulkUpdate({
20
+ ids: selectedRows.map((row) => row.original.id),
21
+ endpoint: "/v1/distribution/channels",
22
+ target: "channels-activate",
23
+ noun: "channel",
24
+ payload: { status: "active" },
25
+ successVerb: messages.page.bulkVerbs.activated,
26
+ clearSelection,
27
+ }) }), _jsx(ConfirmActionButton, { buttonLabel: tab.actions.archive.button, confirmLabel: tab.actions.archive.confirm, cancelLabel: messages.common.cancel, title: formatMessage(tab.actions.archive.title, { countLabel }), description: tab.actions.archive.description, disabled: props.bulkActionTarget === "channels-archive", onConfirm: () => props.handleBulkUpdate({
28
+ ids: selectedRows.map((row) => row.original.id),
29
+ endpoint: "/v1/distribution/channels",
30
+ target: "channels-archive",
31
+ noun: "channel",
32
+ payload: { status: "archived" },
33
+ successVerb: messages.page.bulkVerbs.archived,
34
+ clearSelection,
35
+ }) }), _jsx(ConfirmActionButton, { buttonLabel: tab.actions.delete.button, confirmLabel: tab.actions.delete.confirm, cancelLabel: messages.common.cancel, title: formatMessage(tab.actions.delete.title, { countLabel }), description: tab.actions.delete.description, disabled: props.bulkActionTarget === "channels-delete", variant: "destructive", confirmVariant: "destructive", onConfirm: () => props.handleBulkDelete({
36
+ ids: selectedRows.map((row) => row.original.id),
37
+ endpoint: "/v1/distribution/channels",
38
+ target: "channels-delete",
39
+ noun: "channel",
40
+ clearSelection,
41
+ }) })] }));
42
+ }, onRowClick: (row) => props.onEdit(row.original) })] }));
43
+ }
44
+ export function DistributionContractsTab(props) {
45
+ const i18n = useDistributionUiI18nOrDefault();
46
+ const { messages } = i18n;
47
+ const tab = messages.tabs.contracts;
48
+ return (_jsxs(TabsContent, { value: "contracts", className: "space-y-4", children: [_jsx(SectionHeader, { title: tab.title, description: tab.description, actionLabel: tab.actionLabel, onAction: props.onCreate }), _jsx(DataTable, { columns: contractColumns(props.channels, props.suppliers, props.onOpenRoute, i18n), data: props.filteredContracts, emptyMessage: tab.empty, enableRowSelection: true, getRowId: (row) => row.id, rowSelection: props.contractSelection, onRowSelectionChange: props.setContractSelection, renderSelectionActions: ({ selectedRows, clearSelection }) => {
49
+ const countLabel = formatDistributionCount(messages, "contract", selectedRows.length);
50
+ return (_jsxs(SelectionActionBar, { selectedCount: selectedRows.length, onClear: clearSelection, selectionSummary: getSelectionSummary(selectedRows.length, messages.common.selectionSummary), clearLabel: messages.common.clearSelection, children: [_jsx(ConfirmActionButton, { buttonLabel: tab.actions.activate.button, confirmLabel: tab.actions.activate.confirm, cancelLabel: messages.common.cancel, title: formatMessage(tab.actions.activate.title, { countLabel }), description: tab.actions.activate.description, disabled: props.bulkActionTarget === "contracts-activate", onConfirm: () => props.handleBulkUpdate({
51
+ ids: selectedRows.map((row) => row.original.id),
52
+ endpoint: "/v1/distribution/contracts",
53
+ target: "contracts-activate",
54
+ noun: "contract",
55
+ payload: { status: "active" },
56
+ successVerb: messages.page.bulkVerbs.activated,
57
+ clearSelection,
58
+ }) }), _jsx(ConfirmActionButton, { buttonLabel: tab.actions.expire.button, confirmLabel: tab.actions.expire.confirm, cancelLabel: messages.common.cancel, title: formatMessage(tab.actions.expire.title, { countLabel }), description: tab.actions.expire.description, disabled: props.bulkActionTarget === "contracts-expire", onConfirm: () => props.handleBulkUpdate({
59
+ ids: selectedRows.map((row) => row.original.id),
60
+ endpoint: "/v1/distribution/contracts",
61
+ target: "contracts-expire",
62
+ noun: "contract",
63
+ payload: { status: "expired" },
64
+ successVerb: messages.page.bulkVerbs.expired,
65
+ clearSelection,
66
+ }) }), _jsx(ConfirmActionButton, { buttonLabel: tab.actions.delete.button, confirmLabel: tab.actions.delete.confirm, cancelLabel: messages.common.cancel, title: formatMessage(tab.actions.delete.title, { countLabel }), description: tab.actions.delete.description, disabled: props.bulkActionTarget === "contracts-delete", variant: "destructive", confirmVariant: "destructive", onConfirm: () => props.handleBulkDelete({
67
+ ids: selectedRows.map((row) => row.original.id),
68
+ endpoint: "/v1/distribution/contracts",
69
+ target: "contracts-delete",
70
+ noun: "contract",
71
+ clearSelection,
72
+ }) })] }));
73
+ }, onRowClick: (row) => props.onEdit(row.original) })] }));
74
+ }
75
+ export function DistributionCommissionsTab(props) {
76
+ const i18n = useDistributionUiI18nOrDefault();
77
+ const { messages } = i18n;
78
+ const tab = messages.tabs.commissions;
79
+ return (_jsxs(TabsContent, { value: "commissions", className: "space-y-4", children: [_jsx(SectionHeader, { title: tab.title, description: tab.description, actionLabel: tab.actionLabel, onAction: props.onCreate }), _jsx(DataTable, { columns: commissionColumns(props.contracts, props.products, props.onOpenRoute, i18n), data: props.filteredCommissionRules, emptyMessage: tab.empty, enableRowSelection: true, getRowId: (row) => row.id, rowSelection: props.commissionSelection, onRowSelectionChange: props.setCommissionSelection, renderSelectionActions: ({ selectedRows, clearSelection }) => {
80
+ const countLabel = formatDistributionCount(messages, "commissionRule", selectedRows.length);
81
+ return (_jsx(SelectionActionBar, { selectedCount: selectedRows.length, onClear: clearSelection, selectionSummary: getSelectionSummary(selectedRows.length, messages.common.selectionSummary), clearLabel: messages.common.clearSelection, children: _jsx(ConfirmActionButton, { buttonLabel: tab.actions.delete.button, confirmLabel: tab.actions.delete.confirm, cancelLabel: messages.common.cancel, title: formatMessage(tab.actions.delete.title, { countLabel }), description: tab.actions.delete.description, disabled: props.bulkActionTarget === "commission-rules-delete", variant: "destructive", confirmVariant: "destructive", onConfirm: () => props.handleBulkDelete({
82
+ ids: selectedRows.map((row) => row.original.id),
83
+ endpoint: "/v1/distribution/commission-rules",
84
+ target: "commission-rules-delete",
85
+ noun: "commissionRule",
86
+ clearSelection,
87
+ }) }) }));
88
+ }, onRowClick: (row) => props.onEdit(row.original) })] }));
89
+ }
@@ -0,0 +1,58 @@
1
+ import type { OnChangeFn, RowSelectionState } from "@tanstack/react-table";
2
+ import type { DistributionEntity } from "../i18n/messages.js";
3
+ import type { BookingOption, ChannelBookingLinkRow, ChannelProductMappingRow, ChannelRow, ChannelWebhookEventRow, ProductOption } from "./distribution-shared.js";
4
+ type BulkFn = (args: {
5
+ ids: string[];
6
+ endpoint: string;
7
+ target: string;
8
+ noun: DistributionEntity;
9
+ payload: Record<string, unknown>;
10
+ successVerb: string;
11
+ clearSelection: () => void;
12
+ }) => Promise<void>;
13
+ type DeleteFn = (args: {
14
+ ids: string[];
15
+ endpoint: string;
16
+ target: string;
17
+ noun: DistributionEntity;
18
+ clearSelection: () => void;
19
+ }) => Promise<void>;
20
+ export declare function DistributionMappingsTab(props: {
21
+ channels: ChannelRow[];
22
+ products: ProductOption[];
23
+ filteredMappings: ChannelProductMappingRow[];
24
+ mappingSelection: RowSelectionState;
25
+ setMappingSelection: OnChangeFn<RowSelectionState>;
26
+ bulkActionTarget: string | null;
27
+ handleBulkUpdate: BulkFn;
28
+ handleBulkDelete: DeleteFn;
29
+ onCreate: () => void;
30
+ onOpenRoute: (mappingId: string) => void;
31
+ onEdit: (row: ChannelProductMappingRow) => void;
32
+ }): import("react/jsx-runtime").JSX.Element;
33
+ export declare function DistributionBookingLinksTab(props: {
34
+ channels: ChannelRow[];
35
+ bookings: BookingOption[];
36
+ filteredBookingLinks: ChannelBookingLinkRow[];
37
+ bookingLinkSelection: RowSelectionState;
38
+ setBookingLinkSelection: OnChangeFn<RowSelectionState>;
39
+ bulkActionTarget: string | null;
40
+ handleBulkDelete: DeleteFn;
41
+ onCreate: () => void;
42
+ onOpenRoute: (bookingLinkId: string) => void;
43
+ onEdit: (row: ChannelBookingLinkRow) => void;
44
+ }): import("react/jsx-runtime").JSX.Element;
45
+ export declare function DistributionWebhooksTab(props: {
46
+ channels: ChannelRow[];
47
+ filteredWebhookEvents: ChannelWebhookEventRow[];
48
+ webhookSelection: RowSelectionState;
49
+ setWebhookSelection: OnChangeFn<RowSelectionState>;
50
+ bulkActionTarget: string | null;
51
+ handleBulkUpdate: BulkFn;
52
+ handleBulkDelete: DeleteFn;
53
+ onCreate: () => void;
54
+ onOpenRoute: (webhookEventId: string) => void;
55
+ onEdit: (row: ChannelWebhookEventRow) => void;
56
+ }): import("react/jsx-runtime").JSX.Element;
57
+ export {};
58
+ //# sourceMappingURL=distribution-tabs-secondary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"distribution-tabs-secondary.d.ts","sourceRoot":"","sources":["../../src/components/distribution-tabs-secondary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAM1E,OAAO,KAAK,EAAE,kBAA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