+
+
+
);
};
diff --git a/src/components/Tenanat/SubScription.jsx b/src/components/Tenanat/SubScription.jsx
index 9d6ed387..2835fe56 100644
--- a/src/components/Tenanat/SubScription.jsx
+++ b/src/components/Tenanat/SubScription.jsx
@@ -1,80 +1,199 @@
-import React, { useState } from "react";
+import React, { useState, useEffect } from "react";
import { useSubscriptionPlan } from "../../hooks/useTenant";
import SegmentedControl from "./SegmentedControl";
+import { useFormContext } from "react-hook-form";
+import { CONSTANT_TEXT } from "../../utils/constants";
+import Label from "../common/Label";
+
+const SubScription = ({ onSubmitSubScription }) => {
+ const [frequency, setFrequency] = useState(2);
+ const [selectedPlanId, setSelectedPlanId] = useState(null);
+
+ const {
+ data: plans = [],
+ isError,
+ isLoading,
+ } = useSubscriptionPlan(frequency);
+
+ const {
+ register,
+ setValue,
+ getValues,
+ trigger,
+ formState: { errors },
+ } = useFormContext();
+
+
+ const handleSubscriptionSubmit = async () => {
+ const isValid = await trigger([
+ "planId",
+ "currencyId",
+ "maxUsers",
+ "frequency",
+ "isTrial",
+ "autoRenew",
+ ]);
+
+ if (isValid) {
+ const payload = getValues();
+ onSubmitSubScription(payload);
+ }
+ };
+
+ const handlePlanSelection = (plan) => {
+ setSelectedPlanId(plan.id);
+ setValue("planId", plan.id);
+ setValue("currencyId", plan.currency?.id);
+ setValue("frequency", frequency);
+ };
+
+ const selectedPlan = plans.find((p) => p.id === selectedPlanId);
-const SubScription = () => {
- const [Frequency, setFrequency] = useState(3);
- const[selectedPlanId,setSelectedPlanId] = useState()
- const { data, isError, isLoading } = useSubscriptionPlan(Frequency);
- console.log(Frequency);
return (
- {!isLoading && !isError && data.length > 0 && (
- <>
-
- {data.map((plan) => (
-
+ {!isLoading && !isError && plans.length > 0 && (
+
+ {plans.map((plan) => {
+ const isSelected = plan.id === selectedPlanId;
+
+ return (
+
setSelectedPlanId(plan.id)}
- style={{ cursor: "pointer" }}
+ onClick={() => handlePlanSelection(plan)}
>
-
+
-
+
-
+
{plan.planName}
-
+
{plan.description}
-
- {plan.currency?.symbol}
- {plan.price}
- {/*
- /{selectedBilling.label.toLowerCase()}
- */}
-
+
+ {plan.currency?.symbol} {plan.price}
+
-
- -
-
- Max Users: {plan.maxUser}
+
+ -
+
+ Max Users {plan.maxUser}
- -
-
- Storage: {plan.maxStorage} MB
+
-
+
+ Storage {plan.maxStorage} MB
- -
-
- Trial Days: {plan.trialDays}
+
-
+
+ Trial Days {plan.trialDays}
+
+
+
+ {Object.entries(plan.features.modules)
+ .filter(([key]) => key !== "id")
+ .map(([key, mod]) => (
+
+
+ {mod.name}
+
+ ))}
+
+
setSelectedPlanId(plan.id)}
+ onClick={() => handlePlanSelection(plan)}
>
- {selectedPlanId === plan.id ? "Selected" : "Get Plan"}
+ {isSelected ? "Selected" : "Select Plan"}
- ))}
+ );
+ })}
+
+ {/* Form Inputs */}
+
+
+
+
+
+
+
+
+
+
+
+
+ {CONSTANT_TEXT.RenewsubscriptionLabel}
+
+
- >
+
+ {Object.keys(errors).length > 0 && (
+
+ {Object.entries(errors).map(([key, error]) => (
+
+ {error?.message}
+
+ ))}
+
+ )}
+
+
+
+ Submit
+
+
+
)}
);
diff --git a/src/components/Tenanat/TenantForm.jsx b/src/components/Tenanat/TenantForm.jsx
index d80bde65..a7c12e4b 100644
--- a/src/components/Tenanat/TenantForm.jsx
+++ b/src/components/Tenanat/TenantForm.jsx
@@ -46,7 +46,7 @@ const TenantForm = () => {
const onSubmitTenant = (data) => {
console.log(data);
};
- const onSubmitSubScription = () => {
+ const onSubmitSubScription = (data) => {
console.log(data);
};
@@ -67,13 +67,13 @@ const TenantForm = () => {
name: "SubScription",
icon: "bx bx-star bx-md",
subtitle: "Select a plan",
- component:
,
+ component:
,
},
];
const isSubscriptionTab = activeTab === 2;
return (
-
+
{newTenantConfig.map((step, index) => {
const isActive = activeTab === index;
@@ -113,7 +113,7 @@ const TenantForm = () => {
})}
-