import React, { useState } from "react"; import ContactInfro from "./ContactInfro"; import SubScription from "./SubScription"; import OrganizationInfo from "./OrganizationInfo"; import { useForm, FormProvider } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { getStepFields, newTenantSchema, subscriptionDefaultValues, subscriptionSchema, tenantDefaultValues, } from "./TenantSchema"; import Congratulation from "./congratulation"; const TenantForm = () => { const [activeTab, setActiveTab] = useState(0); const [completedTabs, setCompletedTabs] = useState([]); const tenantForm = useForm({ resolver: zodResolver(newTenantSchema), defaultValues: tenantDefaultValues, }); const subscriptionForm = useForm({ resolver: zodResolver(subscriptionSchema), defaultValues: subscriptionDefaultValues, }); const getCurrentTrigger = () => activeTab === 2 ? subscriptionForm.trigger : tenantForm.trigger; const handleNext = async () => { const currentStepFields = getStepFields(activeTab); const trigger = getCurrentTrigger(); const valid = await trigger(currentStepFields); if (valid) { setCompletedTabs((prev) => [...new Set([...prev, activeTab])]); setActiveTab((prev) => Math.min(prev + 1, newTenantConfig.length - 1)); } }; const handlePrev = () => { setActiveTab((prev) => Math.max(prev - 1, 0)); }; const onSubmitTenant = (data) => { console.log(data); }; const onSubmitSubScription = (data) => { console.log(data); }; const newTenantConfig = [ { name: "Contact Info", icon: "bx bx-user bx-md", subtitle: "Provide Contact Details", component: , }, { name: "Organization", icon: "bx bx-buildings bx-md", subtitle: "Organization Details", component: , }, { name: "SubScription", icon: "bx bx-star bx-md", subtitle: "Select a plan", component: , }, { name: "congratulation", icon: "bx bx-star bx-md", subtitle: "Select a plan", component: , }, ]; const isSubscriptionTab = activeTab === 2; return (
{newTenantConfig.filter((step) => step.name.toLowerCase() !== "congratulation").map((step, index) => { const isActive = activeTab === index; const isCompleted = completedTabs.includes(index); return (
{index < newTenantConfig.length - 1 && (
)}
); })}
{isSubscriptionTab ? (
{newTenantConfig[activeTab].component}
) : (
{newTenantConfig[activeTab].component}
)}
); }; export default TenantForm;