diff --git a/src/App.tsx b/src/App.tsx index 3c6d42f..9b32a33 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -121,6 +121,7 @@ export default function App() { const [editPlanBadge, setEditPlanBadge] = useState(''); const [editPlanHeading, setEditPlanHeading] = useState(''); const [editPlanSubtitle, setEditPlanSubtitle] = useState(''); + const [editPlanModuleIds, setEditPlanModuleIds] = useState([]); const [editPriceSaving, setEditPriceSaving] = useState(false); // Create Custom Plan State @@ -610,6 +611,11 @@ export default function App() { setEditPlanBadge(plan.badge_text || ''); setEditPlanHeading(plan.heading || ''); setEditPlanSubtitle(plan.subtitle || ''); + setEditPlanModuleIds( + Array.isArray(plan.module_ids) && plan.module_ids.length > 0 + ? plan.module_ids + : (plan.modules || []).map((m: any) => m.id).filter(Boolean) + ); }; const handleSavePlanPrice = async (e: React.FormEvent) => { @@ -635,9 +641,14 @@ export default function App() { badge_text: editPlanBadge.trim() || undefined, heading: editPlanHeading.trim() || undefined, subtitle: editPlanSubtitle.trim() || undefined, + module_ids: selectedEditPricePlan.plan_type === 'bundle' ? editPlanModuleIds : undefined, }, { headers: { Authorization: `Bearer ${userToken}` } } ); + const updatedBundleModules = + selectedEditPricePlan.plan_type === 'bundle' + ? adminModulesList.filter((m) => editPlanModuleIds.includes(m.id)) + : undefined; setAdminPlansList((prev) => prev.map((p) => p.base_code === selectedEditPricePlan.base_code @@ -651,6 +662,11 @@ export default function App() { price_inr: inrVal, price_usd: usdVal, price_eur: eurVal, + pricing_status: + inrVal > 0 || usdVal > 0 || eurVal > 0 ? 'configured' : p.pricing_status, + ...(selectedEditPricePlan.plan_type === 'bundle' + ? { module_ids: editPlanModuleIds, modules: updatedBundleModules } + : {}), } : p ) @@ -1363,6 +1379,8 @@ export default function App() { priceInr={editPriceInr} priceUsd={editPriceUsd} priceEur={editPriceEur} + allModules={adminModulesList} + moduleIds={editPlanModuleIds} saving={editPriceSaving} onNameChange={setEditPlanName} onDescChange={setEditPlanDesc} @@ -1372,6 +1390,13 @@ export default function App() { onPriceInrChange={setEditPriceInr} onPriceUsdChange={setEditPriceUsd} onPriceEurChange={setEditPriceEur} + onToggleModule={(id: string) => + setEditPlanModuleIds((prev) => + prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id] + ) + } + onSelectAllModules={() => setEditPlanModuleIds(adminModulesList.map((m) => m.id))} + onClearAllModules={() => setEditPlanModuleIds([])} onSave={handleSavePlanPrice} onClose={() => setSelectedEditPricePlan(null)} /> diff --git a/src/components/plans/EditPriceModal.tsx b/src/components/plans/EditPriceModal.tsx index e32e4f8..c99e6bb 100644 --- a/src/components/plans/EditPriceModal.tsx +++ b/src/components/plans/EditPriceModal.tsx @@ -11,6 +11,8 @@ interface EditPriceModalProps { priceInr: string; priceUsd: string; priceEur: string; + allModules?: any[]; + moduleIds?: string[]; saving: boolean; onNameChange: (v: string) => void; onDescChange: (v: string) => void; @@ -20,6 +22,9 @@ interface EditPriceModalProps { onPriceInrChange: (v: string) => void; onPriceUsdChange: (v: string) => void; onPriceEurChange: (v: string) => void; + onToggleModule?: (id: string) => void; + onSelectAllModules?: () => void; + onClearAllModules?: () => void; onSave: (e: React.FormEvent) => void; onClose: () => void; } @@ -34,6 +39,8 @@ export const EditPriceModal: React.FC = ({ priceInr, priceUsd, priceEur, + allModules = [], + moduleIds = [], saving, onNameChange, onDescChange, @@ -43,6 +50,9 @@ export const EditPriceModal: React.FC = ({ onPriceInrChange, onPriceUsdChange, onPriceEurChange, + onToggleModule, + onSelectAllModules, + onClearAllModules, onSave, onClose, }) => { @@ -168,6 +178,59 @@ export const EditPriceModal: React.FC = ({ + {plan.plan_type === 'bundle' && allModules.length > 0 && onToggleModule && ( +
+
+ +
+ {onSelectAllModules && ( + + )} + {onClearAllModules && ( + + )} +
+
+
+ {allModules.map((mod) => { + const checked = moduleIds.includes(mod.id); + return ( + + ); + })} +
+
+ )} +
- {plan.is_active ? 'Active' : 'Inactive'} + {plan.pricing_status === 'pending_pricing' + ? 'Needs Pricing' + : plan.is_active + ? 'Active' + : 'Inactive'}