// frontend/src/components/admin/PlanForm.jsx import React, { useEffect, useState } from "react"; const BILLING_OPTIONS = [ { value: "monthly", label: "Monthly" }, { value: "quarterly", label: "Quarterly" }, { value: "half_yearly", label: "Half Yearly" }, { value: "annual", label: "Annual" }, ]; export default function PlanForm({ plan, onSave, onCancel, isLoading }) { const [name, setName] = useState(""); const [billingPeriod, setBillingPeriod] = useState("monthly"); const [price, setPrice] = useState(""); const [description, setDescription] = useState(""); const [maxStudents, setMaxStudents] = useState("1"); const [isActive, setIsActive] = useState(true); const [isDefault, setIsDefault] = useState(false); useEffect(() => { if (plan) { setName(plan.name || ""); setBillingPeriod(plan.billing_period || "monthly"); setPrice(plan.price != null ? String(plan.price) : ""); setDescription(plan.description || ""); setMaxStudents(String(plan.max_students || 1)); setIsActive(plan.is_active ?? true); setIsDefault(plan.is_default ?? false); } else { setName(""); setBillingPeriod("monthly"); setPrice(""); setDescription(""); setMaxStudents("1"); setIsActive(true); setIsDefault(false); } }, [plan]); function handleSubmit(e) { e.preventDefault(); const priceNumber = parseFloat(price || "0") || 0; const maxStudentsNumber = parseInt(maxStudents || "1", 10) || 1; onSave({ name, billing_period: billingPeriod, price: priceNumber, description: description || null, max_students: maxStudentsNumber, is_active: isActive, is_default: isDefault, }); } return (
{/* Top Row: Plan Name, Billing Period on left; Price, Max Students on right */}
setName(e.target.value)} />
setPrice(e.target.value)} min="0" step="0.01" />
setMaxStudents(e.target.value)} min="1" />
{/* Description - Full Width */}