diff --git a/src/components/Tenant/SubScriptionHistory.jsx b/src/components/Tenant/SubScriptionHistory.jsx
index 576c1e9e..633de1be 100644
--- a/src/components/Tenant/SubScriptionHistory.jsx
+++ b/src/components/Tenant/SubScriptionHistory.jsx
@@ -4,9 +4,7 @@ import { useDispatch } from "react-redux";
import { setCurrentTenant } from "../../slices/globalVariablesSlice";
import { useNavigate } from "react-router-dom";
import { formatUTCToLocalTime } from "../../utils/dateUtils";
-import { MANAGE_TENANTS, SUBSCRIPTION_PLAN_FREQUENCIES } from "../../utils/constants";
-import { useHasAnyPermission } from "../../hooks/useExpense";
-
+import { SUBSCRIPTION_PLAN_FREQUENCIES } from "../../utils/constants";
const SubScriptionHistory = ({ tenantId }) => {
const { data, isLoading, isError, error } = useTenantDetails(tenantId);
@@ -15,10 +13,8 @@ const SubScriptionHistory = ({ tenantId }) => {
useEffect(() => {
if (data) {
- // Tenant exists → set operationMode: 1
dispatch(setCurrentTenant({ operationMode: 1, data }));
} else {
- // No tenant yet → set operationMode: 0
dispatch(setCurrentTenant({ operationMode: 0, data: null }));
}
}, [data, dispatch]);
@@ -32,7 +28,6 @@ const SubScriptionHistory = ({ tenantId }) => {
const plan = data?.currentPlan;
- // No subscription plan yet → show "Add Subscription" button
if (!plan) {
return (
@@ -46,97 +41,109 @@ const SubScriptionHistory = ({ tenantId }) => {
);
}
- // Subscription plan exists → show details
+ // 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 start = new Date(plan.startDate);
- const end = new Date(plan.endDate);
- const totalDays = Math.ceil((end - start) / (1000 * 60 * 60 * 24));
- const daysLeft = Math.max(
- 0,
- Math.ceil((end - today) / (1000 * 60 * 60 * 24))
- );
- const percentage = Math.min(
- 100,
- Math.round(((totalDays - daysLeft) / totalDays) * 100)
- );
+ 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 getProgressVariant = () => {
- if (percentage < 50) return "success";
- if (percentage < 80) return "warning";
- return "danger";
- };
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-end",
-},
-{
- key: "planName",
- label: "Plan Name",
- getValue: (e) => (
-
- {e.planName}
-
- ),
- align: "text-start",
-},
-
- {
- key: "action",
- label: "Action",
- getValue: (e) => (
-
console.log("Download clicked for", e.id)}
- role="button"
- />
- ),
- align: "text-center",
- },
-];
-
+ {
+ 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 */}
+
+
+
+ ),
+ align: "text-center",
+ },
+ ];
return (
-
+
-
+ {/* Active subscription */}
+
-
{plan.planName || "N/A"}
+
+ {plan.planName || "N/A"}
+
+ {plan.description && (
+
+ )}
- {plan.currency?.symbol} {plan.price}
+ {plan.currency?.symbol || "₹"} {plan.price}
- {plan.description}
+
+ {SUBSCRIPTION_PLAN_FREQUENCIES[plan.frequency] || ""}
+
-
- {/* Progress bar placeholder */}
-
-
{totalDays - daysLeft} days used
-
{daysLeft} days left
+
+
+
+ Active Since :{" "}
+ {plan.startDate ? formatUTCToLocalTime(plan.startDate) : "N/A"} ({daysLeft} days left)
+
+
+
+ Ends on : {plan.endDate ? formatUTCToLocalTime(plan.endDate) : "N/A"}
+
+
-
- Ends on {end.toLocaleDateString()}
-
+ {/* History */}
+
-
-
-
-
-
-
- {SubscriptionColumns.map((col) => (
- |
- {col.label}
- |
- ))}
-
-
-
- {data?.subscriptionHistery
- ?.slice()
- .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)) // latest first
- .map((item) => (
-
- {SubscriptionColumns.map((col) => (
- |
- {col.getValue ? col.getValue(item) : item[col.key] || "N/A"}
- |
- ))}
-
- ))}
-
-
-
+
+
+ {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"}
+ |
+ ))}
+
+ ))}
+
+
);