324 lines
14 KiB
TypeScript
324 lines
14 KiB
TypeScript
import React from 'react';
|
|
import { AlertCircle, RefreshCw } from 'lucide-react';
|
|
import { normalizeCategory } from '../../utils/category';
|
|
|
|
interface CreatePlanModalProps {
|
|
show: boolean;
|
|
code: string;
|
|
name: string;
|
|
desc: string;
|
|
badge: string;
|
|
heading: string;
|
|
subtitle: string;
|
|
type: string;
|
|
duration: string;
|
|
priceInr: string;
|
|
priceUsd: string;
|
|
priceEur: string;
|
|
selectedModuleIds: string[];
|
|
allModules: any[];
|
|
saving: boolean;
|
|
error: string | null;
|
|
onCodeChange: (v: string) => void;
|
|
onNameChange: (v: string) => void;
|
|
onDescChange: (v: string) => void;
|
|
onBadgeChange: (v: string) => void;
|
|
onHeadingChange: (v: string) => void;
|
|
onSubtitleChange: (v: string) => void;
|
|
onTypeChange: (v: string) => void;
|
|
onDurationChange: (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 CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
|
show,
|
|
code,
|
|
name,
|
|
desc,
|
|
badge,
|
|
heading,
|
|
subtitle,
|
|
type,
|
|
duration,
|
|
priceInr,
|
|
priceUsd,
|
|
priceEur,
|
|
selectedModuleIds,
|
|
allModules,
|
|
saving,
|
|
error,
|
|
onCodeChange,
|
|
onNameChange,
|
|
onDescChange,
|
|
onBadgeChange,
|
|
onHeadingChange,
|
|
onSubtitleChange,
|
|
onTypeChange,
|
|
onDurationChange,
|
|
onPriceInrChange,
|
|
onPriceUsdChange,
|
|
onPriceEurChange,
|
|
onToggleModule,
|
|
onSelectAllModules,
|
|
onClearAllModules,
|
|
onSave,
|
|
onClose,
|
|
}) => {
|
|
if (!show) 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-xl 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">Create Custom Plan / Bundle</h3>
|
|
<p className="text-xs text-slate-400">Assemble arbitrary modules into a brand-new package.</p>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={onClose}
|
|
className="text-slate-400 hover:text-slate-600 text-sm font-bold p-1 cursor-pointer"
|
|
>
|
|
✕
|
|
</button>
|
|
</div>
|
|
|
|
{error && (
|
|
<div className="bg-rose-50 border border-rose-200 rounded-xl p-3 text-xs text-rose-700 font-bold flex items-center gap-2">
|
|
<AlertCircle className="h-4 w-4 shrink-0" />
|
|
<span>{error}</span>
|
|
</div>
|
|
)}
|
|
|
|
<form onSubmit={onSave} className="space-y-4">
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Plan Code (Unique)</label>
|
|
<input
|
|
type="text"
|
|
placeholder="e.g. PAIN_CLINICAL_PACK"
|
|
required
|
|
value={code}
|
|
onChange={(e) => onCodeChange(e.target.value.toUpperCase().replace(/\s+/g, '_'))}
|
|
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-mono font-bold text-slate-800 focus:outline-none focus:border-indigo-500 uppercase"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Display Title</label>
|
|
<input
|
|
type="text"
|
|
placeholder="e.g. Pain Management Specialist Pack"
|
|
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-semibold 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">Description</label>
|
|
<textarea
|
|
rows={2}
|
|
placeholder="Details regarding clinical contents unlocked by this pack..."
|
|
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 Fields */}
|
|
<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 & Headlines (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>
|
|
|
|
{/* Type & Duration */}
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Plan Type</label>
|
|
<select
|
|
value={type}
|
|
onChange={(e) => onTypeChange(e.target.value)}
|
|
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
|
>
|
|
<option value="bundle">Bundle (Multi-module pack)</option>
|
|
<option value="one_time">One-time / Standalone</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label className="block text-xs font-bold text-slate-600 mb-1">Billing Duration</label>
|
|
<select
|
|
value={duration}
|
|
onChange={(e) => onDurationChange(e.target.value)}
|
|
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
|
>
|
|
<option value="yearly">1 Year Access</option>
|
|
<option value="monthly">1 Month Access</option>
|
|
<option value="quarterly">3 Months Access</option>
|
|
<option value="lifetime">Lifetime Access (10 Years)</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Multi-Currency Pricing (INR / USD / EUR) */}
|
|
<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"
|
|
placeholder="1499.00"
|
|
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"
|
|
placeholder="19.99"
|
|
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"
|
|
placeholder="19.99"
|
|
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>
|
|
|
|
{/* Module Selection */}
|
|
<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-700">
|
|
Select Included Modules ({selectedModuleIds.length} selected)
|
|
</label>
|
|
<div className="flex items-center gap-2">
|
|
<button
|
|
type="button"
|
|
onClick={onSelectAllModules}
|
|
className="text-[10px] font-bold text-indigo-600 hover:text-indigo-800 cursor-pointer"
|
|
>
|
|
Select All
|
|
</button>
|
|
<span className="text-slate-300">•</span>
|
|
<button
|
|
type="button"
|
|
onClick={onClearAllModules}
|
|
className="text-[10px] font-bold text-slate-500 hover:text-slate-700 cursor-pointer"
|
|
>
|
|
Clear All
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2 max-h-48 overflow-y-auto p-2 bg-slate-50 border border-slate-200 rounded-xl">
|
|
{allModules.map((mod) => {
|
|
const isSelected = selectedModuleIds.includes(mod.id);
|
|
return (
|
|
<label
|
|
key={mod.id}
|
|
className={`flex items-center gap-2.5 p-2 rounded-lg border text-xs cursor-pointer transition-colors ${
|
|
isSelected
|
|
? 'bg-indigo-50/80 border-indigo-300 text-indigo-950 font-bold'
|
|
: 'bg-white border-slate-200 text-slate-700 hover:bg-slate-100/60'
|
|
}`}
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={isSelected}
|
|
onChange={() => onToggleModule(mod.id)}
|
|
className="rounded text-indigo-600 focus:ring-indigo-500 h-3.5 w-3.5 cursor-pointer"
|
|
/>
|
|
<div className="truncate flex-1">
|
|
<p className="truncate text-xs">{mod.name}</p>
|
|
<span className="text-[9px] text-slate-400 font-semibold">{normalizeCategory(mod.category)}</span>
|
|
</div>
|
|
</label>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex gap-2 pt-3 border-t border-slate-100">
|
|
<button
|
|
type="button"
|
|
onClick={onClose}
|
|
className="flex-1 py-2.5 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.5 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-md shadow-indigo-600/20 cursor-pointer disabled:opacity-50"
|
|
>
|
|
{saving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : 'Create & Publish Plan'}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|