acupedia-web-ui/src/components/plans/EditPriceModal.tsx

192 lines
7.8 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;
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;
onSave: (e: React.FormEvent) => void;
onClose: () => void;
}
export const EditPriceModal: React.FC<EditPriceModalProps> = ({
plan,
name,
desc,
badge,
heading,
subtitle,
priceInr,
priceUsd,
priceEur,
saving,
onNameChange,
onDescChange,
onBadgeChange,
onHeadingChange,
onSubtitleChange,
onPriceInrChange,
onPriceUsdChange,
onPriceEurChange,
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>
<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>
);
};