255 lines
10 KiB
TypeScript
255 lines
10 KiB
TypeScript
import React from 'react';
|
|
import { RefreshCw } from 'lucide-react';
|
|
|
|
interface EditPriceModalProps {
|
|
plan: any | null;
|
|
name: string;
|
|
desc: string;
|
|
badge: string;
|
|
heading: string;
|
|
subtitle: string;
|
|
priceInr: string;
|
|
priceUsd: string;
|
|
priceEur: string;
|
|
allModules?: any[];
|
|
moduleIds?: string[];
|
|
saving: boolean;
|
|
onNameChange: (v: string) => void;
|
|
onDescChange: (v: string) => void;
|
|
onBadgeChange: (v: string) => void;
|
|
onHeadingChange: (v: string) => void;
|
|
onSubtitleChange: (v: string) => void;
|
|
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;
|
|
}
|
|
|
|
export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
|
plan,
|
|
name,
|
|
desc,
|
|
badge,
|
|
heading,
|
|
subtitle,
|
|
priceInr,
|
|
priceUsd,
|
|
priceEur,
|
|
allModules = [],
|
|
moduleIds = [],
|
|
saving,
|
|
onNameChange,
|
|
onDescChange,
|
|
onBadgeChange,
|
|
onHeadingChange,
|
|
onSubtitleChange,
|
|
onPriceInrChange,
|
|
onPriceUsdChange,
|
|
onPriceEurChange,
|
|
onToggleModule,
|
|
onSelectAllModules,
|
|
onClearAllModules,
|
|
onSave,
|
|
onClose,
|
|
}) => {
|
|
if (!plan) return null;
|
|
|
|
return (
|
|
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4">
|
|
<div className="bg-white rounded-3xl border border-slate-200 shadow-2xl max-w-lg w-full p-6 space-y-5 max-h-[90vh] overflow-y-auto animate-in fade-in zoom-in duration-150">
|
|
<div className="flex items-center justify-between border-b border-slate-100 pb-3">
|
|
<div>
|
|
<h3 className="text-base font-bold text-slate-800">Edit Plan Details & Pricing</h3>
|
|
<p className="text-xs text-slate-400">Update rates and storefront presentation.</p>
|
|
</div>
|
|
<span className="px-2 py-0.5 rounded text-[10px] font-mono font-bold bg-indigo-50 text-indigo-600 border border-indigo-100">
|
|
{plan.base_code || plan.code}
|
|
</span>
|
|
</div>
|
|
|
|
<form onSubmit={onSave} className="space-y-4">
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Plan Display Name</label>
|
|
<input
|
|
type="text"
|
|
required
|
|
value={name}
|
|
onChange={(e) => onNameChange(e.target.value)}
|
|
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Plan Description</label>
|
|
<textarea
|
|
rows={2}
|
|
value={desc}
|
|
onChange={(e) => onDescChange(e.target.value)}
|
|
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
|
/>
|
|
</div>
|
|
|
|
{/* Storefront Presentation */}
|
|
<div className="bg-indigo-50/60 border border-indigo-100 rounded-2xl p-3.5 space-y-3">
|
|
<span className="text-xs font-bold text-indigo-900 block">🎨 Storefront Presentation (Optional)</span>
|
|
<div>
|
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Badge Pill Text</label>
|
|
<input
|
|
type="text"
|
|
placeholder="✨ CUSTOM PACKAGES & BUNDLES"
|
|
value={badge}
|
|
onChange={(e) => onBadgeChange(e.target.value)}
|
|
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Card Heading</label>
|
|
<input
|
|
type="text"
|
|
placeholder="Special Curated Bundles"
|
|
value={heading}
|
|
onChange={(e) => onHeadingChange(e.target.value)}
|
|
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Card Subtitle / Description</label>
|
|
<input
|
|
type="text"
|
|
placeholder="Custom curriculum collections created exclusively for practitioners."
|
|
value={subtitle}
|
|
onChange={(e) => onSubtitleChange(e.target.value)}
|
|
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
|
<div className="relative">
|
|
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs">₹</span>
|
|
<input
|
|
type="number"
|
|
step="0.01"
|
|
min="0"
|
|
required
|
|
value={priceInr}
|
|
onChange={(e) => onPriceInrChange(e.target.value)}
|
|
className="w-full bg-slate-50 border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Price ($ USD)</label>
|
|
<div className="relative">
|
|
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs">$</span>
|
|
<input
|
|
type="number"
|
|
step="0.01"
|
|
min="0"
|
|
required
|
|
value={priceUsd}
|
|
onChange={(e) => onPriceUsdChange(e.target.value)}
|
|
className="w-full bg-slate-50 border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Price (€ EUR)</label>
|
|
<div className="relative">
|
|
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs">€</span>
|
|
<input
|
|
type="number"
|
|
step="0.01"
|
|
min="0"
|
|
required
|
|
value={priceEur}
|
|
onChange={(e) => onPriceEurChange(e.target.value)}
|
|
className="w-full bg-slate-50 border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{(plan.plan_type === 'bundle' || plan.base_code === 'PATTERN_CORE' || plan.base_code === 'NUTRITION_CORE') && 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"
|
|
onClick={onClose}
|
|
className="flex-1 py-2 rounded-xl text-xs font-bold bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors cursor-pointer"
|
|
>
|
|
Cancel
|
|
</button>
|
|
<button
|
|
type="submit"
|
|
disabled={saving}
|
|
className="flex-1 py-2 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors flex items-center justify-center gap-1.5 shadow-sm cursor-pointer disabled:opacity-50"
|
|
>
|
|
{saving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : 'Save Changes'}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|