import React, { useState } from "react"; import { AppFormProvider, useAppForm } from "../../hooks/appHooks/useAppForm"; import { zodResolver } from "@hookform/resolvers/zod"; import { defaultPurchaseValue, PurchaseSchema, getStepFields, } from "./PurchaseSchema"; import PurchasePartyDetails from "./PurchasePartyDetails"; import PurchaseTransportDetails from "./PurchaseTransportDetails"; import PurchasePaymentDetails from "./PurchasePaymentDetails"; const ManagePurchase = () => { const [activeTab, setActiveTab] = useState(0); const [completedTabs, setCompletedTabs] = useState([]); const stepsConfig = [ { 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: "Payment & Financials", component: , }, ]; const purchaseOrder = useAppForm({ resolver: zodResolver(PurchaseSchema), defaultValues: defaultPurchaseValue, mode: "onChange", }); const handleNext = async () => { const currentStepFields = getStepFields(activeTab); const valid = await purchaseOrder.trigger(currentStepFields); if (valid) { setCompletedTabs((prev) => [...new Set([...prev, activeTab])]); setActiveTab((prev) => Math.min(prev + 1, stepsConfig.length - 1)); } }; const handlePrev = () => { setActiveTab((prev) => Math.max(prev - 1, 0)); }; const onSubmit = (formData) => { console.log("PURCHASE DATA:", formData); }; return (
{/* Header */}
{stepsConfig.map((step, index) => { const isActive = activeTab === index; const isCompleted = completedTabs.includes(index); return (
{index < stepsConfig.length - 1 && (
)}
); })}
{/* Content */}
{stepsConfig[activeTab].component}
{activeTab < stepsConfig.length - 1 ? ( ) : ( )}
); }; export default ManagePurchase;