Compare commits
No commits in common. "main" and "fix/issue-14-module-category-display" have entirely different histories.
main
...
fix/issue-
172
src/App.tsx
172
src/App.tsx
|
|
@ -1,10 +1,9 @@
|
|||
import React, { useState, useEffect, useMemo } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import axios from 'axios';
|
||||
import { Database, RefreshCw, RefreshCcw, Menu, Sparkles } from 'lucide-react';
|
||||
import { API_BASE } from './services/api';
|
||||
import type { AdminTabType } from './types';
|
||||
import { normalizeCategory } from './utils/category';
|
||||
import { isAdminAccount, partitionUserLists } from './utils/roles';
|
||||
|
||||
// Modular Components
|
||||
import { AdminSidebar } from './components/layout/AdminSidebar';
|
||||
|
|
@ -57,7 +56,9 @@ export function extractErrorMessage(err: any, fallback: string = 'An error occur
|
|||
export default function App() {
|
||||
const [userToken, setUserToken] = useState<string | null>(localStorage.getItem('access_token'));
|
||||
const [loggedInUser, setLoggedInUser] = useState<any>(null);
|
||||
const isAdmin = isAdminAccount(loggedInUser);
|
||||
const isAdmin = Boolean(
|
||||
loggedInUser?.roles?.some((role: string) => role === 'super_admin' || role === 'finance_admin' || role === 'admin')
|
||||
);
|
||||
|
||||
// Admin Login State
|
||||
const [adminAuthLoading, setAdminAuthLoading] = useState(false);
|
||||
|
|
@ -105,8 +106,6 @@ export default function App() {
|
|||
const [editModuleName, setEditModuleName] = useState<string>('');
|
||||
const [editModuleDesc, setEditModuleDesc] = useState<string>('');
|
||||
const [editModuleCategory, setEditModuleCategory] = useState<string>('point');
|
||||
const [editModuleIcon, setEditModuleIcon] = useState<string>('folder-outline');
|
||||
const [editModuleColor, setEditModuleColor] = useState<string>('#4F46E5');
|
||||
const [editModuleSaving, setEditModuleSaving] = useState<boolean>(false);
|
||||
|
||||
// Plans State
|
||||
|
|
@ -116,13 +115,11 @@ export default function App() {
|
|||
const [selectedEditPricePlan, setSelectedEditPricePlan] = useState<any | null>(null);
|
||||
const [editPriceInr, setEditPriceInr] = useState<string>('');
|
||||
const [editPriceUsd, setEditPriceUsd] = useState<string>('');
|
||||
const [editPriceEur, setEditPriceEur] = useState<string>('');
|
||||
const [editPlanName, setEditPlanName] = useState<string>('');
|
||||
const [editPlanDesc, setEditPlanDesc] = useState<string>('');
|
||||
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
|
||||
|
|
@ -137,14 +134,13 @@ export default function App() {
|
|||
const [createPlanDuration, setCreatePlanDuration] = useState<string>('yearly');
|
||||
const [createPlanPriceInr, setCreatePlanPriceInr] = useState<string>('');
|
||||
const [createPlanPriceUsd, setCreatePlanPriceUsd] = useState<string>('');
|
||||
const [createPlanPriceEur, setCreatePlanPriceEur] = useState<string>('');
|
||||
const [createPlanModuleIds, setCreatePlanModuleIds] = useState<string[]>([]);
|
||||
const [createPlanSaving, setCreatePlanSaving] = useState<boolean>(false);
|
||||
const [createPlanError, setCreatePlanError] = useState<string | null>(null);
|
||||
|
||||
// Coupons State
|
||||
const [adminCouponsList, setAdminCouponsList] = useState<any[]>([]);
|
||||
const [couponFilterStatus, setCouponFilterStatus] = useState<'all' | 'active' | 'scheduled' | 'fully_redeemed' | 'expired'>('all');
|
||||
const [couponFilterStatus, setCouponFilterStatus] = useState<'all' | 'active' | 'scheduled' | 'expired'>('all');
|
||||
const [couponSearchQuery, setCouponSearchQuery] = useState<string>('');
|
||||
|
||||
// Unified Coupon Modal State
|
||||
|
|
@ -155,11 +151,7 @@ export default function App() {
|
|||
category: 'general',
|
||||
discountType: 'percentage',
|
||||
discountValue: '20',
|
||||
discountValueUsd: '',
|
||||
discountValueEur: '',
|
||||
maxDiscountCap: '0',
|
||||
maxDiscountCapUsd: '',
|
||||
maxDiscountCapEur: '',
|
||||
description: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
|
|
@ -167,10 +159,7 @@ export default function App() {
|
|||
applicablePlanIds: [],
|
||||
applicableModuleIds: [],
|
||||
minSpend: '0',
|
||||
minSpendUsd: '',
|
||||
minSpendEur: '',
|
||||
usageLimit: '0',
|
||||
perUserLimit: '',
|
||||
firstOnly: false,
|
||||
});
|
||||
const [couponSaving, setCouponSaving] = useState<boolean>(false);
|
||||
|
|
@ -186,10 +175,6 @@ export default function App() {
|
|||
// Admins & Practitioners
|
||||
const [adminsList, setAdminsList] = useState<any[]>([]);
|
||||
const [practitionersList, setPractitionersList] = useState<any[]>([]);
|
||||
const { customers: customersList, adminAccounts: resolvedAdminsList } = useMemo(
|
||||
() => partitionUserLists(practitionersList, adminsList),
|
||||
[practitionersList, adminsList]
|
||||
);
|
||||
const [createAdminEmail, setCreateAdminEmail] = useState('');
|
||||
const [createAdminPassword, setCreateAdminPassword] = useState('');
|
||||
const [createAdminName, setCreateAdminName] = useState('');
|
||||
|
|
@ -548,8 +533,6 @@ export default function App() {
|
|||
setEditModuleName(mod.name || '');
|
||||
setEditModuleDesc(mod.description || '');
|
||||
setEditModuleCategory(normalizeCategory(mod.category));
|
||||
setEditModuleIcon(mod.icon || 'folder-outline');
|
||||
setEditModuleColor(mod.color || '#4F46E5');
|
||||
};
|
||||
|
||||
const handleSaveModuleDetails = async (e: React.FormEvent) => {
|
||||
|
|
@ -557,8 +540,6 @@ export default function App() {
|
|||
if (!selectedEditModule || !userToken) return;
|
||||
setEditModuleSaving(true);
|
||||
const normalizedCat = normalizeCategory(editModuleCategory);
|
||||
const nextIcon = editModuleIcon.trim() || 'folder-outline';
|
||||
const nextColor = editModuleColor.trim() || '#4F46E5';
|
||||
try {
|
||||
await axios.put(
|
||||
`${API_BASE}/api/admin/modules/${selectedEditModule.id}`,
|
||||
|
|
@ -566,22 +547,13 @@ export default function App() {
|
|||
name: editModuleName,
|
||||
description: editModuleDesc,
|
||||
category: normalizedCat,
|
||||
icon: nextIcon,
|
||||
color: nextColor,
|
||||
},
|
||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
||||
);
|
||||
setAdminModulesList((prev) =>
|
||||
prev.map((m) =>
|
||||
m.id === selectedEditModule.id
|
||||
? {
|
||||
...m,
|
||||
name: editModuleName,
|
||||
description: editModuleDesc,
|
||||
category: normalizedCat,
|
||||
icon: nextIcon,
|
||||
color: nextColor,
|
||||
}
|
||||
? { ...m, name: editModuleName, description: editModuleDesc, category: normalizedCat }
|
||||
: m
|
||||
)
|
||||
);
|
||||
|
|
@ -623,17 +595,11 @@ export default function App() {
|
|||
setSelectedEditPricePlan(plan);
|
||||
setEditPriceInr(String(plan.price_inr ?? ''));
|
||||
setEditPriceUsd(String(plan.price_usd ?? ''));
|
||||
setEditPriceEur(String(plan.price_eur ?? plan.price_usd ?? ''));
|
||||
setEditPlanName(plan.name || '');
|
||||
setEditPlanDesc(plan.description || '');
|
||||
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) => {
|
||||
|
|
@ -641,36 +607,25 @@ export default function App() {
|
|||
if (!selectedEditPricePlan || !userToken) return;
|
||||
const inrVal = parseFloat(editPriceInr);
|
||||
const usdVal = parseFloat(editPriceUsd);
|
||||
const eurVal = editPriceEur.trim() ? parseFloat(editPriceEur) : usdVal;
|
||||
if (isNaN(inrVal) || inrVal < 0 || isNaN(usdVal) || usdVal < 0 || isNaN(eurVal) || eurVal < 0) {
|
||||
if (isNaN(inrVal) || inrVal < 0 || isNaN(usdVal) || usdVal < 0) {
|
||||
alert('Please enter valid positive pricing values.');
|
||||
return;
|
||||
}
|
||||
setEditPriceSaving(true);
|
||||
try {
|
||||
const isEditableBundle =
|
||||
selectedEditPricePlan.plan_type === 'bundle' ||
|
||||
selectedEditPricePlan.base_code === 'PATTERN_CORE' ||
|
||||
selectedEditPricePlan.base_code === 'NUTRITION_CORE';
|
||||
await axios.put(
|
||||
`${API_BASE}/api/admin/plans/${selectedEditPricePlan.base_code}/pricing`,
|
||||
{
|
||||
price_inr: inrVal,
|
||||
price_usd: usdVal,
|
||||
price_eur: eurVal,
|
||||
name: editPlanName.trim() || undefined,
|
||||
description: editPlanDesc.trim() || undefined,
|
||||
badge_text: editPlanBadge.trim() || undefined,
|
||||
heading: editPlanHeading.trim() || undefined,
|
||||
subtitle: editPlanSubtitle.trim() || undefined,
|
||||
module_ids: isEditableBundle ? editPlanModuleIds : undefined,
|
||||
},
|
||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
||||
);
|
||||
const updatedBundleModules =
|
||||
isEditableBundle
|
||||
? adminModulesList.filter((m) => editPlanModuleIds.includes(m.id))
|
||||
: undefined;
|
||||
setAdminPlansList((prev) =>
|
||||
prev.map((p) =>
|
||||
p.base_code === selectedEditPricePlan.base_code
|
||||
|
|
@ -683,12 +638,6 @@ export default function App() {
|
|||
subtitle: editPlanSubtitle.trim() || selectedEditPricePlan.subtitle,
|
||||
price_inr: inrVal,
|
||||
price_usd: usdVal,
|
||||
price_eur: eurVal,
|
||||
pricing_status:
|
||||
inrVal > 0 || usdVal > 0 || eurVal > 0 ? 'configured' : p.pricing_status,
|
||||
...(isEditableBundle
|
||||
? { module_ids: editPlanModuleIds, modules: updatedBundleModules }
|
||||
: {}),
|
||||
}
|
||||
: p
|
||||
)
|
||||
|
|
@ -716,7 +665,6 @@ export default function App() {
|
|||
setCreatePlanDuration('yearly');
|
||||
setCreatePlanPriceInr('');
|
||||
setCreatePlanPriceUsd('');
|
||||
setCreatePlanPriceEur('');
|
||||
setCreatePlanModuleIds([]);
|
||||
setCreatePlanError(null);
|
||||
setShowCreatePlanModal(true);
|
||||
|
|
@ -731,9 +679,8 @@ export default function App() {
|
|||
}
|
||||
const inrVal = parseFloat(createPlanPriceInr);
|
||||
const usdVal = parseFloat(createPlanPriceUsd);
|
||||
const eurVal = createPlanPriceEur.trim() ? parseFloat(createPlanPriceEur) : usdVal;
|
||||
if (isNaN(inrVal) || inrVal < 0 || isNaN(usdVal) || usdVal < 0 || isNaN(eurVal) || eurVal < 0) {
|
||||
setCreatePlanError('Please provide valid positive prices for INR, USD, and EUR.');
|
||||
if (isNaN(inrVal) || inrVal < 0 || isNaN(usdVal) || usdVal < 0) {
|
||||
setCreatePlanError('Please provide valid positive prices for INR and USD.');
|
||||
return;
|
||||
}
|
||||
if (createPlanModuleIds.length === 0) {
|
||||
|
|
@ -756,7 +703,6 @@ export default function App() {
|
|||
billing_period: createPlanDuration,
|
||||
price_inr: inrVal,
|
||||
price_usd: usdVal,
|
||||
price_eur: eurVal,
|
||||
module_ids: createPlanModuleIds,
|
||||
is_featured: false,
|
||||
},
|
||||
|
|
@ -790,11 +736,7 @@ export default function App() {
|
|||
category: 'general',
|
||||
discountType: 'percentage',
|
||||
discountValue: '20',
|
||||
discountValueUsd: '',
|
||||
discountValueEur: '',
|
||||
maxDiscountCap: '0',
|
||||
maxDiscountCapUsd: '',
|
||||
maxDiscountCapEur: '',
|
||||
description: '',
|
||||
startDate: todayStr,
|
||||
endDate: nextYearStr,
|
||||
|
|
@ -802,10 +744,7 @@ export default function App() {
|
|||
applicablePlanIds: [],
|
||||
applicableModuleIds: [],
|
||||
minSpend: '0',
|
||||
minSpendUsd: '',
|
||||
minSpendEur: '',
|
||||
usageLimit: '0',
|
||||
perUserLimit: '',
|
||||
firstOnly: false,
|
||||
});
|
||||
setCouponModalMode('create');
|
||||
|
|
@ -821,23 +760,16 @@ export default function App() {
|
|||
code: c.code,
|
||||
category: c.coupon_category || 'general',
|
||||
discountType: c.discount_type || 'percentage',
|
||||
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) : '',
|
||||
discountValue: String(c.value ?? 0),
|
||||
maxDiscountCap: String(c.max_discount_limit ?? 0),
|
||||
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_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) : '',
|
||||
minSpend: String(c.min_purchase_amount ?? 0),
|
||||
usageLimit: String(c.usage_limit ?? 0),
|
||||
perUserLimit: c.per_user_limit !== undefined && c.per_user_limit !== null ? String(c.per_user_limit) : '',
|
||||
firstOnly: Boolean(c.is_first_purchase_only),
|
||||
});
|
||||
setCouponModalMode('edit');
|
||||
|
|
@ -855,49 +787,14 @@ 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 trimmedPerUser = couponFormData.perUserLimit.trim();
|
||||
if (trimmedPerUser === '') {
|
||||
alert('Per-user limit is required. Please enter 0 or greater.');
|
||||
setCouponSaving(false);
|
||||
return;
|
||||
}
|
||||
const parsedPerUser = Number(trimmedPerUser);
|
||||
if (!Number.isInteger(parsedPerUser) || parsedPerUser < 0) {
|
||||
alert('Per-user limit must be a whole number (0 or greater).');
|
||||
setCouponSaving(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const payload: any = {
|
||||
code: couponFormData.code.trim().toUpperCase(),
|
||||
discount_type: couponFormData.discountType,
|
||||
coupon_category: couponFormData.category,
|
||||
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,
|
||||
value: parseFloat(couponFormData.discountValue) || 0,
|
||||
max_discount_limit: parseFloat(couponFormData.maxDiscountCap) || 0,
|
||||
usage_limit: parseInt(couponFormData.usageLimit) || 0,
|
||||
per_user_limit: parsedPerUser,
|
||||
min_purchase_amount: minInr,
|
||||
min_purchase_inr: minInr,
|
||||
min_purchase_usd: minUsd,
|
||||
min_purchase_eur: minEur,
|
||||
min_purchase_amount: parseFloat(couponFormData.minSpend) || 0,
|
||||
is_first_purchase_only: couponFormData.firstOnly,
|
||||
is_active: true,
|
||||
description: couponFormData.description.trim() || undefined,
|
||||
|
|
@ -1094,10 +991,10 @@ export default function App() {
|
|||
modules: adminModulesList.length,
|
||||
plans: adminPlansList.length,
|
||||
coupons: adminCouponsList.length,
|
||||
customers: customersList.length,
|
||||
customers: practitionersList.length,
|
||||
subscriptions: usersSubscriptions.length,
|
||||
payments: rzpPayments.length,
|
||||
admins: resolvedAdminsList.length,
|
||||
admins: adminsList.length,
|
||||
}}
|
||||
isCollapsed={isSidebarCollapsed}
|
||||
onToggleCollapse={() => {
|
||||
|
|
@ -1180,9 +1077,9 @@ export default function App() {
|
|||
{adminSubTab === 'overview' && (
|
||||
<SyncOverview
|
||||
stats={{
|
||||
totalUsers: customersList.length,
|
||||
totalUsers: practitionersList.length + adminsList.length,
|
||||
subscriptions: usersSubscriptions.length,
|
||||
superAdmins: resolvedAdminsList.length,
|
||||
superAdmins: adminsList.length,
|
||||
payments: rzpPayments.length,
|
||||
}}
|
||||
adminLogs={adminLogs}
|
||||
|
|
@ -1249,7 +1146,7 @@ export default function App() {
|
|||
|
||||
{adminSubTab === 'customers' && (
|
||||
<CustomersTab
|
||||
customers={customersList}
|
||||
customers={practitionersList}
|
||||
currentPage={customersPage}
|
||||
perPage={customersPerPage}
|
||||
onPageChange={setCustomersPage}
|
||||
|
|
@ -1288,7 +1185,7 @@ export default function App() {
|
|||
|
||||
{adminSubTab === 'admins' && (
|
||||
<AdminsTab
|
||||
admins={resolvedAdminsList}
|
||||
admins={adminsList}
|
||||
name={createAdminName}
|
||||
email={createAdminEmail}
|
||||
password={createAdminPassword}
|
||||
|
|
@ -1320,7 +1217,7 @@ export default function App() {
|
|||
downloadingReport={reportDownloading}
|
||||
successMessage={reportExportSuccess}
|
||||
errorMessage={reportExportError}
|
||||
totalUsers={customersList.length}
|
||||
totalUsers={practitionersList.length + adminsList.length}
|
||||
totalPayments={rzpPayments.length}
|
||||
totalSubscriptions={usersSubscriptions.length}
|
||||
totalCoupons={adminCouponsList.length}
|
||||
|
|
@ -1340,13 +1237,10 @@ export default function App() {
|
|||
name={editModuleName}
|
||||
description={editModuleDesc}
|
||||
category={editModuleCategory}
|
||||
icon={editModuleIcon}
|
||||
color={editModuleColor}
|
||||
saving={editModuleSaving}
|
||||
onNameChange={setEditModuleName}
|
||||
onDescriptionChange={setEditModuleDesc}
|
||||
onIconChange={setEditModuleIcon}
|
||||
onColorChange={setEditModuleColor}
|
||||
onCategoryChange={setEditModuleCategory}
|
||||
onSave={handleSaveModuleDetails}
|
||||
onClose={() => setSelectedEditModule(null)}
|
||||
/>
|
||||
|
|
@ -1363,7 +1257,6 @@ export default function App() {
|
|||
duration={createPlanDuration}
|
||||
priceInr={createPlanPriceInr}
|
||||
priceUsd={createPlanPriceUsd}
|
||||
priceEur={createPlanPriceEur}
|
||||
selectedModuleIds={createPlanModuleIds}
|
||||
allModules={adminModulesList}
|
||||
saving={createPlanSaving}
|
||||
|
|
@ -1377,13 +1270,7 @@ export default function App() {
|
|||
onTypeChange={setCreatePlanType}
|
||||
onDurationChange={setCreatePlanDuration}
|
||||
onPriceInrChange={setCreatePlanPriceInr}
|
||||
onPriceUsdChange={(v) => {
|
||||
setCreatePlanPriceUsd(v);
|
||||
if (!createPlanPriceEur || createPlanPriceEur === createPlanPriceUsd) {
|
||||
setCreatePlanPriceEur(v);
|
||||
}
|
||||
}}
|
||||
onPriceEurChange={setCreatePlanPriceEur}
|
||||
onPriceUsdChange={setCreatePlanPriceUsd}
|
||||
onToggleModule={(id) =>
|
||||
setCreatePlanModuleIds((prev) =>
|
||||
prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id]
|
||||
|
|
@ -1404,9 +1291,6 @@ export default function App() {
|
|||
subtitle={editPlanSubtitle}
|
||||
priceInr={editPriceInr}
|
||||
priceUsd={editPriceUsd}
|
||||
priceEur={editPriceEur}
|
||||
allModules={adminModulesList}
|
||||
moduleIds={editPlanModuleIds}
|
||||
saving={editPriceSaving}
|
||||
onNameChange={setEditPlanName}
|
||||
onDescChange={setEditPlanDesc}
|
||||
|
|
@ -1415,14 +1299,6 @@ export default function App() {
|
|||
onSubtitleChange={setEditPlanSubtitle}
|
||||
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)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -6,11 +6,7 @@ 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;
|
||||
|
|
@ -18,10 +14,7 @@ export interface CouponFormData {
|
|||
applicablePlanIds: string[];
|
||||
applicableModuleIds: string[];
|
||||
minSpend: string;
|
||||
minSpendUsd: string;
|
||||
minSpendEur: string;
|
||||
usageLimit: string;
|
||||
perUserLimit: string;
|
||||
firstOnly: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +105,7 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Discount Type</label>
|
||||
<select
|
||||
|
|
@ -121,112 +114,36 @@ 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>
|
||||
|
||||
{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 pl-3 pr-7 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
|
||||
/>
|
||||
<span className="absolute right-3 top-1/2 -translate-y-1/2 text-xs font-bold text-slate-400 pointer-events-none">%</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>
|
||||
<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>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
|
@ -319,7 +236,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.eur_plan_id, p.id].filter(Boolean);
|
||||
const pids: string[] = [p.inr_plan_id, p.usd_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">
|
||||
|
|
@ -378,55 +295,21 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
|||
<span className="text-xs font-bold text-slate-700">Block 4: Conditions & Usage Limits</span>
|
||||
</div>
|
||||
|
||||
<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-3 gap-3 pt-1 items-start">
|
||||
<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">
|
||||
Total Usage Limit
|
||||
</label>
|
||||
<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>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Global Usage Limit (0=None)</label>
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
|
|
@ -435,47 +318,20 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
|||
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"
|
||||
/>
|
||||
<p className="text-[10px] text-slate-400 font-medium mt-1">
|
||||
0 = Unlimited total uses
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">
|
||||
Per-User Limit *
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
required
|
||||
min="0"
|
||||
value={data.perUserLimit}
|
||||
onChange={(e) => onChange('perUserLimit', e.target.value)}
|
||||
placeholder="e.g. 1"
|
||||
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"
|
||||
/>
|
||||
<p
|
||||
className={`text-[10px] font-medium mt-1 ${
|
||||
data.perUserLimit.trim() === '0' ? 'text-rose-600 font-semibold' : 'text-slate-400'
|
||||
}`}
|
||||
>
|
||||
{data.perUserLimit.trim() === '0'
|
||||
? '0 = Blocked for all users'
|
||||
: '0 = Blocked · 1+ = Uses per user'}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center sm:pt-7">
|
||||
<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 */}
|
||||
|
|
|
|||
|
|
@ -2,41 +2,13 @@ import React, { useState } from 'react';
|
|||
import { Ticket, Plus, Check, Copy, Edit, Trash2 } from 'lucide-react';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
|
||||
type CouponStatusFilter = 'all' | 'active' | 'scheduled' | 'fully_redeemed' | 'expired';
|
||||
|
||||
const STATUS_LABELS: Record<Exclude<CouponStatusFilter, 'all'>, string> = {
|
||||
active: 'Active',
|
||||
scheduled: 'Scheduled',
|
||||
fully_redeemed: 'Fully Redeemed',
|
||||
expired: 'Expired',
|
||||
};
|
||||
|
||||
interface CouponStatusFields {
|
||||
usage_limit?: number;
|
||||
usage_count?: number;
|
||||
schedule_status?: string;
|
||||
is_active?: boolean;
|
||||
}
|
||||
|
||||
const getEffectiveCouponStatus = (coupon: CouponStatusFields): string => {
|
||||
const usageLimit = coupon.usage_limit || 0;
|
||||
const usageCount = coupon.usage_count || 0;
|
||||
if (coupon.schedule_status === 'fully_redeemed') {
|
||||
return 'fully_redeemed';
|
||||
}
|
||||
if (coupon.is_active && usageLimit > 0 && usageCount >= usageLimit) {
|
||||
return 'fully_redeemed';
|
||||
}
|
||||
return coupon.schedule_status ?? '';
|
||||
};
|
||||
|
||||
interface CouponsTabProps {
|
||||
coupons: any[];
|
||||
filterStatus: CouponStatusFilter;
|
||||
filterStatus: 'all' | 'active' | 'scheduled' | 'expired';
|
||||
searchQuery: string;
|
||||
currentPage: number;
|
||||
perPage: number;
|
||||
onFilterStatusChange: (status: CouponStatusFilter) => void;
|
||||
onFilterStatusChange: (status: 'all' | 'active' | 'scheduled' | 'expired') => void;
|
||||
onSearchChange: (query: string) => void;
|
||||
onPageChange: (page: number) => void;
|
||||
onPerPageChange: (perPage: number) => void;
|
||||
|
|
@ -70,7 +42,7 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
};
|
||||
|
||||
const filteredCoupons = coupons.filter((c) => {
|
||||
if (filterStatus !== 'all' && getEffectiveCouponStatus(c) !== filterStatus) return false;
|
||||
if (filterStatus !== 'all' && c.schedule_status !== filterStatus) return false;
|
||||
if (searchQuery.trim()) {
|
||||
const q = searchQuery.toLowerCase();
|
||||
return (
|
||||
|
|
@ -122,7 +94,7 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 bg-slate-50/80 border border-slate-200/60 rounded-2xl p-4">
|
||||
{/* Filter Pills */}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{(['all', 'active', 'scheduled', 'fully_redeemed', 'expired'] as const).map((status) => (
|
||||
{(['all', 'active', 'scheduled', 'expired'] as const).map((status) => (
|
||||
<button
|
||||
key={status}
|
||||
type="button"
|
||||
|
|
@ -130,7 +102,7 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
onFilterStatusChange(status);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer ${
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-bold capitalize transition-all cursor-pointer ${
|
||||
filterStatus === status
|
||||
? 'bg-indigo-600 text-white shadow-sm'
|
||||
: 'bg-white text-slate-600 border border-slate-200 hover:bg-slate-100 shadow-sm'
|
||||
|
|
@ -138,7 +110,7 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
>
|
||||
{status === 'all'
|
||||
? `All (${coupons.length})`
|
||||
: `${STATUS_LABELS[status]} (${coupons.filter((c) => getEffectiveCouponStatus(c) === status).length})`}
|
||||
: `${status} (${coupons.filter((c) => c.schedule_status === status).length})`}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
|
@ -192,13 +164,6 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
const hasCap = isPercent && c.max_discount_limit > 0;
|
||||
const usageLimit = c.usage_limit || 0;
|
||||
const usageCount = c.usage_count || 0;
|
||||
const effectiveStatus = getEffectiveCouponStatus(c);
|
||||
const statusLabel =
|
||||
effectiveStatus === 'fully_redeemed'
|
||||
? 'Fully Redeemed'
|
||||
: effectiveStatus;
|
||||
const hasPerUserLimit =
|
||||
c.per_user_limit !== undefined && c.per_user_limit !== null;
|
||||
const hasSpecific =
|
||||
(c.applicable_plan_ids && c.applicable_plan_ids.length > 0) ||
|
||||
(c.applicable_module_ids && c.applicable_module_ids.length > 0);
|
||||
|
|
@ -234,26 +199,11 @@ 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`
|
||||
) : (
|
||||
<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>
|
||||
)}
|
||||
{isPercent ? `${c.value}% OFF` : `₹${c.value} FLAT`}
|
||||
</div>
|
||||
{hasCap && (
|
||||
<p className="text-[10px] text-slate-400 font-semibold mt-0.5">
|
||||
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}`}
|
||||
Cap: ₹{c.max_discount_limit}
|
||||
</p>
|
||||
)}
|
||||
<span className="block text-[9px] font-bold text-slate-400 capitalize mt-0.5">
|
||||
|
|
@ -265,21 +215,19 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
<span
|
||||
className={`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-extrabold tracking-wider uppercase border ${
|
||||
effectiveStatus === 'active'
|
||||
c.schedule_status === 'active'
|
||||
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
||||
: effectiveStatus === 'scheduled'
|
||||
: c.schedule_status === 'scheduled'
|
||||
? 'bg-amber-50 text-amber-700 border-amber-200'
|
||||
: effectiveStatus === 'fully_redeemed'
|
||||
? 'bg-indigo-50 text-indigo-700 border-indigo-200'
|
||||
: effectiveStatus === 'expired'
|
||||
: c.schedule_status === 'expired'
|
||||
? 'bg-rose-50 text-rose-700 border-rose-200'
|
||||
: 'bg-slate-100 text-slate-500 border-slate-200'
|
||||
}`}
|
||||
>
|
||||
{effectiveStatus === 'active' && (
|
||||
{c.schedule_status === 'active' && (
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse" />
|
||||
)}
|
||||
{statusLabel}
|
||||
{c.schedule_status}
|
||||
</span>
|
||||
<p className="text-[10px] text-slate-400 font-medium mt-1">
|
||||
{c.start_date?.split('T')[0] || '—'} → {c.end_date?.split('T')[0] || '—'}
|
||||
|
|
@ -301,17 +249,6 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
) : (
|
||||
<span className="text-[9px] text-slate-400 font-semibold">Unlimited</span>
|
||||
)}
|
||||
{hasPerUserLimit && (
|
||||
<span
|
||||
className={`block text-[9px] font-bold mt-1 ${
|
||||
c.per_user_limit === 0 ? 'text-rose-600' : 'text-slate-500'
|
||||
}`}
|
||||
>
|
||||
{c.per_user_limit === 0
|
||||
? 'Per user: 0 (Blocked)'
|
||||
: `Max ${c.per_user_limit} / user`}
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
|
||||
{/* Scope & Conditions */}
|
||||
|
|
@ -324,11 +261,9 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
|||
: 'Targeted Items'
|
||||
: 'Storewide'}
|
||||
</span>
|
||||
{(c.min_purchase_amount > 0 || (c.min_purchase_inr && c.min_purchase_inr > 0)) && (
|
||||
{c.min_purchase_amount > 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_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}`}
|
||||
Min: ₹{c.min_purchase_amount}
|
||||
</span>
|
||||
)}
|
||||
{c.is_first_purchase_only && (
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
|||
<Users className="h-5 w-5" />
|
||||
</div>
|
||||
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-indigo-50 text-indigo-700 border border-indigo-100">
|
||||
{totalUsers} Total Customers
|
||||
{totalUsers} Total Users
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
|
|
@ -136,7 +136,7 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
|||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1.5">
|
||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
||||
<span className="text-slate-400 font-semibold">Included Columns:</span>
|
||||
<span className="font-semibold text-slate-700">User ID, Email, Name, Phone, Role, Spend (INR/USD/EUR)</span>
|
||||
<span className="font-semibold text-slate-700">User ID, Email, Name, Phone, Role, Spend</span>
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
||||
<span className="text-slate-400 font-semibold">Target Audience:</span>
|
||||
|
|
@ -234,7 +234,7 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
|||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1.5">
|
||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
||||
<span className="text-slate-400 font-semibold">Metrics Included:</span>
|
||||
<span className="font-semibold text-slate-700">Country, Plan Currency, Status, Days Remaining</span>
|
||||
<span className="font-semibold text-slate-700">Remaining Days, Expiration, Plan Code</span>
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
||||
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
||||
|
|
@ -283,7 +283,7 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
|||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1.5">
|
||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
||||
<span className="text-slate-400 font-semibold">Campaign Metrics:</span>
|
||||
<span className="font-semibold text-slate-700">Code, Category, Discounts & Caps (INR/USD/EUR)</span>
|
||||
<span className="font-semibold text-slate-700">Code, Category, Discount INR, User</span>
|
||||
</div>
|
||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
||||
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
||||
|
|
|
|||
|
|
@ -3,29 +3,15 @@ import { XCircle, RefreshCw } from 'lucide-react';
|
|||
import type { ModuleItem } from '../../types';
|
||||
import { normalizeCategory } from '../../utils/category';
|
||||
|
||||
const ICON_PRESETS = [
|
||||
'medkit-outline',
|
||||
'heart-outline',
|
||||
'woman-outline',
|
||||
'ear-outline',
|
||||
'body-outline',
|
||||
'leaf-outline',
|
||||
'pulse-outline',
|
||||
'folder-outline',
|
||||
];
|
||||
|
||||
interface EditModuleModalProps {
|
||||
module: ModuleItem | null;
|
||||
name: string;
|
||||
description: string;
|
||||
category: string;
|
||||
icon: string;
|
||||
color: string;
|
||||
saving: boolean;
|
||||
onNameChange: (val: string) => void;
|
||||
onDescriptionChange: (val: string) => void;
|
||||
onIconChange: (val: string) => void;
|
||||
onColorChange: (val: string) => void;
|
||||
onCategoryChange: (val: string) => void;
|
||||
onSave: (e: React.FormEvent) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
|
@ -35,13 +21,10 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
|||
name,
|
||||
description,
|
||||
category,
|
||||
icon,
|
||||
color,
|
||||
saving,
|
||||
onNameChange,
|
||||
onDescriptionChange,
|
||||
onIconChange,
|
||||
onColorChange,
|
||||
onCategoryChange,
|
||||
onSave,
|
||||
onClose,
|
||||
}) => {
|
||||
|
|
@ -54,7 +37,7 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
|||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
className="h-8 w-8 rounded-lg flex items-center justify-center font-bold text-white text-xs"
|
||||
style={{ backgroundColor: color || (module as any).color || '#4F46E5' }}
|
||||
style={{ backgroundColor: (module as any).color || '#6366F1' }}
|
||||
>
|
||||
{(module.name || 'M')[0].toUpperCase()}
|
||||
</div>
|
||||
|
|
@ -86,16 +69,17 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
|||
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Category</label>
|
||||
<input
|
||||
type="text"
|
||||
readOnly
|
||||
disabled
|
||||
<select
|
||||
value={normalizeCategory(category)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-500 cursor-not-allowed"
|
||||
/>
|
||||
<p className="text-[10px] text-slate-400 mt-1">
|
||||
Category is fixed to keep core Complete Pack entitlements consistent. Use Plans & Pricing to create custom combo bundles.
|
||||
</p>
|
||||
onChange={(e) => onCategoryChange(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 cursor-pointer"
|
||||
>
|
||||
<option value="Points">Points</option>
|
||||
<option value="Patterns">Patterns</option>
|
||||
<option value="Nutrition">Nutrition</option>
|
||||
<option value="Therapeutics">Therapeutics</option>
|
||||
<option value="General">General</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
|
@ -108,55 +92,6 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
|||
/>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Mobile Icon (Ionicons)</label>
|
||||
<input
|
||||
type="text"
|
||||
value={icon}
|
||||
onChange={(e) => onIconChange(e.target.value)}
|
||||
placeholder="e.g. medkit-outline"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-mono text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Mobile Accent Color</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<input
|
||||
type="color"
|
||||
value={/^#[0-9A-Fa-f]{6}$/.test(color) ? color : '#4F46E5'}
|
||||
onChange={(e) => onColorChange(e.target.value)}
|
||||
className="h-9 w-10 rounded-lg border border-slate-200 cursor-pointer p-0.5 bg-white"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={color}
|
||||
onChange={(e) => onColorChange(e.target.value)}
|
||||
placeholder="#4F46E5"
|
||||
className="flex-1 bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-mono text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{ICON_PRESETS.map((preset) => (
|
||||
<button
|
||||
key={preset}
|
||||
type="button"
|
||||
onClick={() => onIconChange(preset)}
|
||||
className={`px-2 py-1 rounded-lg text-[10px] font-mono border transition-colors cursor-pointer ${
|
||||
icon === preset
|
||||
? 'bg-indigo-50 text-indigo-700 border-indigo-300 font-bold'
|
||||
: 'bg-slate-50 text-slate-600 border-slate-200 hover:bg-slate-100'
|
||||
}`}
|
||||
>
|
||||
{preset}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 pt-2">
|
||||
<button
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -163,20 +163,17 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
const activeModule = modules.find(m => m.code === moduleCode) || null;
|
||||
|
||||
// 1. Load Categories
|
||||
const fetchCategories = async (modCode = moduleCode, selectCatCode?: string, selectDisCode?: string) => {
|
||||
const fetchCategories = async (modCode = moduleCode, selectCatCode?: string) => {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
try {
|
||||
const cats = await moduleBuilderService.getCategories(modCode);
|
||||
setCategories(cats || []);
|
||||
if (cats && cats.length > 0) {
|
||||
const nextCat = (selectCatCode && cats.some(c => c.category_code === selectCatCode))
|
||||
? selectCatCode
|
||||
: (cats.some(c => c.category_code === selectedCategoryCode) ? selectedCategoryCode : cats[0].category_code);
|
||||
const nextCat = selectCatCode || (cats.some(c => c.category_code === selectedCategoryCode) ? selectedCategoryCode : cats[0].category_code);
|
||||
setSelectedCategoryCode(nextCat);
|
||||
const catObj = cats.find(c => c.category_code === nextCat);
|
||||
setCategoryOverview(catObj?.overview || '');
|
||||
await fetchDiseases(nextCat, selectDisCode);
|
||||
} else {
|
||||
setSelectedCategoryCode('');
|
||||
setCategoryOverview('');
|
||||
|
|
@ -220,10 +217,6 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
// Explicitly selected disease (e.g. after modal creation or save)
|
||||
setSelectedDiseaseCode(selectDisCode);
|
||||
setIsCreatingNewDisease(false);
|
||||
await fetchDiseaseDetail(catCode, selectDisCode);
|
||||
} else if (!selectDisCode && disList.length > 0 && selectedDiseaseCode && disList.some(d => d.disease_code === selectedDiseaseCode)) {
|
||||
// Retain currently selected disease if it still exists in list
|
||||
await fetchDiseaseDetail(catCode, selectedDiseaseCode);
|
||||
} else {
|
||||
// Keep blank by default on load so user actively picks or starts fresh
|
||||
setSelectedDiseaseCode('');
|
||||
|
|
@ -239,6 +232,14 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedCategoryCode) {
|
||||
const catObj = categories.find(c => c.category_code === selectedCategoryCode);
|
||||
setCategoryOverview(catObj?.overview || '');
|
||||
fetchDiseases(selectedCategoryCode);
|
||||
}
|
||||
}, [selectedCategoryCode]);
|
||||
|
||||
// 3. Load Disease Details & Patterns when disease changes
|
||||
const fetchDiseaseDetail = async (catCode: string, disCode: string) => {
|
||||
if (!catCode || !disCode) {
|
||||
|
|
@ -290,7 +291,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
if (selectedCategoryCode && selectedDiseaseCode && !isCreatingNewDisease) {
|
||||
fetchDiseaseDetail(selectedCategoryCode, selectedDiseaseCode);
|
||||
}
|
||||
}, [selectedCategoryCode, selectedDiseaseCode]);
|
||||
}, [selectedDiseaseCode]);
|
||||
|
||||
// Revert / Reset to Blank Form
|
||||
const handleResetToBlankForm = () => {
|
||||
|
|
@ -348,7 +349,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
setNewCategoryName('');
|
||||
setModalCatError(null);
|
||||
setSuccessMsg(`Category "${title}" created successfully!`);
|
||||
await fetchCategories(moduleCode, code);
|
||||
await fetchCategories(code);
|
||||
} catch (err: any) {
|
||||
setModalCatError(formatApiError(err, 'Failed to create category. Please try again.'));
|
||||
} finally {
|
||||
|
|
@ -374,7 +375,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
try {
|
||||
await moduleBuilderService.deleteCategory(moduleCode, selectedCategoryCode);
|
||||
setSuccessMsg(`Category "${catName}" deleted successfully.`);
|
||||
await fetchCategories(moduleCode);
|
||||
await fetchCategories();
|
||||
} catch (err: any) {
|
||||
setError(formatApiError(err, 'Failed to delete category.'));
|
||||
} finally {
|
||||
|
|
@ -407,7 +408,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
setModalDisError(null);
|
||||
setError(null);
|
||||
try {
|
||||
const savedDis = await moduleBuilderService.saveDisease(moduleCode, selectedCategoryCode, {
|
||||
await moduleBuilderService.saveDisease(moduleCode, selectedCategoryCode, {
|
||||
category_code: selectedCategoryCode,
|
||||
disease_code: code,
|
||||
name: title,
|
||||
|
|
@ -419,8 +420,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
setModalDisError(null);
|
||||
setIsCreatingNewDisease(false);
|
||||
setSuccessMsg(`Disease "${title}" created successfully!`);
|
||||
const targetDisCode = savedDis?.disease_code || code;
|
||||
await fetchCategories(moduleCode, selectedCategoryCode, targetDisCode);
|
||||
await fetchDiseases(selectedCategoryCode, code);
|
||||
} catch (err: any) {
|
||||
setModalDisError(formatApiError(err, 'Failed to create disease. Please try again.'));
|
||||
} finally {
|
||||
|
|
@ -446,12 +446,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
try {
|
||||
await moduleBuilderService.deleteDisease(moduleCode, selectedCategoryCode, selectedDiseaseCode);
|
||||
setSuccessMsg(`Disease "${disName}" deleted.`);
|
||||
setSelectedDiseaseCode('');
|
||||
setDiseaseName('');
|
||||
setDiseaseOverview('');
|
||||
setPatterns([]);
|
||||
setIsCreatingNewDisease(false);
|
||||
await fetchCategories(moduleCode, selectedCategoryCode);
|
||||
await fetchDiseases(selectedCategoryCode);
|
||||
} catch (err: any) {
|
||||
setError(formatApiError(err, 'Failed to delete disease.'));
|
||||
} finally {
|
||||
|
|
@ -724,7 +719,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
setSelectedDiseaseCode(effectiveDiseaseCode);
|
||||
setSuccessMsg('All disease details and clinical patterns saved successfully!');
|
||||
setTimeout(() => setSuccessMsg(null), 4000);
|
||||
await fetchCategories(moduleCode, selectedCategoryCode, effectiveDiseaseCode);
|
||||
await fetchDiseases(selectedCategoryCode, effectiveDiseaseCode);
|
||||
} catch (err: any) {
|
||||
setError(formatApiError(err, 'Failed to save changes. Please check all fields and try again.'));
|
||||
} finally {
|
||||
|
|
@ -784,17 +779,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
setSuccessMsg(`Production bundle "${filename}" downloaded successfully!`);
|
||||
setTimeout(() => setSuccessMsg(null), 4500);
|
||||
} catch (err: any) {
|
||||
if (err?.response?.data instanceof Blob) {
|
||||
try {
|
||||
const text = await err.response.data.text();
|
||||
const parsed = JSON.parse(text);
|
||||
setError(parsed.detail || 'Failed to export module bundle package.');
|
||||
} catch {
|
||||
setError(formatApiError(err, 'Failed to export module bundle package.'));
|
||||
}
|
||||
} else {
|
||||
setError(formatApiError(err, 'Failed to export module bundle package.'));
|
||||
}
|
||||
setError(formatApiError(err, 'Failed to export module bundle package.'));
|
||||
} finally {
|
||||
setExportingZip(false);
|
||||
}
|
||||
|
|
@ -807,9 +792,8 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
return;
|
||||
}
|
||||
const confirmed = window.confirm(
|
||||
`Compile and sync module "${activeModule?.name || moduleCode}" directly to the server's content repository?\n\n` +
|
||||
`This will write compiled production files (module.json, templates, data, search_facets) into the local repository on the server.\n\n` +
|
||||
`Tip: To save the module files directly to your personal computer, use "Download Acupedia (.zip)" instead.`
|
||||
`Compile and sync module "${activeModule?.name || moduleCode}" directly to the local acupedia-content repository?\n\n` +
|
||||
`This will generate/update the module folder and register it in root config.json.`
|
||||
);
|
||||
if (!confirmed) return;
|
||||
|
||||
|
|
@ -1069,8 +1053,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
|
||||
await moduleBuilderService.importModuleJson(moduleCode, sampleContents);
|
||||
setSuccessMsg('Sample Gynecological Disorders template imported successfully!');
|
||||
fetchModules();
|
||||
await fetchCategories(moduleCode);
|
||||
await fetchCategories();
|
||||
} catch (err: any) {
|
||||
setError(formatApiError(err, 'Failed to import sample template data.'));
|
||||
} finally {
|
||||
|
|
@ -1119,8 +1102,9 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
key={m.code}
|
||||
type="button"
|
||||
onClick={() => handleSwitchModule(m.code)}
|
||||
className={`w-full text-left px-3.5 py-2.5 flex items-center justify-between hover:bg-indigo-50/50 transition-colors ${m.code === moduleCode ? 'bg-indigo-50/70 text-indigo-900 font-bold' : 'text-slate-700'
|
||||
}`}
|
||||
className={`w-full text-left px-3.5 py-2.5 flex items-center justify-between hover:bg-indigo-50/50 transition-colors ${
|
||||
m.code === moduleCode ? 'bg-indigo-50/70 text-indigo-900 font-bold' : 'text-slate-700'
|
||||
}`}
|
||||
>
|
||||
<div>
|
||||
<div className="text-xs font-bold flex items-center gap-1.5">
|
||||
|
|
@ -1255,10 +1239,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setShowExportMenu(false);
|
||||
handleExportZip();
|
||||
}}
|
||||
onClick={handleExportZip}
|
||||
disabled={exportingZip}
|
||||
className="w-full text-left px-3.5 py-2.5 hover:bg-indigo-50/50 flex items-start gap-2.5 transition-colors group"
|
||||
>
|
||||
|
|
@ -1268,27 +1249,24 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
Download Acupedia (.zip)
|
||||
</div>
|
||||
<div className="text-[10px] text-slate-400">
|
||||
Download complete package with module.json, templates/, & data/ to your computer
|
||||
Complete package with module.json, templates/, & data/
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setShowExportMenu(false);
|
||||
handleSyncContentRepo();
|
||||
}}
|
||||
onClick={handleSyncContentRepo}
|
||||
disabled={syncingRepo}
|
||||
className="w-full text-left px-3.5 py-2.5 hover:bg-emerald-50/50 flex items-start gap-2.5 transition-colors group"
|
||||
>
|
||||
<UploadCloud className="h-4 w-4 text-emerald-600 mt-0.5 shrink-0" />
|
||||
<div>
|
||||
<div className="text-xs font-bold text-slate-800 group-hover:text-emerald-600">
|
||||
Sync to Server Repository
|
||||
Sync to acupedia-content
|
||||
</div>
|
||||
<div className="text-[10px] text-slate-400">
|
||||
Compile and write directly to server content repository
|
||||
Save to disk & register in root config.json
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
|
|
@ -1420,12 +1398,8 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
<select
|
||||
value={selectedCategoryCode}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value;
|
||||
setSelectedCategoryCode(val);
|
||||
setSelectedCategoryCode(e.target.value);
|
||||
setError(null);
|
||||
const catObj = categories.find(c => c.category_code === val);
|
||||
setCategoryOverview(catObj?.overview || '');
|
||||
fetchDiseases(val);
|
||||
}}
|
||||
disabled={loading || categories.length === 0}
|
||||
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 cursor-pointer"
|
||||
|
|
@ -1649,10 +1623,11 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
{patterns.map((pat, idx) => (
|
||||
<div
|
||||
key={idx}
|
||||
className={`flex items-center gap-1 px-3 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer ${safePatternIndex === idx
|
||||
className={`flex items-center gap-1 px-3 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer ${
|
||||
safePatternIndex === idx
|
||||
? 'bg-indigo-600 text-white shadow-sm shadow-indigo-600/30'
|
||||
: 'bg-slate-100 hover:bg-slate-200 text-slate-700'
|
||||
}`}
|
||||
}`}
|
||||
onClick={() => {
|
||||
setActivePatternIndex(idx);
|
||||
if (error) setError(null);
|
||||
|
|
@ -1666,8 +1641,9 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
e.stopPropagation();
|
||||
handleRemovePattern(idx);
|
||||
}}
|
||||
className={`h-4 w-4 rounded-full flex items-center justify-center hover:bg-black/10 transition-colors ml-1 ${safePatternIndex === idx ? 'text-white' : 'text-slate-400 hover:text-slate-700'
|
||||
}`}
|
||||
className={`h-4 w-4 rounded-full flex items-center justify-center hover:bg-black/10 transition-colors ml-1 ${
|
||||
safePatternIndex === idx ? 'text-white' : 'text-slate-400 hover:text-slate-700'
|
||||
}`}
|
||||
title="Delete pattern"
|
||||
>
|
||||
<X className="h-2.5 w-2.5" />
|
||||
|
|
@ -1917,10 +1893,11 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
type="button"
|
||||
onClick={() => handleAddPointChip(pt)}
|
||||
disabled={isAdded}
|
||||
className={`text-[10px] font-bold px-2 py-0.5 rounded-lg border transition-all ${isAdded
|
||||
className={`text-[10px] font-bold px-2 py-0.5 rounded-lg border transition-all ${
|
||||
isAdded
|
||||
? 'bg-slate-200 text-slate-400 border-slate-200 cursor-default'
|
||||
: 'bg-white hover:bg-indigo-50 border-slate-200 hover:border-indigo-300 text-slate-700 hover:text-indigo-600'
|
||||
}`}
|
||||
}`}
|
||||
>
|
||||
+{pt}
|
||||
</button>
|
||||
|
|
@ -2086,10 +2063,11 @@ export const ModuleBuilderTabContent: React.FC = () => {
|
|||
key={idx}
|
||||
type="button"
|
||||
onClick={() => setPreviewPatternIdx(idx)}
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-bold transition-all ${previewPatternIdx === idx
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-bold transition-all ${
|
||||
previewPatternIdx === idx
|
||||
? 'bg-indigo-600 text-white shadow-xs'
|
||||
: 'bg-slate-100 hover:bg-slate-200 text-slate-700'
|
||||
}`}
|
||||
}`}
|
||||
>
|
||||
{p.name || `Pattern ${idx + 1}`}
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React, { useState, useMemo } from 'react';
|
||||
import { Receipt, Download, Mail, RefreshCw, Search, ArrowUpDown, ArrowDown, ArrowUp, X, Calendar, ChevronDown } from 'lucide-react';
|
||||
import { Receipt, Download, Mail, RefreshCw, Search, ArrowUpDown, ArrowDown, ArrowUp, X } from 'lucide-react';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
|
||||
interface PaymentsTabProps {
|
||||
|
|
@ -14,21 +14,6 @@ interface PaymentsTabProps {
|
|||
onShareInvoice: (id: string) => void;
|
||||
}
|
||||
|
||||
const MONTH_OPTIONS = [
|
||||
{ value: '01', label: 'January' },
|
||||
{ value: '02', label: 'February' },
|
||||
{ value: '03', label: 'March' },
|
||||
{ value: '04', label: 'April' },
|
||||
{ value: '05', label: 'May' },
|
||||
{ value: '06', label: 'June' },
|
||||
{ value: '07', label: 'July' },
|
||||
{ value: '08', label: 'August' },
|
||||
{ value: '09', label: 'September' },
|
||||
{ value: '10', label: 'October' },
|
||||
{ value: '11', label: 'November' },
|
||||
{ value: '12', label: 'December' },
|
||||
];
|
||||
|
||||
export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
||||
payments,
|
||||
currentPage,
|
||||
|
|
@ -42,59 +27,12 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
|||
}) => {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [sortOrder, setSortOrder] = useState<'desc' | 'asc'>('desc');
|
||||
const [selectedYear, setSelectedYear] = useState<string>('all');
|
||||
const [selectedMonth, setSelectedMonth] = useState<string>('all');
|
||||
const [isCustomYear, setIsCustomYear] = useState<boolean>(false);
|
||||
const [customYearInput, setCustomYearInput] = useState<string>('');
|
||||
|
||||
// Dynamically extract all available years from payments (with fallback to current year)
|
||||
const availableYears = useMemo(() => {
|
||||
const currentYear = new Date().getFullYear();
|
||||
const yearsSet = new Set<number>([currentYear]);
|
||||
for (const p of payments) {
|
||||
if (!p?.created_at) continue;
|
||||
const d = typeof p.created_at === 'number'
|
||||
? new Date(p.created_at * 1000)
|
||||
: new Date(p.created_at);
|
||||
|
||||
if (!isNaN(d.getTime())) {
|
||||
yearsSet.add(d.getFullYear());
|
||||
}
|
||||
}
|
||||
|
||||
return Array.from(yearsSet).sort((a, b) => b - a);
|
||||
}, [payments]);
|
||||
|
||||
// Filter and Sort payments
|
||||
const processedPayments = useMemo(() => {
|
||||
let result = [...payments];
|
||||
|
||||
// Filter by Year
|
||||
if (selectedYear !== 'all') {
|
||||
result = result.filter((p: any) => {
|
||||
if (!p?.created_at) return false;
|
||||
const d = typeof p.created_at === 'number'
|
||||
? new Date(p.created_at * 1000)
|
||||
: new Date(p.created_at);
|
||||
if (isNaN(d.getTime())) return false;
|
||||
return d.getFullYear().toString() === selectedYear;
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by Month
|
||||
if (selectedMonth !== 'all') {
|
||||
result = result.filter((p: any) => {
|
||||
if (!p?.created_at) return false;
|
||||
const d = typeof p.created_at === 'number'
|
||||
? new Date(p.created_at * 1000)
|
||||
: new Date(p.created_at);
|
||||
if (isNaN(d.getTime())) return false;
|
||||
const m = String(d.getMonth() + 1).padStart(2, '0');
|
||||
return m === selectedMonth;
|
||||
});
|
||||
}
|
||||
|
||||
// Filter by Search Query
|
||||
// Filter
|
||||
if (searchQuery.trim()) {
|
||||
const q = searchQuery.toLowerCase().trim();
|
||||
result = result.filter((p: any) => {
|
||||
|
|
@ -126,17 +64,7 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
|||
});
|
||||
|
||||
return result;
|
||||
}, [payments, searchQuery, sortOrder, selectedYear, selectedMonth]);
|
||||
|
||||
const hasDateFilter = selectedYear !== 'all' || selectedMonth !== 'all';
|
||||
|
||||
const handleClearDateFilters = () => {
|
||||
setSelectedYear('all');
|
||||
setSelectedMonth('all');
|
||||
setIsCustomYear(false);
|
||||
setCustomYearInput('');
|
||||
onPageChange(1);
|
||||
};
|
||||
}, [payments, searchQuery, sortOrder]);
|
||||
|
||||
const totalFiltered = processedPayments.length;
|
||||
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
||||
|
|
@ -147,141 +75,35 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
|||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Search & Sort Controls Header */}
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 flex flex-col xl:flex-row justify-between items-stretch xl:items-center gap-3">
|
||||
{/* Left Side: Search & Date Filters */}
|
||||
<div className="flex flex-col sm:flex-row items-stretch sm:items-center gap-3 flex-1">
|
||||
{/* Search Input */}
|
||||
<div className="flex-1 max-w-md relative">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search payment ID, order ID, email, method, invoice..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => {
|
||||
setSearchQuery(e.target.value);
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 flex flex-col sm:flex-row justify-between items-stretch sm:items-center gap-3">
|
||||
{/* Search Input */}
|
||||
<div className="flex-1 max-w-md relative">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search payment ID, order ID, email, method, invoice..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => {
|
||||
setSearchQuery(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-9 pr-8 py-2 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 shadow-sm"
|
||||
/>
|
||||
<Search className="h-3.5 w-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400" />
|
||||
{searchQuery && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setSearchQuery('');
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-9 pr-8 py-2 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 shadow-sm"
|
||||
/>
|
||||
<Search className="h-3.5 w-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400" />
|
||||
{searchQuery && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setSearchQuery('');
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-0.5 cursor-pointer"
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Date Filter Controls: Year & Month */}
|
||||
<div className="flex items-center gap-2 shrink-0">
|
||||
{/* Year Selector (Dynamic with Custom Year support) */}
|
||||
{!isCustomYear ? (
|
||||
<div className="relative">
|
||||
<Calendar className="h-3.5 w-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none" />
|
||||
<select
|
||||
value={selectedYear}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value;
|
||||
if (val === 'custom') {
|
||||
setIsCustomYear(true);
|
||||
setCustomYearInput('');
|
||||
} else {
|
||||
setSelectedYear(val);
|
||||
onPageChange(1);
|
||||
}
|
||||
}}
|
||||
className="appearance-none bg-white border border-slate-200 rounded-xl pl-8.5 pr-8 py-2 text-xs font-bold text-slate-700 hover:border-slate-300 focus:outline-none focus:border-indigo-500 shadow-2xs cursor-pointer transition-colors"
|
||||
title="Filter payments by year"
|
||||
>
|
||||
<option value="all">All Years</option>
|
||||
{availableYears.map((yr) => (
|
||||
<option key={yr} value={String(yr)}>
|
||||
{yr}
|
||||
</option>
|
||||
))}
|
||||
<option value="custom">Custom Year...</option>
|
||||
</select>
|
||||
<ChevronDown className="h-3.5 w-3.5 absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none" />
|
||||
</div>
|
||||
) : (
|
||||
<div className="relative flex items-center">
|
||||
<Calendar className="h-3.5 w-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-indigo-500 pointer-events-none" />
|
||||
<input
|
||||
type="text"
|
||||
autoFocus
|
||||
maxLength={4}
|
||||
placeholder="Year (e.g. 2002)"
|
||||
value={customYearInput}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value.replace(/\D/g, '').slice(0, 4);
|
||||
setCustomYearInput(val);
|
||||
if (val.length === 4) {
|
||||
setSelectedYear(val);
|
||||
onPageChange(1);
|
||||
} else {
|
||||
setSelectedYear('all');
|
||||
onPageChange(1);
|
||||
}
|
||||
}}
|
||||
className="w-34 bg-white border border-indigo-400 rounded-xl pl-8.5 pr-7 py-2 text-xs font-bold text-slate-800 placeholder:text-slate-400 focus:outline-none focus:ring-1 focus:ring-indigo-500 shadow-2xs transition-colors"
|
||||
title="Enter any custom year"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setIsCustomYear(false);
|
||||
setCustomYearInput('');
|
||||
setSelectedYear('all');
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-0.5 cursor-pointer"
|
||||
title="Back to year dropdown"
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Month Selector */}
|
||||
<div className="relative">
|
||||
<select
|
||||
value={selectedMonth}
|
||||
onChange={(e) => {
|
||||
setSelectedMonth(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="appearance-none bg-white border border-slate-200 rounded-xl pl-3.5 pr-8 py-2 text-xs font-bold text-slate-700 hover:border-slate-300 focus:outline-none focus:border-indigo-500 shadow-2xs cursor-pointer transition-colors"
|
||||
title="Filter payments by month"
|
||||
>
|
||||
<option value="all">All Months</option>
|
||||
{MONTH_OPTIONS.map((m) => (
|
||||
<option key={m.value} value={m.value}>
|
||||
{m.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<ChevronDown className="h-3.5 w-3.5 absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none" />
|
||||
</div>
|
||||
|
||||
{hasDateFilter && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleClearDateFilters}
|
||||
className="p-1.5 text-slate-400 hover:text-slate-600 hover:bg-slate-200/60 rounded-lg transition-colors cursor-pointer"
|
||||
title="Reset year and month filters"
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
className="absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-0.5"
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Right Side: Sort & Count Controls */}
|
||||
<div className="flex items-center gap-3 justify-between sm:justify-end shrink-0">
|
||||
{/* Sort & Count Controls */}
|
||||
<div className="flex items-center gap-3 justify-between sm:justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSortOrder(prev => prev === 'desc' ? 'asc' : 'desc')}
|
||||
|
|
@ -312,28 +134,13 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
|||
<div className="border border-slate-200 rounded-2xl p-10 bg-white text-center space-y-2">
|
||||
<p className="text-sm font-bold text-slate-700">No matching payments found</p>
|
||||
<p className="text-xs text-slate-400">
|
||||
No payments match your
|
||||
{hasDateFilter && (
|
||||
<span>
|
||||
{' '}selected period (
|
||||
<strong className="text-slate-600">
|
||||
{selectedMonth !== 'all' ? MONTH_OPTIONS.find((m) => m.value === selectedMonth)?.label : ''}
|
||||
{selectedMonth !== 'all' && selectedYear !== 'all' ? ' ' : ''}
|
||||
{selectedYear !== 'all' ? selectedYear : ''}
|
||||
</strong>
|
||||
)
|
||||
</span>
|
||||
)}
|
||||
{searchQuery ? ` and search query "${searchQuery}"` : ''}.
|
||||
No payments match your search query "{searchQuery}".
|
||||
</p>
|
||||
<button
|
||||
onClick={() => {
|
||||
setSearchQuery('');
|
||||
handleClearDateFilters();
|
||||
}}
|
||||
className="text-xs text-indigo-600 font-bold hover:underline mt-2 inline-block cursor-pointer"
|
||||
onClick={() => setSearchQuery('')}
|
||||
className="text-xs text-indigo-600 font-bold hover:underline mt-2 inline-block"
|
||||
>
|
||||
Reset all filters
|
||||
Clear search query
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ interface CreatePlanModalProps {
|
|||
duration: string;
|
||||
priceInr: string;
|
||||
priceUsd: string;
|
||||
priceEur: string;
|
||||
selectedModuleIds: string[];
|
||||
allModules: any[];
|
||||
saving: boolean;
|
||||
|
|
@ -29,7 +28,6 @@ interface CreatePlanModalProps {
|
|||
onDurationChange: (v: string) => void;
|
||||
onPriceInrChange: (v: string) => void;
|
||||
onPriceUsdChange: (v: string) => void;
|
||||
onPriceEurChange: (v: string) => void;
|
||||
onToggleModule: (id: string) => void;
|
||||
onSelectAllModules: () => void;
|
||||
onClearAllModules: () => void;
|
||||
|
|
@ -49,7 +47,6 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
|||
duration,
|
||||
priceInr,
|
||||
priceUsd,
|
||||
priceEur,
|
||||
selectedModuleIds,
|
||||
allModules,
|
||||
saving,
|
||||
|
|
@ -64,7 +61,6 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
|||
onDurationChange,
|
||||
onPriceInrChange,
|
||||
onPriceUsdChange,
|
||||
onPriceEurChange,
|
||||
onToggleModule,
|
||||
onSelectAllModules,
|
||||
onClearAllModules,
|
||||
|
|
@ -197,8 +193,8 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
|||
</div>
|
||||
</div>
|
||||
|
||||
{/* Multi-Currency Pricing (INR / USD / EUR) */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
||||
{/* Dual Currency Pricing */}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
||||
<div className="relative">
|
||||
|
|
@ -231,21 +227,6 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
|||
/>
|
||||
</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 */}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@ interface EditPriceModalProps {
|
|||
subtitle: string;
|
||||
priceInr: string;
|
||||
priceUsd: string;
|
||||
priceEur: string;
|
||||
allModules?: any[];
|
||||
moduleIds?: string[];
|
||||
saving: boolean;
|
||||
onNameChange: (v: string) => void;
|
||||
onDescChange: (v: string) => void;
|
||||
|
|
@ -21,10 +18,6 @@ interface EditPriceModalProps {
|
|||
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;
|
||||
}
|
||||
|
|
@ -38,9 +31,6 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
|||
subtitle,
|
||||
priceInr,
|
||||
priceUsd,
|
||||
priceEur,
|
||||
allModules = [],
|
||||
moduleIds = [],
|
||||
saving,
|
||||
onNameChange,
|
||||
onDescChange,
|
||||
|
|
@ -49,10 +39,6 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
|||
onSubtitleChange,
|
||||
onPriceInrChange,
|
||||
onPriceUsdChange,
|
||||
onPriceEurChange,
|
||||
onToggleModule,
|
||||
onSelectAllModules,
|
||||
onClearAllModules,
|
||||
onSave,
|
||||
onClose,
|
||||
}) => {
|
||||
|
|
@ -128,7 +114,7 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
||||
<div className="relative">
|
||||
|
|
@ -160,77 +146,8 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
|||
/>
|
||||
</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"
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ export const PlansTab: React.FC<PlansTabProps> = ({
|
|||
<th className="py-3.5 px-4">Plan Details</th>
|
||||
<th className="py-3.5 px-3">Type & Duration</th>
|
||||
<th className="py-3.5 px-3">Included Modules</th>
|
||||
<th className="py-3.5 px-3">Live Pricing (INR / USD / EUR)</th>
|
||||
<th className="py-3.5 px-3">Live Pricing (INR / USD)</th>
|
||||
<th className="py-3.5 px-3 text-center">Subscribers</th>
|
||||
<th className="py-3.5 px-3 text-center">Status</th>
|
||||
<th className="py-3.5 px-4 text-right">Actions</th>
|
||||
|
|
@ -158,11 +158,6 @@ 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">
|
||||
|
|
@ -265,11 +260,7 @@ export const PlansTab: React.FC<PlansTabProps> = ({
|
|||
<td className="py-3.5 px-3 whitespace-nowrap">
|
||||
<div className="space-y-0.5 font-bold">
|
||||
<p className="text-xs text-slate-800 font-mono">₹{plan.price_inr ?? '—'}</p>
|
||||
<div className="flex items-center gap-1.5 text-[10px] font-mono">
|
||||
<span className="text-slate-400">${plan.price_usd ?? '—'}</span>
|
||||
<span className="text-slate-300">•</span>
|
||||
<span className="text-indigo-600 font-bold">€{plan.price_eur ?? plan.price_usd ?? '—'}</span>
|
||||
</div>
|
||||
<p className="text-[10px] text-slate-400 font-mono">${plan.price_usd ?? '—'}</p>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
|
|
@ -291,22 +282,11 @@ 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 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'
|
||||
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'
|
||||
}`}
|
||||
title={
|
||||
plan.pricing_status === 'pending_pricing'
|
||||
? 'Set prices via Edit Info & Price before activating'
|
||||
: plan.is_active
|
||||
? 'Click to deactivate'
|
||||
: 'Click to activate'
|
||||
}
|
||||
title={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 ${
|
||||
|
|
@ -315,11 +295,7 @@ export const PlansTab: React.FC<PlansTabProps> = ({
|
|||
/>
|
||||
</button>
|
||||
<span className="block text-[9px] font-bold text-slate-400 mt-0.5">
|
||||
{plan.pricing_status === 'pending_pricing'
|
||||
? 'Needs Pricing'
|
||||
: plan.is_active
|
||||
? 'Active'
|
||||
: 'Inactive'}
|
||||
{plan.is_active ? 'Active' : 'Inactive'}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export const SyncOverview: React.FC<SyncOverviewProps> = ({
|
|||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div className="bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-indigo-600">{stats.totalUsers}</p>
|
||||
<p className="text-[10px] font-bold text-slate-500 uppercase tracking-wider mt-1">Total Customers</p>
|
||||
<p className="text-[10px] font-bold text-slate-500 uppercase tracking-wider mt-1">Total Users</p>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-purple-50 to-pink-50 border border-purple-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-purple-600">{stats.subscriptions}</p>
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
export const ADMIN_ROLES = new Set(['super_admin', 'admin', 'finance_admin']);
|
||||
|
||||
/**
|
||||
* Returns true when a user object carries at least one administrative role.
|
||||
*/
|
||||
export function isAdminAccount(user?: { roles?: string[] } | null): boolean {
|
||||
if (!Array.isArray(user?.roles)) return false;
|
||||
return user.roles.some((role) => ADMIN_ROLES.has(String(role).trim().toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Separates customer accounts from admin accounts so admins never leak into customer counts.
|
||||
*/
|
||||
export function partitionUserLists<T extends { id?: string; email?: string; roles?: string[] }>(
|
||||
practitioners: T[],
|
||||
admins: T[]
|
||||
): { customers: T[]; adminAccounts: T[] } {
|
||||
const customers: T[] = [];
|
||||
const adminAccounts: T[] = [];
|
||||
const seenAdmins = new Set<string>();
|
||||
|
||||
for (const admin of admins) {
|
||||
const key = String(admin.id || admin.email || '').toLowerCase();
|
||||
if (key) {
|
||||
if (seenAdmins.has(key)) continue;
|
||||
seenAdmins.add(key);
|
||||
}
|
||||
adminAccounts.push(admin);
|
||||
}
|
||||
|
||||
for (const user of practitioners) {
|
||||
if (isAdminAccount(user)) {
|
||||
const key = String(user.id || user.email || '').toLowerCase();
|
||||
if (!key || !seenAdmins.has(key)) {
|
||||
if (key) seenAdmins.add(key);
|
||||
adminAccounts.push(user);
|
||||
}
|
||||
} else {
|
||||
customers.push(user);
|
||||
}
|
||||
}
|
||||
|
||||
return { customers, adminAccounts };
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue