feat(plans): show Needs Pricing badge, disable unpriced toggle, and edit bundle modules
This commit is contained in:
parent
7709d6eba8
commit
1fa7b96195
25
src/App.tsx
25
src/App.tsx
|
|
@ -121,6 +121,7 @@ export default function App() {
|
|||
const [editPlanBadge, setEditPlanBadge] = useState<string>('');
|
||||
const [editPlanHeading, setEditPlanHeading] = useState<string>('');
|
||||
const [editPlanSubtitle, setEditPlanSubtitle] = useState<string>('');
|
||||
const [editPlanModuleIds, setEditPlanModuleIds] = useState<string[]>([]);
|
||||
const [editPriceSaving, setEditPriceSaving] = useState<boolean>(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)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -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<EditPriceModalProps> = ({
|
|||
priceInr,
|
||||
priceUsd,
|
||||
priceEur,
|
||||
allModules = [],
|
||||
moduleIds = [],
|
||||
saving,
|
||||
onNameChange,
|
||||
onDescChange,
|
||||
|
|
@ -43,6 +50,9 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
|||
onPriceInrChange,
|
||||
onPriceUsdChange,
|
||||
onPriceEurChange,
|
||||
onToggleModule,
|
||||
onSelectAllModules,
|
||||
onClearAllModules,
|
||||
onSave,
|
||||
onClose,
|
||||
}) => {
|
||||
|
|
@ -168,6 +178,59 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{plan.plan_type === 'bundle' && allModules.length > 0 && onToggleModule && (
|
||||
<div className="space-y-2 border-t border-slate-100 pt-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="text-xs font-bold text-slate-600">
|
||||
Included Modules ({moduleIds.length} / {allModules.length})
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
{onSelectAllModules && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSelectAllModules}
|
||||
className="text-[11px] font-bold text-indigo-600 hover:text-indigo-800 cursor-pointer"
|
||||
>
|
||||
Select All
|
||||
</button>
|
||||
)}
|
||||
{onClearAllModules && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClearAllModules}
|
||||
className="text-[11px] font-bold text-slate-400 hover:text-slate-600 cursor-pointer"
|
||||
>
|
||||
Clear
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="max-h-40 overflow-y-auto rounded-xl border border-slate-200 bg-slate-50 p-2 grid grid-cols-1 sm:grid-cols-2 gap-1.5">
|
||||
{allModules.map((mod) => {
|
||||
const checked = moduleIds.includes(mod.id);
|
||||
return (
|
||||
<label
|
||||
key={mod.id}
|
||||
className={`flex items-center gap-2 px-2.5 py-1.5 rounded-lg text-xs cursor-pointer transition-colors ${
|
||||
checked
|
||||
? 'bg-indigo-50 text-indigo-800 border border-indigo-200 font-semibold'
|
||||
: 'bg-white text-slate-600 border border-slate-200 hover:bg-slate-100'
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={() => onToggleModule(mod.id)}
|
||||
className="rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
||||
/>
|
||||
<span className="truncate">{mod.name}</span>
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex gap-2 pt-2">
|
||||
<button
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -158,6 +158,11 @@ export const PlansTab: React.FC<PlansTabProps> = ({
|
|||
<div className="space-y-0.5 max-w-xs">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="font-bold text-slate-800">{plan.name}</span>
|
||||
{plan.pricing_status === 'pending_pricing' && (
|
||||
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-bold bg-amber-100 text-amber-800 border border-amber-300">
|
||||
Needs Pricing
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<code className="text-[10px] font-mono text-indigo-600 bg-indigo-50 px-1.5 py-0.5 rounded border border-indigo-100 font-bold">
|
||||
|
|
@ -286,11 +291,22 @@ export const PlansTab: React.FC<PlansTabProps> = ({
|
|||
<td className="py-3.5 px-3 text-center whitespace-nowrap">
|
||||
<button
|
||||
type="button"
|
||||
disabled={plan.pricing_status === 'pending_pricing'}
|
||||
onClick={() => onTogglePlanStatus(plan)}
|
||||
className={`relative inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${
|
||||
plan.is_active ? 'bg-indigo-600' : 'bg-slate-300'
|
||||
className={`relative inline-flex h-5 w-9 shrink-0 rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${
|
||||
plan.pricing_status === 'pending_pricing'
|
||||
? 'bg-slate-200 cursor-not-allowed opacity-60'
|
||||
: plan.is_active
|
||||
? 'bg-indigo-600 cursor-pointer'
|
||||
: 'bg-slate-300 cursor-pointer'
|
||||
}`}
|
||||
title={plan.is_active ? 'Click to deactivate' : 'Click to activate'}
|
||||
title={
|
||||
plan.pricing_status === 'pending_pricing'
|
||||
? 'Set prices via Edit Info & Price before activating'
|
||||
: plan.is_active
|
||||
? 'Click to deactivate'
|
||||
: 'Click to activate'
|
||||
}
|
||||
>
|
||||
<span
|
||||
className={`pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${
|
||||
|
|
@ -299,7 +315,11 @@ export const PlansTab: React.FC<PlansTabProps> = ({
|
|||
/>
|
||||
</button>
|
||||
<span className="block text-[9px] font-bold text-slate-400 mt-0.5">
|
||||
{plan.is_active ? 'Active' : 'Inactive'}
|
||||
{plan.pricing_status === 'pending_pricing'
|
||||
? 'Needs Pricing'
|
||||
: plan.is_active
|
||||
? 'Active'
|
||||
: 'Inactive'}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue