@umituz/web-dashboard 2.2.0 → 2.3.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.
- package/package.json +12 -1
- package/src/domains/billing/components/BillingLayout.tsx +63 -0
- package/src/domains/billing/components/BillingPortal.tsx +198 -0
- package/src/domains/billing/components/InvoiceCard.tsx +143 -0
- package/src/domains/billing/components/PaymentMethodsList.tsx +116 -0
- package/src/domains/billing/components/PlanComparison.tsx +199 -0
- package/src/domains/billing/components/UsageCard.tsx +103 -0
- package/src/domains/billing/components/index.ts +12 -0
- package/src/domains/billing/hooks/index.ts +7 -0
- package/src/domains/billing/hooks/useBilling.ts +385 -0
- package/src/domains/billing/index.ts +69 -0
- package/src/domains/billing/types/billing.ts +347 -0
- package/src/domains/billing/types/index.ts +28 -0
- package/src/domains/billing/utils/billing.ts +344 -0
- package/src/domains/billing/utils/index.ts +29 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Billing Domain
|
|
3
|
+
*
|
|
4
|
+
* Main entry point for billing domain
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Components
|
|
8
|
+
export {
|
|
9
|
+
PlanComparison,
|
|
10
|
+
PaymentMethodsList,
|
|
11
|
+
InvoiceCard,
|
|
12
|
+
UsageCard,
|
|
13
|
+
BillingPortal,
|
|
14
|
+
BillingLayout,
|
|
15
|
+
} from "./components";
|
|
16
|
+
|
|
17
|
+
// Hooks
|
|
18
|
+
export {
|
|
19
|
+
useBilling,
|
|
20
|
+
} from "./hooks";
|
|
21
|
+
|
|
22
|
+
// Utils
|
|
23
|
+
export {
|
|
24
|
+
formatPrice,
|
|
25
|
+
calculateDiscount,
|
|
26
|
+
calculateProratedAmount,
|
|
27
|
+
getPlanPrice,
|
|
28
|
+
calculateUsagePercentage,
|
|
29
|
+
isNearLimit,
|
|
30
|
+
getStatusColor,
|
|
31
|
+
getStatusLabel,
|
|
32
|
+
getInvoiceStatusColor,
|
|
33
|
+
getInvoiceStatusLabel,
|
|
34
|
+
formatCardNumber,
|
|
35
|
+
formatExpiry,
|
|
36
|
+
getDaysRemaining,
|
|
37
|
+
isTrialExpiringSoon,
|
|
38
|
+
getNextBillingDate,
|
|
39
|
+
groupInvoicesByStatus,
|
|
40
|
+
calculateInvoiceTotal,
|
|
41
|
+
sortInvoicesByDate,
|
|
42
|
+
formatFeature,
|
|
43
|
+
isPopularPlan,
|
|
44
|
+
getTrialDaysText,
|
|
45
|
+
} from "./utils";
|
|
46
|
+
|
|
47
|
+
// Types
|
|
48
|
+
export type {
|
|
49
|
+
BillingCycle,
|
|
50
|
+
SubscriptionStatus,
|
|
51
|
+
PlanType,
|
|
52
|
+
Currency,
|
|
53
|
+
PlanTier,
|
|
54
|
+
Subscription,
|
|
55
|
+
PaymentMethodType,
|
|
56
|
+
PaymentMethod,
|
|
57
|
+
InvoiceStatus,
|
|
58
|
+
InvoiceItem,
|
|
59
|
+
Invoice,
|
|
60
|
+
UsageMetric,
|
|
61
|
+
BillingSummary,
|
|
62
|
+
PlanComparisonProps,
|
|
63
|
+
PaymentMethodsListProps,
|
|
64
|
+
InvoiceCardProps,
|
|
65
|
+
UsageCardProps,
|
|
66
|
+
BillingPortalProps,
|
|
67
|
+
BillingLayoutProps,
|
|
68
|
+
BillingConfig,
|
|
69
|
+
} from "./types";
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Billing Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for billing and subscription system
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ComponentType, ReactElement } from "react";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Billing cycle
|
|
11
|
+
*/
|
|
12
|
+
export type BillingCycle = "monthly" | "yearly";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Subscription status
|
|
16
|
+
*/
|
|
17
|
+
export type SubscriptionStatus =
|
|
18
|
+
| "active"
|
|
19
|
+
| "trialing"
|
|
20
|
+
| "past_due"
|
|
21
|
+
| "canceled"
|
|
22
|
+
| "unpaid"
|
|
23
|
+
| "incomplete";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Plan type
|
|
27
|
+
*/
|
|
28
|
+
export type PlanType = "free" | "basic" | "pro" | "enterprise" | "custom";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Currency
|
|
32
|
+
*/
|
|
33
|
+
export type Currency = "USD" | "EUR" | "GBP" | "TRY" | "JPY";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Plan pricing tier
|
|
37
|
+
*/
|
|
38
|
+
export interface PlanTier {
|
|
39
|
+
/** Plan ID */
|
|
40
|
+
id: string;
|
|
41
|
+
/** Plan type */
|
|
42
|
+
type: PlanType;
|
|
43
|
+
/** Plan name */
|
|
44
|
+
name: string;
|
|
45
|
+
/** Plan description */
|
|
46
|
+
description: string;
|
|
47
|
+
/** Badge text */
|
|
48
|
+
badge?: string;
|
|
49
|
+
/** Badge color */
|
|
50
|
+
badgeColor?: string;
|
|
51
|
+
/** Monthly price */
|
|
52
|
+
monthlyPrice: number;
|
|
53
|
+
/** Yearly price */
|
|
54
|
+
yearlyPrice: number;
|
|
55
|
+
/** Currency */
|
|
56
|
+
currency: Currency;
|
|
57
|
+
/** Features list */
|
|
58
|
+
features: (string | { text: string; bold?: boolean; included?: boolean })[];
|
|
59
|
+
/** Highlight/recommend */
|
|
60
|
+
highlight?: boolean;
|
|
61
|
+
/** Maximum users/seats */
|
|
62
|
+
maxUsers?: number;
|
|
63
|
+
/** Storage limit in GB */
|
|
64
|
+
storageLimit?: number;
|
|
65
|
+
/** API call limit */
|
|
66
|
+
apiLimit?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Subscription info
|
|
71
|
+
*/
|
|
72
|
+
export interface Subscription {
|
|
73
|
+
/** Subscription ID */
|
|
74
|
+
id: string;
|
|
75
|
+
/** Plan ID */
|
|
76
|
+
planId: string;
|
|
77
|
+
/** Plan details */
|
|
78
|
+
plan: PlanTier;
|
|
79
|
+
/** Subscription status */
|
|
80
|
+
status: SubscriptionStatus;
|
|
81
|
+
/** Billing cycle */
|
|
82
|
+
cycle: BillingCycle;
|
|
83
|
+
/** Current period start */
|
|
84
|
+
currentPeriodStart: string;
|
|
85
|
+
/** Current period end */
|
|
86
|
+
currentPeriodEnd: string;
|
|
87
|
+
/** Cancel at period end */
|
|
88
|
+
cancelAtPeriodEnd?: boolean;
|
|
89
|
+
/** Trial end date */
|
|
90
|
+
trialEnd?: string;
|
|
91
|
+
/** User/seat count */
|
|
92
|
+
seats?: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Payment method type
|
|
97
|
+
*/
|
|
98
|
+
export type PaymentMethodType = "card" | "bank_account" | "wallet";
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Payment method
|
|
102
|
+
*/
|
|
103
|
+
export interface PaymentMethod {
|
|
104
|
+
/** Payment method ID */
|
|
105
|
+
id: string;
|
|
106
|
+
/** Type */
|
|
107
|
+
type: PaymentMethodType;
|
|
108
|
+
/** Is default */
|
|
109
|
+
isDefault: boolean;
|
|
110
|
+
/** Card details */
|
|
111
|
+
card?: {
|
|
112
|
+
/** Last 4 digits */
|
|
113
|
+
last4: string;
|
|
114
|
+
/** Brand (Visa, Mastercard) */
|
|
115
|
+
brand: string;
|
|
116
|
+
/** Expiry month */
|
|
117
|
+
expiryMonth: number;
|
|
118
|
+
/** Expiry year */
|
|
119
|
+
expiryYear: number;
|
|
120
|
+
/** Cardholder name */
|
|
121
|
+
name?: string;
|
|
122
|
+
};
|
|
123
|
+
/** Bank account details */
|
|
124
|
+
bankAccount?: {
|
|
125
|
+
/** Last 4 digits */
|
|
126
|
+
last4: string;
|
|
127
|
+
/** Bank name */
|
|
128
|
+
bankName: string;
|
|
129
|
+
/** Account type */
|
|
130
|
+
accountType?: "checking" | "savings";
|
|
131
|
+
};
|
|
132
|
+
/** Created date */
|
|
133
|
+
createdAt: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Invoice status
|
|
138
|
+
*/
|
|
139
|
+
export type InvoiceStatus = "draft" | "open" "paid" "void" "uncollectible";
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Invoice item
|
|
143
|
+
*/
|
|
144
|
+
export interface InvoiceItem {
|
|
145
|
+
/** Item description */
|
|
146
|
+
description: string;
|
|
147
|
+
/** Quantity */
|
|
148
|
+
quantity: number;
|
|
149
|
+
/** Unit price */
|
|
150
|
+
unitPrice: number;
|
|
151
|
+
/** Amount */
|
|
152
|
+
amount: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Invoice
|
|
157
|
+
*/
|
|
158
|
+
export interface Invoice {
|
|
159
|
+
/** Invoice ID */
|
|
160
|
+
id: string;
|
|
161
|
+
/** Invoice number */
|
|
162
|
+
number: string;
|
|
163
|
+
/** Amount */
|
|
164
|
+
amount: number;
|
|
165
|
+
/** Currency */
|
|
166
|
+
currency: Currency;
|
|
167
|
+
/** Status */
|
|
168
|
+
status: InvoiceStatus;
|
|
169
|
+
/** Invoice date */
|
|
170
|
+
date: string;
|
|
171
|
+
/** Due date */
|
|
172
|
+
dueDate: string;
|
|
173
|
+
/** Paid date */
|
|
174
|
+
paidAt?: string;
|
|
175
|
+
/** Invoice URL */
|
|
176
|
+
invoiceUrl?: string;
|
|
177
|
+
/** PDF download URL */
|
|
178
|
+
pdfUrl?: string;
|
|
179
|
+
/** Line items */
|
|
180
|
+
items?: InvoiceItem[];
|
|
181
|
+
/** Subtotal */
|
|
182
|
+
subtotal?: number;
|
|
183
|
+
/** Tax amount */
|
|
184
|
+
tax?: number;
|
|
185
|
+
/** Total amount */
|
|
186
|
+
total?: number;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Usage metric
|
|
191
|
+
*/
|
|
192
|
+
export interface UsageMetric {
|
|
193
|
+
/** Metric ID */
|
|
194
|
+
id: string;
|
|
195
|
+
/** Metric name */
|
|
196
|
+
name: string;
|
|
197
|
+
/** Current usage */
|
|
198
|
+
current: number;
|
|
199
|
+
/** Limit */
|
|
200
|
+
limit: number;
|
|
201
|
+
/** Unit */
|
|
202
|
+
unit: string;
|
|
203
|
+
/** Reset period */
|
|
204
|
+
resetPeriod: "daily" | "monthly" | "yearly";
|
|
205
|
+
/** Reset date */
|
|
206
|
+
resetAt?: string;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Billing summary
|
|
211
|
+
*/
|
|
212
|
+
export interface BillingSummary {
|
|
213
|
+
/** Current subscription */
|
|
214
|
+
subscription: Subscription;
|
|
215
|
+
/** Payment methods */
|
|
216
|
+
paymentMethods: PaymentMethod[];
|
|
217
|
+
/** Default payment method */
|
|
218
|
+
defaultPaymentMethod?: PaymentMethod;
|
|
219
|
+
/** Upcoming invoice */
|
|
220
|
+
upcomingInvoice?: {
|
|
221
|
+
amount: number;
|
|
222
|
+
currency: Currency;
|
|
223
|
+
date: string;
|
|
224
|
+
};
|
|
225
|
+
/** Usage metrics */
|
|
226
|
+
usage: UsageMetric[];
|
|
227
|
+
/** Recent invoices */
|
|
228
|
+
recentInvoices: Invoice[];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Plan comparison props
|
|
233
|
+
*/
|
|
234
|
+
export interface PlanComparisonProps {
|
|
235
|
+
/** Available plans */
|
|
236
|
+
plans: PlanTier[];
|
|
237
|
+
/** Selected plan ID */
|
|
238
|
+
selectedPlan?: string;
|
|
239
|
+
/** Billing cycle */
|
|
240
|
+
cycle: BillingCycle;
|
|
241
|
+
/** Show yearly toggle */
|
|
242
|
+
showCycleToggle?: boolean;
|
|
243
|
+
/** Show features */
|
|
244
|
+
showFeatures?: boolean;
|
|
245
|
+
/** On plan select */
|
|
246
|
+
onPlanSelect?: (planId: string) => void;
|
|
247
|
+
/** On cycle change */
|
|
248
|
+
onCycleChange?: (cycle: BillingCycle) => void;
|
|
249
|
+
/** Loading state */
|
|
250
|
+
loading?: boolean;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Payment methods list props
|
|
255
|
+
*/
|
|
256
|
+
export interface PaymentMethodsListProps {
|
|
257
|
+
/** Payment methods */
|
|
258
|
+
paymentMethods: PaymentMethod[];
|
|
259
|
+
/** Loading state */
|
|
260
|
+
loading?: boolean;
|
|
261
|
+
/** On set default */
|
|
262
|
+
onSetDefault?: (methodId: string) => void;
|
|
263
|
+
/** On remove */
|
|
264
|
+
onRemove?: (methodId: string) => void;
|
|
265
|
+
/** On add new */
|
|
266
|
+
onAddNew?: () => void;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Invoice card props
|
|
271
|
+
*/
|
|
272
|
+
export interface InvoiceCardProps {
|
|
273
|
+
/** Invoice data */
|
|
274
|
+
invoice: Invoice;
|
|
275
|
+
/** Compact view */
|
|
276
|
+
compact?: boolean;
|
|
277
|
+
/** On click */
|
|
278
|
+
onClick?: (invoice: Invoice) => void;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Usage card props
|
|
283
|
+
*/
|
|
284
|
+
export interface UsageCardProps {
|
|
285
|
+
/** Usage metric */
|
|
286
|
+
metric: UsageMetric;
|
|
287
|
+
/** Show progress bar */
|
|
288
|
+
showProgress?: boolean;
|
|
289
|
+
/** Show limit */
|
|
290
|
+
showLimit?: boolean;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Billing portal props
|
|
295
|
+
*/
|
|
296
|
+
export interface BillingPortalProps {
|
|
297
|
+
/** Billing summary */
|
|
298
|
+
billing: BillingSummary;
|
|
299
|
+
/** Loading state */
|
|
300
|
+
loading?: boolean;
|
|
301
|
+
/** Error message */
|
|
302
|
+
error?: string;
|
|
303
|
+
/** Show tabs */
|
|
304
|
+
showTabs?: boolean;
|
|
305
|
+
/** Active tab */
|
|
306
|
+
activeTab?: string;
|
|
307
|
+
/** On tab change */
|
|
308
|
+
onTabChange?: (tab: string) => void;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Billing layout props
|
|
313
|
+
*/
|
|
314
|
+
export interface BillingLayoutProps {
|
|
315
|
+
/** Billing configuration */
|
|
316
|
+
config: BillingConfig;
|
|
317
|
+
/** Children content */
|
|
318
|
+
children?: React.ReactNode;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Billing configuration
|
|
323
|
+
*/
|
|
324
|
+
export interface BillingConfig {
|
|
325
|
+
/** Brand name */
|
|
326
|
+
brandName: string;
|
|
327
|
+
/** Available plans */
|
|
328
|
+
plans: PlanTier[];
|
|
329
|
+
/** Supported currencies */
|
|
330
|
+
currencies?: Currency[];
|
|
331
|
+
/** Default currency */
|
|
332
|
+
defaultCurrency?: Currency;
|
|
333
|
+
/** Enable yearly discounts */
|
|
334
|
+
enableYearlyDiscount?: boolean;
|
|
335
|
+
/** Yearly discount percentage */
|
|
336
|
+
yearlyDiscount?: number;
|
|
337
|
+
/** Tax rate */
|
|
338
|
+
taxRate?: number;
|
|
339
|
+
/** Support email */
|
|
340
|
+
supportEmail?: string;
|
|
341
|
+
/** Cancel subscription route */
|
|
342
|
+
cancelRoute?: string;
|
|
343
|
+
/** Update payment route */
|
|
344
|
+
updatePaymentRoute?: string;
|
|
345
|
+
/** Invoice history route */
|
|
346
|
+
invoiceHistoryRoute?: string;
|
|
347
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Billing Types
|
|
3
|
+
*
|
|
4
|
+
* Export all billing-related types
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type {
|
|
8
|
+
BillingCycle,
|
|
9
|
+
SubscriptionStatus,
|
|
10
|
+
PlanType,
|
|
11
|
+
Currency,
|
|
12
|
+
PlanTier,
|
|
13
|
+
Subscription,
|
|
14
|
+
PaymentMethodType,
|
|
15
|
+
PaymentMethod,
|
|
16
|
+
InvoiceStatus,
|
|
17
|
+
InvoiceItem,
|
|
18
|
+
Invoice,
|
|
19
|
+
UsageMetric,
|
|
20
|
+
BillingSummary,
|
|
21
|
+
PlanComparisonProps,
|
|
22
|
+
PaymentMethodsListProps,
|
|
23
|
+
InvoiceCardProps,
|
|
24
|
+
UsageCardProps,
|
|
25
|
+
BillingPortalProps,
|
|
26
|
+
BillingLayoutProps,
|
|
27
|
+
BillingConfig,
|
|
28
|
+
} from "./billing";
|