@agentpaid/paid-nextjs-client 0.3.0-test.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +184 -79
- package/dist/api/api/handleBlocks.ts +144 -0
- package/dist/api/handleBlocks.d.ts +9 -0
- package/dist/api/handleBlocks.d.ts.map +1 -0
- package/dist/api/handleBlocks.js +107 -0
- package/dist/api/handleBlocks.js.map +1 -0
- package/dist/components/PaidActivityLog.d.ts +13 -26
- package/dist/components/PaidActivityLog.d.ts.map +1 -1
- package/dist/components/PaidActivityLog.js +70 -26
- package/dist/components/PaidActivityLog.js.map +1 -1
- package/dist/components/PaidContainer.d.ts +11 -24
- package/dist/components/PaidContainer.d.ts.map +1 -1
- package/dist/components/PaidContainer.js +18 -9
- package/dist/components/PaidContainer.js.map +1 -1
- package/dist/components/PaidInvoiceTable.d.ts +12 -25
- package/dist/components/PaidInvoiceTable.d.ts.map +1 -1
- package/dist/components/PaidInvoiceTable.js +78 -30
- package/dist/components/PaidInvoiceTable.js.map +1 -1
- package/dist/components/PaidPaymentsTable.d.ts +12 -25
- package/dist/components/PaidPaymentsTable.d.ts.map +1 -1
- package/dist/components/PaidPaymentsTable.js +63 -29
- package/dist/components/PaidPaymentsTable.js.map +1 -1
- package/dist/components/components/PaidActivityLog.js +115 -58
- package/dist/components/components/PaidContainer.js +42 -32
- package/dist/components/components/PaidInvoiceTable.js +126 -89
- package/dist/components/components/PaidPaymentsTable.js +111 -72
- package/dist/components/components/ui/Pagination.js +168 -0
- package/dist/components/ui/Pagination.d.ts +10 -0
- package/dist/components/ui/Pagination.d.ts.map +1 -0
- package/dist/components/ui/Pagination.js +111 -0
- package/dist/components/ui/Pagination.js.map +1 -0
- package/dist/hooks/useCache.d.ts +2 -2
- package/dist/hooks/useCache.d.ts.map +1 -1
- package/dist/hooks/useCache.js +10 -17
- package/dist/hooks/useCache.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/styles/paid-activity-log.css +154 -0
- package/dist/styles/paid-container.css +25 -16
- package/dist/styles/paid-invoice-table.css +135 -120
- package/dist/styles/paid-payments-table.css +65 -109
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/apiClient.d.ts +17 -0
- package/dist/utils/apiClient.d.ts.map +1 -0
- package/dist/utils/apiClient.js +60 -0
- package/dist/utils/apiClient.js.map +1 -0
- package/dist/utils/cache.js +1 -1
- package/dist/utils/cache.js.map +1 -1
- package/package.json +1 -1
- package/dist/api/api/handlePaidInvoicePdf.ts +0 -79
- package/dist/api/api/handlePaidInvoices.ts +0 -77
- package/dist/api/api/handlePaidPayments.ts +0 -77
- package/dist/api/api/handlePaidUsage.ts +0 -52
- package/dist/api/handlePaidInvoicePdf.d.ts +0 -6
- package/dist/api/handlePaidInvoicePdf.d.ts.map +0 -1
- package/dist/api/handlePaidInvoicePdf.js +0 -60
- package/dist/api/handlePaidInvoicePdf.js.map +0 -1
- package/dist/api/handlePaidInvoices.d.ts +0 -6
- package/dist/api/handlePaidInvoices.d.ts.map +0 -1
- package/dist/api/handlePaidInvoices.js +0 -56
- package/dist/api/handlePaidInvoices.js.map +0 -1
- package/dist/api/handlePaidPayments.d.ts +0 -6
- package/dist/api/handlePaidPayments.d.ts.map +0 -1
- package/dist/api/handlePaidPayments.js +0 -56
- package/dist/api/handlePaidPayments.js.map +0 -1
- package/dist/api/handlePaidUsage.d.ts +0 -6
- package/dist/api/handlePaidUsage.d.ts.map +0 -1
- package/dist/api/handlePaidUsage.js +0 -35
- package/dist/api/handlePaidUsage.js.map +0 -1
- package/dist/styles/activity-log-table.css +0 -138
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PaidPaymentsTable.d.ts","sourceRoot":"","sources":["../../src/components/PaidPaymentsTable.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"PaidPaymentsTable.d.ts","sourceRoot":"","sources":["../../src/components/PaidPaymentsTable.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAInD,OAAO,mCAAmC,CAAC;AAG3C,UAAU,mBAAmB;IAEzB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IAGxB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAGpC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAGjC,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAeD,UAAU,sBAAsB;IAC5B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,mBAAmB,CAAC;CACnC;AAED,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CA6M9D,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
@@ -2,33 +2,70 @@
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
3
3
|
import { useEffect, useState } from 'react';
|
4
4
|
import { useIsInContainer } from './PaidContainer';
|
5
|
+
import { getCacheKey } from '../utils/cache';
|
6
|
+
import { Pagination } from './ui/Pagination';
|
5
7
|
import '../styles/paid-payments-table.css';
|
6
|
-
|
8
|
+
import { fetchPaidData } from '../utils/apiClient';
|
9
|
+
export const PaidPaymentsTable = ({ customerExternalId, paidStyle = {} }) => {
|
7
10
|
const [payments, setPayments] = useState([]);
|
8
11
|
const [loading, setLoading] = useState(true);
|
9
12
|
const [error, setError] = useState(null);
|
13
|
+
const [currentPage, setCurrentPage] = useState(1);
|
14
|
+
const itemsPerPage = 8;
|
10
15
|
const isInContainer = useIsInContainer();
|
16
|
+
// Calculate pagination
|
17
|
+
const totalPages = Math.ceil(payments.length / itemsPerPage);
|
18
|
+
const startIndex = (currentPage - 1) * itemsPerPage;
|
19
|
+
const endIndex = startIndex + itemsPerPage;
|
20
|
+
const currentPayments = payments.slice(startIndex, endIndex);
|
21
|
+
const handlePageChange = (page) => {
|
22
|
+
setCurrentPage(page);
|
23
|
+
};
|
11
24
|
// Convert paidStyle entries into CSS custom properties
|
12
25
|
const cssVariables = Object.entries(paidStyle).reduce((vars, [key, value]) => {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
26
|
+
if (value !== undefined && value !== null && value !== '') {
|
27
|
+
// Map simplified properties to CSS custom properties
|
28
|
+
const propertyMap = {
|
29
|
+
fontFamily: '--paid-font-family',
|
30
|
+
primaryColor: '--paid-primary-color',
|
31
|
+
secondaryColor: '--paid-secondary-color',
|
32
|
+
containerBackgroundColor: '--paid-container-background-color',
|
33
|
+
tableBackgroundColor: '--paid-table-background-color',
|
34
|
+
tableHeaderBackgroundColor: '--paid-table-header-background-color',
|
35
|
+
tabBackgroundColor: '--paid-tab-background-color',
|
36
|
+
tabActiveBackgroundColor: '--paid-tab-active-background-color',
|
37
|
+
tabHoverBackgroundColor: '--paid-tab-hover-background-color',
|
38
|
+
tableHoverColor: '--paid-table-hover-color',
|
39
|
+
buttonBgColor: '--paid-button-bg-color'
|
40
|
+
};
|
41
|
+
const cssProperty = propertyMap[key];
|
42
|
+
if (cssProperty) {
|
43
|
+
// @ts-ignore allow custom property
|
44
|
+
vars[cssProperty] = value;
|
45
|
+
}
|
20
46
|
}
|
21
|
-
// @ts-ignore allow custom property
|
22
|
-
vars[varName] = value;
|
23
47
|
return vars;
|
24
48
|
}, {});
|
25
|
-
const formatCurrency = (amount) => {
|
49
|
+
const formatCurrency = (amount, currency) => {
|
50
|
+
const symbol = getCurrencySymbol(currency);
|
26
51
|
return new Intl.NumberFormat("en-US", {
|
27
52
|
style: "currency",
|
28
53
|
currency: "USD",
|
29
|
-
minimumFractionDigits:
|
30
|
-
maximumFractionDigits:
|
31
|
-
}).format(amount / 100);
|
54
|
+
minimumFractionDigits: 2,
|
55
|
+
maximumFractionDigits: 2,
|
56
|
+
}).format(amount / 100).replace('$', symbol);
|
57
|
+
};
|
58
|
+
const getCurrencySymbol = (currency) => {
|
59
|
+
switch (currency.toUpperCase()) {
|
60
|
+
case 'USD':
|
61
|
+
return '$';
|
62
|
+
case 'EUR':
|
63
|
+
return '€';
|
64
|
+
case 'GBP':
|
65
|
+
return '£';
|
66
|
+
default:
|
67
|
+
return '$'; // Default to USD symbol
|
68
|
+
}
|
32
69
|
};
|
33
70
|
const formatDate = (dateString) => {
|
34
71
|
return new Date(dateString).toLocaleDateString('en-US', {
|
@@ -50,19 +87,16 @@ export const PaidPaymentsTable = ({ accountExternalId, paidStyle = {} }) => {
|
|
50
87
|
const fetchPaymentData = async () => {
|
51
88
|
try {
|
52
89
|
setLoading(true);
|
53
|
-
console.log('PaidPaymentsTable: Fetching payment data for',
|
54
|
-
//
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
// );
|
62
|
-
// Direct fetch without caching
|
63
|
-
const response = await fetch(`/api/payments/${accountExternalId}`);
|
90
|
+
console.log('PaidPaymentsTable: Fetching payment data for', customerExternalId);
|
91
|
+
// Use cached fetch for payment data
|
92
|
+
const cacheKey = getCacheKey.payments(customerExternalId);
|
93
|
+
console.log('PaidPaymentsTable: Using cache key', cacheKey);
|
94
|
+
const response = await fetchPaidData({
|
95
|
+
paidEndpoint: 'payments',
|
96
|
+
customerExternalId
|
97
|
+
});
|
64
98
|
if (!response.ok) {
|
65
|
-
throw new Error(`
|
99
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
66
100
|
}
|
67
101
|
const data = await response.json();
|
68
102
|
console.log('PaidPaymentsTable: Received data', data);
|
@@ -81,7 +115,7 @@ export const PaidPaymentsTable = ({ accountExternalId, paidStyle = {} }) => {
|
|
81
115
|
const handleCacheRefresh = (event) => {
|
82
116
|
var _a, _b;
|
83
117
|
console.log('PaidPaymentsTable: Cache refresh event received', event.detail);
|
84
|
-
if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.
|
118
|
+
if (((_a = event.detail) === null || _a === void 0 ? void 0 : _a.customerId) === customerExternalId || ((_b = event.detail) === null || _b === void 0 ? void 0 : _b.type) === 'all') {
|
85
119
|
console.log('PaidPaymentsTable: Refetching data due to cache refresh');
|
86
120
|
fetchPaymentData();
|
87
121
|
}
|
@@ -90,14 +124,14 @@ export const PaidPaymentsTable = ({ accountExternalId, paidStyle = {} }) => {
|
|
90
124
|
return () => {
|
91
125
|
window.removeEventListener('cache-refresh', handleCacheRefresh);
|
92
126
|
};
|
93
|
-
}, [
|
127
|
+
}, [customerExternalId]);
|
94
128
|
if (loading) {
|
95
129
|
return _jsx("div", { children: "Loading payment data..." });
|
96
130
|
}
|
97
131
|
if (error) {
|
98
132
|
return _jsxs("div", { children: ["Error: ", error] });
|
99
133
|
}
|
100
|
-
return (_jsx("div", { className: "paid-payment-container", style: { position: 'relative', minWidth: 0, ...cssVariables }, children: _jsxs("div", { className: "paid-payment-table-wrapper", style: { position: '
|
134
|
+
return (_jsx("div", { className: "paid-payment-container", style: { position: 'relative', minWidth: 0, ...cssVariables }, children: _jsxs("div", { className: "paid-payment-table-wrapper", style: { position: 'relative', width: '100%', height: 'auto', left: undefined, top: undefined, boxShadow: undefined, cursor: undefined }, children: [!isInContainer && (_jsx("div", { className: "paid-payment-header", children: _jsx("h3", { className: "paid-payment-title", children: "Payments" }) })), _jsx("div", { style: { background: '#fff', overflow: 'auto', width: '100%', boxSizing: 'border-box' }, children: _jsxs("table", { className: "paid-payment-table", style: { width: '100%', maxWidth: '100%', tableLayout: 'fixed' }, children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { children: "Payment Number" }), _jsx("th", { children: "Payment type" }), _jsx("th", { children: "Due date" }), _jsx("th", { children: "Status" }), _jsx("th", { style: { textAlign: 'center' }, children: "Amount" })] }) }), _jsx("tbody", { children: currentPayments.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: 5, className: "paid-payment-empty", children: "No payments found" }) })) : (currentPayments.map((payment) => (_jsxs("tr", { children: [_jsx("td", { style: { fontWeight: 500 }, children: _jsx("div", { className: "paid-payment-number", children: _jsx("span", { children: "PAY-1" }) }) }), _jsx("td", { children: payment.paymentType }), _jsx("td", { children: formatDate(payment.paymentDate) }), _jsx("td", { children: getStatusBadge(payment.paymentStatus) }), _jsx("td", { style: { textAlign: 'center' }, children: _jsx("div", { className: "paid-payment-amount", children: _jsx("span", { className: "amount-number", children: formatCurrency(payment.amount, payment.currency) }) }) })] }, payment.id)))) })] }) }), _jsx(Pagination, { currentPage: currentPage, totalPages: totalPages, onPageChange: handlePageChange })] }) }));
|
101
135
|
};
|
102
136
|
export default PaidPaymentsTable;
|
103
137
|
//# sourceMappingURL=PaidPaymentsTable.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"PaidPaymentsTable.js","sourceRoot":"","sources":["../../src/components/PaidPaymentsTable.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"PaidPaymentsTable.js","sourceRoot":"","sources":["../../src/components/PaidPaymentsTable.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAc,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;A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C,EAAE,SAAS,EAAC,oBAAoB,kCAEzC,GACJ,CACR,CAAC,CAAC,CAAC,CACA,eAAe,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAC7B,yBACI,aAAI,KAAK,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,YAC1B,cAAK,SAAS,EAAC,qBAAqB,YAChC,mCAAkB,GAChB,GACL,EACL,uBAAK,OAAO,CAAC,WAAW,GAAM,EAC9B,uBAAK,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,GAAM,EAC1C,uBAAK,cAAc,CAAC,OAAO,CAAC,aAAa,CAAC,GAAM,EAChD,aAAI,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,YAC9B,cAAK,SAAS,EAAC,qBAAqB,YAChC,eAAM,SAAS,EAAC,eAAe,YAAE,cAAc,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAQ,GACvF,GACL,KAbA,OAAO,CAAC,EAAE,CAcd,CACR,CAAC,CACL,GACG,IACJ,GACN,EAGN,KAAC,UAAU,IACP,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,gBAAgB,GAChC,IACA,GACJ,CACT,CAAC;AACN,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
@@ -2,35 +2,35 @@
|
|
2
2
|
|
3
3
|
import React, { useEffect, useState } from 'react';
|
4
4
|
import { useIsInContainer } from './PaidContainer';
|
5
|
-
import {
|
6
|
-
import '../
|
5
|
+
import { Pagination } from './ui/Pagination';
|
6
|
+
import { fetchPaidData } from '../utils/apiClient';
|
7
|
+
import '../styles/paid-activity-log.css';
|
7
8
|
|
8
9
|
interface PaidStyleProperties {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
paidThBg?: string;
|
32
|
-
paidRowHoverBg?: string;
|
10
|
+
// Global - Font
|
11
|
+
fontFamily?: string;
|
12
|
+
|
13
|
+
// Global - Font Colors
|
14
|
+
primaryColor?: string;
|
15
|
+
secondaryColor?: string;
|
16
|
+
|
17
|
+
// Background Colors
|
18
|
+
containerBackgroundColor?: string;
|
19
|
+
tableBackgroundColor?: string;
|
20
|
+
tableHeaderBackgroundColor?: string;
|
21
|
+
|
22
|
+
// Tab Colors
|
23
|
+
tabBackgroundColor?: string;
|
24
|
+
tabActiveBackgroundColor?: string;
|
25
|
+
tabHoverBackgroundColor?: string;
|
26
|
+
|
27
|
+
// Table Hover
|
28
|
+
tableHoverColor?: string;
|
29
|
+
|
30
|
+
// Button Background (Status badges & Pagination)
|
31
|
+
buttonBgColor?: string;
|
33
32
|
}
|
33
|
+
|
34
34
|
interface UsageSummary {
|
35
35
|
id: string;
|
36
36
|
updatedAt: string;
|
@@ -47,6 +47,7 @@ interface UsageSummary {
|
|
47
47
|
orderLineAttributeId: string;
|
48
48
|
invoiceId: string | null;
|
49
49
|
invoiceLineId: string | null;
|
50
|
+
currency?: string;
|
50
51
|
}
|
51
52
|
|
52
53
|
interface UsageApiResponse {
|
@@ -56,40 +57,82 @@ interface UsageApiResponse {
|
|
56
57
|
}
|
57
58
|
|
58
59
|
interface PaidActivityLogProps {
|
59
|
-
|
60
|
+
customerExternalId: string;
|
60
61
|
paidStyle?: PaidStyleProperties;
|
61
62
|
}
|
62
63
|
|
63
64
|
export const PaidActivityLog: React.FC<PaidActivityLogProps> = ({
|
64
|
-
|
65
|
+
customerExternalId,
|
65
66
|
paidStyle = {}
|
66
67
|
}) => {
|
67
68
|
const [usageSummaries, setUsageSummaries] = useState<UsageSummary[]>([]);
|
68
69
|
const [loading, setLoading] = useState(true);
|
69
70
|
const [error, setError] = useState<string | null>(null);
|
71
|
+
const [currentPage, setCurrentPage] = useState(1);
|
72
|
+
const itemsPerPage = 8;
|
70
73
|
const isInContainer = useIsInContainer();
|
71
74
|
|
75
|
+
// Calculate pagination
|
76
|
+
const totalPages = Math.ceil(usageSummaries.length / itemsPerPage);
|
77
|
+
const startIndex = (currentPage - 1) * itemsPerPage;
|
78
|
+
const endIndex = startIndex + itemsPerPage;
|
79
|
+
const currentUsageSummaries = usageSummaries.slice(startIndex, endIndex);
|
80
|
+
|
81
|
+
const handlePageChange = (page: number) => {
|
82
|
+
setCurrentPage(page);
|
83
|
+
};
|
84
|
+
|
72
85
|
// Convert paidStyle entries into CSS custom properties
|
73
86
|
const cssVariables: React.CSSProperties = Object.entries(paidStyle).reduce((vars, [key, value]) => {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
const
|
79
|
-
|
87
|
+
// Only set CSS variables if they are explicitly provided
|
88
|
+
// This allows inheritance from parent PaidContainer
|
89
|
+
if (value !== undefined && value !== null && value !== '') {
|
90
|
+
// Map simplified properties to CSS custom properties
|
91
|
+
const propertyMap: Record<string, string> = {
|
92
|
+
fontFamily: '--paid-font-family',
|
93
|
+
primaryColor: '--paid-primary-color',
|
94
|
+
secondaryColor: '--paid-secondary-color',
|
95
|
+
containerBackgroundColor: '--paid-container-background-color',
|
96
|
+
tableBackgroundColor: '--paid-table-background-color',
|
97
|
+
tableHeaderBackgroundColor: '--paid-table-header-background-color',
|
98
|
+
tabBackgroundColor: '--paid-tab-background-color',
|
99
|
+
tabActiveBackgroundColor: '--paid-tab-active-background-color',
|
100
|
+
tabHoverBackgroundColor: '--paid-tab-hover-background-color',
|
101
|
+
tableHoverColor: '--paid-table-hover-color',
|
102
|
+
buttonBgColor: '--paid-button-bg-color'
|
103
|
+
};
|
104
|
+
|
105
|
+
const cssProperty = propertyMap[key];
|
106
|
+
if (cssProperty) {
|
107
|
+
// @ts-ignore allow custom property
|
108
|
+
vars[cssProperty] = value;
|
109
|
+
}
|
80
110
|
}
|
81
|
-
|
82
|
-
vars[varName] = value;
|
111
|
+
|
83
112
|
return vars;
|
84
113
|
}, {} as React.CSSProperties);
|
85
114
|
|
86
|
-
const formatCurrency = (amount: number) => {
|
115
|
+
const formatCurrency = (amount: number, currency?: string) => {
|
116
|
+
const symbol = getCurrencySymbol(currency || 'USD');
|
87
117
|
return new Intl.NumberFormat("en-US", {
|
88
118
|
style: "currency",
|
89
119
|
currency: "USD",
|
90
120
|
minimumFractionDigits: 2,
|
91
121
|
maximumFractionDigits: 2,
|
92
|
-
}).format(amount / 100);
|
122
|
+
}).format(amount / 100).replace('$', symbol);
|
123
|
+
};
|
124
|
+
|
125
|
+
const getCurrencySymbol = (currency: string) => {
|
126
|
+
switch (currency.toUpperCase()) {
|
127
|
+
case 'USD':
|
128
|
+
return '$';
|
129
|
+
case 'EUR':
|
130
|
+
return '€';
|
131
|
+
case 'GBP':
|
132
|
+
return '£';
|
133
|
+
default:
|
134
|
+
return '$'; // Default to USD symbol
|
135
|
+
}
|
93
136
|
};
|
94
137
|
|
95
138
|
const formatEventName = (eventName: string) => {
|
@@ -112,21 +155,17 @@ export const PaidActivityLog: React.FC<PaidActivityLogProps> = ({
|
|
112
155
|
try {
|
113
156
|
setLoading(true);
|
114
157
|
|
115
|
-
//
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
// CACHE_TTL.DATA
|
121
|
-
// );
|
158
|
+
// Use new API client for usage data
|
159
|
+
const response = await fetchPaidData({
|
160
|
+
paidEndpoint: 'usage',
|
161
|
+
customerExternalId
|
162
|
+
});
|
122
163
|
|
123
|
-
// Direct fetch without caching
|
124
|
-
const response = await fetch(`/api/usage/${accountExternalId}`);
|
125
164
|
if (!response.ok) {
|
126
|
-
throw new Error(`
|
165
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
127
166
|
}
|
128
|
-
const data = await response.json();
|
129
167
|
|
168
|
+
const data = await response.json() as UsageApiResponse;
|
130
169
|
const mappedUsageSummaries = (data.data.usageSummary || []).map((summary: any) => ({
|
131
170
|
...summary,
|
132
171
|
accountId: summary.customerId,
|
@@ -140,9 +179,20 @@ export const PaidActivityLog: React.FC<PaidActivityLogProps> = ({
|
|
140
179
|
};
|
141
180
|
|
142
181
|
fetchUsageData();
|
143
|
-
}, [accountExternalId]);
|
144
182
|
|
145
|
-
|
183
|
+
// Listen for cache refresh events
|
184
|
+
const handleCacheRefresh = (event: CustomEvent) => {
|
185
|
+
if (event.detail?.customerId === customerExternalId || event.detail?.type === 'all') {
|
186
|
+
fetchUsageData();
|
187
|
+
}
|
188
|
+
};
|
189
|
+
|
190
|
+
window.addEventListener('cache-refresh', handleCacheRefresh as EventListener);
|
191
|
+
|
192
|
+
return () => {
|
193
|
+
window.removeEventListener('cache-refresh', handleCacheRefresh as EventListener);
|
194
|
+
};
|
195
|
+
}, [customerExternalId]);
|
146
196
|
|
147
197
|
if (loading) {
|
148
198
|
return <div>Loading usage data...</div>;
|
@@ -154,14 +204,14 @@ export const PaidActivityLog: React.FC<PaidActivityLogProps> = ({
|
|
154
204
|
|
155
205
|
return (
|
156
206
|
<div className="paid-activity-log-container" style={{ position: 'relative', minWidth: 0, ...cssVariables }}>
|
157
|
-
<div className="paid-activity-log-table-wrapper" style={{ position: '
|
207
|
+
<div className="paid-activity-log-table-wrapper" style={{ position: 'relative', width: '100%', height: 'auto', left: undefined, top: undefined, boxShadow: undefined, cursor: undefined }}>
|
158
208
|
{!isInContainer && (
|
159
209
|
<div className="paid-activity-log-header">
|
160
|
-
<h3 className="paid-activity-log-title">
|
210
|
+
<h3 className="paid-activity-log-title">Activity Log</h3>
|
161
211
|
</div>
|
162
212
|
)}
|
163
|
-
<div style={{ background: '#fff', overflow: 'auto' }}>
|
164
|
-
<table className="paid-activity-log-table">
|
213
|
+
<div style={{ background: '#fff', overflow: 'auto', width: '100%', boxSizing: 'border-box' }}>
|
214
|
+
<table className="paid-activity-log-table" style={{ width: '100%', maxWidth: '100%', tableLayout: 'fixed' }}>
|
165
215
|
<thead>
|
166
216
|
<tr>
|
167
217
|
<th>Event</th>
|
@@ -172,26 +222,33 @@ export const PaidActivityLog: React.FC<PaidActivityLogProps> = ({
|
|
172
222
|
</tr>
|
173
223
|
</thead>
|
174
224
|
<tbody>
|
175
|
-
{
|
225
|
+
{currentUsageSummaries.length === 0 ? (
|
176
226
|
<tr>
|
177
227
|
<td colSpan={5} className="paid-activity-log-empty">
|
178
228
|
No usage data found
|
179
229
|
</td>
|
180
230
|
</tr>
|
181
231
|
) : (
|
182
|
-
|
232
|
+
currentUsageSummaries.map((summary) => (
|
183
233
|
<tr key={summary.id}>
|
184
234
|
<td style={{ fontWeight: 500 }}>{formatEventName(summary.eventName)}</td>
|
185
235
|
<td>{formatDate(summary.startDate)}</td>
|
186
236
|
<td>{formatDate(summary.endDate)}</td>
|
187
237
|
<td style={{ textAlign: 'center' }}>{summary.eventsQuantity}</td>
|
188
|
-
<td style={{ textAlign: 'center', fontWeight: 500 }}>{formatCurrency(summary.subtotal)}</td>
|
238
|
+
<td style={{ textAlign: 'center', fontWeight: 500 }}>{formatCurrency(summary.subtotal, summary.currency)}</td>
|
189
239
|
</tr>
|
190
240
|
))
|
191
241
|
)}
|
192
242
|
</tbody>
|
193
243
|
</table>
|
194
244
|
</div>
|
245
|
+
|
246
|
+
{/* Pagination */}
|
247
|
+
<Pagination
|
248
|
+
currentPage={currentPage}
|
249
|
+
totalPages={totalPages}
|
250
|
+
onPageChange={handlePageChange}
|
251
|
+
/>
|
195
252
|
</div>
|
196
253
|
</div>
|
197
254
|
);
|
@@ -10,30 +10,28 @@ const PaidContainerContext = createContext<boolean>(false);
|
|
10
10
|
export const useIsInContainer = () => useContext(PaidContainerContext);
|
11
11
|
|
12
12
|
interface PaidStyleProperties {
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
paidThBg?: string;
|
36
|
-
paidRowHoverBg?: string;
|
13
|
+
// Global - Font
|
14
|
+
fontFamily?: string;
|
15
|
+
|
16
|
+
// Global - Font Colors
|
17
|
+
primaryColor?: string;
|
18
|
+
secondaryColor?: string;
|
19
|
+
|
20
|
+
// Background Colors
|
21
|
+
containerBackgroundColor?: string;
|
22
|
+
tableBackgroundColor?: string;
|
23
|
+
tableHeaderBackgroundColor?: string;
|
24
|
+
|
25
|
+
// Tab Colors
|
26
|
+
tabBackgroundColor?: string;
|
27
|
+
tabActiveBackgroundColor?: string;
|
28
|
+
tabHoverBackgroundColor?: string;
|
29
|
+
|
30
|
+
// Table Hover
|
31
|
+
tableHoverColor?: string;
|
32
|
+
|
33
|
+
// Button Background (Status badges & Pagination)
|
34
|
+
buttonBgColor?: string;
|
37
35
|
}
|
38
36
|
|
39
37
|
interface PaidContainerTab {
|
@@ -63,15 +61,27 @@ export const PaidContainer: React.FC<PaidContainerProps> = ({
|
|
63
61
|
|
64
62
|
// Convert paidStyle entries into CSS custom properties
|
65
63
|
const cssVariables: React.CSSProperties = Object.entries(paidStyle).reduce((vars, [key, value]) => {
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
// Map simplified properties to CSS custom properties
|
65
|
+
const propertyMap: Record<string, string> = {
|
66
|
+
fontFamily: '--paid-font-family',
|
67
|
+
primaryColor: '--paid-primary-color',
|
68
|
+
secondaryColor: '--paid-secondary-color',
|
69
|
+
containerBackgroundColor: '--paid-container-background-color',
|
70
|
+
tableBackgroundColor: '--paid-table-background-color',
|
71
|
+
tableHeaderBackgroundColor: '--paid-table-header-background-color',
|
72
|
+
tabBackgroundColor: '--paid-tab-background-color',
|
73
|
+
tabActiveBackgroundColor: '--paid-tab-active-background-color',
|
74
|
+
tabHoverBackgroundColor: '--paid-tab-hover-background-color',
|
75
|
+
tableHoverColor: '--paid-table-hover-color',
|
76
|
+
buttonBgColor: '--paid-button-bg-color'
|
77
|
+
};
|
78
|
+
|
79
|
+
const cssProperty = propertyMap[key];
|
80
|
+
if (cssProperty) {
|
81
|
+
// @ts-ignore allow custom property
|
82
|
+
vars[cssProperty] = value;
|
72
83
|
}
|
73
|
-
|
74
|
-
vars[varName] = value;
|
84
|
+
|
75
85
|
return vars;
|
76
86
|
}, {} as React.CSSProperties);
|
77
87
|
|