feat: add multi-currency EUR support to admin coupons
This commit is contained in:
parent
8e0ee87fd2
commit
1708a9cdb2
51
src/App.tsx
51
src/App.tsx
|
|
@ -153,7 +153,11 @@ export default function App() {
|
|||
category: 'general',
|
||||
discountType: 'percentage',
|
||||
discountValue: '20',
|
||||
discountValueUsd: '',
|
||||
discountValueEur: '',
|
||||
maxDiscountCap: '0',
|
||||
maxDiscountCapUsd: '',
|
||||
maxDiscountCapEur: '',
|
||||
description: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
|
|
@ -161,6 +165,8 @@ export default function App() {
|
|||
applicablePlanIds: [],
|
||||
applicableModuleIds: [],
|
||||
minSpend: '0',
|
||||
minSpendUsd: '',
|
||||
minSpendEur: '',
|
||||
usageLimit: '0',
|
||||
firstOnly: false,
|
||||
});
|
||||
|
|
@ -745,7 +751,11 @@ export default function App() {
|
|||
category: 'general',
|
||||
discountType: 'percentage',
|
||||
discountValue: '20',
|
||||
discountValueUsd: '',
|
||||
discountValueEur: '',
|
||||
maxDiscountCap: '0',
|
||||
maxDiscountCapUsd: '',
|
||||
maxDiscountCapEur: '',
|
||||
description: '',
|
||||
startDate: todayStr,
|
||||
endDate: nextYearStr,
|
||||
|
|
@ -753,6 +763,8 @@ export default function App() {
|
|||
applicablePlanIds: [],
|
||||
applicableModuleIds: [],
|
||||
minSpend: '0',
|
||||
minSpendUsd: '',
|
||||
minSpendEur: '',
|
||||
usageLimit: '0',
|
||||
firstOnly: false,
|
||||
});
|
||||
|
|
@ -769,15 +781,21 @@ export default function App() {
|
|||
code: c.code,
|
||||
category: c.coupon_category || 'general',
|
||||
discountType: c.discount_type || 'percentage',
|
||||
discountValue: String(c.value ?? 0),
|
||||
maxDiscountCap: String(c.max_discount_limit ?? 0),
|
||||
discountValue: String(c.value_inr ?? c.value ?? 0),
|
||||
discountValueUsd: c.value_usd !== undefined && c.value_usd !== null ? String(c.value_usd) : '',
|
||||
discountValueEur: c.value_eur !== undefined && c.value_eur !== null ? String(c.value_eur) : '',
|
||||
maxDiscountCap: String(c.max_discount_inr ?? c.max_discount_limit ?? 0),
|
||||
maxDiscountCapUsd: c.max_discount_usd !== undefined && c.max_discount_usd !== null ? String(c.max_discount_usd) : '',
|
||||
maxDiscountCapEur: c.max_discount_eur !== undefined && c.max_discount_eur !== null ? String(c.max_discount_eur) : '',
|
||||
description: c.description || '',
|
||||
startDate: c.start_date ? c.start_date.split('T')[0] : '',
|
||||
endDate: c.end_date ? c.end_date.split('T')[0] : '',
|
||||
scope: hasSpecific ? 'specific' : 'storewide',
|
||||
applicablePlanIds: c.applicable_plan_ids || [],
|
||||
applicableModuleIds: c.applicable_module_ids || [],
|
||||
minSpend: String(c.min_purchase_amount ?? 0),
|
||||
minSpend: String(c.min_purchase_inr ?? c.min_purchase_amount ?? 0),
|
||||
minSpendUsd: c.min_purchase_usd !== undefined && c.min_purchase_usd !== null ? String(c.min_purchase_usd) : '',
|
||||
minSpendEur: c.min_purchase_eur !== undefined && c.min_purchase_eur !== null ? String(c.min_purchase_eur) : '',
|
||||
usageLimit: String(c.usage_limit ?? 0),
|
||||
firstOnly: Boolean(c.is_first_purchase_only),
|
||||
});
|
||||
|
|
@ -796,14 +814,35 @@ export default function App() {
|
|||
setCouponSaving(true);
|
||||
try {
|
||||
const headers = { Authorization: `Bearer ${userToken}` };
|
||||
const valInr = parseFloat(couponFormData.discountValue) || 0;
|
||||
const valUsd = couponFormData.discountValueUsd.trim() ? parseFloat(couponFormData.discountValueUsd) : undefined;
|
||||
const valEur = couponFormData.discountValueEur.trim() ? parseFloat(couponFormData.discountValueEur) : undefined;
|
||||
|
||||
const capInr = parseFloat(couponFormData.maxDiscountCap) || 0;
|
||||
const capUsd = couponFormData.maxDiscountCapUsd.trim() ? parseFloat(couponFormData.maxDiscountCapUsd) : undefined;
|
||||
const capEur = couponFormData.maxDiscountCapEur.trim() ? parseFloat(couponFormData.maxDiscountCapEur) : undefined;
|
||||
|
||||
const minInr = parseFloat(couponFormData.minSpend) || 0;
|
||||
const minUsd = couponFormData.minSpendUsd.trim() ? parseFloat(couponFormData.minSpendUsd) : undefined;
|
||||
const minEur = couponFormData.minSpendEur.trim() ? parseFloat(couponFormData.minSpendEur) : undefined;
|
||||
|
||||
const payload: any = {
|
||||
code: couponFormData.code.trim().toUpperCase(),
|
||||
discount_type: couponFormData.discountType,
|
||||
coupon_category: couponFormData.category,
|
||||
value: parseFloat(couponFormData.discountValue) || 0,
|
||||
max_discount_limit: parseFloat(couponFormData.maxDiscountCap) || 0,
|
||||
value: valInr,
|
||||
value_inr: valInr,
|
||||
value_usd: valUsd,
|
||||
value_eur: valEur,
|
||||
max_discount_limit: capInr,
|
||||
max_discount_inr: capInr,
|
||||
max_discount_usd: capUsd,
|
||||
max_discount_eur: capEur,
|
||||
usage_limit: parseInt(couponFormData.usageLimit) || 0,
|
||||
min_purchase_amount: parseFloat(couponFormData.minSpend) || 0,
|
||||
min_purchase_amount: minInr,
|
||||
min_purchase_inr: minInr,
|
||||
min_purchase_usd: minUsd,
|
||||
min_purchase_eur: minEur,
|
||||
is_first_purchase_only: couponFormData.firstOnly,
|
||||
is_active: true,
|
||||
description: couponFormData.description.trim() || undefined,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ export interface CouponFormData {
|
|||
category: string;
|
||||
discountType: 'percentage' | 'flat';
|
||||
discountValue: string;
|
||||
discountValueUsd: string;
|
||||
discountValueEur: string;
|
||||
maxDiscountCap: string;
|
||||
maxDiscountCapUsd: string;
|
||||
maxDiscountCapEur: string;
|
||||
description: string;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
|
|
@ -14,6 +18,8 @@ export interface CouponFormData {
|
|||
applicablePlanIds: string[];
|
||||
applicableModuleIds: string[];
|
||||
minSpend: string;
|
||||
minSpendUsd: string;
|
||||
minSpendEur: string;
|
||||
usageLimit: string;
|
||||
firstOnly: boolean;
|
||||
}
|
||||
|
|
@ -105,7 +111,7 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Discount Type</label>
|
||||
<select
|
||||
|
|
@ -114,36 +120,112 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
|||
className="w-full bg-white 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="percentage">Percentage (%)</option>
|
||||
<option value="flat">Flat Amount (₹/$)</option>
|
||||
<option value="flat">Flat Amount (₹ / $ / €)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">
|
||||
{data.discountType === 'percentage' ? 'Percentage (%) *' : 'Flat Amount *'}
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0.01"
|
||||
required
|
||||
value={data.discountValue}
|
||||
onChange={(e) => onChange('discountValue', e.target.value)}
|
||||
className="w-full bg-white 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-[11px] font-bold text-slate-600 mb-1">Max Cap (0=None)</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
disabled={data.discountType !== 'percentage'}
|
||||
value={data.maxDiscountCap}
|
||||
onChange={(e) => onChange('maxDiscountCap', e.target.value)}
|
||||
placeholder="0"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 disabled:opacity-50"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{data.discountType === 'percentage' ? (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-4 gap-2.5">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Discount % *</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0.01"
|
||||
max="100"
|
||||
required
|
||||
value={data.discountValue}
|
||||
onChange={(e) => onChange('discountValue', e.target.value)}
|
||||
placeholder="e.g. 20"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
<span className="absolute right-3 top-2 text-xs font-bold text-slate-400">%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Max Cap ₹ (INR)</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.maxDiscountCap}
|
||||
onChange={(e) => onChange('maxDiscountCap', e.target.value)}
|
||||
placeholder="0 = None"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Max Cap $ (USD)</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.maxDiscountCapUsd}
|
||||
onChange={(e) => onChange('maxDiscountCapUsd', e.target.value)}
|
||||
placeholder="0 = None"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Max Cap € (EUR)</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.maxDiscountCapEur}
|
||||
onChange={(e) => onChange('maxDiscountCapEur', e.target.value)}
|
||||
placeholder="0 = None"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1.5">
|
||||
Flat Discount Amount (by Currency Tier) *
|
||||
</label>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2.5">
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-2 text-xs font-bold text-slate-400">₹</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0.01"
|
||||
required
|
||||
value={data.discountValue}
|
||||
onChange={(e) => onChange('discountValue', e.target.value)}
|
||||
placeholder="INR (₹)"
|
||||
className="w-full bg-white 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 className="relative">
|
||||
<span className="absolute left-3 top-2 text-xs font-bold text-slate-400">$</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.discountValueUsd}
|
||||
onChange={(e) => onChange('discountValueUsd', e.target.value)}
|
||||
placeholder="USD ($)"
|
||||
className="w-full bg-white 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 className="relative">
|
||||
<span className="absolute left-3 top-2 text-xs font-bold text-slate-400">€</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.discountValueEur}
|
||||
onChange={(e) => onChange('discountValueEur', e.target.value)}
|
||||
placeholder="EUR (€)"
|
||||
className="w-full bg-white 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>
|
||||
|
||||
<div>
|
||||
|
|
@ -236,7 +318,7 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
|||
</label>
|
||||
<div className="max-h-28 overflow-y-auto bg-white border border-slate-200 rounded-xl p-2 space-y-1.5">
|
||||
{plans.map((p) => {
|
||||
const pids: string[] = [p.inr_plan_id, p.usd_plan_id, p.id].filter(Boolean);
|
||||
const pids: string[] = [p.inr_plan_id, p.usd_plan_id, p.eur_plan_id, p.id].filter(Boolean);
|
||||
const checked = pids.some((id) => data.applicablePlanIds.includes(id));
|
||||
return (
|
||||
<label key={p.base_code || p.code} className="flex items-center gap-2 text-xs text-slate-700 cursor-pointer">
|
||||
|
|
@ -295,19 +377,51 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
|||
<span className="text-xs font-bold text-slate-700">Block 4: Conditions & Usage Limits</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Min Spend (0=None)</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.minSpend}
|
||||
onChange={(e) => onChange('minSpend', e.target.value)}
|
||||
placeholder="0"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1.5">
|
||||
Minimum Cart Spend (0 = No Minimum)
|
||||
</label>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-2.5">
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-2 text-xs font-bold text-slate-400">₹</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.minSpend}
|
||||
onChange={(e) => onChange('minSpend', e.target.value)}
|
||||
placeholder="Min ₹ (INR)"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-2 text-xs font-bold text-slate-400">$</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.minSpendUsd}
|
||||
onChange={(e) => onChange('minSpendUsd', e.target.value)}
|
||||
placeholder="Min $ (USD)"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-2 text-xs font-bold text-slate-400">€</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.minSpendEur}
|
||||
onChange={(e) => onChange('minSpendEur', e.target.value)}
|
||||
placeholder="Min € (EUR)"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Global Usage Limit (0=None)</label>
|
||||
<input
|
||||
|
|
@ -319,19 +433,20 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
|||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center pt-5">
|
||||
<label className="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={data.firstOnly}
|
||||
onChange={(e) => onChange('firstOnly', e.target.checked)}
|
||||
className="accent-indigo-600 rounded"
|
||||
/>
|
||||
<span className="text-xs font-bold text-slate-700">
|
||||
First Purchase Only
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label className="flex items-center gap-2 cursor-pointer pt-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={data.firstOnly}
|
||||
onChange={(e) => onChange('firstOnly', e.target.checked)}
|
||||
className="accent-indigo-600 rounded"
|
||||
/>
|
||||
<span className="text-xs font-bold text-slate-700">
|
||||
First Purchase Only (Exclusive to new customers with 0 prior subscriptions)
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
|
|
|
|||
|
|
@ -199,11 +199,26 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
{/* Value */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
<div className="inline-flex items-center gap-1 font-extrabold text-slate-800 text-xs">
|
||||
{isPercent ? `${c.value}% OFF` : `₹${c.value} FLAT`}
|
||||
{isPercent ? (
|
||||
`${c.value}% OFF`
|
||||
) : (
|
||||
<div className="flex items-center gap-1.5 flex-wrap">
|
||||
<span>₹{c.value_inr ?? c.value}</span>
|
||||
{c.value_usd !== undefined && c.value_usd !== null && (
|
||||
<span className="text-slate-400 font-medium">/ ${c.value_usd}</span>
|
||||
)}
|
||||
{c.value_eur !== undefined && c.value_eur !== null && (
|
||||
<span className="text-slate-400 font-medium">/ €{c.value_eur}</span>
|
||||
)}
|
||||
<span className="text-[10px] font-bold text-slate-500">FLAT</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{hasCap && (
|
||||
<p className="text-[10px] text-slate-400 font-semibold mt-0.5">
|
||||
Cap: ₹{c.max_discount_limit}
|
||||
Cap: ₹{c.max_discount_inr ?? c.max_discount_limit}
|
||||
{c.max_discount_usd !== undefined && c.max_discount_usd !== null && ` / $${c.max_discount_usd}`}
|
||||
{c.max_discount_eur !== undefined && c.max_discount_eur !== null && ` / €${c.max_discount_eur}`}
|
||||
</p>
|
||||
)}
|
||||
<span className="block text-[9px] font-bold text-slate-400 capitalize mt-0.5">
|
||||
|
|
@ -261,9 +276,11 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
: 'Targeted Items'
|
||||
: 'Storewide'}
|
||||
</span>
|
||||
{c.min_purchase_amount > 0 && (
|
||||
{(c.min_purchase_amount > 0 || (c.min_purchase_inr && c.min_purchase_inr > 0)) && (
|
||||
<span className="text-[9px] font-bold px-1.5 py-0.5 rounded bg-blue-50 text-blue-700 border border-blue-200">
|
||||
Min: ₹{c.min_purchase_amount}
|
||||
Min: ₹{c.min_purchase_inr ?? c.min_purchase_amount}
|
||||
{c.min_purchase_usd !== undefined && c.min_purchase_usd !== null && c.min_purchase_usd > 0 && ` / $${c.min_purchase_usd}`}
|
||||
{c.min_purchase_eur !== undefined && c.min_purchase_eur !== null && c.min_purchase_eur > 0 && ` / €${c.min_purchase_eur}`}
|
||||
</span>
|
||||
)}
|
||||
{c.is_first_purchase_only && (
|
||||
|
|
|
|||
Loading…
Reference in New Issue