diff --git a/src/components/Tenanat/SubScriptionHistory.jsx b/src/components/Tenanat/SubScriptionHistory.jsx index 850a8401..9747e87a 100644 --- a/src/components/Tenanat/SubScriptionHistory.jsx +++ b/src/components/Tenanat/SubScriptionHistory.jsx @@ -3,6 +3,8 @@ import { useTenantDetails } from "../../hooks/useTenant"; import { useDispatch } from "react-redux"; import { setCurrentTenant } from "../../slices/globalVariablesSlice"; import { useNavigate } from "react-router-dom"; +import { formatUTCToLocalTime } from "../../utils/dateUtils"; +import { SUBSCRIPTION_PLAN_FREQUENCIES } from "../../utils/constants"; const SubScriptionHistory = ({ tenantId }) => { const { data, isLoading, isError, error } = useTenantDetails(tenantId); @@ -20,7 +22,7 @@ const SubScriptionHistory = ({ tenantId }) => { }, [data, dispatch]); const handleUpgradePlan = () => { - navigate("/tenants/new-tenant"); + navigate("/tenants/new-tenant"); }; if (isLoading) return
Loading...
; @@ -48,7 +50,10 @@ const SubScriptionHistory = ({ tenantId }) => { 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 daysLeft = Math.max( + 0, + Math.ceil((end - today) / (1000 * 60 * 60 * 24)) + ); const percentage = Math.min( 100, Math.round(((totalDays - daysLeft) / totalDays) * 100) @@ -59,10 +64,81 @@ const SubScriptionHistory = ({ tenantId }) => { 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) => { + switch (e.frequency) { + case 1: + return "Monthly"; + case 3: + return "Quarterly"; + case 12: + return "Yearly"; + default: + return "N/A"; + } + }, + align: "text-start", + }, + { + key: "price", + label: "Amount", + getValue: (e) => ( + <> + {e.currency?.symbol || "₹"} {e.price} + + ), + align: "text-end", + }, + { + key: "submittedBy", + label: "Submitted By", + getValue: (e) => + `${e.createdBy?.firstName ?? ""} ${ + e.createdBy?.lastName ?? "" + }`.trim() || "N/A", + customRender: (e) => ( +
+ + + {`${e.createdBy?.firstName ?? ""} ${ + e.createdBy?.lastName ?? "" + }`.trim() || "N/A"} + +
+ ), + align: "text-start", + }, + { + key: "action", + label: "Action", + customRender: (e) => ( + + ), + align: "text-center", + }, + ]; return (
-

Active Subscription

@@ -101,7 +177,35 @@ const SubScriptionHistory = ({ tenantId }) => {
- {/* Table */} + + + + + + + + + + + + {data?.subscriptionHistery?.map((item) => ( + + + + + + + + ))} + +
DateTypeAmountPlan NameAction
{formatUTCToLocalTime(item.createdAt)}{SUBSCRIPTION_PLAN_FREQUENCIES[item.frequency] || "N/A"} + {item.currency?.symbol} + {item.price} + {item.planName} + +
+ +