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); return (
{plan.planName}
{plan.description}