Compare commits
No commits in common. "207c2820bfb0f67656d945851be03528038f72ae" and "3e2d601739dc2afd1e9912410c267dec99093f42" have entirely different histories.
207c2820bf
...
3e2d601739
@ -47,7 +47,7 @@ const Profile = ({ data }) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{data?.description && (
|
{data?.description && (
|
||||||
<div className="col rounded-2 justify-content-start p-2">
|
<div className="col rounded-2 bg-light justify-content-start p-2">
|
||||||
<p className="m-0">{data?.description}</p>
|
<p className="m-0">{data?.description}</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -185,10 +185,13 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
|
|||||||
</Label>
|
</Label>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
|
min={1}
|
||||||
step={1}
|
step={1}
|
||||||
className="form-control form-control-sm"
|
className="form-control form-control-sm"
|
||||||
{...register("maxUsers", {
|
{...register("maxUsers", {
|
||||||
valueAsNumber: true,
|
valueAsNumber: true,
|
||||||
|
required: "Team size is required",
|
||||||
|
min: { value: 1, message: "Team size must be at least 1" },
|
||||||
})}
|
})}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
if (["e", "E", "+", "-", "."].includes(e.key)) {
|
if (["e", "E", "+", "-", "."].includes(e.key)) {
|
||||||
@ -200,7 +203,9 @@ const SubScription = ({ onSubmitSubScription, onNext }) => {
|
|||||||
|
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="d-flex justify-content-start align-items-center gap-2">
|
<div className="d-flex justify-content-start align-items-center gap-2">
|
||||||
<label className="form-label d-block">Enable auto renew</label>
|
<label className="form-label d-block">
|
||||||
|
Enable auto renew
|
||||||
|
</label>
|
||||||
<label className="switch switch-square switch-sm">
|
<label className="switch switch-square switch-sm">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
|||||||
@ -4,7 +4,9 @@ import { useDispatch } from "react-redux";
|
|||||||
import { setCurrentTenant } from "../../slices/globalVariablesSlice";
|
import { setCurrentTenant } from "../../slices/globalVariablesSlice";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
import { formatUTCToLocalTime } from "../../utils/dateUtils";
|
||||||
import { SUBSCRIPTION_PLAN_FREQUENCIES } from "../../utils/constants";
|
import { MANAGE_TENANTS, SUBSCRIPTION_PLAN_FREQUENCIES } from "../../utils/constants";
|
||||||
|
import { useHasAnyPermission } from "../../hooks/useExpense";
|
||||||
|
|
||||||
|
|
||||||
const SubScriptionHistory = ({ tenantId }) => {
|
const SubScriptionHistory = ({ tenantId }) => {
|
||||||
const { data, isLoading, isError, error } = useTenantDetails(tenantId);
|
const { data, isLoading, isError, error } = useTenantDetails(tenantId);
|
||||||
@ -13,8 +15,10 @@ const SubScriptionHistory = ({ tenantId }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
|
// Tenant exists → set operationMode: 1
|
||||||
dispatch(setCurrentTenant({ operationMode: 1, data }));
|
dispatch(setCurrentTenant({ operationMode: 1, data }));
|
||||||
} else {
|
} else {
|
||||||
|
// No tenant yet → set operationMode: 0
|
||||||
dispatch(setCurrentTenant({ operationMode: 0, data: null }));
|
dispatch(setCurrentTenant({ operationMode: 0, data: null }));
|
||||||
}
|
}
|
||||||
}, [data, dispatch]);
|
}, [data, dispatch]);
|
||||||
@ -28,6 +32,7 @@ const SubScriptionHistory = ({ tenantId }) => {
|
|||||||
|
|
||||||
const plan = data?.currentPlan;
|
const plan = data?.currentPlan;
|
||||||
|
|
||||||
|
// No subscription plan yet → show "Add Subscription" button
|
||||||
if (!plan) {
|
if (!plan) {
|
||||||
return (
|
return (
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
@ -41,14 +46,26 @@ const SubScriptionHistory = ({ tenantId }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format dates
|
// Subscription plan exists → show details
|
||||||
const start = plan?.startDate ? new Date(plan.startDate) : null;
|
|
||||||
const end = plan?.endDate ? new Date(plan.endDate) : null;
|
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
|
const start = new Date(plan.startDate);
|
||||||
|
const end = new Date(plan.endDate);
|
||||||
|
|
||||||
const totalDays = start && end ? Math.ceil((end - start) / (1000 * 60 * 60 * 24)) : 0;
|
const totalDays = Math.ceil((end - start) / (1000 * 60 * 60 * 24));
|
||||||
const daysLeft = end ? Math.max(0, Math.ceil((end - today) / (1000 * 60 * 60 * 24))) : 0;
|
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 getProgressVariant = () => {
|
||||||
|
if (percentage < 50) return "success";
|
||||||
|
if (percentage < 80) return "warning";
|
||||||
|
return "danger";
|
||||||
|
};
|
||||||
const SubscriptionColumns = [
|
const SubscriptionColumns = [
|
||||||
{
|
{
|
||||||
key: "createdAt",
|
key: "createdAt",
|
||||||
@ -59,7 +76,8 @@ const SubScriptionHistory = ({ tenantId }) => {
|
|||||||
{
|
{
|
||||||
key: "frequency",
|
key: "frequency",
|
||||||
label: "Type",
|
label: "Type",
|
||||||
getValue: (e) => SUBSCRIPTION_PLAN_FREQUENCIES[e.frequency] || "N/A",
|
getValue: (e) =>
|
||||||
|
SUBSCRIPTION_PLAN_FREQUENCIES[e.frequency] || "N/A",
|
||||||
align: "text-start",
|
align: "text-start",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -70,80 +88,55 @@ const SubScriptionHistory = ({ tenantId }) => {
|
|||||||
{e.currency?.symbol || "₹"} {e.price}
|
{e.currency?.symbol || "₹"} {e.price}
|
||||||
</span>
|
</span>
|
||||||
),
|
),
|
||||||
align: "text-start",
|
align: "text-end",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "planName",
|
key: "planName",
|
||||||
label: "Plan Name",
|
label: "Plan Name",
|
||||||
getValue: (e) => (
|
getValue: (e) => (
|
||||||
<span className="d-inline-block ps-4">{e.planName}</span>
|
<span className="d-inline-block ps-4">
|
||||||
|
{e.planName}
|
||||||
|
</span>
|
||||||
),
|
),
|
||||||
align: "text-start",
|
align: "text-start",
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
key: "action",
|
key: "action",
|
||||||
label: "Action",
|
label: "Action",
|
||||||
getValue: (e) => (
|
getValue: (e) => (
|
||||||
<div className="dropdown text-center">
|
<i
|
||||||
<button
|
className="bx bx-cloud-download"
|
||||||
className="btn btn-icon btn-sm dropdown-toggle hide-arrow"
|
|
||||||
data-bs-toggle="dropdown"
|
|
||||||
>
|
|
||||||
<i className="bx bx-dots-vertical-rounded"></i>
|
|
||||||
</button>
|
|
||||||
<div className="dropdown-menu dropdown-menu-end">
|
|
||||||
{/* View */}
|
|
||||||
<button
|
|
||||||
className="dropdown-item py-1"
|
|
||||||
onClick={() => navigate(`/employee/${e.id}`)}
|
|
||||||
>
|
|
||||||
<i className="bx bx-detail bx-sm"></i> View
|
|
||||||
</button>
|
|
||||||
{/* Download */}
|
|
||||||
<button
|
|
||||||
className="dropdown-item py-1"
|
|
||||||
onClick={() => console.log("Download clicked for", e.id)}
|
onClick={() => console.log("Download clicked for", e.id)}
|
||||||
>
|
role="button"
|
||||||
<i className="bx bx-cloud-download bx-sm"></i> Download
|
/>
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
),
|
),
|
||||||
align: "text-center",
|
align: "text-center",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className=" p-2">
|
<div className=" p-2">
|
||||||
<div className="text-start mb-3">
|
<div className="text-start mb-3">
|
||||||
{/* Active subscription */}
|
|
||||||
<div className="divider text-start my-1">
|
<div className="divider text-start my-1">
|
||||||
<div className="divider-text">Active Subscription</div>
|
<div className="divider-text">Active Subscription</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col-12 col-sm-8 border rounded p-3 shadow-sm">
|
<div className="col-12 col-sm-8 border rounded p-3 shadow-sm">
|
||||||
<p className="text-primary fw-bold m-0 fs-4">
|
<p className="text-primary fw-bold m-0">{plan.planName || "N/A"}</p>
|
||||||
{plan.planName || "N/A"}
|
|
||||||
</p>
|
|
||||||
{plan.description && (
|
|
||||||
<div className="col rounded-2 justify-content-start p-0">
|
|
||||||
<p className="m-0">{plan.description}</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="d-flex justify-content-between align-items-end mt-2">
|
<div className="d-flex justify-content-between align-items-end mt-2">
|
||||||
<div>
|
<div>
|
||||||
<h3 className="m-0">
|
<h3 className="m-0">
|
||||||
{plan.currency?.symbol || "₹"} {plan.price}
|
{plan.currency?.symbol} {plan.price}
|
||||||
</h3>
|
</h3>
|
||||||
<small className="text-muted">
|
<small className="text-muted">{plan.description}</small>
|
||||||
{SUBSCRIPTION_PLAN_FREQUENCIES[plan.frequency] || ""}
|
|
||||||
</small>
|
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
className="btn btn-sm btn-primary"
|
className="btn btn-sm btn-success"
|
||||||
onClick={handleUpgradePlan}
|
onClick={handleUpgradePlan}
|
||||||
>
|
>
|
||||||
Upgrade Plan
|
Upgrade Plan
|
||||||
@ -151,26 +144,25 @@ const SubScriptionHistory = ({ tenantId }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-3 small text-muted">
|
<div className="mt-3">
|
||||||
<div className="d-flex justify-content-between">
|
{/* Progress bar placeholder */}
|
||||||
<span>
|
<div className="d-flex justify-content-between small text-muted mt-1">
|
||||||
Active Since :{" "}
|
<span>{totalDays - daysLeft} days used</span>
|
||||||
{plan.startDate ? formatUTCToLocalTime(plan.startDate) : "N/A"} ({daysLeft} days left)
|
<span>{daysLeft} days left</span>
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<div className="text-start mt-1">
|
|
||||||
Ends on : {plan.endDate ? formatUTCToLocalTime(plan.endDate) : "N/A"}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* History */}
|
<div className="text-end mt-1 small text-muted">
|
||||||
<div className="divider text-start my-3">
|
Ends on {end.toLocaleDateString()}
|
||||||
<div className="divider-text">
|
|
||||||
<i className="bx bx-history"></i> <small>History</small>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-start my-2">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div className="divider text-start my-1">
|
||||||
|
<div className="divider-text"> <i className="bx bx-history"></i> <small>History</small></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<table className="table border-top dataTable text-nowrap align-middle">
|
<table className="table border-top dataTable text-nowrap align-middle">
|
||||||
<thead className="align-middle">
|
<thead className="align-middle">
|
||||||
@ -185,7 +177,7 @@ const SubScriptionHistory = ({ tenantId }) => {
|
|||||||
<tbody className="align-middle">
|
<tbody className="align-middle">
|
||||||
{data?.subscriptionHistery
|
{data?.subscriptionHistery
|
||||||
?.slice()
|
?.slice()
|
||||||
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt)) // latest first
|
||||||
.map((item) => (
|
.map((item) => (
|
||||||
<tr key={item.id}>
|
<tr key={item.id}>
|
||||||
{SubscriptionColumns.map((col) => (
|
{SubscriptionColumns.map((col) => (
|
||||||
@ -197,6 +189,7 @@ const SubScriptionHistory = ({ tenantId }) => {
|
|||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -7,15 +7,14 @@ import { useForm, FormProvider } from "react-hook-form";
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import {
|
import {
|
||||||
getStepFields,
|
getStepFields,
|
||||||
getSubscriptionSchema,
|
|
||||||
newTenantSchema,
|
newTenantSchema,
|
||||||
subscriptionDefaultValues,
|
subscriptionDefaultValues,
|
||||||
|
subscriptionSchema,
|
||||||
tenantDefaultValues,
|
tenantDefaultValues,
|
||||||
} from "./TenantSchema";
|
} from "./TenantSchema";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
|
|
||||||
const TenantForm = () => {
|
const TenantForm = () => {
|
||||||
|
|
||||||
const HasSelectedCurrentTenant = useSelector(
|
const HasSelectedCurrentTenant = useSelector(
|
||||||
(store) => store.globalVariables.currentTenant
|
(store) => store.globalVariables.currentTenant
|
||||||
);
|
);
|
||||||
@ -46,7 +45,7 @@ const TenantForm = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const subscriptionForm = useForm({
|
const subscriptionForm = useForm({
|
||||||
resolver: zodResolver(getSubscriptionSchema(HasSelectedCurrentTenant?.data?.activeEmployees)),
|
resolver: zodResolver(subscriptionSchema),
|
||||||
defaultValues: subscriptionDefaultValues,
|
defaultValues: subscriptionDefaultValues,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -54,17 +54,16 @@ export const tenantDefaultValues = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const subscriptionSchema = z.object({
|
||||||
export const getSubscriptionSchema = (minUsers) =>
|
// tenantId: z.string().uuid("Invalid tenant ID"),
|
||||||
z.object({
|
|
||||||
planId: z.string().min(1,{message:"Please select Plan"}),
|
planId: z.string().min(1,{message:"Please select Plan"}),
|
||||||
currencyId: z.string().uuid("Invalid currency"),
|
currencyId: z.string().uuid("Invalid currency"),
|
||||||
maxUsers: z
|
maxUsers: z
|
||||||
.number({ invalid_type_error: " Must be a number" })
|
.number({ invalid_type_error: " Must be a number" })
|
||||||
.min(minUsers, { message: `Team size must be greater than or equal to ${minUsers}` }),
|
.min(1, "Team size is required and must be greater than zero"),
|
||||||
frequency: z
|
frequency: z
|
||||||
.number({ invalid_type_error: "Frequency must be a number" })
|
.number({ invalid_type_error: "Frequency must be a number" })
|
||||||
.min(1, "Frequency must be at least 1"),
|
.min(0, "Frequency must be at least 1"),
|
||||||
isTrial: z.boolean(),
|
isTrial: z.boolean(),
|
||||||
autoRenew: z.boolean(),
|
autoRenew: z.boolean(),
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user