+
-
+
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 */}
+
+
+
+
+ | Date |
+ Type |
+ Amount |
+ Plan Name |
+ Action |
+
+
+
+ {sortedHistory.map((item) => (
+
+ | {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 */}
-
+
+
+ {/* Left Card: Active Subscription */}
+
+
+
-
-
{plan.planName || "N/A"}
{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 */}
+
+
+
+ {renderSubscriptionHistory()}
-
-
-
-
- {SubscriptionColumns.map((col) => (
- |
- {col.label}
- |
- ))}
-
-
-
- {data?.subscriptionHistery
- ?.slice()
- .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
- .map((item) => (
-
- {SubscriptionColumns.map((col) => (
- |
- {col.getValue ? col.getValue(item) : item[col.key] || "N/A"}
- |
- ))}
-
- ))}
-
-
);
};
-export default SubScriptionHistory;
+export default SubScriptionHistory;
\ No newline at end of file