From ed1e0cd428ab130dd872d0a18684506f8ef40600 Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 25 Aug 2025 12:46:48 +0530 Subject: [PATCH] updated bill ans plan page --- src/components/Tenant/SubScriptionHistory.jsx | 282 +++++++++--------- 1 file changed, 148 insertions(+), 134 deletions(-) diff --git a/src/components/Tenant/SubScriptionHistory.jsx b/src/components/Tenant/SubScriptionHistory.jsx index 633de1be..a587a84e 100644 --- a/src/components/Tenant/SubScriptionHistory.jsx +++ b/src/components/Tenant/SubScriptionHistory.jsx @@ -27,14 +27,16 @@ const SubScriptionHistory = ({ tenantId }) => { if (isError) return
{error}
; const plan = data?.currentPlan; + const features = data?.currentPlanFeatures; + const subscriptionHistory = data?.subscriptionHistery; if (!plan) { return ( -
- -
+
Add your new subscription
@@ -42,164 +44,176 @@ const SubScriptionHistory = ({ tenantId }) => { } // Format dates - const start = plan?.startDate ? new Date(plan.startDate) : null; const end = plan?.endDate ? new Date(plan.endDate) : null; const today = new Date(); - const totalDays = start && end ? Math.ceil((end - start) / (1000 * 60 * 60 * 24)) : 0; - const daysLeft = end ? Math.max(0, Math.ceil((end - today) / (1000 * 60 * 60 * 24))) : 0; + const daysLeft = end + ? Math.max(0, Math.ceil((end - today) / (1000 * 60 * 60 * 24))) + : 0; - const SubscriptionColumns = [ - { - key: "createdAt", - label: "Date", - getValue: (e) => formatUTCToLocalTime(e?.createdAt), - align: "text-start", - }, - { - key: "frequency", - label: "Type", - getValue: (e) => SUBSCRIPTION_PLAN_FREQUENCIES[e.frequency] || "N/A", - align: "text-start", - }, - { - key: "price", - label: "Amount", - getValue: (e) => ( - - {e.currency?.symbol || "₹"} {e.price} - - ), - align: "text-start", - }, - { - key: "planName", - label: "Plan Name", - getValue: (e) => ( - {e.planName} - ), - align: "text-start", - }, - { - key: "action", - label: "Action", - getValue: (e) => ( -
- -
- {/* View */} - - {/* Download */} - -
+ // Render logic for subscription history table + const renderSubscriptionHistory = () => { + if (!subscriptionHistory || subscriptionHistory.length === 0) { + return ( +
+ No subscription history found
- ), - align: "text-center", - }, - ]; + ); + } + + const sortedHistory = subscriptionHistory + .slice() + .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)); + + return ( + <> + {/* Table for larger screens */} +
+ + + + + + + + + + + + {sortedHistory.map((item) => ( + + + + + + + + ))} + +
DateTypeAmountPlan NameAction
{formatUTCToLocalTime(item?.createdAt)}{SUBSCRIPTION_PLAN_FREQUENCIES[item.frequency] || "N/A"} + {item.currency?.symbol || "₹"} {item.price} + {item.planName} +
+ +
+ + +
+
+
+
+ + {/* Card-based view for smaller screens */} + + + ); + }; return ( -
-
- {/* Active subscription */} -
-
Active Subscription
-
+
+
+ {/* Left Card: Active Subscription */} +
+
+
+
Active Subscription
+
-
-

{plan.planName || "N/A"}

{plan.description && ( -
-

{plan.description}

-
+

{plan.description}

)} -
-
-

- {plan.currency?.symbol || "₹"} {plan.price} -

- - {SUBSCRIPTION_PLAN_FREQUENCIES[plan.frequency] || ""} - -
-
- -
+
+

+ {plan.currency?.symbol || "₹"} {plan.price} +

+ + {SUBSCRIPTION_PLAN_FREQUENCIES[plan.frequency] || ""} +
-
- - Active Since :{" "} - {plan.startDate ? formatUTCToLocalTime(plan.startDate) : "N/A"} ({daysLeft} days left) - +
+ Activated Since:{" "} + {plan.startDate ? formatUTCToLocalTime(plan.startDate) : "N/A"} ( + {daysLeft} days left)
-
- Ends on : {plan.endDate ? formatUTCToLocalTime(plan.endDate) : "N/A"} +
+ Ends on:{" "} + {plan.endDate ? formatUTCToLocalTime(plan.endDate) : "N/A"}
+ + {/* Features list */} +
+
Features
+
+ {features?.modules && + Object.entries(features.modules).map(([key, mod]) => { + if (!mod?.name) return null; + return ( +
+ + {mod.name} +
+ ); + })} +
+
+ +
+ +
- {/* History */} -
-
- History + {/* Right Card: Subscription History */} +
+
+
+
+ History +
+
+ {renderSubscriptionHistory()}
- - - - - {SubscriptionColumns.map((col) => ( - - ))} - - - - {data?.subscriptionHistery - ?.slice() - .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)) - .map((item) => ( - - {SubscriptionColumns.map((col) => ( - - ))} - - ))} - -
- {col.label} -
- {col.getValue ? col.getValue(item) : item[col.key] || "N/A"} -
); }; -export default SubScriptionHistory; +export default SubScriptionHistory; \ No newline at end of file