Compare commits
1 Commits
main
...
fix-admin-
| Author | SHA1 | Date |
|---|---|---|
|
|
5b65523417 |
|
|
@ -27,7 +27,3 @@ dist-ssr
|
||||||
.env
|
.env
|
||||||
.env.*
|
.env.*
|
||||||
!.env.example
|
!.env.example
|
||||||
|
|
||||||
# Generated Git Info
|
|
||||||
.git_*_info
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,6 @@ RUN rm /etc/nginx/conf.d/default.conf
|
||||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
|
|
||||||
# Copy git info metadata if generated on host
|
|
||||||
COPY .git_admin_info* /app/.git_admin_info
|
|
||||||
|
|
||||||
RUN ln -sf /usr/share/nginx/html /usr/share/nginx/html/admin
|
RUN ln -sf /usr/share/nginx/html /usr/share/nginx/html/admin
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
|
|
||||||
380
src/App.tsx
380
src/App.tsx
|
|
@ -1,17 +1,14 @@
|
||||||
import React, { useState, useEffect, useMemo } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { Database, RefreshCw, RefreshCcw, Menu, Sparkles } from 'lucide-react';
|
import { Database, RefreshCw, RefreshCcw } from 'lucide-react';
|
||||||
import { API_BASE } from './services/api';
|
import { API_BASE } from './services/api';
|
||||||
import type { AdminTabType } from './types';
|
import type { AdminTabType } from './types';
|
||||||
import { normalizeCategory } from './utils/category';
|
|
||||||
import { isAdminAccount, partitionUserLists } from './utils/roles';
|
|
||||||
|
|
||||||
// Modular Components
|
// Modular Components
|
||||||
import { AdminSidebar } from './components/layout/AdminSidebar';
|
import { AdminSidebar } from './components/layout/AdminSidebar';
|
||||||
import { SyncOverview } from './components/sync/SyncOverview';
|
import { SyncOverview } from './components/sync/SyncOverview';
|
||||||
import { ModulesTab } from './components/modules/ModulesTab';
|
import { ModulesTab } from './components/modules/ModulesTab';
|
||||||
import { EditModuleModal } from './components/modules/EditModuleModal';
|
import { EditModuleModal } from './components/modules/EditModuleModal';
|
||||||
import { ModuleBuilderTab } from './components/modules/ModuleBuilderTab';
|
|
||||||
import { PlansTab } from './components/plans/PlansTab';
|
import { PlansTab } from './components/plans/PlansTab';
|
||||||
import { CreatePlanModal } from './components/plans/CreatePlanModal';
|
import { CreatePlanModal } from './components/plans/CreatePlanModal';
|
||||||
import { EditPriceModal } from './components/plans/EditPriceModal';
|
import { EditPriceModal } from './components/plans/EditPriceModal';
|
||||||
|
|
@ -26,40 +23,17 @@ import { DatabaseBackupTab } from './components/database/DatabaseBackupTab';
|
||||||
import { ReportsExportTab } from './components/database/ReportsExportTab';
|
import { ReportsExportTab } from './components/database/ReportsExportTab';
|
||||||
import { AdminLoginForm } from './components/auth/AdminLoginForm';
|
import { AdminLoginForm } from './components/auth/AdminLoginForm';
|
||||||
|
|
||||||
export function extractErrorMessage(err: any, fallback: string = 'An error occurred.'): string {
|
|
||||||
if (!err) return fallback;
|
|
||||||
const detail = err.response?.data?.detail ?? err.response?.data?.message ?? err.message;
|
|
||||||
if (typeof detail === 'string') {
|
|
||||||
return detail;
|
|
||||||
}
|
|
||||||
if (detail && typeof detail === 'object') {
|
|
||||||
if (typeof detail.message === 'string' && detail.message) {
|
|
||||||
return detail.message;
|
|
||||||
}
|
|
||||||
if (Array.isArray(detail.issues) && detail.issues.length > 0) {
|
|
||||||
return detail.issues.map((i: any) => i.msg || JSON.stringify(i)).join('; ');
|
|
||||||
}
|
|
||||||
if (Array.isArray(detail.context?.issues) && detail.context.issues.length > 0) {
|
|
||||||
return detail.context.issues.map((i: any) => i.msg || JSON.stringify(i)).join('; ');
|
|
||||||
}
|
|
||||||
if (Array.isArray(detail) && detail.length > 0) {
|
|
||||||
return detail.map((i: any) => i.msg || (typeof i === 'string' ? i : JSON.stringify(i))).join('; ');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
return JSON.stringify(detail);
|
|
||||||
} catch {
|
|
||||||
return fallback;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return fallback;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const [userToken, setUserToken] = useState<string | null>(localStorage.getItem('access_token'));
|
const [userToken, setUserToken] = useState<string | null>(localStorage.getItem('access_token'));
|
||||||
const [loggedInUser, setLoggedInUser] = useState<any>(null);
|
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
|
// Admin Login State
|
||||||
|
const [adminEmail, setAdminEmail] = useState('');
|
||||||
|
const [adminPassword, setAdminPassword] = useState('');
|
||||||
|
const [showAdminPassword, setShowAdminPassword] = useState(false);
|
||||||
const [adminAuthLoading, setAdminAuthLoading] = useState(false);
|
const [adminAuthLoading, setAdminAuthLoading] = useState(false);
|
||||||
const [adminAuthError, setAdminAuthError] = useState<string | null>(null);
|
const [adminAuthError, setAdminAuthError] = useState<string | null>(null);
|
||||||
|
|
||||||
|
|
@ -73,7 +47,6 @@ export default function App() {
|
||||||
const [isSidebarCollapsed, setIsSidebarCollapsed] = useState<boolean>(() => {
|
const [isSidebarCollapsed, setIsSidebarCollapsed] = useState<boolean>(() => {
|
||||||
return localStorage.getItem('admin_sidebar_collapsed') === 'true';
|
return localStorage.getItem('admin_sidebar_collapsed') === 'true';
|
||||||
});
|
});
|
||||||
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState<boolean>(false);
|
|
||||||
|
|
||||||
// Database & Backups State
|
// Database & Backups State
|
||||||
const [dbInfo, setDbInfo] = useState<any | null>(null);
|
const [dbInfo, setDbInfo] = useState<any | null>(null);
|
||||||
|
|
@ -105,8 +78,6 @@ export default function App() {
|
||||||
const [editModuleName, setEditModuleName] = useState<string>('');
|
const [editModuleName, setEditModuleName] = useState<string>('');
|
||||||
const [editModuleDesc, setEditModuleDesc] = useState<string>('');
|
const [editModuleDesc, setEditModuleDesc] = useState<string>('');
|
||||||
const [editModuleCategory, setEditModuleCategory] = useState<string>('point');
|
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);
|
const [editModuleSaving, setEditModuleSaving] = useState<boolean>(false);
|
||||||
|
|
||||||
// Plans State
|
// Plans State
|
||||||
|
|
@ -116,13 +87,11 @@ export default function App() {
|
||||||
const [selectedEditPricePlan, setSelectedEditPricePlan] = useState<any | null>(null);
|
const [selectedEditPricePlan, setSelectedEditPricePlan] = useState<any | null>(null);
|
||||||
const [editPriceInr, setEditPriceInr] = useState<string>('');
|
const [editPriceInr, setEditPriceInr] = useState<string>('');
|
||||||
const [editPriceUsd, setEditPriceUsd] = useState<string>('');
|
const [editPriceUsd, setEditPriceUsd] = useState<string>('');
|
||||||
const [editPriceEur, setEditPriceEur] = useState<string>('');
|
|
||||||
const [editPlanName, setEditPlanName] = useState<string>('');
|
const [editPlanName, setEditPlanName] = useState<string>('');
|
||||||
const [editPlanDesc, setEditPlanDesc] = useState<string>('');
|
const [editPlanDesc, setEditPlanDesc] = useState<string>('');
|
||||||
const [editPlanBadge, setEditPlanBadge] = useState<string>('');
|
const [editPlanBadge, setEditPlanBadge] = useState<string>('');
|
||||||
const [editPlanHeading, setEditPlanHeading] = useState<string>('');
|
const [editPlanHeading, setEditPlanHeading] = useState<string>('');
|
||||||
const [editPlanSubtitle, setEditPlanSubtitle] = useState<string>('');
|
const [editPlanSubtitle, setEditPlanSubtitle] = useState<string>('');
|
||||||
const [editPlanModuleIds, setEditPlanModuleIds] = useState<string[]>([]);
|
|
||||||
const [editPriceSaving, setEditPriceSaving] = useState<boolean>(false);
|
const [editPriceSaving, setEditPriceSaving] = useState<boolean>(false);
|
||||||
|
|
||||||
// Create Custom Plan State
|
// Create Custom Plan State
|
||||||
|
|
@ -137,14 +106,13 @@ export default function App() {
|
||||||
const [createPlanDuration, setCreatePlanDuration] = useState<string>('yearly');
|
const [createPlanDuration, setCreatePlanDuration] = useState<string>('yearly');
|
||||||
const [createPlanPriceInr, setCreatePlanPriceInr] = useState<string>('');
|
const [createPlanPriceInr, setCreatePlanPriceInr] = useState<string>('');
|
||||||
const [createPlanPriceUsd, setCreatePlanPriceUsd] = useState<string>('');
|
const [createPlanPriceUsd, setCreatePlanPriceUsd] = useState<string>('');
|
||||||
const [createPlanPriceEur, setCreatePlanPriceEur] = useState<string>('');
|
|
||||||
const [createPlanModuleIds, setCreatePlanModuleIds] = useState<string[]>([]);
|
const [createPlanModuleIds, setCreatePlanModuleIds] = useState<string[]>([]);
|
||||||
const [createPlanSaving, setCreatePlanSaving] = useState<boolean>(false);
|
const [createPlanSaving, setCreatePlanSaving] = useState<boolean>(false);
|
||||||
const [createPlanError, setCreatePlanError] = useState<string | null>(null);
|
const [createPlanError, setCreatePlanError] = useState<string | null>(null);
|
||||||
|
|
||||||
// Coupons State
|
// Coupons State
|
||||||
const [adminCouponsList, setAdminCouponsList] = useState<any[]>([]);
|
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>('');
|
const [couponSearchQuery, setCouponSearchQuery] = useState<string>('');
|
||||||
|
|
||||||
// Unified Coupon Modal State
|
// Unified Coupon Modal State
|
||||||
|
|
@ -155,11 +123,7 @@ export default function App() {
|
||||||
category: 'general',
|
category: 'general',
|
||||||
discountType: 'percentage',
|
discountType: 'percentage',
|
||||||
discountValue: '20',
|
discountValue: '20',
|
||||||
discountValueUsd: '',
|
|
||||||
discountValueEur: '',
|
|
||||||
maxDiscountCap: '0',
|
maxDiscountCap: '0',
|
||||||
maxDiscountCapUsd: '',
|
|
||||||
maxDiscountCapEur: '',
|
|
||||||
description: '',
|
description: '',
|
||||||
startDate: '',
|
startDate: '',
|
||||||
endDate: '',
|
endDate: '',
|
||||||
|
|
@ -167,10 +131,7 @@ export default function App() {
|
||||||
applicablePlanIds: [],
|
applicablePlanIds: [],
|
||||||
applicableModuleIds: [],
|
applicableModuleIds: [],
|
||||||
minSpend: '0',
|
minSpend: '0',
|
||||||
minSpendUsd: '',
|
|
||||||
minSpendEur: '',
|
|
||||||
usageLimit: '0',
|
usageLimit: '0',
|
||||||
perUserLimit: '',
|
|
||||||
firstOnly: false,
|
firstOnly: false,
|
||||||
});
|
});
|
||||||
const [couponSaving, setCouponSaving] = useState<boolean>(false);
|
const [couponSaving, setCouponSaving] = useState<boolean>(false);
|
||||||
|
|
@ -186,10 +147,6 @@ export default function App() {
|
||||||
// Admins & Practitioners
|
// Admins & Practitioners
|
||||||
const [adminsList, setAdminsList] = useState<any[]>([]);
|
const [adminsList, setAdminsList] = useState<any[]>([]);
|
||||||
const [practitionersList, setPractitionersList] = useState<any[]>([]);
|
const [practitionersList, setPractitionersList] = useState<any[]>([]);
|
||||||
const { customers: customersList, adminAccounts: resolvedAdminsList } = useMemo(
|
|
||||||
() => partitionUserLists(practitionersList, adminsList),
|
|
||||||
[practitionersList, adminsList]
|
|
||||||
);
|
|
||||||
const [createAdminEmail, setCreateAdminEmail] = useState('');
|
const [createAdminEmail, setCreateAdminEmail] = useState('');
|
||||||
const [createAdminPassword, setCreateAdminPassword] = useState('');
|
const [createAdminPassword, setCreateAdminPassword] = useState('');
|
||||||
const [createAdminName, setCreateAdminName] = useState('');
|
const [createAdminName, setCreateAdminName] = useState('');
|
||||||
|
|
@ -260,7 +217,7 @@ export default function App() {
|
||||||
setAdminDataLoading(true);
|
setAdminDataLoading(true);
|
||||||
const headers = { Authorization: `Bearer ${userToken}` };
|
const headers = { Authorization: `Bearer ${userToken}` };
|
||||||
try {
|
try {
|
||||||
const [payRes, adminsRes, practRes, subLedgerRes, modulesRes, plansRes, couponsRes, dbRes] =
|
const [payRes, adminsRes, practRes, subLedgerRes, modulesRes, plansRes, couponsRes, dbRes, contentModsRes] =
|
||||||
await Promise.allSettled([
|
await Promise.allSettled([
|
||||||
axios.get(`${API_BASE}/api/admin/razorpay/payments`, { headers }),
|
axios.get(`${API_BASE}/api/admin/razorpay/payments`, { headers }),
|
||||||
axios.get(`${API_BASE}/api/admin/super-admins`, { headers }),
|
axios.get(`${API_BASE}/api/admin/super-admins`, { headers }),
|
||||||
|
|
@ -270,6 +227,7 @@ export default function App() {
|
||||||
axios.get(`${API_BASE}/api/admin/plans`, { headers }),
|
axios.get(`${API_BASE}/api/admin/plans`, { headers }),
|
||||||
axios.get(`${API_BASE}/api/admin/coupons`, { headers }),
|
axios.get(`${API_BASE}/api/admin/coupons`, { headers }),
|
||||||
axios.get(`${API_BASE}/api/admin/database/info`, { headers }),
|
axios.get(`${API_BASE}/api/admin/database/info`, { headers }),
|
||||||
|
axios.get(`${API_BASE}/api/contents/modules`),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (payRes.status === 'fulfilled') setRzpPayments(payRes.value.data.payments || []);
|
if (payRes.status === 'fulfilled') setRzpPayments(payRes.value.data.payments || []);
|
||||||
|
|
@ -277,12 +235,47 @@ export default function App() {
|
||||||
if (practRes.status === 'fulfilled') setPractitionersList(practRes.value.data || []);
|
if (practRes.status === 'fulfilled') setPractitionersList(practRes.value.data || []);
|
||||||
if (subLedgerRes.status === 'fulfilled') setUsersSubscriptions(subLedgerRes.value.data || []);
|
if (subLedgerRes.status === 'fulfilled') setUsersSubscriptions(subLedgerRes.value.data || []);
|
||||||
if (modulesRes.status === 'fulfilled') {
|
if (modulesRes.status === 'fulfilled') {
|
||||||
const rawMods: any[] = modulesRes.value.data || [];
|
const rawModules: any[] = modulesRes.value.data || [];
|
||||||
const resolved = rawMods.map((m: any) => ({
|
const contentModules: any[] =
|
||||||
|
contentModsRes.status === 'fulfilled' ? contentModsRes.value.data?.modules || [] : [];
|
||||||
|
|
||||||
|
// Generic clinical kind to category mapping
|
||||||
|
const kindToCategory: Record<string, string> = {
|
||||||
|
point: 'point',
|
||||||
|
points: 'point',
|
||||||
|
pattern: 'Patterns',
|
||||||
|
patterns: 'Patterns',
|
||||||
|
'five-elements': 'Patterns',
|
||||||
|
nutrition: 'Nutrition',
|
||||||
|
therapeutic: 'Therapeutics',
|
||||||
|
therapeutics: 'Therapeutics',
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolvedModules = rawModules.map((m: any) => {
|
||||||
|
const matched = contentModules.find(
|
||||||
|
(c: any) =>
|
||||||
|
(c.id && m.id && c.id === m.id) ||
|
||||||
|
(c.slug && m.slug && c.slug.toLowerCase() === m.slug.toLowerCase()) ||
|
||||||
|
(c.code && m.code && c.code.toLowerCase() === m.code.toLowerCase())
|
||||||
|
);
|
||||||
|
|
||||||
|
const explicitCategory = matched?.metadata?.category;
|
||||||
|
const kind = (matched?.metadata?.kind || '').toLowerCase();
|
||||||
|
const kindCategory = kindToCategory[kind];
|
||||||
|
|
||||||
|
const resolvedCategory =
|
||||||
|
explicitCategory ||
|
||||||
|
kindCategory ||
|
||||||
|
(m.category && m.category.toLowerCase() !== 'general' ? m.category : null) ||
|
||||||
|
'General';
|
||||||
|
|
||||||
|
return {
|
||||||
...m,
|
...m,
|
||||||
category: normalizeCategory(m.category || m.metadata?.category || m.metadata?.kind || m.kind),
|
category: resolvedCategory,
|
||||||
}));
|
};
|
||||||
setAdminModulesList(resolved);
|
});
|
||||||
|
|
||||||
|
setAdminModulesList(resolvedModules);
|
||||||
}
|
}
|
||||||
if (plansRes.status === 'fulfilled') setAdminPlansList(plansRes.value.data || []);
|
if (plansRes.status === 'fulfilled') setAdminPlansList(plansRes.value.data || []);
|
||||||
if (couponsRes.status === 'fulfilled') setAdminCouponsList(couponsRes.value.data || []);
|
if (couponsRes.status === 'fulfilled') setAdminCouponsList(couponsRes.value.data || []);
|
||||||
|
|
@ -295,20 +288,21 @@ export default function App() {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Auth Handlers
|
// Auth Handlers
|
||||||
const handleAdminLogin = async (credentials: { email: string; password: string }) => {
|
const handleAdminLogin = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
setAdminAuthLoading(true);
|
setAdminAuthLoading(true);
|
||||||
setAdminAuthError(null);
|
setAdminAuthError(null);
|
||||||
try {
|
try {
|
||||||
const res = await axios.post(`${API_BASE}/api/auth/login`, {
|
const res = await axios.post(`${API_BASE}/api/auth/login`, {
|
||||||
email: credentials.email,
|
email: adminEmail,
|
||||||
password: credentials.password,
|
password: adminPassword,
|
||||||
});
|
});
|
||||||
const token = res.data.access_token;
|
const token = res.data.access_token;
|
||||||
localStorage.setItem('access_token', token);
|
localStorage.setItem('access_token', token);
|
||||||
setUserToken(token);
|
setUserToken(token);
|
||||||
fetchUserProfile(token);
|
fetchUserProfile(token);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setAdminAuthError(extractErrorMessage(err, 'Invalid administrative credentials.'));
|
setAdminAuthError(err.response?.data?.detail || 'Invalid administrative credentials.');
|
||||||
} finally {
|
} finally {
|
||||||
setAdminAuthLoading(false);
|
setAdminAuthLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -318,7 +312,6 @@ export default function App() {
|
||||||
localStorage.removeItem('access_token');
|
localStorage.removeItem('access_token');
|
||||||
setUserToken(null);
|
setUserToken(null);
|
||||||
setLoggedInUser(null);
|
setLoggedInUser(null);
|
||||||
setAdminAuthError(null);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Force Sync Gateway Handler
|
// Force Sync Gateway Handler
|
||||||
|
|
@ -336,7 +329,7 @@ export default function App() {
|
||||||
await fetchUserProfile(userToken!);
|
await fetchUserProfile(userToken!);
|
||||||
await fetchRazorpayAdminData();
|
await fetchRazorpayAdminData();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
const errorMsg = extractErrorMessage(err, 'Failed to sync with Razorpay Gateway.');
|
const errorMsg = err.response?.data?.detail || err.message || String(err);
|
||||||
setAdminLogs((prev) => [`[Admin Sync] FAILED: ${errorMsg}`, ...prev]);
|
setAdminLogs((prev) => [`[Admin Sync] FAILED: ${errorMsg}`, ...prev]);
|
||||||
} finally {
|
} finally {
|
||||||
setAdminSyncing(false);
|
setAdminSyncing(false);
|
||||||
|
|
@ -378,7 +371,7 @@ export default function App() {
|
||||||
setTimeout(() => setDbBackupSuccess(null), 8000);
|
setTimeout(() => setDbBackupSuccess(null), 8000);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setDbBackupError(
|
setDbBackupError(
|
||||||
extractErrorMessage(err, 'Failed to download database backup. Ensure database client is active.')
|
err.response?.data?.detail || 'Failed to download database backup. Ensure database client is active.'
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
setDbBackupDownloading(null);
|
setDbBackupDownloading(null);
|
||||||
|
|
@ -444,7 +437,7 @@ export default function App() {
|
||||||
setReportExportSuccess(`Successfully downloaded ${reportType} report (${filename})`);
|
setReportExportSuccess(`Successfully downloaded ${reportType} report (${filename})`);
|
||||||
setTimeout(() => setReportExportSuccess(null), 8000);
|
setTimeout(() => setReportExportSuccess(null), 8000);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setReportExportError(extractErrorMessage(err, 'Failed to export report CSV.'));
|
setReportExportError(err.response?.data?.detail || 'Failed to export report CSV.');
|
||||||
} finally {
|
} finally {
|
||||||
setReportDownloading(null);
|
setReportDownloading(null);
|
||||||
}
|
}
|
||||||
|
|
@ -462,7 +455,7 @@ export default function App() {
|
||||||
});
|
});
|
||||||
setCustomerDrawerData(res.data);
|
setCustomerDrawerData(res.data);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(extractErrorMessage(err, 'Failed to load customer details.'));
|
alert(err.response?.data?.detail || 'Failed to load customer details.');
|
||||||
} finally {
|
} finally {
|
||||||
setCustomerDrawerLoading(false);
|
setCustomerDrawerLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -487,7 +480,7 @@ export default function App() {
|
||||||
);
|
);
|
||||||
setAdminLogs((prev) => [`[Customer Control] ${res.data.message}`, ...prev]);
|
setAdminLogs((prev) => [`[Customer Control] ${res.data.message}`, ...prev]);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(extractErrorMessage(err, 'Failed to update account status.'));
|
alert(err.response?.data?.detail || 'Failed to update account status.');
|
||||||
} finally {
|
} finally {
|
||||||
setCustomerStatusToggling(false);
|
setCustomerStatusToggling(false);
|
||||||
}
|
}
|
||||||
|
|
@ -509,86 +502,47 @@ export default function App() {
|
||||||
{ is_active: newActive, status: newStatus },
|
{ is_active: newActive, status: newStatus },
|
||||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
{ headers: { Authorization: `Bearer ${userToken}` } }
|
||||||
);
|
);
|
||||||
|
|
||||||
const linkedPlans = adminPlansList.filter((p) =>
|
|
||||||
p.base_code?.toLowerCase() === mod.code?.toLowerCase() ||
|
|
||||||
p.module_ids?.includes(mod.id) ||
|
|
||||||
p.modules?.some((m: any) => m.id === mod.id || m.slug === mod.slug)
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const plan of linkedPlans) {
|
|
||||||
if (plan.is_active !== newActive) {
|
|
||||||
try {
|
|
||||||
await axios.patch(
|
|
||||||
`${API_BASE}/api/admin/plans/${plan.base_code}/status`,
|
|
||||||
{ is_active: newActive },
|
|
||||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
|
||||||
);
|
|
||||||
setAdminPlansList((prev) =>
|
|
||||||
prev.map((p) => (p.base_code === plan.base_code ? { ...p, is_active: newActive } : p))
|
|
||||||
);
|
|
||||||
} catch (planErr) {
|
|
||||||
console.error('Failed to sync linked plan status:', planErr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setAdminLogs((prev) => [`[Catalog] ${mod.name} is now ${newActive ? 'Active' : 'Inactive'}`, ...prev]);
|
setAdminLogs((prev) => [`[Catalog] ${mod.name} is now ${newActive ? 'Active' : 'Inactive'}`, ...prev]);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setAdminModulesList((prev) =>
|
setAdminModulesList((prev) =>
|
||||||
prev.map((m) => (m.id === mod.id ? { ...m, is_active: !newActive, status: !newActive ? 'active' : 'inactive' } : m))
|
prev.map((m) => (m.id === mod.id ? { ...m, is_active: !newActive, status: !newActive ? 'active' : 'inactive' } : m))
|
||||||
);
|
);
|
||||||
alert(extractErrorMessage(err, 'Failed to update module status.'));
|
alert(err.response?.data?.detail || 'Failed to update module status.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleOpenEditModule = (mod: any) => {
|
const handleOpenEditModule = (mod: any) => {
|
||||||
setSelectedEditModule(mod);
|
setSelectedEditModule(mod);
|
||||||
setEditModuleName(mod.name || '');
|
setEditModuleName(mod.name || '');
|
||||||
setEditModuleDesc(mod.description || '');
|
setEditModuleDesc(mod.description || '');
|
||||||
setEditModuleCategory(normalizeCategory(mod.category));
|
setEditModuleCategory(mod.category || 'point');
|
||||||
setEditModuleIcon(mod.icon || 'folder-outline');
|
|
||||||
setEditModuleColor(mod.color || '#4F46E5');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveModuleDetails = async (e: React.FormEvent) => {
|
const handleSaveModuleDetails = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!selectedEditModule || !userToken) return;
|
if (!selectedEditModule || !userToken) return;
|
||||||
setEditModuleSaving(true);
|
setEditModuleSaving(true);
|
||||||
const normalizedCat = normalizeCategory(editModuleCategory);
|
|
||||||
const nextIcon = editModuleIcon.trim() || 'folder-outline';
|
|
||||||
const nextColor = editModuleColor.trim() || '#4F46E5';
|
|
||||||
try {
|
try {
|
||||||
await axios.put(
|
await axios.put(
|
||||||
`${API_BASE}/api/admin/modules/${selectedEditModule.id}`,
|
`${API_BASE}/api/admin/modules/${selectedEditModule.id}`,
|
||||||
{
|
{
|
||||||
name: editModuleName,
|
name: editModuleName,
|
||||||
description: editModuleDesc,
|
description: editModuleDesc,
|
||||||
category: normalizedCat,
|
category: editModuleCategory,
|
||||||
icon: nextIcon,
|
|
||||||
color: nextColor,
|
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
{ headers: { Authorization: `Bearer ${userToken}` } }
|
||||||
);
|
);
|
||||||
setAdminModulesList((prev) =>
|
setAdminModulesList((prev) =>
|
||||||
prev.map((m) =>
|
prev.map((m) =>
|
||||||
m.id === selectedEditModule.id
|
m.id === selectedEditModule.id
|
||||||
? {
|
? { ...m, name: editModuleName, description: editModuleDesc, category: editModuleCategory }
|
||||||
...m,
|
|
||||||
name: editModuleName,
|
|
||||||
description: editModuleDesc,
|
|
||||||
category: normalizedCat,
|
|
||||||
icon: nextIcon,
|
|
||||||
color: nextColor,
|
|
||||||
}
|
|
||||||
: m
|
: m
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
setSelectedEditModule(null);
|
setSelectedEditModule(null);
|
||||||
setAdminLogs((prev) => [`[Catalog] Updated metadata for '${editModuleName}'`, ...prev]);
|
setAdminLogs((prev) => [`[Catalog] Updated metadata for '${editModuleName}'`, ...prev]);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(extractErrorMessage(err, 'Failed to update module details.'));
|
alert(err.response?.data?.detail || 'Failed to update module details.');
|
||||||
} finally {
|
} finally {
|
||||||
setEditModuleSaving(false);
|
setEditModuleSaving(false);
|
||||||
}
|
}
|
||||||
|
|
@ -615,7 +569,7 @@ export default function App() {
|
||||||
setAdminPlansList((prev) =>
|
setAdminPlansList((prev) =>
|
||||||
prev.map((p) => (p.base_code === plan.base_code ? { ...p, is_active: !newActive } : p))
|
prev.map((p) => (p.base_code === plan.base_code ? { ...p, is_active: !newActive } : p))
|
||||||
);
|
);
|
||||||
alert(extractErrorMessage(err, 'Failed to update plan status.'));
|
alert(err.response?.data?.detail || 'Failed to update plan status.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -623,17 +577,11 @@ export default function App() {
|
||||||
setSelectedEditPricePlan(plan);
|
setSelectedEditPricePlan(plan);
|
||||||
setEditPriceInr(String(plan.price_inr ?? ''));
|
setEditPriceInr(String(plan.price_inr ?? ''));
|
||||||
setEditPriceUsd(String(plan.price_usd ?? ''));
|
setEditPriceUsd(String(plan.price_usd ?? ''));
|
||||||
setEditPriceEur(String(plan.price_eur ?? plan.price_usd ?? ''));
|
|
||||||
setEditPlanName(plan.name || '');
|
setEditPlanName(plan.name || '');
|
||||||
setEditPlanDesc(plan.description || '');
|
setEditPlanDesc(plan.description || '');
|
||||||
setEditPlanBadge(plan.badge_text || '');
|
setEditPlanBadge(plan.badge_text || '');
|
||||||
setEditPlanHeading(plan.heading || '');
|
setEditPlanHeading(plan.heading || '');
|
||||||
setEditPlanSubtitle(plan.subtitle || '');
|
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) => {
|
const handleSavePlanPrice = async (e: React.FormEvent) => {
|
||||||
|
|
@ -641,36 +589,25 @@ export default function App() {
|
||||||
if (!selectedEditPricePlan || !userToken) return;
|
if (!selectedEditPricePlan || !userToken) return;
|
||||||
const inrVal = parseFloat(editPriceInr);
|
const inrVal = parseFloat(editPriceInr);
|
||||||
const usdVal = parseFloat(editPriceUsd);
|
const usdVal = parseFloat(editPriceUsd);
|
||||||
const eurVal = editPriceEur.trim() ? parseFloat(editPriceEur) : usdVal;
|
if (isNaN(inrVal) || inrVal < 0 || isNaN(usdVal) || usdVal < 0) {
|
||||||
if (isNaN(inrVal) || inrVal < 0 || isNaN(usdVal) || usdVal < 0 || isNaN(eurVal) || eurVal < 0) {
|
|
||||||
alert('Please enter valid positive pricing values.');
|
alert('Please enter valid positive pricing values.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setEditPriceSaving(true);
|
setEditPriceSaving(true);
|
||||||
try {
|
try {
|
||||||
const isEditableBundle =
|
|
||||||
selectedEditPricePlan.plan_type === 'bundle' ||
|
|
||||||
selectedEditPricePlan.base_code === 'PATTERN_CORE' ||
|
|
||||||
selectedEditPricePlan.base_code === 'NUTRITION_CORE';
|
|
||||||
await axios.put(
|
await axios.put(
|
||||||
`${API_BASE}/api/admin/plans/${selectedEditPricePlan.base_code}/pricing`,
|
`${API_BASE}/api/admin/plans/${selectedEditPricePlan.base_code}/pricing`,
|
||||||
{
|
{
|
||||||
price_inr: inrVal,
|
price_inr: inrVal,
|
||||||
price_usd: usdVal,
|
price_usd: usdVal,
|
||||||
price_eur: eurVal,
|
|
||||||
name: editPlanName.trim() || undefined,
|
name: editPlanName.trim() || undefined,
|
||||||
description: editPlanDesc.trim() || undefined,
|
description: editPlanDesc.trim() || undefined,
|
||||||
badge_text: editPlanBadge.trim() || undefined,
|
badge_text: editPlanBadge.trim() || undefined,
|
||||||
heading: editPlanHeading.trim() || undefined,
|
heading: editPlanHeading.trim() || undefined,
|
||||||
subtitle: editPlanSubtitle.trim() || undefined,
|
subtitle: editPlanSubtitle.trim() || undefined,
|
||||||
module_ids: isEditableBundle ? editPlanModuleIds : undefined,
|
|
||||||
},
|
},
|
||||||
{ headers: { Authorization: `Bearer ${userToken}` } }
|
{ headers: { Authorization: `Bearer ${userToken}` } }
|
||||||
);
|
);
|
||||||
const updatedBundleModules =
|
|
||||||
isEditableBundle
|
|
||||||
? adminModulesList.filter((m) => editPlanModuleIds.includes(m.id))
|
|
||||||
: undefined;
|
|
||||||
setAdminPlansList((prev) =>
|
setAdminPlansList((prev) =>
|
||||||
prev.map((p) =>
|
prev.map((p) =>
|
||||||
p.base_code === selectedEditPricePlan.base_code
|
p.base_code === selectedEditPricePlan.base_code
|
||||||
|
|
@ -683,12 +620,6 @@ export default function App() {
|
||||||
subtitle: editPlanSubtitle.trim() || selectedEditPricePlan.subtitle,
|
subtitle: editPlanSubtitle.trim() || selectedEditPricePlan.subtitle,
|
||||||
price_inr: inrVal,
|
price_inr: inrVal,
|
||||||
price_usd: usdVal,
|
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
|
: p
|
||||||
)
|
)
|
||||||
|
|
@ -699,7 +630,7 @@ export default function App() {
|
||||||
...prev,
|
...prev,
|
||||||
]);
|
]);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(extractErrorMessage(err, 'Failed to update plan.'));
|
alert(err.response?.data?.detail || 'Failed to update plan.');
|
||||||
} finally {
|
} finally {
|
||||||
setEditPriceSaving(false);
|
setEditPriceSaving(false);
|
||||||
}
|
}
|
||||||
|
|
@ -716,7 +647,6 @@ export default function App() {
|
||||||
setCreatePlanDuration('yearly');
|
setCreatePlanDuration('yearly');
|
||||||
setCreatePlanPriceInr('');
|
setCreatePlanPriceInr('');
|
||||||
setCreatePlanPriceUsd('');
|
setCreatePlanPriceUsd('');
|
||||||
setCreatePlanPriceEur('');
|
|
||||||
setCreatePlanModuleIds([]);
|
setCreatePlanModuleIds([]);
|
||||||
setCreatePlanError(null);
|
setCreatePlanError(null);
|
||||||
setShowCreatePlanModal(true);
|
setShowCreatePlanModal(true);
|
||||||
|
|
@ -731,9 +661,8 @@ export default function App() {
|
||||||
}
|
}
|
||||||
const inrVal = parseFloat(createPlanPriceInr);
|
const inrVal = parseFloat(createPlanPriceInr);
|
||||||
const usdVal = parseFloat(createPlanPriceUsd);
|
const usdVal = parseFloat(createPlanPriceUsd);
|
||||||
const eurVal = createPlanPriceEur.trim() ? parseFloat(createPlanPriceEur) : usdVal;
|
if (isNaN(inrVal) || inrVal < 0 || isNaN(usdVal) || usdVal < 0) {
|
||||||
if (isNaN(inrVal) || inrVal < 0 || isNaN(usdVal) || usdVal < 0 || isNaN(eurVal) || eurVal < 0) {
|
setCreatePlanError('Please provide valid positive prices for INR and USD.');
|
||||||
setCreatePlanError('Please provide valid positive prices for INR, USD, and EUR.');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (createPlanModuleIds.length === 0) {
|
if (createPlanModuleIds.length === 0) {
|
||||||
|
|
@ -756,7 +685,6 @@ export default function App() {
|
||||||
billing_period: createPlanDuration,
|
billing_period: createPlanDuration,
|
||||||
price_inr: inrVal,
|
price_inr: inrVal,
|
||||||
price_usd: usdVal,
|
price_usd: usdVal,
|
||||||
price_eur: eurVal,
|
|
||||||
module_ids: createPlanModuleIds,
|
module_ids: createPlanModuleIds,
|
||||||
is_featured: false,
|
is_featured: false,
|
||||||
},
|
},
|
||||||
|
|
@ -772,7 +700,7 @@ export default function App() {
|
||||||
}
|
}
|
||||||
setShowCreatePlanModal(false);
|
setShowCreatePlanModal(false);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
setCreatePlanError(extractErrorMessage(err, 'Failed to create custom plan.'));
|
setCreatePlanError(err.response?.data?.detail || 'Failed to create custom plan.');
|
||||||
} finally {
|
} finally {
|
||||||
setCreatePlanSaving(false);
|
setCreatePlanSaving(false);
|
||||||
}
|
}
|
||||||
|
|
@ -790,11 +718,7 @@ export default function App() {
|
||||||
category: 'general',
|
category: 'general',
|
||||||
discountType: 'percentage',
|
discountType: 'percentage',
|
||||||
discountValue: '20',
|
discountValue: '20',
|
||||||
discountValueUsd: '',
|
|
||||||
discountValueEur: '',
|
|
||||||
maxDiscountCap: '0',
|
maxDiscountCap: '0',
|
||||||
maxDiscountCapUsd: '',
|
|
||||||
maxDiscountCapEur: '',
|
|
||||||
description: '',
|
description: '',
|
||||||
startDate: todayStr,
|
startDate: todayStr,
|
||||||
endDate: nextYearStr,
|
endDate: nextYearStr,
|
||||||
|
|
@ -802,10 +726,7 @@ export default function App() {
|
||||||
applicablePlanIds: [],
|
applicablePlanIds: [],
|
||||||
applicableModuleIds: [],
|
applicableModuleIds: [],
|
||||||
minSpend: '0',
|
minSpend: '0',
|
||||||
minSpendUsd: '',
|
|
||||||
minSpendEur: '',
|
|
||||||
usageLimit: '0',
|
usageLimit: '0',
|
||||||
perUserLimit: '',
|
|
||||||
firstOnly: false,
|
firstOnly: false,
|
||||||
});
|
});
|
||||||
setCouponModalMode('create');
|
setCouponModalMode('create');
|
||||||
|
|
@ -821,23 +742,16 @@ export default function App() {
|
||||||
code: c.code,
|
code: c.code,
|
||||||
category: c.coupon_category || 'general',
|
category: c.coupon_category || 'general',
|
||||||
discountType: c.discount_type || 'percentage',
|
discountType: c.discount_type || 'percentage',
|
||||||
discountValue: String(c.value_inr ?? c.value ?? 0),
|
discountValue: String(c.value ?? 0),
|
||||||
discountValueUsd: c.value_usd !== undefined && c.value_usd !== null ? String(c.value_usd) : '',
|
maxDiscountCap: String(c.max_discount_limit ?? 0),
|
||||||
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 || '',
|
description: c.description || '',
|
||||||
startDate: c.start_date ? c.start_date.split('T')[0] : '',
|
startDate: c.start_date ? c.start_date.split('T')[0] : '',
|
||||||
endDate: c.end_date ? c.end_date.split('T')[0] : '',
|
endDate: c.end_date ? c.end_date.split('T')[0] : '',
|
||||||
scope: hasSpecific ? 'specific' : 'storewide',
|
scope: hasSpecific ? 'specific' : 'storewide',
|
||||||
applicablePlanIds: c.applicable_plan_ids || [],
|
applicablePlanIds: c.applicable_plan_ids || [],
|
||||||
applicableModuleIds: c.applicable_module_ids || [],
|
applicableModuleIds: c.applicable_module_ids || [],
|
||||||
minSpend: String(c.min_purchase_inr ?? c.min_purchase_amount ?? 0),
|
minSpend: String(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),
|
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),
|
firstOnly: Boolean(c.is_first_purchase_only),
|
||||||
});
|
});
|
||||||
setCouponModalMode('edit');
|
setCouponModalMode('edit');
|
||||||
|
|
@ -846,58 +760,17 @@ export default function App() {
|
||||||
const handleSaveCoupon = async (e: React.FormEvent) => {
|
const handleSaveCoupon = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!couponFormData.code.trim() || !userToken) return;
|
if (!couponFormData.code.trim() || !userToken) return;
|
||||||
|
|
||||||
if (couponFormData.startDate && couponFormData.endDate && couponFormData.endDate <= couponFormData.startDate) {
|
|
||||||
alert('Invalid date range: Expiration date must be later than start date.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCouponSaving(true);
|
setCouponSaving(true);
|
||||||
try {
|
try {
|
||||||
const headers = { Authorization: `Bearer ${userToken}` };
|
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 = {
|
const payload: any = {
|
||||||
code: couponFormData.code.trim().toUpperCase(),
|
code: couponFormData.code.trim().toUpperCase(),
|
||||||
discount_type: couponFormData.discountType,
|
discount_type: couponFormData.discountType,
|
||||||
coupon_category: couponFormData.category,
|
coupon_category: couponFormData.category,
|
||||||
value: valInr,
|
value: parseFloat(couponFormData.discountValue) || 0,
|
||||||
value_inr: valInr,
|
max_discount_limit: parseFloat(couponFormData.maxDiscountCap) || 0,
|
||||||
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,
|
usage_limit: parseInt(couponFormData.usageLimit) || 0,
|
||||||
per_user_limit: parsedPerUser,
|
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_first_purchase_only: couponFormData.firstOnly,
|
||||||
is_active: true,
|
is_active: true,
|
||||||
description: couponFormData.description.trim() || undefined,
|
description: couponFormData.description.trim() || undefined,
|
||||||
|
|
@ -929,7 +802,7 @@ export default function App() {
|
||||||
setSelectedEditCoupon(null);
|
setSelectedEditCoupon(null);
|
||||||
await fetchRazorpayAdminData();
|
await fetchRazorpayAdminData();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(extractErrorMessage(err, 'Failed to save coupon.'));
|
alert(err.response?.data?.detail || 'Failed to save coupon.');
|
||||||
} finally {
|
} finally {
|
||||||
setCouponSaving(false);
|
setCouponSaving(false);
|
||||||
}
|
}
|
||||||
|
|
@ -956,7 +829,7 @@ export default function App() {
|
||||||
setAdminCouponsList((prev) =>
|
setAdminCouponsList((prev) =>
|
||||||
prev.map((item) => (item.id === c.id ? { ...item, is_active: !newActive } : item))
|
prev.map((item) => (item.id === c.id ? { ...item, is_active: !newActive } : item))
|
||||||
);
|
);
|
||||||
alert(extractErrorMessage(err, 'Failed to update coupon status.'));
|
alert(err.response?.data?.detail || 'Failed to update coupon status.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -969,7 +842,7 @@ export default function App() {
|
||||||
setAdminCouponsList((prev) => prev.filter((item) => item.id !== c.id));
|
setAdminCouponsList((prev) => prev.filter((item) => item.id !== c.id));
|
||||||
setAdminLogs((prev) => [`[Coupons] Deleted promo code ${c.code}.`, ...prev]);
|
setAdminLogs((prev) => [`[Coupons] Deleted promo code ${c.code}.`, ...prev]);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(extractErrorMessage(err, 'Failed to delete coupon.'));
|
alert(err.response?.data?.detail || 'Failed to delete coupon.');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -994,7 +867,7 @@ export default function App() {
|
||||||
throw new Error('Invoice URL is missing in server response.');
|
throw new Error('Invoice URL is missing in server response.');
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(extractErrorMessage(err, 'Could not download invoice.'));
|
alert(err.response?.data?.detail || 'Could not download invoice.');
|
||||||
} finally {
|
} finally {
|
||||||
setDownloadingInvoiceId(null);
|
setDownloadingInvoiceId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -1008,7 +881,7 @@ export default function App() {
|
||||||
const res = await axios.post(`${API_BASE}/api/admin/payments/${paymentId}/share-invoice`, {}, { headers });
|
const res = await axios.post(`${API_BASE}/api/admin/payments/${paymentId}/share-invoice`, {}, { headers });
|
||||||
alert(res.data?.message || 'Invoice shared successfully via email!');
|
alert(res.data?.message || 'Invoice shared successfully via email!');
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(extractErrorMessage(err, 'Could not share invoice.'));
|
alert(err.response?.data?.detail || 'Could not share invoice.');
|
||||||
} finally {
|
} finally {
|
||||||
setSharingInvoiceId(null);
|
setSharingInvoiceId(null);
|
||||||
}
|
}
|
||||||
|
|
@ -1036,7 +909,7 @@ export default function App() {
|
||||||
setCreateAdminName('');
|
setCreateAdminName('');
|
||||||
await fetchRazorpayAdminData();
|
await fetchRazorpayAdminData();
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
alert(`Admin creation failed: ${extractErrorMessage(err, 'Admin creation failed.')}`);
|
alert(`Admin creation failed: ${err.response?.data?.detail || err.message}`);
|
||||||
} finally {
|
} finally {
|
||||||
setAdminActionLoading(false);
|
setAdminActionLoading(false);
|
||||||
}
|
}
|
||||||
|
|
@ -1046,46 +919,24 @@ export default function App() {
|
||||||
if (!loggedInUser || !isAdmin) {
|
if (!loggedInUser || !isAdmin) {
|
||||||
return (
|
return (
|
||||||
<AdminLoginForm
|
<AdminLoginForm
|
||||||
|
email={adminEmail}
|
||||||
|
password={adminPassword}
|
||||||
|
showPassword={showAdminPassword}
|
||||||
loading={adminAuthLoading}
|
loading={adminAuthLoading}
|
||||||
error={adminAuthError}
|
error={adminAuthError}
|
||||||
loggedInUser={loggedInUser}
|
loggedInUser={loggedInUser}
|
||||||
isAdmin={isAdmin}
|
isAdmin={isAdmin}
|
||||||
|
onEmailChange={setAdminEmail}
|
||||||
|
onPasswordChange={setAdminPassword}
|
||||||
|
onToggleShowPassword={() => setShowAdminPassword(!showAdminPassword)}
|
||||||
onSubmit={handleAdminLogin}
|
onSubmit={handleAdminLogin}
|
||||||
onLogout={handleLogout}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-slate-50 flex flex-col md:flex-row text-slate-800 selection:bg-indigo-500 selection:text-white">
|
<div className="min-h-screen bg-slate-50 flex flex-col md:flex-row text-slate-800 selection:bg-indigo-500 selection:text-white">
|
||||||
{/* Mobile Top Header Bar (Only visible on screens < md) */}
|
{/* 1. Collapsible Sidebar */}
|
||||||
<header className="md:hidden flex items-center justify-between px-4 py-3 bg-[#0A0A0E] text-white border-b border-slate-800 sticky top-0 z-30 shadow-md">
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={() => setIsMobileMenuOpen(true)}
|
|
||||||
className="p-2 -ml-2 rounded-xl text-slate-300 hover:text-white hover:bg-slate-800/80 transition-colors cursor-pointer border border-transparent hover:border-slate-700/60"
|
|
||||||
aria-label="Open navigation menu"
|
|
||||||
>
|
|
||||||
<Menu className="h-5 w-5" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="h-7 w-7 rounded-lg bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-xs">
|
|
||||||
<Sparkles className="h-3.5 w-3.5 text-white" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h1 className="text-xs font-black tracking-tight text-white leading-tight">ACUPEDIA</h1>
|
|
||||||
<p className="text-[7px] text-slate-400 font-bold tracking-widest uppercase leading-none">ADMIN CONSOLE</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Current Tab Indicator Badge on Mobile */}
|
|
||||||
<div className="text-[11px] font-bold text-indigo-400 bg-indigo-950/80 border border-indigo-500/30 px-2.5 py-0.5 rounded-full capitalize max-w-[120px] truncate">
|
|
||||||
{adminSubTab === 'users_subscriptions' ? 'Subscriptions' : adminSubTab.replace('_', ' ')}
|
|
||||||
</div>
|
|
||||||
</header>
|
|
||||||
|
|
||||||
{/* 1. Collapsible & Responsive Sidebar */}
|
|
||||||
<AdminSidebar
|
<AdminSidebar
|
||||||
loggedInUser={loggedInUser}
|
loggedInUser={loggedInUser}
|
||||||
activeTab={adminSubTab}
|
activeTab={adminSubTab}
|
||||||
|
|
@ -1094,10 +945,10 @@ export default function App() {
|
||||||
modules: adminModulesList.length,
|
modules: adminModulesList.length,
|
||||||
plans: adminPlansList.length,
|
plans: adminPlansList.length,
|
||||||
coupons: adminCouponsList.length,
|
coupons: adminCouponsList.length,
|
||||||
customers: customersList.length,
|
customers: practitionersList.length + adminsList.length,
|
||||||
subscriptions: usersSubscriptions.length,
|
subscriptions: usersSubscriptions.length,
|
||||||
payments: rzpPayments.length,
|
payments: rzpPayments.length,
|
||||||
admins: resolvedAdminsList.length,
|
admins: adminsList.length,
|
||||||
}}
|
}}
|
||||||
isCollapsed={isSidebarCollapsed}
|
isCollapsed={isSidebarCollapsed}
|
||||||
onToggleCollapse={() => {
|
onToggleCollapse={() => {
|
||||||
|
|
@ -1108,8 +959,6 @@ export default function App() {
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
onLogout={handleLogout}
|
onLogout={handleLogout}
|
||||||
isMobileOpen={isMobileMenuOpen}
|
|
||||||
onCloseMobile={() => setIsMobileMenuOpen(false)}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* 2. Main Administrative Workspace */}
|
{/* 2. Main Administrative Workspace */}
|
||||||
|
|
@ -1124,7 +973,6 @@ export default function App() {
|
||||||
<h2 className="text-xl sm:text-2xl font-black text-slate-900 tracking-tight">
|
<h2 className="text-xl sm:text-2xl font-black text-slate-900 tracking-tight">
|
||||||
{adminSubTab === 'overview' && 'System Overview & Audit Logs'}
|
{adminSubTab === 'overview' && 'System Overview & Audit Logs'}
|
||||||
{adminSubTab === 'modules' && 'Curriculum Modules'}
|
{adminSubTab === 'modules' && 'Curriculum Modules'}
|
||||||
{adminSubTab === 'module_builder' && 'Clinical Module Builder'}
|
|
||||||
{adminSubTab === 'plans' && 'Subscription Plans & Pricing'}
|
{adminSubTab === 'plans' && 'Subscription Plans & Pricing'}
|
||||||
{adminSubTab === 'coupons' && 'Promotions & Coupons'}
|
{adminSubTab === 'coupons' && 'Promotions & Coupons'}
|
||||||
{adminSubTab === 'customers' && 'Customer Directory'}
|
{adminSubTab === 'customers' && 'Customer Directory'}
|
||||||
|
|
@ -1137,7 +985,6 @@ export default function App() {
|
||||||
<p className="text-slate-500 text-xs font-semibold">
|
<p className="text-slate-500 text-xs font-semibold">
|
||||||
{adminSubTab === 'overview' && 'Real-time telemetry, synchronized payment logs, and platform health metrics.'}
|
{adminSubTab === 'overview' && 'Real-time telemetry, synchronized payment logs, and platform health metrics.'}
|
||||||
{adminSubTab === 'modules' && 'Configure learning modules, categories, pricing, and availability states.'}
|
{adminSubTab === 'modules' && 'Configure learning modules, categories, pricing, and availability states.'}
|
||||||
{adminSubTab === 'module_builder' && 'Author and customize disease categories, clinical patterns, and treatment formulas.'}
|
|
||||||
{adminSubTab === 'plans' && 'Manage localized pricing tiers, curriculum module bundles, and active pricing.'}
|
{adminSubTab === 'plans' && 'Manage localized pricing tiers, curriculum module bundles, and active pricing.'}
|
||||||
{adminSubTab === 'coupons' && 'Manage discount codes, percentage cuts, module restrictions, and expiry dates.'}
|
{adminSubTab === 'coupons' && 'Manage discount codes, percentage cuts, module restrictions, and expiry dates.'}
|
||||||
{adminSubTab === 'customers' && 'Inspect practitioner accounts, credentials, countries, and purchased plans.'}
|
{adminSubTab === 'customers' && 'Inspect practitioner accounts, credentials, countries, and purchased plans.'}
|
||||||
|
|
@ -1145,7 +992,7 @@ export default function App() {
|
||||||
{adminSubTab === 'payments' && 'View Razorpay transactions, currencies, invoice details, and captured amounts.'}
|
{adminSubTab === 'payments' && 'View Razorpay transactions, currencies, invoice details, and captured amounts.'}
|
||||||
{adminSubTab === 'admins' && 'Assign administrator credentials and RBAC privilege levels.'}
|
{adminSubTab === 'admins' && 'Assign administrator credentials and RBAC privilege levels.'}
|
||||||
{adminSubTab === 'database' && 'Export PostgreSQL dumps and verify database connectivity.'}
|
{adminSubTab === 'database' && 'Export PostgreSQL dumps and verify database connectivity.'}
|
||||||
{adminSubTab === 'reports' && 'Download revenue ledgers, customer records, and financial reports.'}
|
{adminSubTab === 'reports' && 'Download accounting CSVs, tax summaries, and financial reports.'}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -1180,9 +1027,9 @@ export default function App() {
|
||||||
{adminSubTab === 'overview' && (
|
{adminSubTab === 'overview' && (
|
||||||
<SyncOverview
|
<SyncOverview
|
||||||
stats={{
|
stats={{
|
||||||
totalUsers: customersList.length,
|
totalUsers: practitionersList.length + adminsList.length,
|
||||||
subscriptions: usersSubscriptions.length,
|
subscriptions: usersSubscriptions.length,
|
||||||
superAdmins: resolvedAdminsList.length,
|
superAdmins: adminsList.length,
|
||||||
payments: rzpPayments.length,
|
payments: rzpPayments.length,
|
||||||
}}
|
}}
|
||||||
adminLogs={adminLogs}
|
adminLogs={adminLogs}
|
||||||
|
|
@ -1208,10 +1055,6 @@ export default function App() {
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{adminSubTab === 'module_builder' && (
|
|
||||||
<ModuleBuilderTab />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{adminSubTab === 'plans' && (
|
{adminSubTab === 'plans' && (
|
||||||
<PlansTab
|
<PlansTab
|
||||||
plans={adminPlansList}
|
plans={adminPlansList}
|
||||||
|
|
@ -1249,7 +1092,7 @@ export default function App() {
|
||||||
|
|
||||||
{adminSubTab === 'customers' && (
|
{adminSubTab === 'customers' && (
|
||||||
<CustomersTab
|
<CustomersTab
|
||||||
customers={customersList}
|
customers={practitionersList}
|
||||||
currentPage={customersPage}
|
currentPage={customersPage}
|
||||||
perPage={customersPerPage}
|
perPage={customersPerPage}
|
||||||
onPageChange={setCustomersPage}
|
onPageChange={setCustomersPage}
|
||||||
|
|
@ -1288,7 +1131,7 @@ export default function App() {
|
||||||
|
|
||||||
{adminSubTab === 'admins' && (
|
{adminSubTab === 'admins' && (
|
||||||
<AdminsTab
|
<AdminsTab
|
||||||
admins={resolvedAdminsList}
|
admins={adminsList}
|
||||||
name={createAdminName}
|
name={createAdminName}
|
||||||
email={createAdminEmail}
|
email={createAdminEmail}
|
||||||
password={createAdminPassword}
|
password={createAdminPassword}
|
||||||
|
|
@ -1320,7 +1163,7 @@ export default function App() {
|
||||||
downloadingReport={reportDownloading}
|
downloadingReport={reportDownloading}
|
||||||
successMessage={reportExportSuccess}
|
successMessage={reportExportSuccess}
|
||||||
errorMessage={reportExportError}
|
errorMessage={reportExportError}
|
||||||
totalUsers={customersList.length}
|
totalUsers={practitionersList.length + adminsList.length}
|
||||||
totalPayments={rzpPayments.length}
|
totalPayments={rzpPayments.length}
|
||||||
totalSubscriptions={usersSubscriptions.length}
|
totalSubscriptions={usersSubscriptions.length}
|
||||||
totalCoupons={adminCouponsList.length}
|
totalCoupons={adminCouponsList.length}
|
||||||
|
|
@ -1340,13 +1183,10 @@ export default function App() {
|
||||||
name={editModuleName}
|
name={editModuleName}
|
||||||
description={editModuleDesc}
|
description={editModuleDesc}
|
||||||
category={editModuleCategory}
|
category={editModuleCategory}
|
||||||
icon={editModuleIcon}
|
|
||||||
color={editModuleColor}
|
|
||||||
saving={editModuleSaving}
|
saving={editModuleSaving}
|
||||||
onNameChange={setEditModuleName}
|
onNameChange={setEditModuleName}
|
||||||
onDescriptionChange={setEditModuleDesc}
|
onDescriptionChange={setEditModuleDesc}
|
||||||
onIconChange={setEditModuleIcon}
|
onCategoryChange={setEditModuleCategory}
|
||||||
onColorChange={setEditModuleColor}
|
|
||||||
onSave={handleSaveModuleDetails}
|
onSave={handleSaveModuleDetails}
|
||||||
onClose={() => setSelectedEditModule(null)}
|
onClose={() => setSelectedEditModule(null)}
|
||||||
/>
|
/>
|
||||||
|
|
@ -1363,7 +1203,6 @@ export default function App() {
|
||||||
duration={createPlanDuration}
|
duration={createPlanDuration}
|
||||||
priceInr={createPlanPriceInr}
|
priceInr={createPlanPriceInr}
|
||||||
priceUsd={createPlanPriceUsd}
|
priceUsd={createPlanPriceUsd}
|
||||||
priceEur={createPlanPriceEur}
|
|
||||||
selectedModuleIds={createPlanModuleIds}
|
selectedModuleIds={createPlanModuleIds}
|
||||||
allModules={adminModulesList}
|
allModules={adminModulesList}
|
||||||
saving={createPlanSaving}
|
saving={createPlanSaving}
|
||||||
|
|
@ -1377,13 +1216,7 @@ export default function App() {
|
||||||
onTypeChange={setCreatePlanType}
|
onTypeChange={setCreatePlanType}
|
||||||
onDurationChange={setCreatePlanDuration}
|
onDurationChange={setCreatePlanDuration}
|
||||||
onPriceInrChange={setCreatePlanPriceInr}
|
onPriceInrChange={setCreatePlanPriceInr}
|
||||||
onPriceUsdChange={(v) => {
|
onPriceUsdChange={setCreatePlanPriceUsd}
|
||||||
setCreatePlanPriceUsd(v);
|
|
||||||
if (!createPlanPriceEur || createPlanPriceEur === createPlanPriceUsd) {
|
|
||||||
setCreatePlanPriceEur(v);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
onPriceEurChange={setCreatePlanPriceEur}
|
|
||||||
onToggleModule={(id) =>
|
onToggleModule={(id) =>
|
||||||
setCreatePlanModuleIds((prev) =>
|
setCreatePlanModuleIds((prev) =>
|
||||||
prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id]
|
prev.includes(id) ? prev.filter((x) => x !== id) : [...prev, id]
|
||||||
|
|
@ -1404,9 +1237,6 @@ export default function App() {
|
||||||
subtitle={editPlanSubtitle}
|
subtitle={editPlanSubtitle}
|
||||||
priceInr={editPriceInr}
|
priceInr={editPriceInr}
|
||||||
priceUsd={editPriceUsd}
|
priceUsd={editPriceUsd}
|
||||||
priceEur={editPriceEur}
|
|
||||||
allModules={adminModulesList}
|
|
||||||
moduleIds={editPlanModuleIds}
|
|
||||||
saving={editPriceSaving}
|
saving={editPriceSaving}
|
||||||
onNameChange={setEditPlanName}
|
onNameChange={setEditPlanName}
|
||||||
onDescChange={setEditPlanDesc}
|
onDescChange={setEditPlanDesc}
|
||||||
|
|
@ -1415,14 +1245,6 @@ export default function App() {
|
||||||
onSubtitleChange={setEditPlanSubtitle}
|
onSubtitleChange={setEditPlanSubtitle}
|
||||||
onPriceInrChange={setEditPriceInr}
|
onPriceInrChange={setEditPriceInr}
|
||||||
onPriceUsdChange={setEditPriceUsd}
|
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}
|
onSave={handleSavePlanPrice}
|
||||||
onClose={() => setSelectedEditPricePlan(null)}
|
onClose={() => setSelectedEditPricePlan(null)}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,33 @@
|
||||||
import React, { useState } from 'react';
|
import React from 'react';
|
||||||
import { Sparkles, AlertCircle, Shield, Eye, EyeOff } from 'lucide-react';
|
import { Sparkles, AlertCircle, Shield, Eye, EyeOff } from 'lucide-react';
|
||||||
|
|
||||||
interface AdminLoginFormProps {
|
interface AdminLoginFormProps {
|
||||||
|
email: string;
|
||||||
|
password: string;
|
||||||
|
showPassword: boolean;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
loggedInUser: any;
|
loggedInUser: any;
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
onSubmit: (credentials: { email: string; password: string }) => void;
|
onEmailChange: (v: string) => void;
|
||||||
onLogout?: () => void;
|
onPasswordChange: (v: string) => void;
|
||||||
|
onToggleShowPassword: () => void;
|
||||||
|
onSubmit: (e: React.FormEvent) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
|
export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
|
||||||
|
email,
|
||||||
|
password,
|
||||||
|
showPassword,
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
loggedInUser,
|
loggedInUser,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
|
onEmailChange,
|
||||||
|
onPasswordChange,
|
||||||
|
onToggleShowPassword,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onLogout,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [email, setEmail] = useState('');
|
|
||||||
const [password, setPassword] = useState('');
|
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
|
||||||
|
|
||||||
const handleSubmit = (e: React.FormEvent) => {
|
|
||||||
e.preventDefault();
|
|
||||||
onSubmit({ email, password });
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-[#08080C] text-slate-100 flex items-center justify-center p-4 selection:bg-indigo-500 selection:text-white">
|
<div className="min-h-screen bg-[#08080C] text-slate-100 flex items-center justify-center p-4 selection:bg-indigo-500 selection:text-white">
|
||||||
<div className="w-full max-w-md bg-slate-900/90 border border-slate-800 rounded-3xl p-8 shadow-2xl backdrop-blur-xl space-y-6">
|
<div className="w-full max-w-md bg-slate-900/90 border border-slate-800 rounded-3xl p-8 shadow-2xl backdrop-blur-xl space-y-6">
|
||||||
|
|
@ -46,33 +47,21 @@ export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{loggedInUser && !isAdmin && (
|
{loggedInUser && !isAdmin && (
|
||||||
<div className="p-3 bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs rounded-xl font-bold flex flex-col gap-2">
|
<div className="p-3 bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs rounded-xl font-bold flex items-center gap-2">
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Shield className="h-4 w-4 shrink-0" />
|
<Shield className="h-4 w-4 shrink-0" />
|
||||||
<span>Account {loggedInUser.email} lacks administrative privileges.</span>
|
<span>Account {loggedInUser.email} lacks administrative privileges.</span>
|
||||||
</div>
|
</div>
|
||||||
{onLogout && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onLogout}
|
|
||||||
className="text-[11px] text-amber-300 hover:text-white underline text-left cursor-pointer"
|
|
||||||
>
|
|
||||||
Log out
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<form onSubmit={handleSubmit} className="space-y-4">
|
<form onSubmit={onSubmit} className="space-y-4">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-400">Admin Email</label>
|
<label className="text-[10px] uppercase font-black tracking-wider text-slate-400">Admin Email</label>
|
||||||
<input
|
<input
|
||||||
type="email"
|
type="email"
|
||||||
required
|
required
|
||||||
value={email}
|
value={email}
|
||||||
onChange={(e) => setEmail(e.target.value)}
|
onChange={(e) => onEmailChange(e.target.value)}
|
||||||
placeholder="admin@acupedia.in"
|
placeholder="admin@acupedia.in"
|
||||||
autoComplete="username"
|
|
||||||
className="w-full px-4 py-3 rounded-xl bg-slate-800/80 border border-slate-700 text-white text-xs font-semibold focus:outline-none focus:border-indigo-500"
|
className="w-full px-4 py-3 rounded-xl bg-slate-800/80 border border-slate-700 text-white text-xs font-semibold focus:outline-none focus:border-indigo-500"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -84,14 +73,13 @@ export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
|
||||||
type={showPassword ? 'text' : 'password'}
|
type={showPassword ? 'text' : 'password'}
|
||||||
required
|
required
|
||||||
value={password}
|
value={password}
|
||||||
onChange={(e) => setPassword(e.target.value)}
|
onChange={(e) => onPasswordChange(e.target.value)}
|
||||||
placeholder="••••••••"
|
placeholder="••••••••"
|
||||||
autoComplete="current-password"
|
|
||||||
className="w-full px-4 py-3 rounded-xl bg-slate-800/80 border border-slate-700 text-white text-xs font-semibold focus:outline-none focus:border-indigo-500"
|
className="w-full px-4 py-3 rounded-xl bg-slate-800/80 border border-slate-700 text-white text-xs font-semibold focus:outline-none focus:border-indigo-500"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setShowPassword(!showPassword)}
|
onClick={onToggleShowPassword}
|
||||||
className="absolute right-3 top-3 text-slate-400 hover:text-white cursor-pointer"
|
className="absolute right-3 top-3 text-slate-400 hover:text-white cursor-pointer"
|
||||||
>
|
>
|
||||||
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
||||||
|
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
import { Component, type ErrorInfo, type ReactNode } from 'react';
|
|
||||||
import { AlertTriangle, RefreshCw } from 'lucide-react';
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
children: ReactNode;
|
|
||||||
fallbackTitle?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface State {
|
|
||||||
hasError: boolean;
|
|
||||||
error: Error | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ErrorBoundary extends Component<Props, State> {
|
|
||||||
public state: State = {
|
|
||||||
hasError: false,
|
|
||||||
error: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
public static getDerivedStateFromError(error: Error): State {
|
|
||||||
return { hasError: true, error };
|
|
||||||
}
|
|
||||||
|
|
||||||
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
||||||
console.error('ErrorBoundary caught an error:', error, errorInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public handleReset = () => {
|
|
||||||
this.setState({ hasError: false, error: null });
|
|
||||||
};
|
|
||||||
|
|
||||||
public render() {
|
|
||||||
if (this.state.hasError) {
|
|
||||||
return (
|
|
||||||
<div className="p-8 bg-white border border-rose-200 rounded-3xl shadow-sm text-center space-y-4 max-w-lg mx-auto my-8">
|
|
||||||
<div className="h-12 w-12 rounded-2xl bg-rose-50 text-rose-600 flex items-center justify-center mx-auto">
|
|
||||||
<AlertTriangle className="h-6 w-6" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h3 className="text-base font-black text-slate-900">
|
|
||||||
{this.props.fallbackTitle || 'Something went wrong in this section'}
|
|
||||||
</h3>
|
|
||||||
<p className="text-xs text-slate-500 font-medium mt-1">
|
|
||||||
{this.state.error?.message || 'An unexpected rendering error occurred.'}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={this.handleReset}
|
|
||||||
className="px-4 py-2 bg-indigo-600 hover:bg-indigo-500 text-white text-xs font-bold rounded-xl inline-flex items-center gap-1.5 shadow"
|
|
||||||
>
|
|
||||||
<RefreshCw className="h-3.5 w-3.5" />
|
|
||||||
Try Again
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.props.children;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,11 +6,7 @@ export interface CouponFormData {
|
||||||
category: string;
|
category: string;
|
||||||
discountType: 'percentage' | 'flat';
|
discountType: 'percentage' | 'flat';
|
||||||
discountValue: string;
|
discountValue: string;
|
||||||
discountValueUsd: string;
|
|
||||||
discountValueEur: string;
|
|
||||||
maxDiscountCap: string;
|
maxDiscountCap: string;
|
||||||
maxDiscountCapUsd: string;
|
|
||||||
maxDiscountCapEur: string;
|
|
||||||
description: string;
|
description: string;
|
||||||
startDate: string;
|
startDate: string;
|
||||||
endDate: string;
|
endDate: string;
|
||||||
|
|
@ -18,10 +14,7 @@ export interface CouponFormData {
|
||||||
applicablePlanIds: string[];
|
applicablePlanIds: string[];
|
||||||
applicableModuleIds: string[];
|
applicableModuleIds: string[];
|
||||||
minSpend: string;
|
minSpend: string;
|
||||||
minSpendUsd: string;
|
|
||||||
minSpendEur: string;
|
|
||||||
usageLimit: string;
|
usageLimit: string;
|
||||||
perUserLimit: string;
|
|
||||||
firstOnly: boolean;
|
firstOnly: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +42,6 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
if (!mode) return null;
|
if (!mode) return null;
|
||||||
|
|
||||||
const isEdit = mode === 'edit';
|
const isEdit = mode === 'edit';
|
||||||
const isDateRangeInvalid = Boolean(data.startDate && data.endDate && data.endDate <= data.startDate);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4">
|
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4">
|
||||||
|
|
@ -82,7 +74,7 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
<span className="text-xs font-bold text-slate-700">Block 1: Promo Code & Discount Value</span>
|
<span className="text-xs font-bold text-slate-700">Block 1: Promo Code & Discount Value</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Coupon Code *</label>
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Coupon Code *</label>
|
||||||
<input
|
<input
|
||||||
|
|
@ -112,7 +104,7 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-3">
|
<div className="grid grid-cols-3 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Discount Type</label>
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Discount Type</label>
|
||||||
<select
|
<select
|
||||||
|
|
@ -121,112 +113,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"
|
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="percentage">Percentage (%)</option>
|
||||||
<option value="flat">Flat Amount (₹ / $ / €)</option>
|
<option value="flat">Flat Amount (₹/$)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{data.discountType === 'percentage' ? (
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-4 gap-2.5">
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Discount % *</label>
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">
|
||||||
<div className="relative">
|
{data.discountType === 'percentage' ? 'Percentage (%) *' : 'Flat Amount *'}
|
||||||
|
</label>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
step="0.01"
|
step="0.01"
|
||||||
min="0.01"
|
min="0.01"
|
||||||
max="100"
|
|
||||||
required
|
required
|
||||||
value={data.discountValue}
|
value={data.discountValue}
|
||||||
onChange={(e) => onChange('discountValue', e.target.value)}
|
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"
|
||||||
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>
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Max Cap ₹ (INR)</label>
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Max Cap (0=None)</label>
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
step="0.01"
|
step="0.01"
|
||||||
min="0"
|
min="0"
|
||||||
|
disabled={data.discountType !== 'percentage'}
|
||||||
value={data.maxDiscountCap}
|
value={data.maxDiscountCap}
|
||||||
onChange={(e) => onChange('maxDiscountCap', e.target.value)}
|
onChange={(e) => onChange('maxDiscountCap', e.target.value)}
|
||||||
placeholder="0 = None"
|
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"
|
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>
|
|
||||||
<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>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -248,16 +164,14 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
<span className="text-xs font-bold text-slate-700">Block 2: Schedule & Date Window</span>
|
<span className="text-xs font-bold text-slate-700">Block 2: Schedule & Date Window</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Start Date</label>
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Start Date</label>
|
||||||
<input
|
<input
|
||||||
type="date"
|
type="date"
|
||||||
value={data.startDate}
|
value={data.startDate}
|
||||||
onChange={(e) => onChange('startDate', e.target.value)}
|
onChange={(e) => onChange('startDate', e.target.value)}
|
||||||
className={`w-full bg-white border rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none cursor-pointer ${
|
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 cursor-pointer"
|
||||||
isDateRangeInvalid ? 'border-rose-400 focus:border-rose-500' : 'border-slate-200 focus:border-indigo-500'
|
|
||||||
}`}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -266,19 +180,10 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
type="date"
|
type="date"
|
||||||
value={data.endDate}
|
value={data.endDate}
|
||||||
onChange={(e) => onChange('endDate', e.target.value)}
|
onChange={(e) => onChange('endDate', e.target.value)}
|
||||||
className={`w-full bg-white border rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none cursor-pointer ${
|
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 cursor-pointer"
|
||||||
isDateRangeInvalid ? 'border-rose-400 focus:border-rose-500' : 'border-slate-200 focus:border-indigo-500'
|
|
||||||
}`}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{isDateRangeInvalid && (
|
|
||||||
<div className="text-xs font-semibold text-rose-600 bg-rose-50 border border-rose-200 rounded-xl px-3 py-2 flex items-center gap-2">
|
|
||||||
<span>⚠️</span>
|
|
||||||
<span>Invalid date range: Expiration date must be later than start date.</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* BLOCK 3: Scope & Item Restrictions */}
|
{/* BLOCK 3: Scope & Item Restrictions */}
|
||||||
|
|
@ -319,20 +224,16 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
</label>
|
</label>
|
||||||
<div className="max-h-28 overflow-y-auto bg-white border border-slate-200 rounded-xl p-2 space-y-1.5">
|
<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) => {
|
{plans.map((p) => {
|
||||||
const pids: string[] = [p.inr_plan_id, p.usd_plan_id, p.eur_plan_id, p.id].filter(Boolean);
|
const pid = p.inr_plan_id || p.id;
|
||||||
const checked = pids.some((id) => data.applicablePlanIds.includes(id));
|
const checked = data.applicablePlanIds.includes(pid);
|
||||||
return (
|
return (
|
||||||
<label key={p.base_code || p.code} className="flex items-center gap-2 text-xs text-slate-700 cursor-pointer">
|
<label key={p.base_code || p.code} className="flex items-center gap-2 text-xs text-slate-700 cursor-pointer">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
if (e.target.checked) {
|
if (e.target.checked) onChange('applicablePlanIds', [...data.applicablePlanIds, pid]);
|
||||||
const toAdd = pids.filter((id) => !data.applicablePlanIds.includes(id));
|
else onChange('applicablePlanIds', data.applicablePlanIds.filter((x) => x !== pid));
|
||||||
onChange('applicablePlanIds', [...data.applicablePlanIds, ...toAdd]);
|
|
||||||
} else {
|
|
||||||
onChange('applicablePlanIds', data.applicablePlanIds.filter((x) => !pids.includes(x)));
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
className="accent-indigo-600 rounded"
|
className="accent-indigo-600 rounded"
|
||||||
/>
|
/>
|
||||||
|
|
@ -378,55 +279,21 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
<span className="text-xs font-bold text-slate-700">Block 4: Conditions & Usage Limits</span>
|
<span className="text-xs font-bold text-slate-700">Block 4: Conditions & Usage Limits</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[11px] font-bold text-slate-600 mb-1.5">
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Min Spend (0=None)</label>
|
||||||
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
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
step="0.01"
|
step="0.01"
|
||||||
min="0"
|
min="0"
|
||||||
value={data.minSpend}
|
value={data.minSpend}
|
||||||
onChange={(e) => onChange('minSpend', e.target.value)}
|
onChange={(e) => onChange('minSpend', e.target.value)}
|
||||||
placeholder="Min ₹ (INR)"
|
placeholder="0"
|
||||||
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"
|
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 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>
|
<div>
|
||||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">
|
<label className="block text-[11px] font-bold text-slate-600 mb-1">Global Usage Limit (0=None)</label>
|
||||||
Total Usage Limit
|
|
||||||
</label>
|
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0"
|
||||||
|
|
@ -435,35 +302,10 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
placeholder="0"
|
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"
|
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>
|
||||||
<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>
|
||||||
<div className="flex items-center sm:pt-7">
|
|
||||||
<label className="flex items-center gap-2 cursor-pointer">
|
<label className="flex items-center gap-2 cursor-pointer pt-1">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={data.firstOnly}
|
checked={data.firstOnly}
|
||||||
|
|
@ -471,12 +313,10 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
className="accent-indigo-600 rounded"
|
className="accent-indigo-600 rounded"
|
||||||
/>
|
/>
|
||||||
<span className="text-xs font-bold text-slate-700">
|
<span className="text-xs font-bold text-slate-700">
|
||||||
First Purchase Only
|
First Purchase Only (Exclusive to new customers with 0 prior subscriptions)
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Actions */}
|
{/* Actions */}
|
||||||
<div className="flex gap-3 pt-2">
|
<div className="flex gap-3 pt-2">
|
||||||
|
|
@ -489,8 +329,8 @@ export const CouponModal: React.FC<CouponModalProps> = ({
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={saving || isDateRangeInvalid}
|
disabled={saving}
|
||||||
className="flex-1 py-2.5 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors flex items-center justify-center gap-1.5 shadow-md shadow-indigo-600/20 cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed"
|
className="flex-1 py-2.5 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors flex items-center justify-center gap-1.5 shadow-md shadow-indigo-600/20 cursor-pointer disabled:opacity-50"
|
||||||
>
|
>
|
||||||
{saving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : isEdit ? 'Save Changes' : 'Save & Publish Coupon'}
|
{saving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : isEdit ? 'Save Changes' : 'Save & Publish Coupon'}
|
||||||
</button>
|
</button>
|
||||||
|
|
|
||||||
|
|
@ -2,41 +2,13 @@ import React, { useState } from 'react';
|
||||||
import { Ticket, Plus, Check, Copy, Edit, Trash2 } from 'lucide-react';
|
import { Ticket, Plus, Check, Copy, Edit, Trash2 } from 'lucide-react';
|
||||||
import { Pagination } from '../common/Pagination';
|
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 {
|
interface CouponsTabProps {
|
||||||
coupons: any[];
|
coupons: any[];
|
||||||
filterStatus: CouponStatusFilter;
|
filterStatus: 'all' | 'active' | 'scheduled' | 'expired';
|
||||||
searchQuery: string;
|
searchQuery: string;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
perPage: number;
|
perPage: number;
|
||||||
onFilterStatusChange: (status: CouponStatusFilter) => void;
|
onFilterStatusChange: (status: 'all' | 'active' | 'scheduled' | 'expired') => void;
|
||||||
onSearchChange: (query: string) => void;
|
onSearchChange: (query: string) => void;
|
||||||
onPageChange: (page: number) => void;
|
onPageChange: (page: number) => void;
|
||||||
onPerPageChange: (perPage: number) => void;
|
onPerPageChange: (perPage: number) => void;
|
||||||
|
|
@ -70,7 +42,7 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const filteredCoupons = coupons.filter((c) => {
|
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()) {
|
if (searchQuery.trim()) {
|
||||||
const q = searchQuery.toLowerCase();
|
const q = searchQuery.toLowerCase();
|
||||||
return (
|
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">
|
<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 */}
|
{/* Filter Pills */}
|
||||||
<div className="flex flex-wrap items-center gap-1.5">
|
<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
|
<button
|
||||||
key={status}
|
key={status}
|
||||||
type="button"
|
type="button"
|
||||||
|
|
@ -130,7 +102,7 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||||
onFilterStatusChange(status);
|
onFilterStatusChange(status);
|
||||||
onPageChange(1);
|
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
|
filterStatus === status
|
||||||
? 'bg-indigo-600 text-white shadow-sm'
|
? 'bg-indigo-600 text-white shadow-sm'
|
||||||
: 'bg-white text-slate-600 border border-slate-200 hover:bg-slate-100 shadow-sm'
|
: 'bg-white text-slate-600 border border-slate-200 hover:bg-slate-100 shadow-sm'
|
||||||
|
|
@ -138,12 +110,12 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||||
>
|
>
|
||||||
{status === 'all'
|
{status === 'all'
|
||||||
? `All (${coupons.length})`
|
? `All (${coupons.length})`
|
||||||
: `${STATUS_LABELS[status]} (${coupons.filter((c) => getEffectiveCouponStatus(c) === status).length})`}
|
: `${status} (${coupons.filter((c) => c.schedule_status === status).length})`}
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex flex-col sm:flex-row items-stretch sm:items-center gap-2.5 sm:gap-3 w-full sm:w-auto">
|
<div className="flex items-center gap-3 w-full sm:w-auto">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Search code or description..."
|
placeholder="Search code or description..."
|
||||||
|
|
@ -157,7 +129,7 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onOpenCreateCoupon}
|
onClick={onOpenCreateCoupon}
|
||||||
className="inline-flex items-center justify-center gap-1.5 px-4 py-2 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white shadow-md shadow-indigo-600/20 transition-all cursor-pointer whitespace-nowrap"
|
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white shadow-md shadow-indigo-600/20 transition-all cursor-pointer whitespace-nowrap"
|
||||||
>
|
>
|
||||||
<Plus className="h-3.5 w-3.5" /> Create Coupon
|
<Plus className="h-3.5 w-3.5" /> Create Coupon
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -174,7 +146,7 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||||
) : (
|
) : (
|
||||||
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="w-full text-left text-xs min-w-[720px]">
|
<table className="w-full text-left text-xs">
|
||||||
<thead className="bg-slate-50 border-b border-slate-200 text-slate-500 uppercase tracking-wider text-[10px] font-extrabold">
|
<thead className="bg-slate-50 border-b border-slate-200 text-slate-500 uppercase tracking-wider text-[10px] font-extrabold">
|
||||||
<tr>
|
<tr>
|
||||||
<th className="py-3 px-4">Coupon Code</th>
|
<th className="py-3 px-4">Coupon Code</th>
|
||||||
|
|
@ -192,13 +164,6 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||||
const hasCap = isPercent && c.max_discount_limit > 0;
|
const hasCap = isPercent && c.max_discount_limit > 0;
|
||||||
const usageLimit = c.usage_limit || 0;
|
const usageLimit = c.usage_limit || 0;
|
||||||
const usageCount = c.usage_count || 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 =
|
const hasSpecific =
|
||||||
(c.applicable_plan_ids && c.applicable_plan_ids.length > 0) ||
|
(c.applicable_plan_ids && c.applicable_plan_ids.length > 0) ||
|
||||||
(c.applicable_module_ids && c.applicable_module_ids.length > 0);
|
(c.applicable_module_ids && c.applicable_module_ids.length > 0);
|
||||||
|
|
@ -234,26 +199,11 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||||
{/* Value */}
|
{/* Value */}
|
||||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||||
<div className="inline-flex items-center gap-1 font-extrabold text-slate-800 text-xs">
|
<div className="inline-flex items-center gap-1 font-extrabold text-slate-800 text-xs">
|
||||||
{isPercent ? (
|
{isPercent ? `${c.value}% OFF` : `₹${c.value} FLAT`}
|
||||||
`${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>
|
</div>
|
||||||
{hasCap && (
|
{hasCap && (
|
||||||
<p className="text-[10px] text-slate-400 font-semibold mt-0.5">
|
<p className="text-[10px] text-slate-400 font-semibold mt-0.5">
|
||||||
Cap: ₹{c.max_discount_inr ?? c.max_discount_limit}
|
Cap: ₹{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>
|
</p>
|
||||||
)}
|
)}
|
||||||
<span className="block text-[9px] font-bold text-slate-400 capitalize mt-0.5">
|
<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">
|
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||||
<span
|
<span
|
||||||
className={`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-extrabold tracking-wider uppercase border ${
|
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'
|
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
||||||
: effectiveStatus === 'scheduled'
|
: c.schedule_status === 'scheduled'
|
||||||
? 'bg-amber-50 text-amber-700 border-amber-200'
|
? 'bg-amber-50 text-amber-700 border-amber-200'
|
||||||
: effectiveStatus === 'fully_redeemed'
|
: c.schedule_status === 'expired'
|
||||||
? 'bg-indigo-50 text-indigo-700 border-indigo-200'
|
|
||||||
: effectiveStatus === 'expired'
|
|
||||||
? 'bg-rose-50 text-rose-700 border-rose-200'
|
? 'bg-rose-50 text-rose-700 border-rose-200'
|
||||||
: 'bg-slate-100 text-slate-500 border-slate-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" />
|
<span className="h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse" />
|
||||||
)}
|
)}
|
||||||
{statusLabel}
|
{c.schedule_status}
|
||||||
</span>
|
</span>
|
||||||
<p className="text-[10px] text-slate-400 font-medium mt-1">
|
<p className="text-[10px] text-slate-400 font-medium mt-1">
|
||||||
{c.start_date?.split('T')[0] || '—'} → {c.end_date?.split('T')[0] || '—'}
|
{c.start_date?.split('T')[0] || '—'} → {c.end_date?.split('T')[0] || '—'}
|
||||||
|
|
@ -301,34 +249,17 @@ export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||||
) : (
|
) : (
|
||||||
<span className="text-[9px] text-slate-400 font-semibold">Unlimited</span>
|
<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>
|
</td>
|
||||||
|
|
||||||
{/* Scope & Conditions */}
|
{/* Scope & Conditions */}
|
||||||
<td className="py-3.5 px-4">
|
<td className="py-3.5 px-4">
|
||||||
<div className="flex flex-wrap gap-1">
|
<div className="flex flex-wrap gap-1">
|
||||||
<span className="text-[9px] font-extrabold px-1.5 py-0.5 rounded bg-slate-100 text-slate-600 border border-slate-200">
|
<span className="text-[9px] font-extrabold px-1.5 py-0.5 rounded bg-slate-100 text-slate-600 border border-slate-200">
|
||||||
{hasSpecific
|
{hasSpecific ? 'Targeted Items' : 'Storewide'}
|
||||||
? c.applicable_plan_ids && c.applicable_plan_ids.length > 0 && (!c.applicable_module_ids || c.applicable_module_ids.length === 0)
|
|
||||||
? `Restricted to ${c.plan_names?.length || 1} Plan${(c.plan_names?.length || 1) > 1 ? 's' : ''}`
|
|
||||||
: 'Targeted Items'
|
|
||||||
: 'Storewide'}
|
|
||||||
</span>
|
</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">
|
<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}
|
Min: ₹{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>
|
</span>
|
||||||
)}
|
)}
|
||||||
{c.is_first_purchase_only && (
|
{c.is_first_purchase_only && (
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Database, BookOpen, Download, RefreshCw, CheckCircle, AlertCircle } from 'lucide-react';
|
import { Database, BookOpen, Download, RefreshCw, CheckCircle, AlertCircle, ShieldCheck } from 'lucide-react';
|
||||||
|
|
||||||
interface DatabaseBackupTabProps {
|
interface DatabaseBackupTabProps {
|
||||||
dbInfo: any | null;
|
dbInfo: any | null;
|
||||||
|
|
@ -106,16 +106,16 @@ export const DatabaseBackupTab: React.FC<DatabaseBackupTabProps> = ({
|
||||||
Downloads a complete SQL dump of all database schemas, including clinical data, user profiles, authentication records, subscriptions, transactions, and coupons.
|
Downloads a complete SQL dump of all database schemas, including clinical data, user profiles, authentication records, subscriptions, transactions, and coupons.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<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="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Format:</span>
|
<span className="text-slate-400 font-semibold">Format:</span>
|
||||||
<span className="font-mono font-bold text-slate-700">Compressed .sql.gz (gzip -9)</span>
|
<span className="font-mono font-bold text-slate-700">Compressed .sql.gz (gzip -9)</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Estimated Download Size:</span>
|
<span className="text-slate-400 font-semibold">Estimated Download Size:</span>
|
||||||
<span className="font-mono font-bold text-indigo-600">~1.4 MB</span>
|
<span className="font-mono font-bold text-indigo-600">~1.4 MB</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Relational Integrity:</span>
|
<span className="text-slate-400 font-semibold">Relational Integrity:</span>
|
||||||
<span className="font-bold text-emerald-600">ACID Consistent (pg_dump)</span>
|
<span className="font-bold text-emerald-600">ACID Consistent (pg_dump)</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -154,16 +154,16 @@ export const DatabaseBackupTab: React.FC<DatabaseBackupTabProps> = ({
|
||||||
Exports strictly the <code className="text-emerald-700 bg-emerald-50 px-1 py-0.5 rounded font-mono font-bold">acu_content</code> schema. Includes acupuncture points, clinical modules, questions bank, protocols, and taxonomy data without user accounts or payment data.
|
Exports strictly the <code className="text-emerald-700 bg-emerald-50 px-1 py-0.5 rounded font-mono font-bold">acu_content</code> schema. Includes acupuncture points, clinical modules, questions bank, protocols, and taxonomy data without user accounts or payment data.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<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="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Target Schema:</span>
|
<span className="text-slate-400 font-semibold">Target Schema:</span>
|
||||||
<span className="font-mono font-bold text-slate-700">acu_content</span>
|
<span className="font-mono font-bold text-slate-700">acu_content</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Target Entities:</span>
|
<span className="text-slate-400 font-semibold">Target Entities:</span>
|
||||||
<span className="font-bold text-slate-700">Modules, Points, Channels, Quizzes</span>
|
<span className="font-bold text-slate-700">Modules, Points, Channels, Quizzes</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Use Case:</span>
|
<span className="text-slate-400 font-semibold">Use Case:</span>
|
||||||
<span className="font-bold text-emerald-600">Content Staging & Seed Distribution</span>
|
<span className="font-bold text-emerald-600">Content Staging & Seed Distribution</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -190,6 +190,36 @@ export const DatabaseBackupTab: React.FC<DatabaseBackupTabProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Recovery Instructions */}
|
||||||
|
<div className="bg-slate-50/80 border border-slate-200 rounded-3xl p-6 space-y-4">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<ShieldCheck className="h-5 w-5 text-indigo-600" />
|
||||||
|
<h3 className="text-sm font-black text-slate-800">Disaster Recovery & Restore Instructions</h3>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-slate-500 font-medium">
|
||||||
|
In the event of a system rebuild or migration, you can restore any downloaded snapshot file directly using standard PostgreSQL CLI utilities:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="bg-slate-900 rounded-2xl p-4 font-mono text-xs text-slate-200 space-y-2 overflow-x-auto shadow-inner">
|
||||||
|
<div className="text-slate-400 text-[11px] font-semibold"># 1. Restore directly via pipeline into Docker or host database:</div>
|
||||||
|
<div className="text-emerald-400 font-bold">
|
||||||
|
gunzip -c panaceadb_backup_full_latest.sql.gz | docker exec -i panacea-postgres psql -U postgres -d panaceadb
|
||||||
|
</div>
|
||||||
|
<div className="text-slate-400 text-[11px] font-semibold pt-1"># 2. Or uncompress first and inspect the raw SQL statements:</div>
|
||||||
|
<div className="text-indigo-300">
|
||||||
|
gunzip panaceadb_backup_full_latest.sql.gz
|
||||||
|
</div>
|
||||||
|
<div className="text-indigo-300">
|
||||||
|
head -n 40 panaceadb_backup_full_latest.sql
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center justify-between text-[11px] text-slate-400 font-semibold pt-1">
|
||||||
|
<span>PostgreSQL Engine: {dbInfo?.postgres_version || '16.14'}</span>
|
||||||
|
<span>Internal Host: {dbInfo?.host || 'db'}:{dbInfo?.port || 5432}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||||
Reports & Financial Export Hub
|
Reports & Financial Export Hub
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-xs text-slate-300 max-w-2xl font-medium leading-relaxed">
|
<p className="text-xs text-slate-300 max-w-2xl font-medium leading-relaxed">
|
||||||
Generate and download audit-compliant CSV spreadsheets for registered customers, Razorpay payment transactions and sales revenue, active subscriber entitlements, and promotional coupon redemptions.
|
Generate and download audit-compliant CSV spreadsheets for registered customers, Razorpay payment transactions with GST tax splits (CGST 9% / SGST 9%), active subscriber entitlements, and promotional coupon redemptions.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -124,7 +124,7 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||||
<Users className="h-5 w-5" />
|
<Users className="h-5 w-5" />
|
||||||
</div>
|
</div>
|
||||||
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-indigo-50 text-indigo-700 border border-indigo-100">
|
<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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -133,12 +133,12 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||||
Export complete customer database with contact details, country, active subscription counts, active plans, total order counts, and cumulative lifetime spend.
|
Export complete customer database with contact details, country, active subscription counts, active plans, total order counts, and cumulative lifetime spend.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<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="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Included Columns:</span>
|
<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>
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Target Audience:</span>
|
<span className="text-slate-400 font-semibold">Target Audience:</span>
|
||||||
<span className="font-semibold text-indigo-600">CRM & Growth Audits</span>
|
<span className="font-semibold text-indigo-600">CRM & Growth Audits</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -165,7 +165,7 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Report 2: Financial & Revenue Ledger */}
|
{/* Report 2: Financial & GST Tax Ledger */}
|
||||||
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-emerald-300 transition-all space-y-4">
|
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-emerald-300 transition-all space-y-4">
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
|
|
@ -177,19 +177,19 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<h3 className="text-base font-black text-slate-800">Payments & Revenue Ledger</h3>
|
<h3 className="text-base font-black text-slate-800">Payments & GST Tax Ledger</h3>
|
||||||
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
||||||
Accounting & transaction ledger containing Razorpay Payment IDs, invoice numbers, base plan fees, coupon discounts, order currency, and total amounts paid.
|
Accounting & taxation ledger containing Razorpay Payment IDs, invoice numbers, base plan fees, coupon discounts, taxable subtotal, CGST (9%), SGST (9%), and net total paid.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<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="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Financial Scope:</span>
|
<span className="text-slate-400 font-semibold">Tax Compliance:</span>
|
||||||
<span className="font-semibold text-emerald-600">Collected Revenue & Order Totals</span>
|
<span className="font-semibold text-emerald-600">CGST (9%) + SGST (9%) Breakdown</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
||||||
<span className="font-semibold text-slate-700">Financial Reconciliation & Revenue Auditing</span>
|
<span className="font-semibold text-slate-700">Monthly GST Filing & Bookkeeping</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -207,7 +207,7 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<Download className="h-3.5 w-3.5" /> Export Payments & Revenue Ledger (.csv)
|
<Download className="h-3.5 w-3.5" /> Export Tax & Revenue Ledger (.csv)
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -231,12 +231,12 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||||
Export clinical plan access records, customer identities, subscription status, billing cycle, auto-renewal flag, activation dates, expiration dates, and remaining days.
|
Export clinical plan access records, customer identities, subscription status, billing cycle, auto-renewal flag, activation dates, expiration dates, and remaining days.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<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="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Metrics Included:</span>
|
<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>
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
||||||
<span className="font-semibold text-blue-600">Churn & Expiration Tracking</span>
|
<span className="font-semibold text-blue-600">Churn & Expiration Tracking</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -280,12 +280,12 @@ export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||||
Track coupon performance and redemptions across orders, including discount rates, caps, customer emails, associated invoices, and total discount value granted.
|
Track coupon performance and redemptions across orders, including discount rates, caps, customer emails, associated invoices, and total discount value granted.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<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="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Campaign Metrics:</span>
|
<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>
|
||||||
<div className="flex flex-col sm:flex-row sm:justify-between gap-0.5 sm:gap-2">
|
<div className="flex justify-between">
|
||||||
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
||||||
<span className="font-semibold text-purple-600">Marketing & Partner ROI</span>
|
<span className="font-semibold text-purple-600">Marketing & Partner ROI</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import React from 'react';
|
||||||
import {
|
import {
|
||||||
Sparkles, ChevronLeft, ChevronRight, LogOut,
|
Sparkles, ChevronLeft, ChevronRight, LogOut,
|
||||||
List, BookOpen, Tag, Ticket, Users, CheckCircle,
|
List, BookOpen, Tag, Ticket, Users, CheckCircle,
|
||||||
Receipt, Shield, Database, FileText, X, Layers
|
Receipt, Shield, Database, FileText
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import type { LoggedInUser, AdminTabType } from '../../types';
|
import type { LoggedInUser, AdminTabType } from '../../types';
|
||||||
|
|
||||||
|
|
@ -29,8 +29,6 @@ interface AdminSidebarProps {
|
||||||
isCollapsed: boolean;
|
isCollapsed: boolean;
|
||||||
onToggleCollapse: () => void;
|
onToggleCollapse: () => void;
|
||||||
onLogout: () => void;
|
onLogout: () => void;
|
||||||
isMobileOpen?: boolean;
|
|
||||||
onCloseMobile?: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
|
|
@ -41,30 +39,10 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
isCollapsed,
|
isCollapsed,
|
||||||
onToggleCollapse,
|
onToggleCollapse,
|
||||||
onLogout,
|
onLogout,
|
||||||
isMobileOpen = false,
|
|
||||||
onCloseMobile,
|
|
||||||
}) => {
|
}) => {
|
||||||
React.useEffect(() => {
|
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
|
||||||
if (e.key === 'Escape' && isMobileOpen && onCloseMobile) {
|
|
||||||
onCloseMobile();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
window.addEventListener('keydown', handleKeyDown);
|
|
||||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
||||||
}, [isMobileOpen, onCloseMobile]);
|
|
||||||
|
|
||||||
const handleTabClick = (key: AdminTabType) => {
|
|
||||||
onSelectTab(key);
|
|
||||||
if (onCloseMobile) {
|
|
||||||
onCloseMobile();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const tabs: TabItem[] = [
|
const tabs: TabItem[] = [
|
||||||
{ key: 'overview', label: 'Overview & Logs', icon: <List className="h-4 w-4 shrink-0" /> },
|
{ key: 'overview', label: 'Overview & Logs', icon: <List className="h-4 w-4 shrink-0" /> },
|
||||||
{ key: 'modules', label: 'Modules', count: counts.modules, icon: <BookOpen className="h-4 w-4 shrink-0" /> },
|
{ key: 'modules', label: 'Modules', count: counts.modules, icon: <BookOpen className="h-4 w-4 shrink-0" /> },
|
||||||
{ key: 'module_builder', label: 'Module Builder', icon: <Layers className="h-4 w-4 shrink-0" /> },
|
|
||||||
{ key: 'plans', label: 'Plans & Pricing', count: counts.plans, icon: <Tag className="h-4 w-4 shrink-0" /> },
|
{ key: 'plans', label: 'Plans & Pricing', count: counts.plans, icon: <Tag className="h-4 w-4 shrink-0" /> },
|
||||||
{ key: 'coupons', label: 'Coupons', count: counts.coupons, icon: <Ticket className="h-4 w-4 shrink-0" /> },
|
{ key: 'coupons', label: 'Coupons', count: counts.coupons, icon: <Ticket className="h-4 w-4 shrink-0" /> },
|
||||||
{ key: 'customers', label: 'Customers', count: counts.customers, icon: <Users className="h-4 w-4 shrink-0" /> },
|
{ key: 'customers', label: 'Customers', count: counts.customers, icon: <Users className="h-4 w-4 shrink-0" /> },
|
||||||
|
|
@ -75,35 +53,20 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
{ key: 'reports', label: 'Reports & Exports', icon: <FileText className="h-4 w-4 shrink-0" /> },
|
{ key: 'reports', label: 'Reports & Exports', icon: <FileText className="h-4 w-4 shrink-0" /> },
|
||||||
];
|
];
|
||||||
|
|
||||||
const showExpandedContent = !isCollapsed || isMobileOpen;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
{/* Mobile Backdrop Overlay */}
|
|
||||||
{isMobileOpen && (
|
|
||||||
<div
|
|
||||||
className="fixed inset-0 z-40 bg-slate-950/75 backdrop-blur-xs md:hidden"
|
|
||||||
onClick={onCloseMobile}
|
|
||||||
aria-hidden="true"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<aside
|
<aside
|
||||||
className={`bg-[#0A0A0E] border-r border-slate-800/80 flex flex-col justify-between py-4 text-slate-300 shadow-2xl select-none z-50
|
className={`bg-[#0A0A0E] border-b md:border-b-0 md:border-r border-slate-800/80 flex flex-col justify-between py-4 transition-all duration-300 ease-in-out flex-shrink-0 text-slate-300 shadow-2xl select-none relative z-30 ${
|
||||||
fixed md:sticky top-0 inset-y-0 left-0 md:h-screen overflow-y-auto transition-transform duration-300 ease-in-out flex-shrink-0
|
isCollapsed ? 'w-full md:w-[68px] px-2' : 'w-full md:w-60 px-3'
|
||||||
${isMobileOpen ? 'translate-x-0' : '-translate-x-full md:translate-x-0'}
|
}`}
|
||||||
${isCollapsed ? 'md:w-[68px] md:px-2' : 'md:w-60 md:px-3'}
|
|
||||||
w-72 max-w-[85vw] px-3
|
|
||||||
`}
|
|
||||||
>
|
>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{/* Brand & Collapse Header */}
|
{/* Brand & Collapse Header */}
|
||||||
<div className={`flex items-center ${!showExpandedContent ? 'justify-center' : 'justify-between'} gap-2 px-1`}>
|
<div className={`flex items-center ${isCollapsed ? 'justify-center' : 'justify-between'} gap-2 px-1`}>
|
||||||
<div className="flex items-center gap-2.5 min-w-0">
|
<div className="flex items-center gap-2.5 min-w-0">
|
||||||
<div className="h-8 w-8 rounded-xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-md shadow-indigo-500/20 shrink-0">
|
<div className="h-8 w-8 rounded-xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-md shadow-indigo-500/20 shrink-0">
|
||||||
<Sparkles className="h-4 w-4 text-white" />
|
<Sparkles className="h-4 w-4 text-white" />
|
||||||
</div>
|
</div>
|
||||||
{showExpandedContent && (
|
{!isCollapsed && (
|
||||||
<div className="min-w-0">
|
<div className="min-w-0">
|
||||||
<h1 className="text-sm font-black tracking-tight text-white truncate">
|
<h1 className="text-sm font-black tracking-tight text-white truncate">
|
||||||
ACUPEDIA
|
ACUPEDIA
|
||||||
|
|
@ -113,18 +76,6 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
{/* Close Button on Mobile Drawer */}
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onCloseMobile}
|
|
||||||
className="flex md:hidden h-7 w-7 rounded-lg bg-slate-800/80 hover:bg-slate-700 text-slate-400 hover:text-white items-center justify-center transition-colors cursor-pointer border border-slate-700/60"
|
|
||||||
aria-label="Close sidebar"
|
|
||||||
>
|
|
||||||
<X className="h-4 w-4" />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{/* Collapse Button on Desktop */}
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onToggleCollapse}
|
onClick={onToggleCollapse}
|
||||||
|
|
@ -134,7 +85,6 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
{isCollapsed ? <ChevronRight className="h-3.5 w-3.5" /> : <ChevronLeft className="h-3.5 w-3.5" />}
|
{isCollapsed ? <ChevronRight className="h-3.5 w-3.5" /> : <ChevronLeft className="h-3.5 w-3.5" />}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Navigation Tabs */}
|
{/* Navigation Tabs */}
|
||||||
<nav className="space-y-1">
|
<nav className="space-y-1">
|
||||||
|
|
@ -144,16 +94,16 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
<button
|
<button
|
||||||
key={tab.key}
|
key={tab.key}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => handleTabClick(tab.key)}
|
onClick={() => onSelectTab(tab.key)}
|
||||||
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-xs font-bold transition-all cursor-pointer relative group ${
|
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-xs font-bold transition-all cursor-pointer relative group ${
|
||||||
isActive
|
isActive
|
||||||
? 'bg-indigo-600 text-white shadow-lg shadow-indigo-600/30'
|
? 'bg-indigo-600 text-white shadow-lg shadow-indigo-600/30'
|
||||||
: 'text-slate-400 hover:text-slate-100 hover:bg-slate-800/60'
|
: 'text-slate-400 hover:text-slate-100 hover:bg-slate-800/60'
|
||||||
} ${!showExpandedContent ? 'justify-center px-0' : ''}`}
|
} ${isCollapsed ? 'justify-center px-0' : ''}`}
|
||||||
title={!showExpandedContent ? `${tab.label} ${tab.count !== undefined ? `(${tab.count})` : ''}` : undefined}
|
title={isCollapsed ? `${tab.label} ${tab.count !== undefined ? `(${tab.count})` : ''}` : undefined}
|
||||||
>
|
>
|
||||||
{tab.icon}
|
{tab.icon}
|
||||||
{showExpandedContent && (
|
{!isCollapsed && (
|
||||||
<>
|
<>
|
||||||
<span className="truncate flex-1 text-left">{tab.label}</span>
|
<span className="truncate flex-1 text-left">{tab.label}</span>
|
||||||
{tab.count !== undefined && (
|
{tab.count !== undefined && (
|
||||||
|
|
@ -170,7 +120,7 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{/* Collapsed active dot */}
|
{/* Collapsed active dot */}
|
||||||
{!showExpandedContent && isActive && (
|
{isCollapsed && isActive && (
|
||||||
<span className="absolute right-1.5 top-1/2 -translate-y-1/2 w-1.5 h-1.5 bg-white rounded-full shadow-xs" />
|
<span className="absolute right-1.5 top-1/2 -translate-y-1/2 w-1.5 h-1.5 bg-white rounded-full shadow-xs" />
|
||||||
)}
|
)}
|
||||||
</button>
|
</button>
|
||||||
|
|
@ -181,7 +131,7 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
|
|
||||||
{/* User Footer */}
|
{/* User Footer */}
|
||||||
<div className="pt-3 border-t border-slate-800/80 mt-4">
|
<div className="pt-3 border-t border-slate-800/80 mt-4">
|
||||||
{showExpandedContent ? (
|
{!isCollapsed ? (
|
||||||
<div className="space-y-2.5 px-1">
|
<div className="space-y-2.5 px-1">
|
||||||
<div className="flex items-center gap-2.5">
|
<div className="flex items-center gap-2.5">
|
||||||
<div className="h-8 w-8 rounded-xl bg-gradient-to-tr from-indigo-950 to-indigo-900 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-black text-xs shrink-0 shadow-inner">
|
<div className="h-8 w-8 rounded-xl bg-gradient-to-tr from-indigo-950 to-indigo-900 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-black text-xs shrink-0 shadow-inner">
|
||||||
|
|
@ -196,10 +146,7 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => {
|
onClick={onLogout}
|
||||||
if (onCloseMobile) onCloseMobile();
|
|
||||||
onLogout();
|
|
||||||
}}
|
|
||||||
className="w-full flex items-center justify-center gap-2 py-2 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 hover:text-white transition-colors cursor-pointer border border-slate-700/60"
|
className="w-full flex items-center justify-center gap-2 py-2 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 hover:text-white transition-colors cursor-pointer border border-slate-700/60"
|
||||||
>
|
>
|
||||||
<LogOut className="h-3.5 w-3.5" /> Log Out
|
<LogOut className="h-3.5 w-3.5" /> Log Out
|
||||||
|
|
@ -225,6 +172,5 @@ export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,16 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { XCircle, RefreshCw } from 'lucide-react';
|
import { XCircle, RefreshCw } from 'lucide-react';
|
||||||
import type { ModuleItem } from '../../types';
|
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 {
|
interface EditModuleModalProps {
|
||||||
module: ModuleItem | null;
|
module: ModuleItem | null;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
category: string;
|
category: string;
|
||||||
icon: string;
|
|
||||||
color: string;
|
|
||||||
saving: boolean;
|
saving: boolean;
|
||||||
onNameChange: (val: string) => void;
|
onNameChange: (val: string) => void;
|
||||||
onDescriptionChange: (val: string) => void;
|
onDescriptionChange: (val: string) => void;
|
||||||
onIconChange: (val: string) => void;
|
onCategoryChange: (val: string) => void;
|
||||||
onColorChange: (val: string) => void;
|
|
||||||
onSave: (e: React.FormEvent) => void;
|
onSave: (e: React.FormEvent) => void;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
@ -35,13 +20,10 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
category,
|
category,
|
||||||
icon,
|
|
||||||
color,
|
|
||||||
saving,
|
saving,
|
||||||
onNameChange,
|
onNameChange,
|
||||||
onDescriptionChange,
|
onDescriptionChange,
|
||||||
onIconChange,
|
onCategoryChange,
|
||||||
onColorChange,
|
|
||||||
onSave,
|
onSave,
|
||||||
onClose,
|
onClose,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
@ -54,7 +36,7 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<div
|
<div
|
||||||
className="h-8 w-8 rounded-lg flex items-center justify-center font-bold text-white text-xs"
|
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()}
|
{(module.name || 'M')[0].toUpperCase()}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -86,16 +68,17 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Category</label>
|
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Category</label>
|
||||||
<input
|
<select
|
||||||
type="text"
|
value={category}
|
||||||
readOnly
|
onChange={(e) => onCategoryChange(e.target.value)}
|
||||||
disabled
|
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"
|
||||||
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"
|
<option value="point">Points</option>
|
||||||
/>
|
<option value="Patterns">Patterns</option>
|
||||||
<p className="text-[10px] text-slate-400 mt-1">
|
<option value="Nutrition">Nutrition</option>
|
||||||
Category is fixed to keep core Complete Pack entitlements consistent. Use Plans & Pricing to create custom combo bundles.
|
<option value="Therapeutics">Therapeutics</option>
|
||||||
</p>
|
<option value="General">General</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -108,55 +91,6 @@ export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
||||||
/>
|
/>
|
||||||
</div>
|
</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">
|
<div className="flex gap-2 pt-2">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -2,7 +2,6 @@ import React from 'react';
|
||||||
import { Edit } from 'lucide-react';
|
import { Edit } from 'lucide-react';
|
||||||
import type { ModuleItem } from '../../types';
|
import type { ModuleItem } from '../../types';
|
||||||
import { Pagination } from '../common/Pagination';
|
import { Pagination } from '../common/Pagination';
|
||||||
import { normalizeCategory, CLINICAL_CATEGORIES } from '../../utils/category';
|
|
||||||
|
|
||||||
interface ModulesTabProps {
|
interface ModulesTabProps {
|
||||||
modules: ModuleItem[];
|
modules: ModuleItem[];
|
||||||
|
|
@ -50,7 +49,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
|
|
||||||
const matchesCategory =
|
const matchesCategory =
|
||||||
categoryFilter === 'all' ||
|
categoryFilter === 'all' ||
|
||||||
normalizeCategory(m.category).toLowerCase() === categoryFilter.toLowerCase();
|
(m.category || '').toLowerCase() === categoryFilter.toLowerCase();
|
||||||
|
|
||||||
return matchesSearch && matchesStatus && matchesCategory;
|
return matchesSearch && matchesStatus && matchesCategory;
|
||||||
});
|
});
|
||||||
|
|
@ -61,7 +60,13 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
const startIndex = (safePage - 1) * perPage;
|
const startIndex = (safePage - 1) * perPage;
|
||||||
const paginatedModules = filtered.slice(startIndex, startIndex + perPage);
|
const paginatedModules = filtered.slice(startIndex, startIndex + perPage);
|
||||||
|
|
||||||
const categories = CLINICAL_CATEGORIES;
|
const categories = [
|
||||||
|
{ key: 'all', label: 'All Categories' },
|
||||||
|
{ key: 'point', label: 'Points' },
|
||||||
|
{ key: 'Patterns', label: 'Patterns' },
|
||||||
|
{ key: 'Nutrition', label: 'Nutrition' },
|
||||||
|
{ key: 'Therapeutics', label: 'Therapeutics' },
|
||||||
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-5">
|
<div className="space-y-5">
|
||||||
|
|
@ -119,7 +124,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
const count =
|
const count =
|
||||||
cat.key === 'all'
|
cat.key === 'all'
|
||||||
? modules.length
|
? modules.length
|
||||||
: modules.filter((m) => normalizeCategory(m.category).toLowerCase() === cat.key.toLowerCase()).length;
|
: modules.filter((m) => (m.category || '').toLowerCase() === cat.key.toLowerCase()).length;
|
||||||
const isSelected = categoryFilter.toLowerCase() === cat.key.toLowerCase();
|
const isSelected = categoryFilter.toLowerCase() === cat.key.toLowerCase();
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
|
|
@ -151,7 +156,7 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
) : (
|
) : (
|
||||||
<div className="bg-white border border-slate-200 rounded-2xl overflow-hidden shadow-sm p-4">
|
<div className="bg-white border border-slate-200 rounded-2xl overflow-hidden shadow-sm p-4">
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="w-full text-left border-collapse text-xs min-w-[650px]">
|
<table className="w-full text-left border-collapse text-xs">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider border-b border-slate-200">
|
<tr className="bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider border-b border-slate-200">
|
||||||
<th className="py-3 px-3.5">Module Name & Details</th>
|
<th className="py-3 px-3.5">Module Name & Details</th>
|
||||||
|
|
@ -203,10 +208,11 @@ export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||||
{/* Column 3: Category */}
|
{/* Column 3: Category */}
|
||||||
<td className="py-3.5 px-3.5">
|
<td className="py-3.5 px-3.5">
|
||||||
<span className="text-[10px] font-bold text-indigo-600 bg-indigo-50 px-2.5 py-1 rounded-lg border border-indigo-100 uppercase tracking-wider">
|
<span className="text-[10px] font-bold text-indigo-600 bg-indigo-50 px-2.5 py-1 rounded-lg border border-indigo-100 uppercase tracking-wider">
|
||||||
{normalizeCategory(mod.category)}
|
{mod.category === 'point' ? 'Points' : mod.category || 'General'}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|
||||||
{/* Column 4: Linked Plans */}
|
{/* Column 4: Linked Plans */}
|
||||||
<td className="py-3.5 px-3.5 font-semibold text-slate-600">
|
<td className="py-3.5 px-3.5 font-semibold text-slate-600">
|
||||||
<span className="bg-slate-100 text-slate-700 px-2 py-0.5 rounded-md text-[10px] font-bold border border-slate-200">
|
<span className="bg-slate-100 text-slate-700 px-2 py-0.5 rounded-md text-[10px] font-bold border border-slate-200">
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState, useMemo } from 'react';
|
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';
|
import { Pagination } from '../common/Pagination';
|
||||||
|
|
||||||
interface PaymentsTabProps {
|
interface PaymentsTabProps {
|
||||||
|
|
@ -14,21 +14,6 @@ interface PaymentsTabProps {
|
||||||
onShareInvoice: (id: string) => void;
|
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> = ({
|
export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
||||||
payments,
|
payments,
|
||||||
currentPage,
|
currentPage,
|
||||||
|
|
@ -42,59 +27,12 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
||||||
}) => {
|
}) => {
|
||||||
const [searchQuery, setSearchQuery] = useState('');
|
const [searchQuery, setSearchQuery] = useState('');
|
||||||
const [sortOrder, setSortOrder] = useState<'desc' | 'asc'>('desc');
|
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
|
// Filter and Sort payments
|
||||||
const processedPayments = useMemo(() => {
|
const processedPayments = useMemo(() => {
|
||||||
let result = [...payments];
|
let result = [...payments];
|
||||||
|
|
||||||
// Filter by Year
|
// Filter
|
||||||
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
|
|
||||||
if (searchQuery.trim()) {
|
if (searchQuery.trim()) {
|
||||||
const q = searchQuery.toLowerCase().trim();
|
const q = searchQuery.toLowerCase().trim();
|
||||||
result = result.filter((p: any) => {
|
result = result.filter((p: any) => {
|
||||||
|
|
@ -126,17 +64,7 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}, [payments, searchQuery, sortOrder, selectedYear, selectedMonth]);
|
}, [payments, searchQuery, sortOrder]);
|
||||||
|
|
||||||
const hasDateFilter = selectedYear !== 'all' || selectedMonth !== 'all';
|
|
||||||
|
|
||||||
const handleClearDateFilters = () => {
|
|
||||||
setSelectedYear('all');
|
|
||||||
setSelectedMonth('all');
|
|
||||||
setIsCustomYear(false);
|
|
||||||
setCustomYearInput('');
|
|
||||||
onPageChange(1);
|
|
||||||
};
|
|
||||||
|
|
||||||
const totalFiltered = processedPayments.length;
|
const totalFiltered = processedPayments.length;
|
||||||
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
||||||
|
|
@ -147,9 +75,7 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{/* Search & Sort Controls Header */}
|
{/* 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">
|
<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">
|
||||||
{/* Left Side: Search & Date Filters */}
|
|
||||||
<div className="flex flex-col sm:flex-row items-stretch sm:items-center gap-3 flex-1">
|
|
||||||
{/* Search Input */}
|
{/* Search Input */}
|
||||||
<div className="flex-1 max-w-md relative">
|
<div className="flex-1 max-w-md relative">
|
||||||
<input
|
<input
|
||||||
|
|
@ -169,119 +95,15 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
||||||
setSearchQuery('');
|
setSearchQuery('');
|
||||||
onPageChange(1);
|
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"
|
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" />
|
<X className="h-3.5 w-3.5" />
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Date Filter Controls: Year & Month */}
|
{/* Sort & Count Controls */}
|
||||||
<div className="flex items-center gap-2 shrink-0">
|
<div className="flex items-center gap-3 justify-between sm:justify-end">
|
||||||
{/* 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>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Right Side: Sort & Count Controls */}
|
|
||||||
<div className="flex items-center gap-3 justify-between sm:justify-end shrink-0">
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setSortOrder(prev => prev === 'desc' ? 'asc' : 'desc')}
|
onClick={() => setSortOrder(prev => prev === 'desc' ? 'asc' : 'desc')}
|
||||||
|
|
@ -312,34 +134,19 @@ export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
||||||
<div className="border border-slate-200 rounded-2xl p-10 bg-white text-center space-y-2">
|
<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-sm font-bold text-slate-700">No matching payments found</p>
|
||||||
<p className="text-xs text-slate-400">
|
<p className="text-xs text-slate-400">
|
||||||
No payments match your
|
No payments match your search query "{searchQuery}".
|
||||||
{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}"` : ''}.
|
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => setSearchQuery('')}
|
||||||
setSearchQuery('');
|
className="text-xs text-indigo-600 font-bold hover:underline mt-2 inline-block"
|
||||||
handleClearDateFilters();
|
|
||||||
}}
|
|
||||||
className="text-xs text-indigo-600 font-bold hover:underline mt-2 inline-block cursor-pointer"
|
|
||||||
>
|
>
|
||||||
Reset all filters
|
Clear search query
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="w-full text-xs min-w-[760px]">
|
<table className="w-full text-xs">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-b border-slate-200 bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider">
|
<tr className="border-b border-slate-200 bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider">
|
||||||
<th className="text-left py-3 px-3">Payment ID</th>
|
<th className="text-left py-3 px-3">Payment ID</th>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { AlertCircle, RefreshCw } from 'lucide-react';
|
import { AlertCircle, RefreshCw } from 'lucide-react';
|
||||||
import { normalizeCategory } from '../../utils/category';
|
|
||||||
|
|
||||||
interface CreatePlanModalProps {
|
interface CreatePlanModalProps {
|
||||||
show: boolean;
|
show: boolean;
|
||||||
|
|
@ -14,7 +13,6 @@ interface CreatePlanModalProps {
|
||||||
duration: string;
|
duration: string;
|
||||||
priceInr: string;
|
priceInr: string;
|
||||||
priceUsd: string;
|
priceUsd: string;
|
||||||
priceEur: string;
|
|
||||||
selectedModuleIds: string[];
|
selectedModuleIds: string[];
|
||||||
allModules: any[];
|
allModules: any[];
|
||||||
saving: boolean;
|
saving: boolean;
|
||||||
|
|
@ -29,7 +27,6 @@ interface CreatePlanModalProps {
|
||||||
onDurationChange: (v: string) => void;
|
onDurationChange: (v: string) => void;
|
||||||
onPriceInrChange: (v: string) => void;
|
onPriceInrChange: (v: string) => void;
|
||||||
onPriceUsdChange: (v: string) => void;
|
onPriceUsdChange: (v: string) => void;
|
||||||
onPriceEurChange: (v: string) => void;
|
|
||||||
onToggleModule: (id: string) => void;
|
onToggleModule: (id: string) => void;
|
||||||
onSelectAllModules: () => void;
|
onSelectAllModules: () => void;
|
||||||
onClearAllModules: () => void;
|
onClearAllModules: () => void;
|
||||||
|
|
@ -49,7 +46,6 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
||||||
duration,
|
duration,
|
||||||
priceInr,
|
priceInr,
|
||||||
priceUsd,
|
priceUsd,
|
||||||
priceEur,
|
|
||||||
selectedModuleIds,
|
selectedModuleIds,
|
||||||
allModules,
|
allModules,
|
||||||
saving,
|
saving,
|
||||||
|
|
@ -64,7 +60,6 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
||||||
onDurationChange,
|
onDurationChange,
|
||||||
onPriceInrChange,
|
onPriceInrChange,
|
||||||
onPriceUsdChange,
|
onPriceUsdChange,
|
||||||
onPriceEurChange,
|
|
||||||
onToggleModule,
|
onToggleModule,
|
||||||
onSelectAllModules,
|
onSelectAllModules,
|
||||||
onClearAllModules,
|
onClearAllModules,
|
||||||
|
|
@ -197,8 +192,8 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Multi-Currency Pricing (INR / USD / EUR) */}
|
{/* Dual Currency Pricing */}
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
|
@ -231,21 +226,6 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
|
|
||||||
{/* Module Selection */}
|
{/* Module Selection */}
|
||||||
|
|
@ -292,7 +272,7 @@ export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
||||||
/>
|
/>
|
||||||
<div className="truncate flex-1">
|
<div className="truncate flex-1">
|
||||||
<p className="truncate text-xs">{mod.name}</p>
|
<p className="truncate text-xs">{mod.name}</p>
|
||||||
<span className="text-[9px] text-slate-400 font-semibold">{normalizeCategory(mod.category)}</span>
|
<span className="text-[9px] text-slate-400 font-semibold">{mod.category || 'General'}</span>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,6 @@ interface EditPriceModalProps {
|
||||||
subtitle: string;
|
subtitle: string;
|
||||||
priceInr: string;
|
priceInr: string;
|
||||||
priceUsd: string;
|
priceUsd: string;
|
||||||
priceEur: string;
|
|
||||||
allModules?: any[];
|
|
||||||
moduleIds?: string[];
|
|
||||||
saving: boolean;
|
saving: boolean;
|
||||||
onNameChange: (v: string) => void;
|
onNameChange: (v: string) => void;
|
||||||
onDescChange: (v: string) => void;
|
onDescChange: (v: string) => void;
|
||||||
|
|
@ -21,10 +18,6 @@ interface EditPriceModalProps {
|
||||||
onSubtitleChange: (v: string) => void;
|
onSubtitleChange: (v: string) => void;
|
||||||
onPriceInrChange: (v: string) => void;
|
onPriceInrChange: (v: string) => void;
|
||||||
onPriceUsdChange: (v: string) => void;
|
onPriceUsdChange: (v: string) => void;
|
||||||
onPriceEurChange: (v: string) => void;
|
|
||||||
onToggleModule?: (id: string) => void;
|
|
||||||
onSelectAllModules?: () => void;
|
|
||||||
onClearAllModules?: () => void;
|
|
||||||
onSave: (e: React.FormEvent) => void;
|
onSave: (e: React.FormEvent) => void;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
@ -38,9 +31,6 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
||||||
subtitle,
|
subtitle,
|
||||||
priceInr,
|
priceInr,
|
||||||
priceUsd,
|
priceUsd,
|
||||||
priceEur,
|
|
||||||
allModules = [],
|
|
||||||
moduleIds = [],
|
|
||||||
saving,
|
saving,
|
||||||
onNameChange,
|
onNameChange,
|
||||||
onDescChange,
|
onDescChange,
|
||||||
|
|
@ -49,10 +39,6 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
||||||
onSubtitleChange,
|
onSubtitleChange,
|
||||||
onPriceInrChange,
|
onPriceInrChange,
|
||||||
onPriceUsdChange,
|
onPriceUsdChange,
|
||||||
onPriceEurChange,
|
|
||||||
onToggleModule,
|
|
||||||
onSelectAllModules,
|
|
||||||
onClearAllModules,
|
|
||||||
onSave,
|
onSave,
|
||||||
onClose,
|
onClose,
|
||||||
}) => {
|
}) => {
|
||||||
|
|
@ -128,7 +114,7 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-3 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
|
|
@ -160,76 +146,7 @@ export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
|
||||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price (€ EUR)</label>
|
|
||||||
<div className="relative">
|
|
||||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs">€</span>
|
|
||||||
<input
|
|
||||||
type="number"
|
|
||||||
step="0.01"
|
|
||||||
min="0"
|
|
||||||
required
|
|
||||||
value={priceEur}
|
|
||||||
onChange={(e) => onPriceEurChange(e.target.value)}
|
|
||||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{(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">
|
<div className="flex gap-2 pt-2">
|
||||||
<button
|
<button
|
||||||
|
|
|
||||||
|
|
@ -133,13 +133,13 @@ export const PlansTab: React.FC<PlansTabProps> = ({
|
||||||
) : (
|
) : (
|
||||||
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-sm bg-white p-4">
|
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-sm bg-white p-4">
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="w-full text-left border-collapse min-w-[720px]">
|
<table className="w-full text-left border-collapse">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="bg-slate-50 border-b border-slate-200 text-[11px] uppercase font-bold text-slate-400 tracking-wider">
|
<tr className="bg-slate-50 border-b border-slate-200 text-[11px] uppercase font-bold text-slate-400 tracking-wider">
|
||||||
<th className="py-3.5 px-4">Plan Details</th>
|
<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">Type & Duration</th>
|
||||||
<th className="py-3.5 px-3">Included Modules</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">Subscribers</th>
|
||||||
<th className="py-3.5 px-3 text-center">Status</th>
|
<th className="py-3.5 px-3 text-center">Status</th>
|
||||||
<th className="py-3.5 px-4 text-right">Actions</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="space-y-0.5 max-w-xs">
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<span className="font-bold text-slate-800">{plan.name}</span>
|
<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>
|
||||||
<div className="flex items-center gap-2">
|
<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">
|
<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">
|
<td className="py-3.5 px-3 whitespace-nowrap">
|
||||||
<div className="space-y-0.5 font-bold">
|
<div className="space-y-0.5 font-bold">
|
||||||
<p className="text-xs text-slate-800 font-mono">₹{plan.price_inr ?? '—'}</p>
|
<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">
|
<p className="text-[10px] text-slate-400 font-mono">${plan.price_usd ?? '—'}</p>
|
||||||
<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>
|
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|
@ -291,22 +282,11 @@ export const PlansTab: React.FC<PlansTabProps> = ({
|
||||||
<td className="py-3.5 px-3 text-center whitespace-nowrap">
|
<td className="py-3.5 px-3 text-center whitespace-nowrap">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={plan.pricing_status === 'pending_pricing'}
|
|
||||||
onClick={() => onTogglePlanStatus(plan)}
|
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 ${
|
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.pricing_status === 'pending_pricing'
|
plan.is_active ? 'bg-indigo-600' : 'bg-slate-300'
|
||||||
? 'bg-slate-200 cursor-not-allowed opacity-60'
|
|
||||||
: plan.is_active
|
|
||||||
? 'bg-indigo-600 cursor-pointer'
|
|
||||||
: 'bg-slate-300 cursor-pointer'
|
|
||||||
}`}
|
}`}
|
||||||
title={
|
title={plan.is_active ? 'Click to deactivate' : 'Click to activate'}
|
||||||
plan.pricing_status === 'pending_pricing'
|
|
||||||
? 'Set prices via Edit Info & Price before activating'
|
|
||||||
: plan.is_active
|
|
||||||
? 'Click to deactivate'
|
|
||||||
: 'Click to activate'
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<span
|
<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 ${
|
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>
|
</button>
|
||||||
<span className="block text-[9px] font-bold text-slate-400 mt-0.5">
|
<span className="block text-[9px] font-bold text-slate-400 mt-0.5">
|
||||||
{plan.pricing_status === 'pending_pricing'
|
{plan.is_active ? 'Active' : 'Inactive'}
|
||||||
? 'Needs Pricing'
|
|
||||||
: plan.is_active
|
|
||||||
? 'Active'
|
|
||||||
: 'Inactive'}
|
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ export const SubscriptionsTab: React.FC<SubscriptionsTabProps> = ({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Sort & Count Bar */}
|
{/* Sort & Count Bar */}
|
||||||
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-2 pt-2 border-t border-slate-200/60">
|
<div className="flex justify-between items-center pt-2 border-t border-slate-200/60">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setSortOrder(prev => prev === 'desc' ? 'asc' : 'desc')}
|
onClick={() => setSortOrder(prev => prev === 'desc' ? 'asc' : 'desc')}
|
||||||
|
|
@ -126,7 +126,7 @@ export const SubscriptionsTab: React.FC<SubscriptionsTabProps> = ({
|
||||||
) : (
|
) : (
|
||||||
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
||||||
<div className="overflow-x-auto">
|
<div className="overflow-x-auto">
|
||||||
<table className="w-full text-xs min-w-[700px]">
|
<table className="w-full text-xs">
|
||||||
<thead>
|
<thead>
|
||||||
<tr className="border-b border-slate-200 bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider">
|
<tr className="border-b border-slate-200 bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider">
|
||||||
<th className="text-left py-3 px-3">Subscriber</th>
|
<th className="text-left py-3 px-3">Subscriber</th>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export const SyncOverview: React.FC<SyncOverviewProps> = ({
|
||||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
<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">
|
<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-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>
|
||||||
<div className="bg-gradient-to-br from-purple-50 to-pink-50 border border-purple-200/60 rounded-2xl p-4 text-center">
|
<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>
|
<p className="text-2xl font-black text-purple-600">{stats.subscriptions}</p>
|
||||||
|
|
@ -117,15 +117,15 @@ export const SyncTopCards: React.FC<{
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Compliance & Transaction Processing Box */}
|
{/* Compliance Box */}
|
||||||
<div className="bg-white border border-slate-200 rounded-2xl p-5 shadow-sm space-y-3">
|
<div className="bg-white border border-slate-200 rounded-2xl p-5 shadow-sm space-y-3">
|
||||||
<h3 className="text-sm font-bold text-slate-800 flex items-center gap-2">
|
<h3 className="text-sm font-bold text-slate-800 flex items-center gap-2">
|
||||||
<Shield className="h-4 w-4 text-emerald-500" /> Gateway & Transaction Processing
|
<Shield className="h-4 w-4 text-emerald-500" /> Tax Compliance
|
||||||
</h3>
|
</h3>
|
||||||
<div className="text-[10px] text-slate-500 space-y-1 font-semibold">
|
<div className="text-[10px] text-slate-400 space-y-1 font-bold">
|
||||||
<p>✓ All-inclusive customer pricing (no tax markup)</p>
|
<p>✓ CGST: 9% split</p>
|
||||||
<p>✓ Merchant gateway fees handled directly via Razorpay</p>
|
<p>✓ SGST: 9% split</p>
|
||||||
<p>✓ Automated invoice & payment receipt generation</p>
|
<p>✓ ISO compliance generated automatically</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,19 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
<div className="fixed inset-0 z-50 bg-slate-950/60 backdrop-blur-xs flex justify-end animate-in fade-in duration-200">
|
<div className="fixed inset-0 z-50 bg-slate-950/60 backdrop-blur-xs flex justify-end animate-in fade-in duration-200">
|
||||||
<div className="w-full max-w-xl bg-white h-full shadow-2xl flex flex-col justify-between overflow-hidden animate-in slide-in-from-right duration-200">
|
<div className="w-full max-w-xl bg-white h-full shadow-2xl flex flex-col justify-between overflow-hidden animate-in slide-in-from-right duration-200">
|
||||||
{/* Drawer Top Bar */}
|
{/* Drawer Top Bar */}
|
||||||
<div className="p-4 sm:p-5 border-b border-slate-200 bg-slate-50 flex items-center justify-between shrink-0 gap-3">
|
<div className="p-5 border-b border-slate-200 bg-slate-50 flex items-center justify-between shrink-0">
|
||||||
<div className="flex items-center gap-3 min-w-0">
|
<div className="flex items-center gap-3">
|
||||||
<div className="h-10 w-10 sm:h-11 sm:w-11 rounded-2xl bg-indigo-600 text-white font-black text-sm sm:text-base flex items-center justify-center shadow-md shrink-0">
|
<div className="h-11 w-11 rounded-2xl bg-indigo-600 text-white font-black text-base flex items-center justify-center shadow-md">
|
||||||
{customerData?.display_name ? customerData.display_name[0].toUpperCase() : 'U'}
|
{customerData?.display_name ? customerData.display_name[0].toUpperCase() : 'U'}
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0 flex-1">
|
<div>
|
||||||
<div className="flex items-center gap-2 flex-wrap">
|
<div className="flex items-center gap-2">
|
||||||
<h3 className="text-sm sm:text-base font-black text-slate-800 truncate">
|
<h3 className="text-base font-black text-slate-800">
|
||||||
{customerData?.display_name || 'Customer Account'}
|
{customerData?.display_name || 'Customer Account'}
|
||||||
</h3>
|
</h3>
|
||||||
{customerData && (
|
{customerData && (
|
||||||
<span
|
<span
|
||||||
className={`text-[10px] font-black uppercase px-2 py-0.5 rounded-full border shrink-0 ${
|
className={`text-[10px] font-black uppercase px-2 py-0.5 rounded-full border ${
|
||||||
customerData.is_active
|
customerData.is_active
|
||||||
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
||||||
: 'bg-rose-50 text-rose-700 border-rose-200'
|
: 'bg-rose-50 text-rose-700 border-rose-200'
|
||||||
|
|
@ -57,22 +57,21 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-slate-400 font-semibold truncate">{customerData?.email || 'Loading...'}</p>
|
<p className="text-xs text-slate-400 font-semibold">{customerData?.email || 'Loading...'}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
className="h-8 w-8 rounded-full bg-slate-200/80 hover:bg-slate-300 text-slate-600 flex items-center justify-center text-sm font-black transition-colors cursor-pointer shrink-0"
|
className="h-8 w-8 rounded-full bg-slate-200/80 hover:bg-slate-300 text-slate-600 flex items-center justify-center text-sm font-black transition-colors cursor-pointer"
|
||||||
aria-label="Close customer drawer"
|
|
||||||
>
|
>
|
||||||
✕
|
✕
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Drawer Body */}
|
{/* Drawer Body */}
|
||||||
<div className="flex-1 overflow-y-auto p-4 sm:p-6 space-y-5 sm:space-y-6">
|
<div className="flex-1 overflow-y-auto p-6 space-y-6">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<div className="flex flex-col items-center justify-center py-20 space-y-3">
|
<div className="flex flex-col items-center justify-center py-20 space-y-3">
|
||||||
<RefreshCw className="h-8 w-8 animate-spin text-indigo-600" />
|
<RefreshCw className="h-8 w-8 animate-spin text-indigo-600" />
|
||||||
|
|
@ -81,10 +80,10 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
) : customerData ? (
|
) : customerData ? (
|
||||||
<>
|
<>
|
||||||
{/* Account Status Control */}
|
{/* Account Status Control */}
|
||||||
<div className="bg-slate-50 border border-slate-200 rounded-2xl p-4 flex flex-col sm:flex-row sm:items-center justify-between gap-3 shadow-2xs">
|
<div className="bg-slate-50 border border-slate-200 rounded-2xl p-4 flex items-center justify-between shadow-2xs">
|
||||||
<div className="space-y-0.5 min-w-0">
|
<div className="space-y-0.5">
|
||||||
<div className="flex items-center gap-1.5">
|
<div className="flex items-center gap-1.5">
|
||||||
<Shield className="h-3.5 w-3.5 text-indigo-600 shrink-0" />
|
<Shield className="h-3.5 w-3.5 text-indigo-600" />
|
||||||
<span className="text-xs font-bold text-slate-800">Account Access Control</span>
|
<span className="text-xs font-bold text-slate-800">Account Access Control</span>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-[11px] text-slate-500 font-medium">
|
<p className="text-[11px] text-slate-500 font-medium">
|
||||||
|
|
@ -98,7 +97,7 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
type="button"
|
type="button"
|
||||||
onClick={onToggleStatus}
|
onClick={onToggleStatus}
|
||||||
disabled={statusToggling}
|
disabled={statusToggling}
|
||||||
className={`self-start sm:self-auto shrink-0 px-3.5 py-1.5 rounded-xl text-xs font-black transition-all flex items-center gap-1.5 cursor-pointer shadow-xs disabled:opacity-50 ${
|
className={`px-3 py-1.5 rounded-xl text-xs font-black transition-all flex items-center gap-1.5 cursor-pointer shadow-xs disabled:opacity-50 ${
|
||||||
customerData.is_active
|
customerData.is_active
|
||||||
? 'bg-rose-50 hover:bg-rose-100 text-rose-700 border border-rose-200'
|
? 'bg-rose-50 hover:bg-rose-100 text-rose-700 border border-rose-200'
|
||||||
: 'bg-emerald-600 hover:bg-emerald-500 text-white shadow-emerald-600/20'
|
: 'bg-emerald-600 hover:bg-emerald-500 text-white shadow-emerald-600/20'
|
||||||
|
|
@ -115,7 +114,7 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Drawer Sub-Tabs */}
|
{/* Drawer Sub-Tabs */}
|
||||||
<div className="flex border-b border-slate-200 gap-1.5 pb-1 overflow-x-auto select-none">
|
<div className="flex border-b border-slate-200 gap-1 pb-1">
|
||||||
{[
|
{[
|
||||||
{ id: 'overview' as const, label: 'Overview' },
|
{ id: 'overview' as const, label: 'Overview' },
|
||||||
{
|
{
|
||||||
|
|
@ -131,7 +130,7 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
key={tab.id}
|
key={tab.id}
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => onTabChange(tab.id)}
|
onClick={() => onTabChange(tab.id)}
|
||||||
className={`px-3 py-2 text-xs font-bold rounded-xl transition-all cursor-pointer shrink-0 whitespace-nowrap ${
|
className={`px-3 py-2 text-xs font-bold rounded-xl transition-all cursor-pointer ${
|
||||||
activeTab === tab.id
|
activeTab === tab.id
|
||||||
? 'bg-indigo-600 text-white shadow-xs'
|
? 'bg-indigo-600 text-white shadow-xs'
|
||||||
: 'text-slate-500 hover:text-slate-800 hover:bg-slate-100'
|
: 'text-slate-500 hover:text-slate-800 hover:bg-slate-100'
|
||||||
|
|
@ -146,9 +145,9 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
{activeTab === 'overview' && (
|
{activeTab === 'overview' && (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<div className="grid grid-cols-2 gap-3">
|
||||||
<div className="bg-slate-50 rounded-2xl p-3 border border-slate-200/60 min-w-0">
|
<div className="bg-slate-50 rounded-2xl p-3 border border-slate-200/60">
|
||||||
<span className="text-[10px] font-bold text-slate-400 uppercase tracking-wider block">Total Spent</span>
|
<span className="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Total Spent</span>
|
||||||
<p className="text-lg sm:text-xl font-black text-slate-800 mt-0.5 truncate">
|
<p className="text-xl font-black text-slate-800 mt-0.5">
|
||||||
{customerData.total_spent_formatted ||
|
{customerData.total_spent_formatted ||
|
||||||
formatCurrency(
|
formatCurrency(
|
||||||
customerData.total_spent ?? customerData.total_spent_inr ?? 0,
|
customerData.total_spent ?? customerData.total_spent_inr ?? 0,
|
||||||
|
|
@ -156,9 +155,9 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="bg-slate-50 rounded-2xl p-3 border border-slate-200/60 min-w-0">
|
<div className="bg-slate-50 rounded-2xl p-3 border border-slate-200/60">
|
||||||
<span className="text-[10px] font-bold text-slate-400 uppercase tracking-wider block">Total Orders</span>
|
<span className="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Total Orders</span>
|
||||||
<p className="text-lg sm:text-xl font-black text-slate-800 mt-0.5 truncate">{customerData.total_orders || 0}</p>
|
<p className="text-xl font-black text-slate-800 mt-0.5">{customerData.total_orders || 0}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -166,35 +165,35 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
<h4 className="text-xs font-bold text-slate-700 uppercase tracking-wider border-b border-slate-100 pb-2">
|
<h4 className="text-xs font-bold text-slate-700 uppercase tracking-wider border-b border-slate-100 pb-2">
|
||||||
Contact & Account Information
|
Contact & Account Information
|
||||||
</h4>
|
</h4>
|
||||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3 text-xs">
|
<div className="grid grid-cols-2 gap-y-2.5 text-xs">
|
||||||
<div className="min-w-0">
|
<div>
|
||||||
<span className="text-slate-400 font-semibold block text-[10px]">Email Address</span>
|
<span className="text-slate-400 font-semibold block text-[10px]">Email Address</span>
|
||||||
<span className="font-bold text-slate-700 break-all">{customerData.email}</span>
|
<span className="font-bold text-slate-700">{customerData.email}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0">
|
<div>
|
||||||
<span className="text-slate-400 font-semibold block text-[10px]">Phone Number</span>
|
<span className="text-slate-400 font-semibold block text-[10px]">Phone Number</span>
|
||||||
<span className="font-bold text-slate-700 break-words">{customerData.phone_number || 'Not provided'}</span>
|
<span className="font-bold text-slate-700">{customerData.phone_number || 'Not provided'}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0">
|
<div>
|
||||||
<span className="text-slate-400 font-semibold block text-[10px]">Country</span>
|
<span className="text-slate-400 font-semibold block text-[10px]">Country</span>
|
||||||
<span className="font-bold text-slate-700">{customerData.country || 'India'}</span>
|
<span className="font-bold text-slate-700">{customerData.country || 'India'}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0">
|
<div>
|
||||||
<span className="text-slate-400 font-semibold block text-[10px]">Assigned Roles</span>
|
<span className="text-slate-400 font-semibold block text-[10px]">Assigned Roles</span>
|
||||||
<span className="font-bold text-indigo-600 capitalize">
|
<span className="font-bold text-indigo-600 capitalize">
|
||||||
{customerData.roles?.join(', ') || 'user'}
|
{customerData.roles?.join(', ') || 'user'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="min-w-0">
|
<div>
|
||||||
<span className="text-slate-400 font-semibold block text-[10px]">Member Since</span>
|
<span className="text-slate-400 font-semibold block text-[10px]">Member Since</span>
|
||||||
<span className="font-bold text-slate-700">
|
<span className="font-bold text-slate-700">
|
||||||
{customerData.created_at ? customerData.created_at.split('T')[0] : 'N/A'}
|
{customerData.created_at ? customerData.created_at.split('T')[0] : 'N/A'}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{customerData.external_ref && (
|
{customerData.external_ref && (
|
||||||
<div className="min-w-0">
|
<div>
|
||||||
<span className="text-slate-400 font-semibold block text-[10px]">Gateway Ref</span>
|
<span className="text-slate-400 font-semibold block text-[10px]">Gateway Ref</span>
|
||||||
<span className="font-bold font-mono text-[10px] text-slate-600 break-all">{customerData.external_ref}</span>
|
<span className="font-bold font-mono text-[10px] text-slate-600">{customerData.external_ref}</span>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -282,25 +281,25 @@ export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={idx}
|
key={idx}
|
||||||
className="flex flex-col sm:flex-row sm:items-center justify-between gap-2.5 bg-slate-50 border border-slate-200 rounded-xl p-3.5 text-xs shadow-2xs"
|
className="flex justify-between items-center bg-slate-50 border border-slate-200 rounded-xl p-3.5 text-xs shadow-2xs"
|
||||||
>
|
>
|
||||||
<div className="space-y-0.5 min-w-0">
|
<div className="space-y-0.5">
|
||||||
<div className="flex items-center gap-2 flex-wrap">
|
<div className="flex items-center gap-2">
|
||||||
<span className="font-mono font-bold text-slate-800 break-all">{invNumber}</span>
|
<span className="font-mono font-bold text-slate-800">{invNumber}</span>
|
||||||
{tx.invoice?.invoice_number && (
|
{tx.invoice?.invoice_number && (
|
||||||
<span className="text-[9px] bg-indigo-50 border border-indigo-200 text-indigo-700 font-bold px-1.5 py-0.2 rounded shrink-0">
|
<span className="text-[9px] bg-indigo-50 border border-indigo-200 text-indigo-700 font-bold px-1.5 py-0.2 rounded">
|
||||||
Invoice
|
Invoice
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-[10px] text-slate-400 break-all">
|
<p className="text-[10px] text-slate-400">
|
||||||
{tx.created_at?.split('T')[0] || '—'}
|
{tx.created_at?.split('T')[0] || '—'}
|
||||||
{tx.gateway_transaction_id && ` • ${tx.gateway_transaction_id}`}
|
{tx.gateway_transaction_id && ` • ${tx.gateway_transaction_id}`}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center justify-between sm:justify-end gap-3 shrink-0 pt-1 sm:pt-0 border-t sm:border-t-0 border-slate-200/60">
|
<div className="flex items-center gap-3">
|
||||||
<div className="text-left sm:text-right">
|
<div className="text-right">
|
||||||
<p className="font-bold text-slate-800">{formatCurrency(amount, curr)}</p>
|
<p className="font-bold text-slate-800">{formatCurrency(amount, curr)}</p>
|
||||||
<span
|
<span
|
||||||
className={`text-[10px] font-bold ${
|
className={`text-[10px] font-bold ${
|
||||||
|
|
|
||||||
|
|
@ -1,228 +0,0 @@
|
||||||
import { api } from './api';
|
|
||||||
|
|
||||||
export interface BuilderModuleSummary {
|
|
||||||
id?: string;
|
|
||||||
code: string;
|
|
||||||
name: string;
|
|
||||||
slug: string;
|
|
||||||
short_description?: string | null;
|
|
||||||
description?: string | null;
|
|
||||||
kind: string;
|
|
||||||
managed_by: string;
|
|
||||||
default_template_code?: string | null;
|
|
||||||
sort_order: number;
|
|
||||||
is_active: boolean;
|
|
||||||
category_count: number;
|
|
||||||
disease_count: number;
|
|
||||||
pattern_count: number;
|
|
||||||
created_at?: string;
|
|
||||||
updated_at?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BuilderCategorySummary {
|
|
||||||
id?: string;
|
|
||||||
module_code: string;
|
|
||||||
category_code: string;
|
|
||||||
name: string;
|
|
||||||
overview?: string | null;
|
|
||||||
sort_order: number;
|
|
||||||
disease_count: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BuilderDiseaseSummary {
|
|
||||||
id?: string;
|
|
||||||
module_code: string;
|
|
||||||
category_code: string;
|
|
||||||
disease_code: string;
|
|
||||||
name: string;
|
|
||||||
overview?: string | null;
|
|
||||||
sort_order: number;
|
|
||||||
pattern_count: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PatternClinicalData {
|
|
||||||
clinical_manifestations: string[];
|
|
||||||
tongue: string;
|
|
||||||
pulse: string;
|
|
||||||
treatment_principle: string;
|
|
||||||
acupuncture: {
|
|
||||||
points: string;
|
|
||||||
method: string;
|
|
||||||
};
|
|
||||||
explanation: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BuilderPattern {
|
|
||||||
id?: string;
|
|
||||||
module_code: string;
|
|
||||||
category_code: string;
|
|
||||||
disease_code: string;
|
|
||||||
pattern_code: string;
|
|
||||||
name: string;
|
|
||||||
description?: string | null;
|
|
||||||
clinical_data: PatternClinicalData;
|
|
||||||
sort_order: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface BuilderDiseaseDetail {
|
|
||||||
id?: string;
|
|
||||||
module_code: string;
|
|
||||||
category_code: string;
|
|
||||||
disease_code: string;
|
|
||||||
name: string;
|
|
||||||
overview?: string | null;
|
|
||||||
sort_order: number;
|
|
||||||
patterns: BuilderPattern[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SaveFullDiseasePayload {
|
|
||||||
category_code: string;
|
|
||||||
disease_code: string;
|
|
||||||
name: string;
|
|
||||||
overview?: string | null;
|
|
||||||
patterns: {
|
|
||||||
category_code: string;
|
|
||||||
disease_code: string;
|
|
||||||
pattern_code: string;
|
|
||||||
name: string;
|
|
||||||
description?: string | null;
|
|
||||||
clinical_data: PatternClinicalData;
|
|
||||||
sort_order: number;
|
|
||||||
}[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const moduleBuilderService = {
|
|
||||||
// Modules
|
|
||||||
async getModules(): Promise<BuilderModuleSummary[]> {
|
|
||||||
const res = await api.get('/api/admin/module-builder/modules');
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
async createModule(data: {
|
|
||||||
name: string;
|
|
||||||
code?: string;
|
|
||||||
slug?: string;
|
|
||||||
short_description?: string;
|
|
||||||
description?: string;
|
|
||||||
kind?: string;
|
|
||||||
managed_by?: string;
|
|
||||||
sort_order?: number;
|
|
||||||
}): Promise<BuilderModuleSummary> {
|
|
||||||
const res = await api.post('/api/admin/module-builder/modules', data);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
async deleteModule(moduleCode: string): Promise<boolean> {
|
|
||||||
const res = await api.delete(`/api/admin/module-builder/modules/${moduleCode}`);
|
|
||||||
return res.data?.status === 'deleted' || res.status === 200;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Categories
|
|
||||||
async getCategories(moduleCode: string): Promise<BuilderCategorySummary[]> {
|
|
||||||
const res = await api.get(`/api/admin/module-builder/${moduleCode}/categories`);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
async saveCategory(
|
|
||||||
moduleCode: string,
|
|
||||||
data: { category_code: string; name: string; overview?: string; sort_order?: number }
|
|
||||||
): Promise<BuilderCategorySummary> {
|
|
||||||
const res = await api.post(`/api/admin/module-builder/${moduleCode}/categories`, data);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
async deleteCategory(moduleCode: string, categoryCode: string): Promise<boolean> {
|
|
||||||
const res = await api.delete(`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}`);
|
|
||||||
return res.data?.success ?? true;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Diseases
|
|
||||||
async getDiseases(moduleCode: string, categoryCode: string): Promise<BuilderDiseaseSummary[]> {
|
|
||||||
const res = await api.get(`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}/diseases`);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
async getDiseaseDetail(
|
|
||||||
moduleCode: string,
|
|
||||||
categoryCode: string,
|
|
||||||
diseaseCode: string
|
|
||||||
): Promise<BuilderDiseaseDetail> {
|
|
||||||
const res = await api.get(
|
|
||||||
`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}/diseases/${diseaseCode}`
|
|
||||||
);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
async saveDisease(
|
|
||||||
moduleCode: string,
|
|
||||||
categoryCode: string,
|
|
||||||
data: { disease_code: string; name: string; overview?: string; sort_order?: number; category_code?: string }
|
|
||||||
): Promise<BuilderDiseaseSummary> {
|
|
||||||
const res = await api.post(
|
|
||||||
`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}/diseases`,
|
|
||||||
{ ...data, category_code: categoryCode }
|
|
||||||
);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
async deleteDisease(
|
|
||||||
moduleCode: string,
|
|
||||||
categoryCode: string,
|
|
||||||
diseaseCode: string
|
|
||||||
): Promise<boolean> {
|
|
||||||
const res = await api.delete(
|
|
||||||
`/api/admin/module-builder/${moduleCode}/categories/${categoryCode}/diseases/${diseaseCode}`
|
|
||||||
);
|
|
||||||
return res.data?.success ?? true;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Save Full Disease with Patterns
|
|
||||||
async saveFullDisease(
|
|
||||||
moduleCode: string,
|
|
||||||
payload: SaveFullDiseasePayload
|
|
||||||
): Promise<BuilderDiseaseDetail> {
|
|
||||||
const res = await api.post(`/api/admin/module-builder/${moduleCode}/save-full`, payload);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Export JSON
|
|
||||||
async exportModuleJson(moduleCode: string): Promise<any> {
|
|
||||||
const res = await api.get(`/api/admin/module-builder/${moduleCode}/export-json`);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Export Production ZIP Package
|
|
||||||
async exportBundleZip(moduleCode: string): Promise<{ blob: Blob; filename: string }> {
|
|
||||||
const res = await api.get(`/api/admin/module-builder/${moduleCode}/export-bundle`, {
|
|
||||||
responseType: 'blob',
|
|
||||||
});
|
|
||||||
const disposition = res.headers['content-disposition'] || '';
|
|
||||||
let filename = `${moduleCode}_package.zip`;
|
|
||||||
const match = disposition.match(/filename="?([^";]+)"?/);
|
|
||||||
if (match && match[1]) {
|
|
||||||
filename = match[1];
|
|
||||||
}
|
|
||||||
return { blob: res.data, filename };
|
|
||||||
},
|
|
||||||
|
|
||||||
// Sync Directly to Content Repo
|
|
||||||
async syncContentRepo(moduleCode: string): Promise<{
|
|
||||||
status: string;
|
|
||||||
module_code: string;
|
|
||||||
module_name: string;
|
|
||||||
target_dir: string;
|
|
||||||
files_written: number;
|
|
||||||
config_updated: boolean;
|
|
||||||
message: string;
|
|
||||||
}> {
|
|
||||||
const res = await api.post(`/api/admin/module-builder/${moduleCode}/sync-content-repo`);
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
// Import JSON
|
|
||||||
async importModuleJson(moduleCode: string, contents: any[]): Promise<any> {
|
|
||||||
const res = await api.post(`/api/admin/module-builder/${moduleCode}/import-json`, { contents });
|
|
||||||
return res.data;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
export type AdminTabType =
|
export type AdminTabType =
|
||||||
| 'overview'
|
| 'overview'
|
||||||
| 'modules'
|
| 'modules'
|
||||||
| 'module_builder'
|
|
||||||
| 'plans'
|
| 'plans'
|
||||||
| 'coupons'
|
| 'coupons'
|
||||||
| 'customers'
|
| 'customers'
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
/**
|
|
||||||
* Generic clinical category resolver and normalizer.
|
|
||||||
* Maps raw categories or content kinds into standardized display categories.
|
|
||||||
*/
|
|
||||||
export function normalizeCategory(categoryOrKind?: string | null): string {
|
|
||||||
if (!categoryOrKind) return 'General';
|
|
||||||
const val = categoryOrKind.trim();
|
|
||||||
const lower = val.toLowerCase();
|
|
||||||
if (lower === 'point' || lower === 'points') return 'Points';
|
|
||||||
if (lower === 'pattern' || lower === 'patterns' || lower === 'five-elements') return 'Patterns';
|
|
||||||
if (lower === 'nutrition') return 'Nutrition';
|
|
||||||
if (lower === 'therapeutic' || lower === 'therapeutics') return 'Therapeutics';
|
|
||||||
if (lower === 'general') return 'General';
|
|
||||||
return val;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CLINICAL_CATEGORIES = [
|
|
||||||
{ key: 'all', label: 'All Categories' },
|
|
||||||
{ key: 'Points', label: 'Points' },
|
|
||||||
{ key: 'Patterns', label: 'Patterns' },
|
|
||||||
{ key: 'Nutrition', label: 'Nutrition' },
|
|
||||||
{ key: 'Therapeutics', label: 'Therapeutics' },
|
|
||||||
];
|
|
||||||
|
|
@ -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