feat: initial commit for standalone acupedia storefront

This commit is contained in:
Urvish Prajapati 2026-09-10 12:56:24 +05:30
commit 90bc14d37e
33 changed files with 8444 additions and 0 deletions

5
.env.example Normal file
View File

@ -0,0 +1,5 @@
# API Base URL (defaults to http://localhost:8000 when running on localhost)
VITE_API_BASE=http://localhost:8000
# Base URL Path (e.g., /store/ or / if using root domain)
VITE_BASE_PATH=/store/

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Environment variables
.env
.env.*
!.env.example

32
README.md Normal file
View File

@ -0,0 +1,32 @@
# Acupedia Storefront
Customer-facing e-commerce storefront for practitioners to explore TCM curriculum modules, customize subscription plans, apply coupons, and checkout via Razorpay.
## Tech Stack
- **Framework**: React 19 + TypeScript + Vite
- **Styling**: TailwindCSS v4
- **Icons**: Lucide React
- **Payments**: Razorpay Checkout SDK
- **HTTP Client**: Axios
## Local Development
1. Install dependencies:
```bash
npm install
```
2. Start development server:
```bash
npm run dev
```
Server runs by default on `http://localhost:3000/store/`.
## Production Build
```bash
npm run build
```
Build output will be in the `dist/` directory.
## Environment Variables
Create a `.env` file based on `.env.example`:
- `VITE_API_BASE`: Backend API URL (default: `http://localhost:8000`).
- `VITE_BASE_PATH`: Base routing path (default: `/store/`).

22
eslint.config.js Normal file
View File

@ -0,0 +1,22 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
globals: globals.browser,
},
},
])

25
index.html Normal file
View File

@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Acupedia TCM Storefront - Module subscriptions, passes, and clinical certifications." />
<!-- Google Fonts: Outfit -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
<title>Acupedia Storefront — Clinical Modules & Passes</title>
<style>
body {
font-family: 'Outfit', sans-serif !important;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

4469
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

36
package.json Normal file
View File

@ -0,0 +1,36 @@
{
"name": "panacea-store-frontend",
"private": true,
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.7.0",
"lucide-react": "^0.460.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@tailwindcss/postcss": "^4.0.0",
"@types/node": "^22.0.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"@vitejs/plugin-react": "^4.3.0",
"autoprefixer": "^10.4.0",
"eslint": "^9.0.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.0",
"globals": "^15.0.0",
"postcss": "^8.4.0",
"tailwindcss": "^4.0.0",
"typescript": "^5.8.0",
"typescript-eslint": "^8.0.0",
"vite": "^6.0.0"
}
}

7
postcss.config.js Normal file
View File

@ -0,0 +1,7 @@
export default {
plugins: {
'@tailwindcss/postcss': {},
autoprefixer: {},
},
}

1
public/favicon.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 KiB

24
public/icons.svg Normal file
View File

@ -0,0 +1,24 @@
<svg xmlns="http://www.w3.org/2000/svg">
<symbol id="bluesky-icon" viewBox="0 0 16 17">
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
</symbol>
<symbol id="discord-icon" viewBox="0 0 20 19">
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
</symbol>
<symbol id="documentation-icon" viewBox="0 0 21 20">
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
</symbol>
<symbol id="github-icon" viewBox="0 0 19 19">
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
</symbol>
<symbol id="social-icon" viewBox="0 0 20 20">
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
</symbol>
<symbol id="x-icon" viewBox="0 0 19 19">
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
</symbol>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

903
src/App.tsx Normal file
View File

@ -0,0 +1,903 @@
import { useState, useEffect } from 'react';
import axios from 'axios';
import { CURRICULUM_MODULES } from './constants/modules';
import type { ModuleItem, Currency, UserProfile, VerificationResult, PublicPlan } from './types';
import { API_BASE } from './services/api';
import { loadRazorpayScript } from './services/razorpay';
// Modular Subcomponents
import { StoreHeader } from './components/layout/StoreHeader';
import { StoreFooter } from './components/layout/StoreFooter';
import { LifetimeBanner } from './components/catalog/LifetimeBanner';
import { CatalogSection } from './components/catalog/CatalogSection';
import { CartDrawer } from './components/cart/CartDrawer';
import { SubscriptionsView } from './components/subscriptions/SubscriptionsView';
import { AuthModal } from './components/auth/AuthModal';
import { ProfileDrawer } from './components/auth/ProfileDrawer';
import { PaymentSuccessModal } from './components/checkout/PaymentSuccessModal';
import { PasswordUpdatedModal } from './components/auth/PasswordUpdatedModal';
const getInitialTab = (): 'storefront' | 'subscriptions' => {
if (typeof window !== 'undefined') {
const path = window.location.pathname.toLowerCase();
if (path.includes('/subscriptions')) return 'subscriptions';
}
return 'storefront';
};
export default function App() {
const [activeTab, setActiveTab] = useState<'storefront' | 'subscriptions'>(getInitialTab);
const switchTab = (tab: 'storefront' | 'subscriptions') => {
setActiveTab(tab);
if (typeof window !== 'undefined') {
const isStorePrefix = window.location.pathname.startsWith('/store');
const basePath = isStorePrefix ? '/store' : '';
const newPath = tab === 'storefront' ? (basePath || '/') : (basePath + '/' + tab);
if (window.location.pathname !== newPath) {
window.history.pushState({ tab }, '', newPath);
}
}
};
useEffect(() => {
const handlePopState = () => {
setActiveTab(getInitialTab());
};
window.addEventListener('popstate', handlePopState);
return () => window.removeEventListener('popstate', handlePopState);
}, []);
const [currency, setCurrency] = useState<Currency>('INR');
// Auth state
const [userToken, setUserToken] = useState<string | null>(localStorage.getItem('access_token'));
const [loggedInUser, setLoggedInUser] = useState<UserProfile | null>(null);
const [showAuthModal, setShowAuthModal] = useState<boolean>(false);
const [authMode, setAuthMode] = useState<'login' | 'register' | 'forgot'>('login');
const [resetStep, setResetStep] = useState<'request' | 'verify'>('request');
const [resetOtp, setResetOtp] = useState('');
const [resetNewPassword, setResetNewPassword] = useState('');
const [resetConfirmPassword, setResetConfirmPassword] = useState('');
const [resetSuccessMessage, setResetSuccessMessage] = useState<string | null>(null);
const [passwordUpdatedPopup, setPasswordUpdatedPopup] = useState<boolean>(false);
// In-app Change Password state (Profile Drawer)
const [showPasswordChange, setShowPasswordChange] = useState<boolean>(false);
const [changeOldPassword, setChangeOldPassword] = useState<string>('');
const [changeNewPassword, setChangeNewPassword] = useState<string>('');
const [changeConfirmPassword, setChangeConfirmPassword] = useState<string>('');
const [changePasswordLoading, setChangePasswordLoading] = useState<boolean>(false);
const [changePasswordError, setChangePasswordError] = useState<string | null>(null);
const [changePasswordSuccess, setChangePasswordSuccess] = useState<boolean>(false);
// Auth Form State
const [authEmail, setAuthEmail] = useState('');
const [authPassword, setAuthPassword] = useState('');
const [authDisplayName, setAuthDisplayName] = useState('');
const [authPhone, setAuthPhone] = useState('');
const [authDialCode, setAuthDialCode] = useState('+91');
const [authCountry, setAuthCountry] = useState('India');
const [authLoading, setAuthLoading] = useState(false);
const [authError, setAuthError] = useState<string | null>(null);
// Cart state
const [cart, setCart] = useState<ModuleItem[]>([]);
const [couponCode, setCouponCode] = useState<string>('');
const [appliedCoupon, setAppliedCoupon] = useState<string | null>(null);
// Storefront toggle states for showing locked modules in each category
const [showLockedByCategory, setShowLockedByCategory] = useState<{ [key: string]: boolean }>({
Points: true,
Pattern: true,
Nutrition: true,
Therapeutics: true,
Lifetime: true
});
// Calculation / API state
const [pricingCalc, setPricingCalc] = useState<any>(null);
const [loadingPricing, setLoadingPricing] = useState<boolean>(false);
const [checkoutLoading, setCheckoutLoading] = useState<boolean>(false);
// Active payment state
const [verificationResult, setVerificationResult] = useState<VerificationResult | null>(null);
const [razorpayKeyId, setRazorpayKeyId] = useState<string>('');
// Profile Update & Drawer State
const [showProfileDrawer, setShowProfileDrawer] = useState<boolean>(false);
const [profileDisplayName, setProfileDisplayName] = useState<string>('');
const [profilePhone, setProfilePhone] = useState<string>('');
const [profileCountry, setProfileCountry] = useState<string>('India');
const [profileSaving, setProfileSaving] = useState<boolean>(false);
const [profileError, setProfileError] = useState<string | null>(null);
const [profileSuccess, setProfileSuccess] = useState<boolean>(false);
// Dynamic Public Storefront Plans
const [publicPlans, setPublicPlans] = useState<PublicPlan[]>([]);
const fetchPublicPlans = async () => {
try {
const res = await axios.get(`${API_BASE}/api/plans`);
if (Array.isArray(res.data)) {
setPublicPlans(res.data);
}
} catch (err) {
console.error('Failed to load public plans:', err);
}
};
const getLivePlan = (code: string) => {
return publicPlans.find(p => p.code === code || p.base_code === code);
};
const getModulePrice = (item: ModuleItem) => {
const livePlan = getLivePlan(item.code);
if (livePlan) {
return {
priceInr: livePlan.price_inr ?? item.priceInr,
priceUsd: livePlan.price_usd ?? item.priceUsd,
priceEur: item.priceEur,
isActive: livePlan.is_active !== undefined ? livePlan.is_active : true,
};
}
return {
priceInr: item.priceInr,
priceUsd: item.priceUsd,
priceEur: item.priceEur,
isActive: true,
};
};
// Load configuration & user profile on startup
useEffect(() => {
const params = new URLSearchParams(window.location.search);
const urlToken = params.get('token');
const urlPlanCode = params.get('planCode');
let activeToken = userToken;
if (urlToken) {
localStorage.setItem('access_token', urlToken);
setUserToken(urlToken);
activeToken = urlToken;
fetchUserProfile(urlToken);
}
if (urlPlanCode) {
const targetModule = CURRICULUM_MODULES.find(m => m.code === urlPlanCode);
if (targetModule) {
setCart([targetModule]);
setShowLockedByCategory(prev => ({
...prev,
[targetModule.category]: true
}));
}
}
if (urlToken || urlPlanCode) {
const newUrl = window.location.pathname;
window.history.replaceState({}, document.title, newUrl);
}
// Fetch public Razorpay Config
axios.get(`${API_BASE}/api/checkout/config`)
.then(res => {
setRazorpayKeyId(res.data.razorpay_key_id);
})
.catch(err => {
console.error('Failed to load checkout config:', err);
});
fetchPublicPlans();
if (activeToken && !urlToken) {
fetchUserProfile(activeToken);
}
if (!activeToken && !urlToken) {
setAuthMode('login');
setShowAuthModal(true);
}
}, [userToken]);
// Recalculate price whenever cart, coupon, or currency changes
useEffect(() => {
if (cart.length === 0) {
setPricingCalc(null);
return;
}
calculatePricing();
}, [cart, appliedCoupon, currency]);
// Update currency automatically on country selection during registration
useEffect(() => {
if (authMode === 'register') {
if (authCountry === 'India') {
setCurrency('INR');
} else {
setCurrency('USD');
}
}
}, [authCountry, authMode]);
const fetchUserProfile = async (token: string) => {
try {
const res = await axios.get(`${API_BASE}/api/auth/profile`, {
headers: { 'Authorization': `Bearer ${token}` }
});
setLoggedInUser(res.data);
setProfileDisplayName(res.data.display_name || '');
setProfilePhone(res.data.phone_number || '');
setProfileCountry(res.data.country || 'India');
if (res.data.country === 'India') {
setCurrency('INR');
} else {
setCurrency('USD');
}
} catch (err) {
console.error('Failed to fetch user profile:', err);
handleLogout();
}
};
const handleLogout = () => {
localStorage.removeItem('access_token');
setUserToken(null);
setLoggedInUser(null);
setCart([]);
setAppliedCoupon(null);
switchTab('storefront');
setShowProfileDrawer(false);
setProfileDisplayName('');
setProfilePhone('');
setProfileCountry('India');
setProfileError(null);
setProfileSuccess(false);
};
const handleUpdateProfile = async (e: React.FormEvent) => {
e.preventDefault();
if (!userToken) return;
setProfileSaving(true);
setProfileError(null);
setProfileSuccess(false);
try {
await axios.put(`${API_BASE}/api/auth/profile`, {
full_name: profileDisplayName,
phone_number: profilePhone,
country: profileCountry
}, {
headers: { 'Authorization': `Bearer ${userToken}` }
});
setProfileSuccess(true);
await fetchUserProfile(userToken);
setTimeout(() => setProfileSuccess(false), 3000);
} catch (err: any) {
console.error(err);
setProfileError(err.response?.data?.detail || 'Failed to update profile details.');
} finally {
setProfileSaving(false);
}
};
const handleAuthSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setAuthLoading(true);
setAuthError(null);
const endpoint = authMode === 'login' ? '/api/auth/login' : '/api/auth/register';
const fullPhone = authPhone ? `${authDialCode}${authPhone}` : undefined;
const payload = authMode === 'login'
? { email: authEmail, password: authPassword }
: {
email: authEmail,
password: authPassword,
full_name: authDisplayName || undefined,
phone_number: fullPhone,
country: authCountry
};
try {
const res = await axios.post(`${API_BASE}${endpoint}`, payload);
const token = res.data.access_token;
localStorage.setItem('access_token', token);
setUserToken(token);
await fetchUserProfile(token);
setShowAuthModal(false);
setAuthPassword('');
setAuthEmail('');
setAuthDisplayName('');
setAuthPhone('');
} catch (err: any) {
setAuthError(err.response?.data?.detail || 'Authentication failed. Please check credentials.');
} finally {
setAuthLoading(false);
}
};
const handleChangePassword = async (e: React.FormEvent) => {
e.preventDefault();
if (!userToken) return;
setChangePasswordError(null);
setChangePasswordSuccess(false);
if (!changeOldPassword) {
setChangePasswordError('Please enter your current password.');
return;
}
if (changeNewPassword.length < 8) {
setChangePasswordError('New password must be at least 8 characters long.');
return;
}
if (!/[A-Z]/.test(changeNewPassword)) {
setChangePasswordError('New password must contain at least one uppercase letter.');
return;
}
if (!/[0-9]/.test(changeNewPassword)) {
setChangePasswordError('New password must contain at least one number.');
return;
}
if (!/[^A-Za-z0-9]/.test(changeNewPassword)) {
setChangePasswordError('New password must contain at least one special character.');
return;
}
if (changeNewPassword !== changeConfirmPassword) {
setChangePasswordError('New passwords do not match.');
return;
}
setChangePasswordLoading(true);
try {
await axios.post(`${API_BASE}/api/auth/change-password`, {
old_password: changeOldPassword,
new_password: changeNewPassword
}, {
headers: { 'Authorization': `Bearer ${userToken}` }
});
setChangePasswordSuccess(true);
setPasswordUpdatedPopup(true);
setChangeOldPassword('');
setChangeNewPassword('');
setChangeConfirmPassword('');
setShowPasswordChange(false);
} catch (err: any) {
console.error(err);
setChangePasswordError(err.response?.data?.detail || 'Failed to update password.');
} finally {
setChangePasswordLoading(false);
}
};
const handleForgotPasswordRequest = async (e: React.FormEvent) => {
e.preventDefault();
setAuthLoading(true);
setAuthError(null);
setResetSuccessMessage(null);
try {
const res = await axios.post(`${API_BASE}/api/auth/forgot-password`, {
email: authEmail
});
setResetSuccessMessage(res.data.message || 'Verification code sent to your email.');
setResetStep('verify');
} catch (err: any) {
console.error(err);
setAuthError(err.response?.data?.detail || 'Failed to send reset code.');
} finally {
setAuthLoading(false);
}
};
const handleResetPasswordSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setAuthLoading(true);
setAuthError(null);
if (resetNewPassword.length < 8) {
setAuthError('New password must be at least 8 characters long.');
setAuthLoading(false);
return;
}
if (!/[A-Z]/.test(resetNewPassword)) {
setAuthError('New password must contain at least one uppercase letter.');
setAuthLoading(false);
return;
}
if (!/[0-9]/.test(resetNewPassword)) {
setAuthError('New password must contain at least one number.');
setAuthLoading(false);
return;
}
if (!/[^A-Za-z0-9]/.test(resetNewPassword)) {
setAuthError('New password must contain at least one special character.');
setAuthLoading(false);
return;
}
if (resetNewPassword !== resetConfirmPassword) {
setAuthError('Passwords do not match.');
setAuthLoading(false);
return;
}
try {
await axios.post(`${API_BASE}/api/auth/reset-password`, {
email: authEmail,
otp_code: resetOtp,
new_password: resetNewPassword
});
setPasswordUpdatedPopup(true);
setAuthMode('login');
setResetStep('request');
setResetOtp('');
setResetNewPassword('');
setResetConfirmPassword('');
setAuthPassword('');
setAuthError(null);
} catch (err: any) {
console.error(err);
setAuthError(err.response?.data?.detail || 'Failed to reset password.');
} finally {
setAuthLoading(false);
}
};
const calculatePricing = async () => {
setLoadingPricing(true);
try {
const headers = userToken ? { 'Authorization': `Bearer ${userToken}` } : {};
const res = await axios.post(`${API_BASE}/api/cart/calculate`, {
cart_item_codes: cart.map(item => item.code),
coupon_code: appliedCoupon || undefined,
currency: currency
}, { headers });
setPricingCalc(res.data);
} catch (err) {
console.error('Pricing engine calculation error:', err);
} finally {
setLoadingPricing(false);
}
};
const toggleCartItem = (module: ModuleItem) => {
if (isModuleUnlocked(module.code)) return;
const live = getModulePrice(module);
if (!live.isActive) return;
const dynamicModule: ModuleItem = {
...module,
priceInr: live.priceInr,
priceUsd: live.priceUsd,
};
const exists = cart.find(item => item.code === module.code);
if (exists) {
setCart(cart.filter(item => item.code !== module.code));
} else {
if (module.code === 'LIFETIME_ALL') {
setCart([dynamicModule]);
} else if (module.code === 'POINTS_PACK') {
setCart([
...cart.filter(item => !['LIFETIME_ALL', 'POINTS_ACU', 'POINTS_SCALP', 'POINTS_EAR', 'POINTS_TUNG'].includes(item.code)),
dynamicModule
]);
} else if (['POINTS_ACU', 'POINTS_SCALP', 'POINTS_EAR', 'POINTS_TUNG'].includes(module.code)) {
setCart([
...cart.filter(item => !['LIFETIME_ALL', 'POINTS_PACK'].includes(item.code)),
dynamicModule
]);
} else if (module.code === 'THERAPEUTICS_CORE') {
setCart([
...cart.filter(item => !['LIFETIME_ALL', 'THERAPEUTICS_GYNAE', 'THERAPEUTICS_EAR'].includes(item.code)),
dynamicModule
]);
} else if (['THERAPEUTICS_GYNAE', 'THERAPEUTICS_EAR'].includes(module.code)) {
setCart([
...cart.filter(item => !['LIFETIME_ALL', 'THERAPEUTICS_CORE'].includes(item.code)),
dynamicModule
]);
} else {
setCart([...cart.filter(item => item.code !== 'LIFETIME_ALL'), dynamicModule]);
}
}
};
const applyPromoCode = () => {
if (!couponCode.trim()) return;
setAppliedCoupon(couponCode.toUpperCase().trim());
};
const removePromoCode = () => {
setAppliedCoupon(null);
setCouponCode('');
};
const isModuleUnlocked = (code: string) => {
if (!loggedInUser?.active_subscriptions) return false;
const hasLifetime = loggedInUser.active_subscriptions.some((sub: any) =>
sub.plan_code === 'LIFETIME_ALL' || sub.plan_code === 'LIFETIME_ALL_USD'
);
if (hasLifetime) return true;
if (code === 'POINTS_ACU' || code === 'POINTS_SCALP' || code === 'POINTS_EAR' || code === 'POINTS_TUNG') {
const hasPointsPack = loggedInUser.active_subscriptions.some((sub: any) =>
sub.plan_code === 'POINTS_PACK' || sub.plan_code === 'POINTS_PACK_USD'
);
if (hasPointsPack) return true;
}
if (code === 'THERAPEUTICS_GYNAE' || code === 'THERAPEUTICS_EAR') {
const hasTherapeuticsPack = loggedInUser.active_subscriptions.some((sub: any) =>
sub.plan_code === 'THERAPEUTICS_CORE' || sub.plan_code === 'THERAPEUTICS_CORE_USD'
);
if (hasTherapeuticsPack) return true;
}
return loggedInUser.active_subscriptions.some((sub: any) => sub.plan_code === code || sub.plan_code === `${code}_USD`);
};
// Automatically remove already unlocked modules from the cart
useEffect(() => {
if (loggedInUser && cart.length > 0) {
const filteredCart = cart.filter(item => !isModuleUnlocked(item.code));
if (filteredCart.length !== cart.length) {
setCart(filteredCart);
}
}
}, [loggedInUser, cart]);
const handleCheckout = async () => {
if (cart.length === 0 || checkoutLoading) return;
if (!userToken) {
setAuthMode('register');
setShowAuthModal(true);
return;
}
setCheckoutLoading(true);
setVerificationResult(null);
try {
const orderRes = await axios.post(`${API_BASE}/api/checkout/create-order`, {
cart_item_codes: cart.map(item => item.code),
coupon_code: appliedCoupon || undefined,
currency: currency
}, {
headers: { 'Authorization': `Bearer ${userToken}` }
});
const { razorpay_order_id, grand_total } = orderRes.data;
const sdkLoaded = await loadRazorpayScript();
if (!sdkLoaded) {
alert('Failed to load Razorpay SDK. Please check your network connection.');
setCheckoutLoading(false);
return;
}
if (!razorpayKeyId) {
alert('Payment system configuration is loading. Please try again in a moment.');
setCheckoutLoading(false);
return;
}
if (!loggedInUser?.phone_number) {
const inputPhone = prompt("A billing phone number is required for Razorpay checkout. Please enter your contact number:");
if (!inputPhone) {
setCheckoutLoading(false);
return;
}
try {
const res = await axios.put(`${API_BASE}/api/auth/profile`, {
phone_number: inputPhone
}, {
headers: { 'Authorization': `Bearer ${userToken}` }
});
if (res.data.status === 'success') {
loggedInUser.phone_number = inputPhone;
setLoggedInUser({ ...loggedInUser });
}
} catch (err: any) {
alert("Failed to save phone number: " + (err.response?.data?.detail || err.message));
setCheckoutLoading(false);
return;
}
}
const rzpOptions = {
key: razorpayKeyId,
amount: Math.round(grand_total * 100),
currency: currency,
name: 'Acupedia',
description: cart.map(c => c.name).join(', '),
order_id: razorpay_order_id,
customer_id: loggedInUser?.external_ref || undefined,
prefill: {
name: loggedInUser?.display_name || '',
email: loggedInUser?.email || '',
contact: loggedInUser?.phone_number || loggedInUser?.phone || ''
},
handler: async function (response: any) {
setCheckoutLoading(true);
try {
const verifyRes = await axios.post(`${API_BASE}/api/checkout/verify`, {
razorpay_order_id: response.razorpay_order_id,
razorpay_payment_id: response.razorpay_payment_id,
razorpay_signature: response.razorpay_signature,
currency: currency
}, {
headers: { 'Authorization': `Bearer ${userToken}` }
});
setVerificationResult({
status: 'success',
paymentId: response.razorpay_payment_id,
orderId: response.razorpay_order_id,
invoiceNumber: verifyRes.data.invoice_number,
invoiceUrl: verifyRes.data.invoice_url,
amount: grand_total,
currency: currency,
items: cart.map(c => c.name),
message: verifyRes.data.message || 'Payment verified successfully and module entitlements unlocked!'
});
if (/Android|iPhone|iPad|iPod/i.test(navigator.userAgent)) {
setTimeout(() => {
window.location.href = 'acupedia://';
}, 1500);
}
setCart([]);
setAppliedCoupon(null);
await fetchUserProfile(userToken);
} catch (err: any) {
setVerificationResult({
status: 'error',
message: err.response?.data?.detail || 'Signature verification failed.'
});
} finally {
setCheckoutLoading(false);
}
},
theme: {
color: '#6366F1'
}
};
const razorpayInstance = new (window as any).Razorpay(rzpOptions);
razorpayInstance.on('payment.failed', function (resp: any) {
alert(`Payment failed! Reason: ${resp.error.description}`);
});
razorpayInstance.open();
} catch (err: any) {
console.error(err);
alert(err.response?.data?.detail || 'Failed to initialize Razorpay checkout transaction.');
} finally {
setCheckoutLoading(false);
}
};
const [downloadingModalInvoice, setDownloadingModalInvoice] = useState<boolean>(false);
const handleDownloadCheckoutInvoice = async (paymentId: string, directUrl?: string) => {
if (directUrl) {
window.open(directUrl, '_blank');
switchTab('subscriptions');
setVerificationResult(null);
return;
}
if (!userToken) return;
setDownloadingModalInvoice(true);
try {
const headers = { 'Authorization': `Bearer ${userToken}` };
const res = await axios.get(`${API_BASE}/api/checkout/payment/${paymentId}/invoice`, { headers });
const { short_url } = res.data;
if (short_url) {
window.open(short_url, '_blank');
switchTab('subscriptions');
setVerificationResult(null);
} else {
throw new Error('Invoice download URL is not available.');
}
} catch (err: any) {
const errorMsg = err.response?.data?.detail || err.message || String(err);
alert(`Could not download invoice: ${errorMsg}`);
} finally {
setDownloadingModalInvoice(false);
}
};
const hasUserLifetimeAccess = loggedInUser?.active_subscriptions?.some((sub: any) =>
sub.plan_code === 'LIFETIME_ALL' || sub.plan_code === 'LIFETIME_ALL_USD'
);
return (
<div className="min-h-screen bg-slate-50 flex flex-col text-slate-800 selection:bg-indigo-500 selection:text-white">
{/* 🧭 Storefront Header */}
<StoreHeader
activeTab={activeTab}
onSwitchTab={switchTab}
loggedInUser={loggedInUser}
onOpenProfile={() => setShowProfileDrawer(true)}
onOpenAuth={(mode) => {
setAuthMode(mode);
setShowAuthModal(true);
}}
/>
{/* 📦 Main Body */}
<main className="flex-1 overflow-y-auto max-w-7xl mx-auto p-4 sm:p-6 lg:p-8 w-full flex flex-col justify-between">
{activeTab === 'storefront' ? (
<div className="space-y-8 flex-1">
{/* 🏅 Dynamic Gold Lifetime Banner */}
{hasUserLifetimeAccess && <LifetimeBanner />}
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6 xl:gap-8">
{/* 📦 Catalog Section */}
<CatalogSection
curriculumModules={CURRICULUM_MODULES}
publicPlans={publicPlans}
cart={cart}
currency={currency}
isModuleUnlocked={isModuleUnlocked}
getModulePrice={getModulePrice}
toggleCartItem={toggleCartItem}
showLockedByCategory={showLockedByCategory}
setShowLockedByCategory={setShowLockedByCategory}
/>
{/* 🛒 Cart Drawer Summary */}
<CartDrawer
cart={cart}
currency={currency}
setCurrency={setCurrency}
toggleCartItem={toggleCartItem}
couponCode={couponCode}
setCouponCode={setCouponCode}
appliedCoupon={appliedCoupon}
applyPromoCode={applyPromoCode}
removePromoCode={removePromoCode}
pricingCalc={pricingCalc}
loadingPricing={loadingPricing}
loggedInUser={loggedInUser}
onUpdateBillingPhone={async () => {
const newPhone = prompt("Enter billing phone number:", loggedInUser?.phone_number || '');
if (newPhone !== null && loggedInUser) {
try {
const res = await axios.put(`${API_BASE}/api/auth/profile`, {
phone_number: newPhone
}, {
headers: { 'Authorization': `Bearer ${userToken}` }
});
if (res.data.status === 'success') {
setLoggedInUser({ ...loggedInUser, phone_number: newPhone });
alert('Phone number updated successfully for billing!');
}
} catch (err: any) {
alert(err.response?.data?.detail || 'Failed to update phone number.');
}
}
}}
verificationResult={verificationResult}
checkoutLoading={checkoutLoading}
handleCheckout={handleCheckout}
/>
</div>
</div>
) : (
/* 🧾 Tab: User Personal Subscriptions Ledger */
<SubscriptionsView
loggedInUser={loggedInUser}
onOpenAuth={() => {
setAuthMode('login');
setShowAuthModal(true);
}}
onSwitchTab={switchTab}
curriculumModules={CURRICULUM_MODULES}
/>
)}
{/* 💳 Footer */}
<StoreFooter />
</main>
{/* 🔐 Auth Modal (Login / Register / Forgot Password) */}
<AuthModal
isOpen={showAuthModal}
onClose={() => setShowAuthModal(false)}
authMode={authMode}
setAuthMode={setAuthMode}
authEmail={authEmail}
setAuthEmail={setAuthEmail}
authPassword={authPassword}
setAuthPassword={setAuthPassword}
authDisplayName={authDisplayName}
setAuthDisplayName={setAuthDisplayName}
authPhone={authPhone}
setAuthPhone={setAuthPhone}
authDialCode={authDialCode}
setAuthDialCode={setAuthDialCode}
authCountry={authCountry}
setAuthCountry={setAuthCountry}
authLoading={authLoading}
authError={authError}
setAuthError={setAuthError}
onAuthSubmit={handleAuthSubmit}
resetStep={resetStep}
setResetStep={setResetStep}
resetOtp={resetOtp}
setResetOtp={setResetOtp}
resetNewPassword={resetNewPassword}
setResetNewPassword={setResetNewPassword}
resetConfirmPassword={resetConfirmPassword}
setResetConfirmPassword={setResetConfirmPassword}
resetSuccessMessage={resetSuccessMessage}
setResetSuccessMessage={setResetSuccessMessage}
onForgotPasswordRequest={handleForgotPasswordRequest}
onResetPasswordSubmit={handleResetPasswordSubmit}
/>
{/* 🎉 Payment Success Modal */}
{verificationResult && verificationResult.status === 'success' && (
<PaymentSuccessModal
verificationResult={verificationResult}
onClose={() => setVerificationResult(null)}
loggedInUser={loggedInUser}
onDownloadInvoice={handleDownloadCheckoutInvoice}
downloadingInvoice={downloadingModalInvoice}
/>
)}
{/* 🧭 Profile Drawer */}
<ProfileDrawer
isOpen={showProfileDrawer}
onClose={() => setShowProfileDrawer(false)}
loggedInUser={loggedInUser}
profileDisplayName={profileDisplayName}
setProfileDisplayName={setProfileDisplayName}
profilePhone={profilePhone}
setProfilePhone={setProfilePhone}
profileCountry={profileCountry}
setProfileCountry={setProfileCountry}
setCurrency={setCurrency}
profileSaving={profileSaving}
profileError={profileError}
profileSuccess={profileSuccess}
onUpdateProfile={handleUpdateProfile}
showPasswordChange={showPasswordChange}
setShowPasswordChange={setShowPasswordChange}
changeOldPassword={changeOldPassword}
setChangeOldPassword={setChangeOldPassword}
changeNewPassword={changeNewPassword}
setChangeNewPassword={setChangeNewPassword}
changeConfirmPassword={changeConfirmPassword}
setChangeConfirmPassword={setChangeConfirmPassword}
changePasswordLoading={changePasswordLoading}
changePasswordError={changePasswordError}
changePasswordSuccess={changePasswordSuccess}
onChangePassword={handleChangePassword}
onLogout={handleLogout}
onBrowseStorefront={() => {
setShowProfileDrawer(false);
switchTab('storefront');
}}
curriculumModules={CURRICULUM_MODULES}
/>
{/* 🔐 Password Updated Success Modal */}
<PasswordUpdatedModal
isOpen={passwordUpdatedPopup}
onClose={() => setPasswordUpdatedPopup(false)}
/>
</div>
);
}

View File

@ -0,0 +1,418 @@
import React, { useState } from 'react';
import {
XCircle, Sparkles, AlertCircle, CheckCircle, RefreshCw,
Phone, Globe, Eye, EyeOff, LogIn, UserPlus
} from 'lucide-react';
import { COUNTRY_CODES } from '../../constants/countries';
interface AuthModalProps {
isOpen: boolean;
onClose: () => void;
authMode: 'login' | 'register' | 'forgot';
setAuthMode: (mode: 'login' | 'register' | 'forgot') => void;
authEmail: string;
setAuthEmail: (email: string) => void;
authPassword: string;
setAuthPassword: (pwd: string) => void;
authDisplayName: string;
setAuthDisplayName: (name: string) => void;
authPhone: string;
setAuthPhone: (phone: string) => void;
authDialCode: string;
setAuthDialCode: (code: string) => void;
authCountry: string;
setAuthCountry: (country: string) => void;
authLoading: boolean;
authError: string | null;
setAuthError: (err: string | null) => void;
onAuthSubmit: (e: React.FormEvent) => Promise<void>;
// Forgot password flow
resetStep: 'request' | 'verify';
setResetStep: (step: 'request' | 'verify') => void;
resetOtp: string;
setResetOtp: (otp: string) => void;
resetNewPassword: string;
setResetNewPassword: (pwd: string) => void;
resetConfirmPassword: string;
setResetConfirmPassword: (pwd: string) => void;
resetSuccessMessage: string | null;
setResetSuccessMessage: (msg: string | null) => void;
onForgotPasswordRequest: (e: React.FormEvent) => Promise<void>;
onResetPasswordSubmit: (e: React.FormEvent) => Promise<void>;
}
export const AuthModal: React.FC<AuthModalProps> = ({
isOpen,
onClose,
authMode,
setAuthMode,
authEmail,
setAuthEmail,
authPassword,
setAuthPassword,
authDisplayName,
setAuthDisplayName,
authPhone,
setAuthPhone,
authDialCode,
setAuthDialCode,
authCountry,
setAuthCountry,
authLoading,
authError,
setAuthError,
onAuthSubmit,
resetStep,
setResetStep,
resetOtp,
setResetOtp,
resetNewPassword,
setResetNewPassword,
resetConfirmPassword,
setResetConfirmPassword,
resetSuccessMessage,
setResetSuccessMessage,
onForgotPasswordRequest,
onResetPasswordSubmit,
}) => {
const [showPassword, setShowPassword] = useState(false);
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-slate-950/70 backdrop-blur-md transition-all duration-300">
<div className="relative w-full max-w-md bg-slate-900 border border-slate-800 rounded-3xl p-6 md:p-8 space-y-6 shadow-2xl text-slate-100">
{/* Close button */}
<button
onClick={onClose}
className="absolute top-4 right-4 h-8 w-8 rounded-full bg-slate-800 hover:bg-slate-700/80 flex items-center justify-center text-slate-400 hover:text-slate-200 transition-colors"
>
<XCircle className="h-5 w-5" />
</button>
{/* Title / Headers */}
<div className="text-center space-y-1.5">
<div className="h-10 w-10 rounded-xl bg-indigo-600 flex items-center justify-center mx-auto shadow-md">
<Sparkles className="h-5 w-5 text-white animate-spin" style={{ animationDuration: '6s' }} />
</div>
<h3 className="text-xl font-black tracking-tight text-white">
{authMode === 'login'
? 'Welcome Back!'
: authMode === 'register'
? 'Create Clinical Account'
: 'Reset Password'}
</h3>
<p className="text-xs text-slate-400 leading-relaxed font-semibold">
{authMode === 'login'
? 'Sign in to access your saved TCM modules and invoices.'
: authMode === 'register'
? 'Onboard as a clinical practitioner to access TCM modules.'
: resetStep === 'request'
? 'Enter your registered email to receive a 6-digit verification code.'
: 'Enter the 6-digit code sent to your email and your new password.'}
</p>
</div>
{/* Error badge */}
{authError && (
<div className="p-3.5 bg-rose-500/10 border border-rose-500/30 text-rose-400 text-xs rounded-xl font-bold flex gap-2 items-center">
<AlertCircle className="h-4.5 w-4.5 flex-shrink-0" />
<span>{authError}</span>
</div>
)}
{/* Success message for OTP */}
{resetSuccessMessage && authMode === 'forgot' && (
<div className="p-3.5 bg-emerald-500/10 border border-emerald-500/30 text-emerald-400 text-xs rounded-xl font-bold flex gap-2 items-center">
<CheckCircle className="h-4.5 w-4.5 flex-shrink-0" />
<span>{resetSuccessMessage}</span>
</div>
)}
{/* Forgot Password Flow */}
{authMode === 'forgot' ? (
resetStep === 'request' ? (
<form onSubmit={onForgotPasswordRequest} className="space-y-4 text-left">
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
Registered Email Address
</label>
<input
type="email"
required
value={authEmail}
onChange={(e) => setAuthEmail(e.target.value)}
placeholder="doctor@example.com"
className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 placeholder:text-slate-700"
/>
</div>
<button
type="submit"
disabled={authLoading}
className="w-full h-11 bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-sm rounded-xl transition-all duration-300 flex items-center justify-center gap-2 mt-4 shadow-lg shadow-indigo-600/10"
>
{authLoading ? <RefreshCw className="h-4 w-4 animate-spin" /> : 'Send Verification Code'}
</button>
<div className="text-center pt-2 text-xs">
<button
type="button"
onClick={() => {
setAuthMode('login');
setAuthError(null);
}}
className="text-indigo-400 hover:text-indigo-300 font-bold underline"
>
&larr; Back to sign in
</button>
</div>
</form>
) : (
<form onSubmit={onResetPasswordSubmit} className="space-y-4 text-left">
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
6-Digit Verification Code (OTP)
</label>
<input
type="text"
required
maxLength={6}
value={resetOtp}
onChange={(e) => setResetOtp(e.target.value.replace(/\D/g, ''))}
placeholder="123456"
className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-base font-mono font-bold tracking-widest text-center text-indigo-400 focus:outline-none focus:border-indigo-500"
/>
</div>
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
New Password
</label>
<input
type="password"
required
value={resetNewPassword}
onChange={(e) => setResetNewPassword(e.target.value)}
placeholder="Min 8 chars (1 uppercase, 1 number, 1 special)"
className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500"
/>
</div>
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
Confirm New Password
</label>
<input
type="password"
required
value={resetConfirmPassword}
onChange={(e) => setResetConfirmPassword(e.target.value)}
placeholder="Re-enter new password"
className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500"
/>
</div>
<button
type="submit"
disabled={authLoading}
className="w-full h-11 bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-sm rounded-xl transition-all duration-300 flex items-center justify-center gap-2 mt-4 shadow-lg shadow-emerald-600/10"
>
{authLoading ? <RefreshCw className="h-4 w-4 animate-spin" /> : 'Set New Password'}
</button>
<div className="flex justify-between items-center pt-2 text-xs">
<button
type="button"
onClick={() => {
setResetStep('request');
setAuthError(null);
}}
className="text-slate-400 hover:text-white font-semibold"
>
Resend code
</button>
<button
type="button"
onClick={() => {
setAuthMode('login');
setAuthError(null);
}}
className="text-indigo-400 hover:text-indigo-300 font-bold underline"
>
Back to sign in
</button>
</div>
</form>
)
) : (
/* Standard Login & Register Form */
<form onSubmit={onAuthSubmit} className="space-y-4 text-left">
{/* Common: Email */}
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
Email Address
</label>
<input
type="email"
required
value={authEmail}
onChange={(e) => setAuthEmail(e.target.value)}
placeholder="doctor@example.com"
className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 placeholder:text-slate-700"
/>
</div>
{/* Register exclusive: Display Name */}
{authMode === 'register' && (
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
Display Name
</label>
<input
type="text"
required
value={authDisplayName}
onChange={(e) => setAuthDisplayName(e.target.value)}
placeholder="Dr. John Doe"
className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 placeholder:text-slate-700"
/>
</div>
)}
{/* Register exclusive: Phone Number with Country Code */}
{authMode === 'register' && (
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500 flex items-center gap-1">
<Phone className="h-3 w-3 text-indigo-400" /> Phone Number
</label>
<div className="flex gap-2">
<div className="relative">
<select
value={authDialCode}
onChange={(e) => setAuthDialCode(e.target.value)}
className="w-[90px] bg-slate-950 border border-slate-800 rounded-xl px-3 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 appearance-none"
>
{COUNTRY_CODES.map((cc) => (
<option key={cc.code} value={cc.code}>
{cc.label}
</option>
))}
</select>
</div>
<input
type="tel"
value={authPhone}
onChange={(e) => setAuthPhone(e.target.value)}
placeholder="9876543210"
className="flex-1 bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 placeholder:text-slate-700"
/>
</div>
</div>
)}
{/* Register exclusive: Country */}
{authMode === 'register' && (
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500 flex items-center gap-1">
<Globe className="h-3 w-3 text-indigo-400" /> Country (Defaults currency)
</label>
<div className="relative">
<select
value={authCountry}
onChange={(e) => setAuthCountry(e.target.value)}
className="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 appearance-none"
>
<option value="India">India (Calculates in INR ₹)</option>
<option value="United States">United States (Calculates in USD $)</option>
<option value="United Kingdom">United Kingdom (Calculates in USD $)</option>
<option value="Germany">Germany (Calculates in USD $)</option>
<option value="Australia">Australia (Calculates in USD $)</option>
</select>
<div className="absolute right-4 top-1/2 -translate-y-1/2 pointer-events-none text-slate-500 text-xs">
▼
</div>
</div>
</div>
)}
{/* Common: Password */}
<div className="space-y-1.5">
<div className="flex justify-between items-center">
<label className="text-[10px] uppercase font-black tracking-wider text-slate-500">
Password
</label>
{authMode === 'login' && (
<button
type="button"
onClick={() => {
setAuthMode('forgot');
setResetStep('request');
setAuthError(null);
setResetSuccessMessage(null);
}}
className="text-[11px] text-indigo-400 hover:text-indigo-300 font-semibold"
>
Forgot password?
</button>
)}
</div>
<div className="relative">
<input
type={showPassword ? 'text' : 'password'}
required
value={authPassword}
onChange={(e) => setAuthPassword(e.target.value)}
placeholder="••••••••"
className="w-full bg-slate-950 border border-slate-800 rounded-xl pl-4 pr-12 py-2.5 text-sm font-semibold text-white focus:outline-none focus:border-indigo-500 placeholder:text-slate-700"
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-4 top-1/2 -translate-y-1/2 text-slate-500 hover:text-slate-300 transition-colors p-1"
>
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
</button>
</div>
</div>
{/* Submit trigger button */}
<button
type="submit"
disabled={authLoading}
className="w-full h-11 bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-sm rounded-xl transition-all duration-300 flex items-center justify-center gap-2 mt-4 shadow-lg shadow-indigo-600/10"
>
{authLoading ? (
<RefreshCw className="h-4 w-4 animate-spin" />
) : (
<>
{authMode === 'login' ? <LogIn className="h-4 w-4" /> : <UserPlus className="h-4 w-4" />}
{authMode === 'login' ? 'Sign In Session' : 'Register Clinical Profile'}
</>
)}
</button>
</form>
)}
{/* Toggle auth mode links */}
{authMode !== 'forgot' && (
<div className="text-center pt-2 text-xs">
<span className="text-slate-400 font-semibold">
{authMode === 'login' ? "Don't have an account? " : 'Already registered? '}
</span>
<button
type="button"
onClick={() => {
setAuthMode(authMode === 'login' ? 'register' : 'login');
setAuthError(null);
}}
className="text-indigo-400 hover:text-indigo-300 font-bold underline"
>
{authMode === 'login' ? 'Create clinical account' : 'Sign in here'}
</button>
</div>
)}
</div>
</div>
);
};

View File

@ -0,0 +1,33 @@
import React from 'react';
import { CheckCircle } from 'lucide-react';
interface PasswordUpdatedModalProps {
isOpen: boolean;
onClose: () => void;
}
export const PasswordUpdatedModal: React.FC<PasswordUpdatedModalProps> = ({ isOpen, onClose }) => {
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-[200] flex items-center justify-center p-4 bg-slate-950/70 backdrop-blur-md animate-in fade-in duration-200">
<div className="relative w-full max-w-sm bg-slate-900 border border-emerald-500/40 rounded-3xl p-6 shadow-2xl text-center space-y-4 text-white">
<div className="h-14 w-14 rounded-2xl bg-emerald-950/80 border border-emerald-500/30 text-emerald-400 flex items-center justify-center mx-auto shadow-[0_0_25px_rgba(16,185,129,0.3)]">
<CheckCircle className="h-8 w-8" />
</div>
<div className="space-y-1.5">
<h3 className="text-lg font-bold text-white">Password Updated!</h3>
<p className="text-xs text-slate-400 leading-relaxed font-medium">
Your password has been securely updated. You can now use your new password across the storefront and mobile application.
</p>
</div>
<button
onClick={onClose}
className="w-full py-2.5 bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-xs rounded-xl transition-colors shadow-lg shadow-emerald-600/20"
>
Continue to Storefront
</button>
</div>
</div>
);
};

View File

@ -0,0 +1,401 @@
import React, { useState } from 'react';
import {
XCircle, Users, ShieldCheck, CheckCircle, AlertCircle,
Eye, EyeOff, RefreshCw, LogOut
} from 'lucide-react';
import type { UserProfile, ModuleItem, Currency } from '../../types';
interface ProfileDrawerProps {
isOpen: boolean;
onClose: () => void;
loggedInUser: UserProfile | null;
profileDisplayName: string;
setProfileDisplayName: (name: string) => void;
profilePhone: string;
setProfilePhone: (phone: string) => void;
profileCountry: string;
setProfileCountry: (country: string) => void;
setCurrency: (currency: Currency) => void;
profileSaving: boolean;
profileError: string | null;
profileSuccess: boolean;
onUpdateProfile: (e: React.FormEvent) => Promise<void>;
showPasswordChange: boolean;
setShowPasswordChange: (show: boolean) => void;
changeOldPassword: string;
setChangeOldPassword: (pwd: string) => void;
changeNewPassword: string;
setChangeNewPassword: (pwd: string) => void;
changeConfirmPassword: string;
setChangeConfirmPassword: (pwd: string) => void;
changePasswordLoading: boolean;
changePasswordError: string | null;
changePasswordSuccess: boolean;
onChangePassword: (e: React.FormEvent) => Promise<void>;
onLogout: () => void;
onBrowseStorefront: () => void;
curriculumModules: ModuleItem[];
}
export const ProfileDrawer: React.FC<ProfileDrawerProps> = ({
isOpen,
onClose,
loggedInUser,
profileDisplayName,
setProfileDisplayName,
profilePhone,
setProfilePhone,
profileCountry,
setProfileCountry,
setCurrency,
profileSaving,
profileError,
profileSuccess,
onUpdateProfile,
showPasswordChange,
setShowPasswordChange,
changeOldPassword,
setChangeOldPassword,
changeNewPassword,
setChangeNewPassword,
changeConfirmPassword,
setChangeConfirmPassword,
changePasswordLoading,
changePasswordError,
changePasswordSuccess,
onChangePassword,
onLogout,
onBrowseStorefront,
curriculumModules,
}) => {
const [showOldPassword, setShowOldPassword] = useState(false);
const [showNewPassword, setShowNewPassword] = useState(false);
if (!isOpen || !loggedInUser) return null;
return (
<div className="fixed inset-0 z-50 overflow-hidden flex justify-end">
{/* Overlay Backdrop */}
<div
className="absolute inset-0 bg-slate-900/60 backdrop-blur-sm transition-opacity"
onClick={onClose}
/>
{/* Drawer Container */}
<div className="relative w-full max-w-md bg-white h-full shadow-2xl flex flex-col justify-between z-10 animate-slide-in overflow-hidden border-l border-slate-200">
{/* Drawer Header */}
<div className="px-6 py-5 bg-[#0A0A0E] text-white flex items-center justify-between border-b border-slate-800">
<div className="flex items-center gap-3">
<div className="h-10 w-10 rounded-full bg-gradient-to-tr from-indigo-600 to-violet-500 border border-indigo-400/30 flex items-center justify-center text-white font-black text-base shadow-inner">
{(loggedInUser.display_name || loggedInUser.email || 'U')[0].toUpperCase()}
</div>
<div>
<h3 className="text-sm font-bold text-white leading-tight">
{loggedInUser.display_name || 'My Account'}
</h3>
<p className="text-[11px] text-slate-400 font-medium">{loggedInUser.email}</p>
</div>
</div>
<button
onClick={onClose}
className="text-slate-400 hover:text-white transition-colors p-1"
>
<XCircle className="h-5 w-5" />
</button>
</div>
{/* Drawer Body (Scrollable) */}
<div className="flex-1 p-6 space-y-8 overflow-y-auto">
{/* Profile Details Form */}
<div className="space-y-4">
<h4 className="text-xs font-bold text-slate-400 uppercase tracking-widest flex items-center gap-1.5">
<Users className="h-4 w-4 text-indigo-500" /> Update Account details
</h4>
<form
onSubmit={onUpdateProfile}
className="space-y-4 bg-slate-50 border border-slate-200/60 p-4 rounded-2xl"
>
{profileSuccess && (
<div className="p-3 bg-emerald-50 border border-emerald-200 text-emerald-700 text-xs font-semibold rounded-xl">
Changes saved successfully! ✓
</div>
)}
{profileError && (
<div className="p-3 bg-rose-50 border border-rose-200 text-rose-700 text-xs font-semibold rounded-xl">
{profileError}
</div>
)}
<div className="space-y-1.5">
<label className="text-xs font-bold text-slate-500">Display Name</label>
<input
type="text"
value={profileDisplayName}
onChange={(e) => setProfileDisplayName(e.target.value)}
required
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 focus:ring-1 focus:ring-indigo-500"
/>
</div>
<div className="space-y-1.5">
<label className="text-xs font-bold text-slate-500">Phone Number</label>
<input
type="text"
value={profilePhone}
onChange={(e) => setProfilePhone(e.target.value)}
placeholder="+919876543210"
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 focus:ring-1 focus:ring-indigo-500"
/>
</div>
<div className="space-y-1.5">
<label className="text-xs font-bold text-slate-500">Billing Country</label>
<select
value={profileCountry}
onChange={(e) => {
setProfileCountry(e.target.value);
if (e.target.value === 'India') {
setCurrency('INR');
} else {
setCurrency('USD');
}
}}
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"
>
<option value="India">India</option>
<option value="United States">United States</option>
<option value="United Kingdom">United Kingdom</option>
<option value="Australia">Australia</option>
<option value="Germany">Germany</option>
<option value="France">France</option>
<option value="Japan">Japan</option>
<option value="China">China</option>
<option value="Singapore">Singapore</option>
<option value="Canada">Canada</option>
</select>
</div>
<button
type="submit"
disabled={profileSaving}
className="w-full py-2 bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-xs rounded-xl transition-colors disabled:bg-slate-300 flex items-center justify-center gap-1.5 shadow shadow-indigo-600/10"
>
{profileSaving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : 'Save Profile Details'}
</button>
</form>
</div>
{/* Security & Password Section */}
<div className="space-y-3">
<div className="flex justify-between items-center">
<h4 className="text-xs font-bold text-slate-400 uppercase tracking-widest flex items-center gap-1.5">
<ShieldCheck className="h-4 w-4 text-indigo-500" /> Security & Password
</h4>
<button
type="button"
onClick={() => {
setShowPasswordChange(!showPasswordChange);
}}
className="text-xs text-indigo-600 hover:text-indigo-700 font-bold"
>
{showPasswordChange ? 'Hide Form' : 'Change Password'}
</button>
</div>
{showPasswordChange && (
<form
onSubmit={onChangePassword}
className="space-y-3.5 bg-slate-50 border border-slate-200/60 p-4 rounded-2xl animate-in fade-in duration-200"
>
{changePasswordSuccess && (
<div className="p-3 bg-emerald-50 border border-emerald-200 text-emerald-700 text-xs font-semibold rounded-xl flex items-center gap-2">
<CheckCircle className="h-4 w-4 flex-shrink-0" />
<span>Password updated successfully!</span>
</div>
)}
{changePasswordError && (
<div className="p-3 bg-rose-50 border border-rose-200 text-rose-700 text-xs font-semibold rounded-xl flex items-center gap-2">
<AlertCircle className="h-4 w-4 flex-shrink-0" />
<span>{changePasswordError}</span>
</div>
)}
<div className="space-y-1">
<label className="text-xs font-bold text-slate-500">Current Password</label>
<div className="relative">
<input
type={showOldPassword ? 'text' : 'password'}
required
value={changeOldPassword}
onChange={(e) => setChangeOldPassword(e.target.value)}
placeholder="Enter current password"
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 pr-10 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500"
/>
<button
type="button"
onClick={() => setShowOldPassword(!showOldPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-0.5"
>
{showOldPassword ? <EyeOff className="h-3.5 w-3.5" /> : <Eye className="h-3.5 w-3.5" />}
</button>
</div>
</div>
<div className="space-y-1">
<label className="text-xs font-bold text-slate-500">New Password</label>
<div className="relative">
<input
type={showNewPassword ? 'text' : 'password'}
required
value={changeNewPassword}
onChange={(e) => setChangeNewPassword(e.target.value)}
placeholder="Min 8 chars, 1 uppercase, 1 digit, 1 special"
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 pr-10 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500"
/>
<button
type="button"
onClick={() => setShowNewPassword(!showNewPassword)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-0.5"
>
{showNewPassword ? <EyeOff className="h-3.5 w-3.5" /> : <Eye className="h-3.5 w-3.5" />}
</button>
</div>
</div>
<div className="space-y-1">
<label className="text-xs font-bold text-slate-500">Confirm New Password</label>
<input
type="password"
required
value={changeConfirmPassword}
onChange={(e) => setChangeConfirmPassword(e.target.value)}
placeholder="Repeat new password"
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"
/>
</div>
<div className="flex flex-wrap gap-2 text-[10px] text-slate-500 pt-1">
<span className={changeNewPassword.length >= 8 ? 'text-emerald-600 font-bold' : ''}>
&bull; 8+ chars
</span>
<span className={/[A-Z]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
&bull; 1 uppercase
</span>
<span className={/[0-9]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
&bull; 1 number
</span>
<span className={/[^A-Za-z0-9]/.test(changeNewPassword) ? 'text-emerald-600 font-bold' : ''}>
&bull; 1 special char
</span>
</div>
<button
type="submit"
disabled={changePasswordLoading}
className="w-full py-2 bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-xs rounded-xl transition-colors disabled:bg-slate-300 flex items-center justify-center gap-1.5 shadow shadow-indigo-600/10"
>
{changePasswordLoading ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : 'Update Password'}
</button>
</form>
)}
</div>
{/* Subscriptions Nested Details */}
<div className="space-y-4">
<h4 className="text-xs font-bold text-slate-400 uppercase tracking-widest flex items-center gap-1.5">
<CheckCircle className="h-4 w-4 text-emerald-500" /> Ongoing subscriptions
</h4>
{!loggedInUser.active_subscriptions || loggedInUser.active_subscriptions.length === 0 ? (
<div className="bg-slate-50 border border-slate-200/60 rounded-2xl p-6 text-center space-y-2">
<p className="text-xs text-slate-500 font-semibold">No active subscriptions owned.</p>
<button
onClick={onBrowseStorefront}
className="text-xs text-indigo-600 font-bold hover:underline"
>
Browse storefront catalog
</button>
</div>
) : (
<div className="space-y-4">
{loggedInUser.active_subscriptions.map((sub: any) => {
const moduleMeta = curriculumModules.find((m) => m.code === sub.plan_code);
let daysLeft = 0;
const hasExpiry = !!sub.expires_at;
if (hasExpiry) {
const expiry = new Date(sub.expires_at);
const now = new Date();
const diffTime = expiry.getTime() - now.getTime();
daysLeft = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
}
return (
<div key={sub.id} className="bg-slate-50 border border-slate-200 rounded-2xl p-4 space-y-3">
<div className="flex justify-between items-start gap-2">
<h5 className="text-xs font-bold text-slate-800 leading-tight">
{moduleMeta ? moduleMeta.name : sub.plan_code.replace(/_/g, ' ').toUpperCase()}
</h5>
<span
className={`text-[8px] font-black uppercase px-2 py-0.5 rounded flex-shrink-0 ${
sub.plan_code === 'LIFETIME_ALL'
? 'bg-amber-100 text-amber-800 border border-amber-200'
: 'bg-indigo-50 text-indigo-700 border border-indigo-200'
}`}
>
{sub.plan_code === 'LIFETIME_ALL' ? 'Lifetime' : '1 Year'}
</span>
</div>
<div className="text-[10px] text-slate-400 font-semibold space-y-1">
<div className="flex justify-between">
<span>Activated:</span>
<span className="text-slate-600 font-bold">
{sub.started_at
? new Date(sub.started_at).toLocaleDateString(undefined, { dateStyle: 'medium' })
: 'N/A'}
</span>
</div>
<div className="flex justify-between">
<span>Expires:</span>
<span className="text-slate-600 font-bold">
{hasExpiry
? new Date(sub.expires_at).toLocaleDateString(undefined, { dateStyle: 'medium' })
: 'Lifetime'}
</span>
</div>
</div>
<div className="pt-2 border-t border-slate-200/60 flex justify-between items-center">
<span className="text-[9px] text-slate-400 font-bold uppercase tracking-wider">Status:</span>
{!hasExpiry || sub.plan_code === 'LIFETIME_ALL' ? (
<span className="text-[9px] bg-amber-100 text-amber-800 border border-amber-200 font-black px-2 py-0.5 rounded-lg">
👑 Lifetime Pass
</span>
) : (
<span className="text-[9px] bg-emerald-100 text-emerald-800 border border-emerald-200 font-black px-2 py-0.5 rounded-lg">
{daysLeft > 0 ? `${daysLeft} Days Left` : 'Expired'}
</span>
)}
</div>
</div>
);
})}
</div>
)}
</div>
</div>
{/* Log Out at the bottom of the drawer */}
<div className="p-6 border-t border-slate-100 bg-slate-50 flex-shrink-0">
<button
onClick={onLogout}
className="w-full flex items-center justify-center gap-2 py-2.5 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 transition-colors duration-300"
>
<LogOut className="h-4 w-4" /> Log Out Session
</button>
</div>
</div>
</div>
);
};

View File

@ -0,0 +1,317 @@
import React from 'react';
import { ShoppingCart, ShoppingBag, Trash2, RefreshCw, CreditCard, XCircle } from 'lucide-react';
import type { ModuleItem, Currency, UserProfile, VerificationResult } from '../../types';
interface CartDrawerProps {
cart: ModuleItem[];
currency: Currency;
setCurrency: (c: Currency) => void;
toggleCartItem: (module: ModuleItem) => void;
couponCode: string;
setCouponCode: (code: string) => void;
appliedCoupon: string | null;
applyPromoCode: () => void;
removePromoCode: () => void;
pricingCalc: any;
loadingPricing: boolean;
loggedInUser: UserProfile | null;
onUpdateBillingPhone: () => void;
verificationResult: VerificationResult | null;
checkoutLoading: boolean;
handleCheckout: () => void;
}
export const CartDrawer: React.FC<CartDrawerProps> = ({
cart,
currency,
setCurrency,
toggleCartItem,
couponCode,
setCouponCode,
appliedCoupon,
applyPromoCode,
removePromoCode,
pricingCalc,
loadingPricing,
loggedInUser,
onUpdateBillingPhone,
verificationResult,
checkoutLoading,
handleCheckout,
}) => {
return (
<div className="xl:col-span-1">
<div className="sticky top-12 bg-white border border-slate-200 rounded-3xl p-6 shadow-xl space-y-6">
<div className="flex justify-between items-center border-b border-slate-100 pb-4">
<h3 className="text-lg font-bold text-slate-800 flex items-center gap-2 min-w-0">
<ShoppingCart className="h-5 w-5 text-indigo-500 flex-shrink-0" />
<span className="truncate">Cart Summary</span>
</h3>
<span className="text-xs font-bold bg-indigo-50 text-indigo-600 px-2.5 py-0.5 rounded-full border border-indigo-100 flex-shrink-0">
{cart.length} {cart.length === 1 ? 'Item' : 'Items'}
</span>
</div>
{/* Currency selector toggle */}
<div className="flex flex-col sm:flex-row gap-2 sm:items-center justify-between">
<span className="text-xs font-bold text-slate-500">Billing Currency:</span>
<div className="flex bg-slate-100 rounded-lg p-0.5 border border-slate-200 self-end sm:self-auto flex-shrink-0">
<button
onClick={() => setCurrency('INR')}
className={`px-3 py-1 rounded-md text-xs font-bold transition-all duration-300 ${
currency === 'INR'
? 'bg-white text-slate-900 shadow-sm border border-slate-200/50'
: 'text-slate-500 hover:text-slate-800'
}`}
>
INR (₹)
</button>
<button
onClick={() => setCurrency('USD')}
className={`px-3 py-1 rounded-md text-xs font-bold transition-all duration-300 ${
currency === 'USD'
? 'bg-white text-slate-900 shadow-sm border border-slate-200/50'
: 'text-slate-500 hover:text-slate-800'
}`}
>
USD ($)
</button>
</div>
</div>
{/* Selected modules list */}
{cart.length === 0 ? (
<div className="text-center py-10 space-y-3">
<div className="h-12 w-12 rounded-2xl bg-slate-50 border border-slate-200/60 flex items-center justify-center mx-auto text-slate-400">
<ShoppingBag className="h-5 w-5" />
</div>
<p className="text-xs text-slate-500 max-w-[200px] mx-auto leading-relaxed font-semibold">
Your checkout cart is empty. Select from curriculum.
</p>
</div>
) : (
<div className="space-y-3 max-h-[220px] overflow-y-auto pr-1">
{cart.map((item) => (
<div
key={item.code}
className="flex justify-between items-center gap-4 bg-slate-50 border border-slate-200/60 p-3 rounded-2xl"
>
<div className="flex-1 min-w-0">
<p className="text-xs font-bold text-slate-800 truncate">{item.name}</p>
<p className="text-[9px] text-slate-400 tracking-wider uppercase font-semibold">{item.category}</p>
</div>
<div className="flex items-center gap-3">
<span className="text-xs font-bold text-indigo-600">
{currency === 'INR'
? `₹${item.priceInr}`
: currency === 'EUR'
? `€${item.priceEur}`
: `$${item.priceUsd}`}
</span>
<button
onClick={() => toggleCartItem(item)}
className="h-7 w-7 rounded-lg bg-rose-50 text-rose-500 hover:bg-rose-100 flex items-center justify-center transition-colors"
title="Remove item"
>
<Trash2 className="h-3.5 w-3.5" />
</button>
</div>
</div>
))}
</div>
)}
{/* Coupon Code Input */}
{cart.length > 0 && (
<div className="space-y-2">
<label className="text-xs font-bold text-slate-500">Promo / Coupon Code</label>
<div className="flex gap-2">
<input
type="text"
value={couponCode}
onChange={(e) => setCouponCode(e.target.value)}
placeholder="e.g. AGENT40, EVENT_NEW"
className="flex-1 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 placeholder:text-slate-400 uppercase"
/>
<button
onClick={applyPromoCode}
className="bg-indigo-600 hover:bg-indigo-500 transition-colors text-white font-bold text-xs px-4 py-2 rounded-xl shadow shadow-indigo-600/10"
>
Apply
</button>
</div>
{appliedCoupon &&
(pricingCalc?.coupon_error ? (
<div className="flex justify-between items-center bg-rose-50 border border-rose-200 text-rose-700 text-xs px-3 py-2 rounded-xl font-bold">
<span className="flex items-center gap-1">⚠️ {pricingCalc.coupon_error}</span>
<button
onClick={removePromoCode}
className="text-rose-700 hover:text-rose-900 font-bold ml-2 cursor-pointer"
>
Remove
</button>
</div>
) : (
<div className="flex justify-between items-center bg-emerald-50 border border-emerald-200 text-emerald-700 text-xs px-3 py-2 rounded-xl font-bold">
<span>
Coupon Active: {appliedCoupon} ✓{' '}
{pricingCalc?.coupon_applied && pricingCalc.coupon_applied !== 'None'
? `(${pricingCalc.coupon_applied.replace(/Code: \w+ - /, '')})`
: ''}
</span>
<button
onClick={removePromoCode}
className="text-emerald-700 hover:text-rose-600 font-bold ml-2 cursor-pointer"
>
Remove
</button>
</div>
))}
</div>
)}
{/* Checkout Summary Calculations */}
{pricingCalc && cart.length > 0 && (
<div className="space-y-3 bg-slate-50 border border-slate-200/60 p-4 rounded-2xl">
<div className="flex justify-between text-xs text-slate-600 font-bold">
<span>Base Subtotal</span>
<span>
{currency === 'INR'
? `₹${pricingCalc.base_subtotal}`
: currency === 'EUR'
? `€${pricingCalc.base_subtotal}`
: `$${pricingCalc.base_subtotal}`}
</span>
</div>
{pricingCalc.total_discounts > 0 && (
<div className="flex justify-between text-xs text-emerald-700 font-bold">
<span>Total Discounts</span>
<span>
-{currency === 'INR'
? `₹${pricingCalc.total_discounts}`
: currency === 'EUR'
? `€${pricingCalc.total_discounts}`
: `$${pricingCalc.total_discounts}`}
</span>
</div>
)}
{pricingCalc.convenience_fee > 0 && (
<div className="flex justify-between text-xs text-slate-600 font-bold">
<span>Gateway fee ({pricingCalc.convenience_fee_rate}%)</span>
<span>
{currency === 'INR'
? `₹${pricingCalc.convenience_fee}`
: currency === 'EUR'
? `€${pricingCalc.convenience_fee}`
: `$${pricingCalc.convenience_fee}`}
</span>
</div>
)}
{pricingCalc.gst_amount > 0 && (
<div className="space-y-0.5">
<div className="flex justify-between text-xs text-slate-600 font-bold">
<span>GST (18%)</span>
<span>
{currency === 'INR'
? `₹${pricingCalc.gst_amount}`
: currency === 'EUR'
? `€${pricingCalc.gst_amount}`
: `$${pricingCalc.gst_amount}`}
</span>
</div>
<div className="flex justify-between text-[10px] text-slate-400 font-semibold italic">
<span>
(Taxable Amount:{' '}
{currency === 'INR'
? `₹${pricingCalc.taxable_amount}`
: currency === 'EUR'
? `€${pricingCalc.taxable_amount}`
: `$${pricingCalc.taxable_amount}`}
)
</span>
<span></span>
</div>
</div>
)}
<div className="h-px bg-slate-200 my-2" />
<div className="flex justify-between items-center text-sm font-bold text-slate-800">
<span>Total Chargeable</span>
<span className="text-indigo-600 text-lg font-extrabold">
{currency === 'INR'
? `₹${pricingCalc.grand_total}`
: currency === 'EUR'
? `€${pricingCalc.grand_total}`
: `$${pricingCalc.grand_total}`}
</span>
</div>
</div>
)}
{/* Billing Details Prefill Summary */}
{loggedInUser && cart.length > 0 && (
<div className="bg-slate-50 border border-slate-200/60 rounded-2xl p-4 space-y-3 my-2 text-left">
<div className="flex justify-between items-center">
<span className="text-[10px] uppercase font-black tracking-wider text-slate-400">
Billing Profile
</span>
<button
onClick={onUpdateBillingPhone}
className="text-[9px] text-indigo-600 hover:text-indigo-500 font-black uppercase tracking-wider underline focus:outline-none"
>
{loggedInUser.phone_number ? 'Edit Number' : 'Add Number'}
</button>
</div>
<div className="space-y-1">
<div className="flex justify-between text-xs font-semibold text-slate-600">
<span>Email:</span>
<span className="text-slate-800 font-bold truncate max-w-[180px]">{loggedInUser.email}</span>
</div>
<div className="flex justify-between text-xs font-semibold text-slate-600">
<span>Phone:</span>
<span className="text-slate-800 font-bold">
{loggedInUser.phone_number || (
<span className="text-rose-500 font-black italic">Required for checkout</span>
)}
</span>
</div>
</div>
</div>
)}
{/* Verification failure result badge */}
{verificationResult && verificationResult.status === 'error' && (
<div className="p-4 rounded-2xl border flex gap-3 bg-rose-50 border-rose-200 text-rose-700">
<XCircle className="h-5 w-5 flex-shrink-0" />
<div className="space-y-1">
<p className="text-xs font-black uppercase">Verification Failed</p>
<p className="text-[11px] leading-relaxed font-bold">{verificationResult.message}</p>
</div>
</div>
)}
{/* Checkout Trigger */}
{cart.length > 0 && (
<div className="space-y-4 pt-2">
<button
onClick={handleCheckout}
disabled={checkoutLoading || loadingPricing}
className="w-full h-12 bg-indigo-600 hover:bg-indigo-500 disabled:bg-slate-200 disabled:text-slate-400 transition-all duration-300 text-white font-bold text-sm rounded-2xl shadow-xl shadow-indigo-600/10 flex items-center justify-center gap-2"
>
{checkoutLoading ? (
<RefreshCw className="h-4 w-4 animate-spin" />
) : (
<>
<CreditCard className="h-4 w-4" /> Secure Payment with Razorpay
</>
)}
</button>
<p className="text-[10px] text-slate-400 text-center leading-relaxed font-semibold">
* Integrated with Razorpay Gateway API (Test Mode).
</p>
</div>
)}
</div>
</div>
);
};

View File

@ -0,0 +1,740 @@
import React from 'react';
import { BookOpen, Check } from 'lucide-react';
import type { ModuleItem, PublicPlan, Currency } from '../../types';
interface CatalogSectionProps {
curriculumModules: ModuleItem[];
publicPlans: PublicPlan[];
cart: ModuleItem[];
currency: Currency;
isModuleUnlocked: (code: string) => boolean;
getModulePrice: (item: ModuleItem) => {
priceInr: number;
priceUsd: number;
priceEur: number;
isActive: boolean;
};
toggleCartItem: (module: ModuleItem) => void;
showLockedByCategory: { [key: string]: boolean };
setShowLockedByCategory: React.Dispatch<React.SetStateAction<{ [key: string]: boolean }>>;
}
export const CatalogSection: React.FC<CatalogSectionProps> = ({
curriculumModules,
publicPlans,
cart,
currency,
isModuleUnlocked,
getModulePrice,
toggleCartItem,
showLockedByCategory,
setShowLockedByCategory,
}) => {
return (
<div className="xl:col-span-2 space-y-6">
<div className="space-y-2">
<div className="inline-flex items-center gap-1.5 bg-cyan-50 border border-cyan-200 text-cyan-700 text-xs px-3 py-1 rounded-full font-semibold">
<BookOpen className="h-3.5 w-3.5 animate-pulse" /> Mobile App Curriculum Catalog
</div>
<h2 className="text-3xl font-extrabold text-slate-900 tracking-tight">Unlock Professional TCM Modules</h2>
<p className="text-slate-500 max-w-2xl text-sm leading-relaxed font-semibold">
Unlock acupoint maps, organ syndrome references, and advanced dietetics. Entitling your login grants instant synchronization on your TCM iOS/Android app.
</p>
</div>
{/* 5 Premium Modules Structured Catalog */}
<div className="md:columns-2 columns-1 gap-6 space-y-6">
{/* CARD 1: Points Reference Module */}
<div className="rounded-3xl p-6 bg-white border border-slate-200/80 shadow-sm flex flex-col space-y-4 break-inside-avoid">
<div className="space-y-2">
<div className="flex justify-between items-center gap-2">
<div className="flex items-center gap-1.5 min-w-0">
<span className="text-[10px] bg-blue-50 text-blue-600 border border-blue-200 font-bold tracking-wider uppercase px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
Points
</span>
<button
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Points: !prev.Points }))}
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
>
{showLockedByCategory.Points ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Points' && !isModuleUnlocked(m.code)).length})
</button>
</div>
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
1-Year Access
</span>
</div>
<h3 className="text-lg font-bold text-slate-800">Points Reference Module</h3>
<p className="text-xs text-slate-500 leading-relaxed font-semibold">
Unlock high-definition acupuncture point mapping tables and clinical micro-systems.
</p>
</div>
<div className="space-y-2">
{(() => {
const items = curriculumModules.filter(m => m.category === 'Points');
const visible = items.filter(sub => {
const isUnlocked = isModuleUnlocked(sub.code);
const live = getModulePrice(sub);
if (!isUnlocked && !live.isActive) return false;
if (!isUnlocked && !showLockedByCategory.Points) return false;
return true;
});
if (visible.length === 0) {
return (
<div className="py-6 text-center border border-dashed border-slate-200 rounded-2xl bg-slate-50/50">
<p className="text-xs text-slate-500 font-medium">Locked modules are currently hidden.</p>
<button
type="button"
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Points: true }))}
className="mt-1 text-xs text-blue-600 hover:text-blue-700 font-bold hover:underline cursor-pointer"
>
Click here to show locked modules
</button>
</div>
);
}
return visible.map((sub) => {
const isUnlocked = isModuleUnlocked(sub.code);
const isInCart = cart.some(item => item.code === sub.code);
const live = getModulePrice(sub);
return (
<div
key={`${sub.code}-${sub.name}`}
onClick={() => {
if (isUnlocked || !live.isActive) return;
toggleCartItem(sub);
}}
className={`flex justify-between items-center p-3 rounded-2xl border transition-all duration-300 select-none ${
isUnlocked
? 'border-emerald-100 bg-emerald-50/20 cursor-default'
: !live.isActive
? 'border-slate-100 bg-slate-50/50 opacity-60 cursor-not-allowed'
: isInCart
? 'border-indigo-400 bg-indigo-50/20 shadow-sm cursor-pointer'
: 'border-slate-100 bg-slate-50/80 hover:border-slate-300 cursor-pointer'
}`}
>
<div className="flex-1 pr-2">
<div className="flex items-center gap-1.5 flex-wrap">
<span className="text-xs font-bold text-slate-800">{sub.name.replace("Points: ", "")}</span>
{sub.code === 'POINTS_PACK' && (
<span className="text-[8px] bg-gradient-to-r from-indigo-500 to-purple-600 text-white font-extrabold px-1.5 py-0.5 rounded tracking-wider uppercase">
Complete Pack
</span>
)}
{!isUnlocked && !live.isActive && (
<span className="text-[8px] bg-slate-200 text-slate-600 font-bold px-1.5 py-0.5 rounded tracking-wider uppercase">
Temporarily Unavailable
</span>
)}
</div>
<p className="text-[10px] text-slate-400 font-semibold mt-0.5 leading-tight">
{sub.desc.replace(/1 Year:\s*/i, '')}
</p>
</div>
<div className="flex items-center gap-3 flex-shrink-0">
{isUnlocked ? (
<span className="text-[10px] bg-emerald-50 text-emerald-700 font-extrabold tracking-wider px-2 py-0.5 rounded border border-emerald-200 flex items-center gap-0.5 shadow-sm">
<Check className="h-2.5 w-2.5" /> UNLOCKED
</span>
) : !live.isActive ? (
<span className="text-[10px] bg-slate-100 text-slate-400 font-bold tracking-wider px-2 py-0.5 rounded border border-slate-200">
INACTIVE
</span>
) : (
<span className="text-xs font-extrabold text-slate-700">
{currency === 'INR' ? `₹${live.priceInr}` : currency === 'EUR' ? `€${live.priceEur}` : `$${live.priceUsd}`}
</span>
)}
{!isUnlocked && live.isActive && (
<div className={`h-4.5 w-4.5 rounded-full border flex items-center justify-center transition-all duration-300 ${isInCart ? 'bg-indigo-600 border-indigo-500' : 'border-slate-300'}`}>
{isInCart && <div className="h-1.5 w-1.5 rounded-full bg-white" />}
</div>
)}
</div>
</div>
);
});
})()}
</div>
</div>
{/* CARD 2: Pattern Diagnosis Module */}
<div className="rounded-3xl p-6 bg-white border border-slate-200/80 shadow-sm flex flex-col space-y-4 break-inside-avoid">
<div className="space-y-2">
<div className="flex justify-between items-center gap-2">
<div className="flex items-center gap-1.5 min-w-0">
<span className="text-[10px] bg-rose-50 text-rose-600 border border-rose-200 font-bold tracking-wider uppercase px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
Pattern
</span>
<button
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Pattern: !prev.Pattern }))}
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
>
{showLockedByCategory.Pattern ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Pattern' && !isModuleUnlocked(m.code)).length})
</button>
</div>
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
1-Year Access
</span>
</div>
<h3 className="text-lg font-bold text-slate-800">Pattern Diagnosis Module</h3>
<p className="text-xs text-slate-500 leading-relaxed font-semibold">
Full comprehensive study of professional TCM syndrome differentiation methodologies.
</p>
</div>
<div className="space-y-2">
{(() => {
const items = curriculumModules.filter(m => m.category === 'Pattern');
const visible = items.filter(sub => {
const isUnlocked = isModuleUnlocked(sub.code);
const live = getModulePrice(sub);
if (!isUnlocked && !live.isActive) return false;
if (!isUnlocked && !showLockedByCategory.Pattern) return false;
return true;
});
if (visible.length === 0) {
return (
<div className="py-6 text-center border border-dashed border-slate-200 rounded-2xl bg-slate-50/50">
<p className="text-xs text-slate-500 font-medium">Locked modules are currently hidden.</p>
<button
type="button"
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Pattern: true }))}
className="mt-1 text-xs text-rose-600 hover:text-rose-700 font-bold hover:underline cursor-pointer"
>
Click here to show locked modules
</button>
</div>
);
}
return visible.map((sub) => {
const isUnlocked = isModuleUnlocked(sub.code);
const isInCart = cart.some(item => item.code === sub.code);
const live = getModulePrice(sub);
return (
<div
key={`${sub.code}-${sub.name}`}
onClick={() => {
if (isUnlocked || !live.isActive) return;
toggleCartItem(sub);
}}
className={`flex justify-between items-center p-3 rounded-2xl border transition-all duration-300 select-none ${
isUnlocked
? 'border-emerald-100 bg-emerald-50/20 cursor-default'
: !live.isActive
? 'border-slate-100 bg-slate-50/50 opacity-60 cursor-not-allowed'
: isInCart
? 'border-indigo-400 bg-indigo-50/20 shadow-sm cursor-pointer'
: 'border-slate-100 bg-slate-50/80 hover:border-slate-300 cursor-pointer'
}`}
>
<div className="flex-1 pr-2">
<div className="flex items-center gap-1.5 flex-wrap">
<span className="text-xs font-bold text-slate-800">{sub.name}</span>
{!isUnlocked && !live.isActive && (
<span className="text-[8px] bg-slate-200 text-slate-600 font-bold px-1.5 py-0.5 rounded tracking-wider uppercase">
Temporarily Unavailable
</span>
)}
</div>
<p className="text-[10px] text-slate-400 font-semibold mt-0.5 leading-tight">
{sub.desc.replace(/1 Year:\s*/i, '')}
</p>
</div>
<div className="flex items-center gap-3 flex-shrink-0">
{isUnlocked ? (
<span className="text-[10px] bg-emerald-50 text-emerald-700 font-extrabold tracking-wider px-2 py-0.5 rounded border border-emerald-200 flex items-center gap-0.5 shadow-sm">
<Check className="h-2.5 w-2.5" /> UNLOCKED
</span>
) : !live.isActive ? (
<span className="text-[10px] bg-slate-100 text-slate-400 font-bold tracking-wider px-2 py-0.5 rounded border border-slate-200">
INACTIVE
</span>
) : (
<span className="text-xs font-extrabold text-slate-700">
{currency === 'INR' ? `₹${live.priceInr}` : currency === 'EUR' ? `€${live.priceEur}` : `$${live.priceUsd}`}
</span>
)}
{!isUnlocked && live.isActive && (
<div className={`h-4.5 w-4.5 rounded-full border flex items-center justify-center transition-all duration-300 ${isInCart ? 'bg-indigo-600 border-indigo-500' : 'border-slate-300'}`}>
{isInCart && <div className="h-1.5 w-1.5 rounded-full bg-white" />}
</div>
)}
</div>
</div>
);
});
})()}
</div>
</div>
{/* CARD 3: TCM Nutrition & Dietetics */}
<div className="rounded-3xl p-6 bg-white border border-slate-200/80 shadow-sm flex flex-col space-y-4 break-inside-avoid">
<div className="space-y-2">
<div className="flex justify-between items-center gap-2">
<div className="flex items-center gap-1.5 min-w-0">
<span className="text-[10px] bg-emerald-50 text-emerald-600 border border-emerald-200 font-bold tracking-wider uppercase px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
Nutrition
</span>
<button
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Nutrition: !prev.Nutrition }))}
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
>
{showLockedByCategory.Nutrition ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Nutrition' && !isModuleUnlocked(m.code)).length})
</button>
</div>
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
1-Year Access
</span>
</div>
<h3 className="text-lg font-bold text-slate-800">TCM Nutrition & Dietetics</h3>
<p className="text-xs text-slate-500 leading-relaxed font-semibold">
Thermal nature, five-flavor dynamics, and clinical organ dietary prescriptions.
</p>
</div>
<div className="space-y-2">
{(() => {
const items = curriculumModules.filter(m => m.category === 'Nutrition');
const visible = items.filter(sub => {
const isUnlocked = isModuleUnlocked(sub.code);
const live = getModulePrice(sub);
if (!isUnlocked && !live.isActive) return false;
if (!isUnlocked && !showLockedByCategory.Nutrition) return false;
return true;
});
if (visible.length === 0) {
return (
<div className="py-6 text-center border border-dashed border-slate-200 rounded-2xl bg-slate-50/50">
<p className="text-xs text-slate-500 font-medium">Locked modules are currently hidden.</p>
<button
type="button"
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Nutrition: true }))}
className="mt-1 text-xs text-emerald-600 hover:text-emerald-700 font-bold hover:underline cursor-pointer"
>
Click here to show locked modules
</button>
</div>
);
}
return visible.map((sub) => {
const isUnlocked = isModuleUnlocked(sub.code);
const isInCart = cart.some(item => item.code === sub.code);
const live = getModulePrice(sub);
return (
<div
key={`${sub.code}-${sub.name}`}
onClick={() => {
if (isUnlocked || !live.isActive) return;
toggleCartItem(sub);
}}
className={`flex justify-between items-center p-3 rounded-2xl border transition-all duration-300 select-none ${
isUnlocked
? 'border-emerald-100 bg-emerald-50/20 cursor-default'
: !live.isActive
? 'border-slate-100 bg-slate-50/50 opacity-60 cursor-not-allowed'
: isInCart
? 'border-indigo-400 bg-indigo-50/20 shadow-sm cursor-pointer'
: 'border-slate-100 bg-slate-50/80 hover:border-slate-300 cursor-pointer'
}`}
>
<div className="flex-1 pr-2">
<div className="flex items-center gap-1.5 flex-wrap">
<span className="text-xs font-bold text-slate-800">{sub.name}</span>
{!isUnlocked && !live.isActive && (
<span className="text-[8px] bg-slate-200 text-slate-600 font-bold px-1.5 py-0.5 rounded tracking-wider uppercase">
Temporarily Unavailable
</span>
)}
</div>
<p className="text-[10px] text-slate-400 font-semibold mt-0.5 leading-tight">
{sub.desc.replace(/1 Year:\s*/i, '')}
</p>
</div>
<div className="flex items-center gap-3 flex-shrink-0">
{isUnlocked ? (
<span className="text-[10px] bg-emerald-50 text-emerald-700 font-extrabold tracking-wider px-2 py-0.5 rounded border border-emerald-200 flex items-center gap-0.5 shadow-sm">
<Check className="h-2.5 w-2.5" /> UNLOCKED
</span>
) : !live.isActive ? (
<span className="text-[10px] bg-slate-100 text-slate-400 font-bold tracking-wider px-2 py-0.5 rounded border border-slate-200">
INACTIVE
</span>
) : (
<span className="text-xs font-extrabold text-slate-700">
{currency === 'INR' ? `₹${live.priceInr}` : currency === 'EUR' ? `€${live.priceEur}` : `$${live.priceUsd}`}
</span>
)}
{!isUnlocked && live.isActive && (
<div className={`h-4.5 w-4.5 rounded-full border flex items-center justify-center transition-all duration-300 ${isInCart ? 'bg-indigo-600 border-indigo-500' : 'border-slate-300'}`}>
{isInCart && <div className="h-1.5 w-1.5 rounded-full bg-white" />}
</div>
)}
</div>
</div>
);
});
})()}
</div>
</div>
{/* CARD 4: Clinical Therapeutics */}
<div className="rounded-3xl p-6 bg-white border border-slate-200/80 shadow-sm flex flex-col space-y-4 break-inside-avoid">
<div className="space-y-2">
<div className="flex justify-between items-center gap-2">
<div className="flex items-center gap-1.5 min-w-0">
<span className="text-[10px] bg-purple-50 text-purple-600 border border-purple-200 font-bold tracking-wider uppercase px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
Therapeutics
</span>
<button
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Therapeutics: !prev.Therapeutics }))}
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-1.5 py-0.5 rounded transition-colors whitespace-nowrap shrink-0"
>
{showLockedByCategory.Therapeutics ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Therapeutics' && !isModuleUnlocked(m.code)).length})
</button>
</div>
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
1-Year Access
</span>
</div>
<h3 className="text-lg font-bold text-slate-800">Clinical Therapeutics</h3>
<p className="text-xs text-slate-500 leading-relaxed font-semibold">
Master specific treatment modalities including Auricular Acupuncture and Gynaecology.
</p>
</div>
<div className="space-y-2">
{(() => {
const items = curriculumModules.filter(m => m.category === 'Therapeutics');
const visible = items.filter(sub => {
const isUnlocked = isModuleUnlocked(sub.code);
const live = getModulePrice(sub);
if (!isUnlocked && !live.isActive) return false;
if (!isUnlocked && !showLockedByCategory.Therapeutics) return false;
return true;
});
if (visible.length === 0) {
return (
<div className="py-6 text-center border border-dashed border-slate-200 rounded-2xl bg-slate-50/50">
<p className="text-xs text-slate-500 font-medium">Locked modules are currently hidden.</p>
<button
type="button"
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Therapeutics: true }))}
className="mt-1 text-xs text-purple-600 hover:text-purple-700 font-bold hover:underline cursor-pointer"
>
Click here to show locked modules
</button>
</div>
);
}
return visible.map((sub) => {
const isUnlocked = isModuleUnlocked(sub.code);
const isInCart = cart.some(item => item.code === sub.code);
const live = getModulePrice(sub);
return (
<div
key={`${sub.code}-${sub.name}`}
onClick={() => {
if (isUnlocked || !live.isActive) return;
toggleCartItem(sub);
}}
className={`flex justify-between items-center p-3 rounded-2xl border transition-all duration-300 select-none ${
isUnlocked
? 'border-emerald-100 bg-emerald-50/20 cursor-default'
: !live.isActive
? 'border-slate-100 bg-slate-50/50 opacity-60 cursor-not-allowed'
: isInCart
? 'border-indigo-400 bg-indigo-50/20 shadow-sm cursor-pointer'
: 'border-slate-100 bg-slate-50/80 hover:border-slate-300 cursor-pointer'
}`}
>
<div className="flex-1 pr-2">
<div className="flex items-center gap-1.5 flex-wrap">
<span className="text-xs font-bold text-slate-800">{sub.name.replace("Therapeutics: ", "")}</span>
{sub.code === 'THERAPEUTICS_CORE' && (
<span className="text-[8px] bg-gradient-to-r from-indigo-500 to-cyan-500 text-white font-extrabold px-1.5 py-0.5 rounded tracking-wider uppercase">
Complete Pack
</span>
)}
{!isUnlocked && !live.isActive && (
<span className="text-[8px] bg-slate-200 text-slate-600 font-bold px-1.5 py-0.5 rounded tracking-wider uppercase">
Temporarily Unavailable
</span>
)}
</div>
<p className="text-[10px] text-slate-400 font-semibold mt-0.5 leading-tight">
{sub.desc.replace(/1 Year:\s*/i, '')}
</p>
</div>
<div className="flex items-center gap-3 flex-shrink-0">
{isUnlocked ? (
<span className="text-[10px] bg-emerald-50 text-emerald-700 font-extrabold tracking-wider px-2 py-0.5 rounded border border-emerald-200 flex items-center gap-0.5 shadow-sm">
<Check className="h-2.5 w-2.5" /> UNLOCKED
</span>
) : !live.isActive ? (
<span className="text-[10px] bg-slate-100 text-slate-400 font-bold tracking-wider px-2 py-0.5 rounded border border-slate-200">
INACTIVE
</span>
) : (
<span className="text-xs font-extrabold text-slate-700">
{currency === 'INR' ? `₹${live.priceInr}` : currency === 'EUR' ? `€${live.priceEur}` : `$${live.priceUsd}`}
</span>
)}
{!isUnlocked && live.isActive && (
<div className={`h-4.5 w-4.5 rounded-full border flex items-center justify-center transition-all duration-300 ${isInCart ? 'bg-indigo-600 border-indigo-500' : 'border-slate-300'}`}>
{isInCart && <div className="h-1.5 w-1.5 rounded-full bg-white" />}
</div>
)}
</div>
</div>
);
});
})()}
</div>
</div>
{/* CARD 5: Lifetime Unlimited Pass */}
<div className="rounded-3xl p-6 bg-gradient-to-br from-amber-500/10 via-yellow-500/5 to-amber-600/10 border border-amber-300/40 shadow-md flex flex-col justify-between space-y-4 relative overflow-hidden select-none break-inside-avoid">
<div className="absolute -top-12 -right-12 h-32 w-32 bg-amber-400/10 rounded-full blur-2xl pointer-events-none" />
<div className="flex flex-col md:flex-row justify-between items-start md:items-center gap-4">
<div className="space-y-1">
<div className="flex items-center gap-2">
<div className="inline-flex items-center gap-1.5 bg-amber-100 border border-amber-300 text-amber-800 text-[10px] font-black tracking-widest uppercase px-3 py-1 rounded-full shadow-sm">
👑 Elite Access Suite
</div>
<button
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Lifetime: !prev.Lifetime }))}
className="text-[9px] bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 font-bold px-2 py-1 rounded transition-colors"
>
{showLockedByCategory.Lifetime ? 'Hide Locked' : 'Show Locked'} ({curriculumModules.filter(m => m.category === 'Lifetime' && !isModuleUnlocked(m.code)).length})
</button>
</div>
<h3 className="text-xl font-black text-amber-900 tracking-tight">Lifetime Unlimited Access Pass</h3>
</div>
</div>
<div className="space-y-2">
{(() => {
const items = curriculumModules.filter(m => m.category === 'Lifetime');
const visible = items.filter(sub => {
const isUnlocked = isModuleUnlocked(sub.code);
const live = getModulePrice(sub);
if (!isUnlocked && !live.isActive) return false;
if (!isUnlocked && !showLockedByCategory.Lifetime) return false;
return true;
});
if (visible.length === 0) {
return (
<div className="py-6 text-center border border-dashed border-amber-300/60 rounded-2xl bg-amber-50/30">
<p className="text-xs text-amber-800 font-medium">Locked pass is currently hidden.</p>
<button
type="button"
onClick={() => setShowLockedByCategory(prev => ({ ...prev, Lifetime: true }))}
className="mt-1 text-xs text-amber-900 hover:text-black font-bold hover:underline cursor-pointer"
>
Click here to show locked pass
</button>
</div>
);
}
return visible.map((sub) => {
const isUnlocked = isModuleUnlocked(sub.code);
const isInCart = cart.some(item => item.code === sub.code);
const live = getModulePrice(sub);
return (
<div
key={`${sub.code}-${sub.name}`}
onClick={() => {
if (isUnlocked || !live.isActive) return;
toggleCartItem(sub);
}}
className={`flex justify-between items-center p-3 rounded-2xl border transition-all duration-300 select-none ${
isUnlocked
? 'border-emerald-100 bg-emerald-50/20 cursor-default'
: !live.isActive
? 'border-amber-200/50 bg-amber-50/30 opacity-60 cursor-not-allowed'
: isInCart
? 'border-indigo-400 bg-indigo-50/20 shadow-sm cursor-pointer'
: 'border-slate-100 bg-slate-50/80 hover:border-slate-300 cursor-pointer'
}`}
>
<div className="flex-1 pr-2">
<div className="flex items-center gap-1.5 flex-wrap">
<span className="text-xs font-bold text-slate-800">{sub.name}</span>
{!isUnlocked && !live.isActive && (
<span className="text-[8px] bg-slate-200 text-slate-600 font-bold px-1.5 py-0.5 rounded tracking-wider uppercase">
Temporarily Unavailable
</span>
)}
</div>
<p className="text-[10px] text-slate-400 font-semibold mt-0.5 leading-tight">
{sub.desc.replace(/10 Years:\s*/i, '')}
</p>
</div>
<div className="flex items-center gap-3 flex-shrink-0">
{isUnlocked ? (
<span className="text-[10px] bg-emerald-50 text-emerald-700 font-extrabold tracking-wider px-2 py-0.5 rounded border border-emerald-200 flex items-center gap-0.5 shadow-sm">
<Check className="h-2.5 w-2.5" /> UNLOCKED
</span>
) : !live.isActive ? (
<span className="text-[10px] bg-slate-100 text-slate-400 font-bold tracking-wider px-2 py-0.5 rounded border border-slate-200">
INACTIVE
</span>
) : (
<span className="text-xs font-extrabold text-slate-700">
{currency === 'INR' ? `₹${live.priceInr}` : currency === 'EUR' ? `€${live.priceEur}` : `$${live.priceUsd}`}
</span>
)}
{!isUnlocked && live.isActive && (
<div className={`h-4.5 w-4.5 rounded-full border flex items-center justify-center transition-all duration-300 ${isInCart ? 'bg-indigo-600 border-indigo-500' : 'border-slate-300'}`}>
{isInCart && <div className="h-1.5 w-1.5 rounded-full bg-white" />}
</div>
)}
</div>
</div>
);
});
})()}
</div>
</div>
{/* CARD 6: Custom Packages & Bundles (Dynamic Admin Plans) */}
{(() => {
const customPlans = publicPlans.filter((p: any) => {
const code = p.base_code || p.code;
const isCustom = !['POINTS_ACU', 'POINTS_SCALP', 'POINTS_EAR', 'POINTS_TUNG', 'POINTS_PACK', 'PATTERN_CORE', 'NUTRITION_CORE', 'THERAPEUTICS_GYNAE', 'THERAPEUTICS_EAR', 'THERAPEUTICS_CORE', 'LIFETIME_ALL'].includes(code);
const isActive = p.is_active !== false;
return isCustom && isActive;
});
if (customPlans.length === 0) return null;
const firstPlan = customPlans[0];
const headerBadge = firstPlan.badge_text || 'Custom Packages & Bundles';
const headerTitle = firstPlan.heading || 'Special Curated Bundles';
const headerSubtitle = firstPlan.subtitle || 'Custom curriculum collections created exclusively for practitioners.';
return (
<div className="rounded-3xl p-6 bg-white border border-slate-200/80 shadow-sm flex flex-col space-y-4 break-inside-avoid">
<div className="space-y-2">
<div className="flex justify-between items-center gap-2">
<span className="text-[10px] bg-slate-100 text-slate-700 border border-slate-200 font-bold tracking-wider uppercase px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
{headerBadge}
</span>
<span className="text-[10px] bg-slate-100/80 text-slate-500 border border-slate-200/70 font-extrabold uppercase tracking-wider px-2 py-0.5 rounded-md whitespace-nowrap shrink-0">
Custom Bundle
</span>
</div>
<h3 className="text-lg font-bold text-slate-800">{headerTitle}</h3>
<p className="text-xs text-slate-500 leading-relaxed font-semibold">{headerSubtitle}</p>
</div>
<div className="space-y-2">
{customPlans.map((cPlan: any) => {
const pCode = cPlan.base_code || cPlan.code;
const isUnlocked = isModuleUnlocked(pCode);
const isInCart = cart.some(item => item.code === pCode);
const pInr = cPlan.price_inr ?? 0;
const pUsd = cPlan.price_usd ?? 0;
const customModuleItem: ModuleItem = {
code: pCode,
name: cPlan.name,
category: 'Bundle',
priceInr: pInr,
priceUsd: pUsd,
priceEur: pUsd,
desc: cPlan.description || 'Custom bundled access.',
color: 'from-slate-700 to-slate-900'
};
return (
<div
key={pCode}
onClick={() => {
if (isUnlocked) return;
toggleCartItem(customModuleItem);
}}
className={`flex justify-between items-center p-3 rounded-2xl border transition-all duration-300 select-none ${
isUnlocked
? 'border-emerald-100 bg-emerald-50/20 cursor-default'
: isInCart
? 'border-indigo-400 bg-indigo-50/20 shadow-sm cursor-pointer'
: 'border-slate-100 bg-slate-50/80 hover:border-slate-300 cursor-pointer'
}`}
>
<div className="flex-1 pr-2">
<div className="flex items-center gap-1.5 flex-wrap">
<span className="text-xs font-bold text-slate-800">{cPlan.name}</span>
{cPlan.badge_text && (
<span className="text-[8px] bg-slate-200 text-slate-700 font-bold px-1.5 py-0.5 rounded tracking-wider uppercase">
{cPlan.badge_text}
</span>
)}
</div>
{cPlan.description && (
<p className="text-[10px] text-slate-400 font-semibold mt-0.5 leading-tight">
{cPlan.description}
</p>
)}
{cPlan.modules && cPlan.modules.length > 0 && (
<div className="flex flex-wrap gap-1 mt-1.5">
{cPlan.modules.map((m: any) => (
<span key={m.slug || m.id} className="text-[8px] bg-slate-100 text-slate-600 px-1.5 py-0.5 rounded font-medium">
{m.name}
</span>
))}
</div>
)}
</div>
<div className="flex items-center gap-3 flex-shrink-0">
{isUnlocked ? (
<span className="text-[10px] bg-emerald-50 text-emerald-700 font-extrabold tracking-wider px-2 py-0.5 rounded border border-emerald-200 flex items-center gap-0.5 shadow-sm">
<Check className="h-2.5 w-2.5" /> UNLOCKED
</span>
) : (
<span className="text-xs font-extrabold text-slate-700">
{currency === 'INR' ? `₹${pInr}` : `$${pUsd}`}
</span>
)}
{!isUnlocked && (
<div className={`h-4.5 w-4.5 rounded-full border flex items-center justify-center transition-all duration-300 ${isInCart ? 'bg-indigo-600 border-indigo-500' : 'border-slate-300'}`}>
{isInCart && <div className="h-1.5 w-1.5 rounded-full bg-white" />}
</div>
)}
</div>
</div>
);
})}
</div>
</div>
);
})()}
</div>
</div>
);
};

View File

@ -0,0 +1,21 @@
import React from 'react';
export const LifetimeBanner: React.FC = () => {
return (
<div className="relative rounded-3xl p-6 bg-gradient-to-r from-amber-500 via-yellow-400 to-amber-600 border border-yellow-300/30 text-slate-900 shadow-2xl flex flex-col md:flex-row justify-between items-center gap-4 overflow-hidden select-none">
<div className="absolute top-0 right-0 h-48 w-48 bg-white/10 rotate-12 rounded-full blur-xl pointer-events-none" />
<div className="space-y-1 text-center md:text-left">
<div className="inline-flex items-center gap-1 bg-slate-900 text-yellow-400 text-[10px] font-black tracking-widest uppercase px-2.5 py-0.5 rounded-full">
👑 Active Elite Pass
</div>
<h2 className="text-xl font-black tracking-tight">LIFETIME ACCESS PASSPORT ACTIVE!</h2>
<p className="text-xs text-slate-900/85 font-semibold">
All current modules and future clinical updates are completely unlocked for your account. Valid for 10 years.
</p>
</div>
<div className="h-10 w-10 rounded-full bg-slate-900 flex items-center justify-center text-yellow-400 font-extrabold text-sm shadow">
10Y
</div>
</div>
);
};

View File

@ -0,0 +1,196 @@
import React from 'react';
import { XCircle, CheckCircle, Check, Download, RefreshCw, Smartphone } from 'lucide-react';
import type { VerificationResult, UserProfile } from '../../types';
interface PaymentSuccessModalProps {
verificationResult: VerificationResult;
onClose: () => void;
loggedInUser: UserProfile | null;
onDownloadInvoice: (paymentId: string, invoiceUrl?: string) => void;
downloadingInvoice: boolean;
}
export const PaymentSuccessModal: React.FC<PaymentSuccessModalProps> = ({
verificationResult,
onClose,
loggedInUser,
onDownloadInvoice,
downloadingInvoice,
}) => {
return (
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-slate-950/75 backdrop-blur-md transition-all duration-300">
<div className="relative w-full max-w-xl bg-slate-900 border border-slate-800 rounded-2xl p-5 md:p-6 space-y-4 shadow-2xl text-slate-100 overflow-hidden animate-in fade-in zoom-in-95 duration-200">
{/* Ambient Background Glow */}
<div className="absolute -top-10 left-1/2 -translate-x-1/2 w-48 h-48 bg-emerald-500/10 rounded-full blur-3xl pointer-events-none" />
{/* Close button */}
<button
onClick={onClose}
className="absolute top-3 right-3 h-7 w-7 rounded-full bg-slate-800 hover:bg-slate-700/80 flex items-center justify-center text-slate-400 hover:text-slate-200 transition-colors"
>
<XCircle className="h-4 w-4" />
</button>
{/* Glowing animated green checkmark */}
<div className="text-center space-y-2 relative z-10">
<div
className="inline-flex items-center justify-center h-12 w-12 rounded-full bg-emerald-950/80 border border-emerald-500/30 text-emerald-400 shadow-[0_0_20px_rgba(16,185,129,0.25)] animate-bounce"
style={{ animationDuration: '2.5s' }}
>
<CheckCircle className="h-7 w-7" />
</div>
<h3 className="text-lg font-black tracking-tight text-white">
Thank You for Your Purchase!
</h3>
<p className="text-[10px] text-emerald-400 font-extrabold uppercase tracking-wider bg-emerald-950/50 border border-emerald-800/60 px-3 py-1 rounded-full inline-block">
Clinical Modules Unlocked Successfully
</p>
</div>
{/* Content: Mobile App Access Onboarding */}
<div className="bg-slate-950 border border-slate-800/80 rounded-xl p-4 space-y-3 relative z-10">
<p className="text-[11px] text-slate-300 leading-relaxed font-semibold text-center">
Your subscription entitlements are active! Access your content inside the{' '}
<span className="text-indigo-400 font-bold">Acupedia Mobile App</span>. Log in with:{' '}
<span className="text-white underline font-bold">
{loggedInUser?.email || 'your registered email'}
</span>
.
</p>
{/* App download badges */}
<div className="flex justify-center items-center gap-2.5">
{/* Apple App Store */}
<a
href="#appstore"
onClick={(e) => e.preventDefault()}
className="flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white px-3.5 py-2 rounded-lg border border-slate-800 hover:border-slate-700 transition-all duration-300 shadow-sm group"
>
<svg className="w-4 h-4 fill-current text-slate-300 group-hover:text-white transition-colors" viewBox="0 0 24 24">
<path d="M18.71,19.5 C17.88,20.74 17,21.95 15.66,21.97 C14.32,22 13.89,21.18 12.37,21.18 C10.84,21.18 10.37,21.95 9.1,22 C7.79,22.05 6.8,20.68 5.96,19.48 C4.25,17 2.94,12.45 4.7,9.39 C5.57,7.87 7.13,6.91 8.82,6.88 C10.1,6.86 11.32,7.75 12.11,7.75 C12.89,7.75 14.37,6.68 15.92,6.84 C16.57,6.87 18.39,7.1 19.56,8.82 C19.47,8.88 17.39,10.1 17.41,12.63 C17.44,15.65 20.06,16.66 20.1,16.67 C20.08,16.74 19.67,18.11 18.71,19.5 M15.97,4.17 C16.63,3.37 17.07,2.28 16.95,1 C16,1.04 14.9,1.6 14.24,2.38 C13.68,3.04 13.19,4.14 13.34,5.39 C14.39,5.47 15.4,4.88 15.97,4.17 Z" />
</svg>
<div className="text-left leading-none">
<p className="text-[8px] text-slate-400 font-bold uppercase tracking-wider mb-0.5">Download on the</p>
<p className="text-xs font-black text-slate-200 group-hover:text-white transition-colors">App Store</p>
</div>
</a>
{/* Google Play Store */}
<a
href="#playstore"
onClick={(e) => e.preventDefault()}
className="flex items-center gap-2 bg-slate-900 hover:bg-slate-800 text-white px-3.5 py-2 rounded-lg border border-slate-800 hover:border-slate-700 transition-all duration-300 shadow-sm group"
>
<svg className="w-4 h-4 fill-current text-slate-300 group-hover:text-white transition-colors" viewBox="0 0 24 24">
<path d="M3,5.27V18.73L16.55,12L3,5.27M17.87,11.33L21,12.92C21.67,13.25 21.67,13.75 21,14.08L17.87,15.67L15,12L17.87,11.33M3,3C3.58,3 4.2,3.22 4.67,3.58L16,11.08L13.13,12L3,3M3,21L13.13,12L16,12.92L4.67,20.42C4.2,20.78 3.58,21 3,21Z" />
</svg>
<div className="text-left leading-none">
<p className="text-[8px] text-slate-400 font-bold uppercase tracking-wider mb-0.5">Get it on</p>
<p className="text-xs font-black text-slate-200 group-hover:text-white transition-colors">Google Play</p>
</div>
</a>
</div>
</div>
{/* Details listing: ID, Invoice, Amount, Items */}
<div className="bg-slate-950/60 border border-slate-800/80 rounded-xl p-3.5 space-y-2.5 text-[11px] relative z-10">
<div className="flex justify-between items-center text-slate-400 font-semibold">
<span>Invoice</span>
<div className="flex items-center gap-1.5">
<span className="text-white font-mono font-bold bg-slate-800 px-2 py-0.5 rounded text-[10px] border border-slate-700/50">
{verificationResult.invoiceNumber}
</span>
{verificationResult.invoiceNumber && (
<button
onClick={() =>
onDownloadInvoice(
verificationResult.paymentId || '',
verificationResult.invoiceUrl
)
}
disabled={downloadingInvoice}
className="text-indigo-400 hover:text-indigo-300 transition-colors p-0.5"
title="Download Invoice PDF"
>
<Download className="h-3 w-3" />
</button>
)}
</div>
</div>
<div className="flex justify-between items-center text-slate-400 font-semibold">
<span>Payment ID</span>
<span className="text-white font-mono font-bold bg-slate-800 px-2 py-0.5 rounded text-[10px] border border-slate-700/50">
{verificationResult.paymentId}
</span>
</div>
<div className="flex justify-between items-center text-slate-400 font-semibold">
<span>Amount Paid</span>
<span className="text-indigo-400 font-extrabold text-xs">
{verificationResult.currency === 'INR'
? `₹${verificationResult.amount}`
: verificationResult.currency === 'EUR'
? `€${verificationResult.amount}`
: `$${verificationResult.amount}`}
</span>
</div>
<div className="h-px bg-slate-800/85" />
<div className="space-y-1 text-left">
<span className="text-[9px] text-slate-500 font-bold uppercase tracking-wider block">
Unlocked Modules
</span>
<div className="flex flex-wrap gap-1">
{verificationResult.items?.map((itemName: string, idx: number) => (
<span
key={idx}
className="bg-indigo-950/50 text-indigo-300 border border-indigo-900/60 text-[9px] font-bold px-2 py-0.5 rounded-md flex items-center gap-1 shadow-sm"
>
<Check className="h-2 w-2 text-indigo-400" /> {itemName}
</span>
))}
</div>
</div>
</div>
{/* Action buttons */}
<div className="space-y-2 relative z-10 mt-2">
{verificationResult.invoiceNumber && (
<button
onClick={() =>
onDownloadInvoice(
verificationResult.paymentId || '',
verificationResult.invoiceUrl
)
}
disabled={downloadingInvoice}
className="w-full h-9 bg-slate-800 hover:bg-slate-700/80 border border-slate-700 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md"
>
{downloadingInvoice ? (
<RefreshCw className="h-3.5 w-3.5 animate-spin text-indigo-400" />
) : (
<Download className="h-3.5 w-3.5 text-indigo-400" />
)}
{downloadingInvoice ? 'Downloading...' : 'Download Invoice PDF'}
</button>
)}
<a
href="acupedia://"
className="w-full h-9 bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md shadow-emerald-600/10 no-underline decoration-0"
>
<Smartphone className="h-3.5 w-3.5 text-emerald-200" />
Open Acupedia Mobile App
</a>
<button
onClick={onClose}
className="w-full h-9 bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-xs rounded-lg transition-all duration-300 flex items-center justify-center gap-2 shadow-md shadow-indigo-600/10"
>
Return to Storefront
</button>
</div>
</div>
</div>
);
};

View File

@ -0,0 +1,117 @@
import React from 'react';
import { ChevronLeft, ChevronRight } from 'lucide-react';
export interface PaginationProps {
currentPage: number;
totalItems: number;
itemsPerPage: number;
onPageChange: (page: number) => void;
onItemsPerPageChange?: (perPage: number) => void;
pageSizeOptions?: number[];
}
export const Pagination: React.FC<PaginationProps> = ({
currentPage,
totalItems,
itemsPerPage,
onPageChange,
onItemsPerPageChange,
pageSizeOptions = [6, 12, 24, 48],
}) => {
const totalPages = Math.max(1, Math.ceil(totalItems / itemsPerPage));
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = Math.min(startIndex + itemsPerPage, totalItems);
if (totalItems <= 0) {
return null;
}
const getPageNumbers = () => {
if (totalPages <= 7) {
return Array.from({ length: totalPages }, (_, i) => i + 1);
}
if (currentPage <= 4) {
return [1, 2, 3, 4, 5, '...', totalPages];
}
if (currentPage >= totalPages - 3) {
return [1, '...', totalPages - 4, totalPages - 3, totalPages - 2, totalPages - 1, totalPages];
}
return [1, '...', currentPage - 1, currentPage, currentPage + 1, '...', totalPages];
};
return (
<div className="flex flex-col sm:flex-row justify-between items-center gap-4 mt-6 pt-4 border-t border-slate-200 text-xs font-semibold text-slate-500">
{onItemsPerPageChange && (
<div className="flex items-center gap-2">
<span>Show</span>
<select
value={itemsPerPage}
onChange={(e) => {
onItemsPerPageChange(Number(e.target.value));
onPageChange(1);
}}
className="bg-white border border-slate-200 rounded-xl px-2.5 py-1 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer shadow-sm"
>
{pageSizeOptions.map((opt) => (
<option key={opt} value={opt}>
{opt}
</option>
))}
</select>
<span>per page</span>
</div>
)}
<span>
Showing <span className="text-slate-800 font-bold">{totalItems === 0 ? 0 : startIndex + 1}</span> to{' '}
<span className="text-slate-800 font-bold">{endIndex}</span> of{' '}
<span className="text-slate-800 font-bold">{totalItems}</span> items
</span>
<div className="flex items-center gap-1">
<button
type="button"
onClick={() => onPageChange(Math.max(1, currentPage - 1))}
disabled={currentPage <= 1}
className="h-8 px-2.5 rounded-xl border border-slate-200 bg-white hover:bg-slate-50 text-slate-700 disabled:opacity-40 disabled:hover:bg-white flex items-center gap-1 cursor-pointer transition-all shadow-sm"
>
<ChevronLeft className="h-3.5 w-3.5" /> Prev
</button>
{getPageNumbers().map((item, idx) => {
if (item === '...') {
return (
<span key={`ellipsis-${idx}`} className="px-2 text-slate-400">
...
</span>
);
}
const pNum = Number(item);
return (
<button
key={pNum}
type="button"
onClick={() => onPageChange(pNum)}
className={`h-8 min-w-8 px-2 rounded-xl border flex items-center justify-center cursor-pointer transition-all ${
currentPage === pNum
? 'bg-indigo-600 border-indigo-600 text-white font-black shadow-sm'
: 'border-slate-200 bg-white hover:bg-slate-50 text-slate-700 shadow-sm'
}`}
>
{pNum}
</button>
);
})}
<button
type="button"
onClick={() => onPageChange(Math.min(totalPages, currentPage + 1))}
disabled={currentPage >= totalPages}
className="h-8 px-2.5 rounded-xl border border-slate-200 bg-white hover:bg-slate-50 text-slate-700 disabled:opacity-40 disabled:hover:bg-white flex items-center gap-1 cursor-pointer transition-all shadow-sm"
>
Next <ChevronRight className="h-3.5 w-3.5" />
</button>
</div>
</div>
);
};

View File

@ -0,0 +1,13 @@
import React from 'react';
import { Lock } from 'lucide-react';
export const StoreFooter: React.FC = () => {
return (
<footer className="border-t border-slate-200 pt-6 mt-12 flex flex-col sm:flex-row justify-between items-center gap-2 text-xs text-slate-400 font-bold">
<p>© 2026 Acupedia Systems. All Rights Reserved.</p>
<p className="flex items-center gap-1">
<Lock className="h-3 w-3" /> Razorpay Gateway Integration (Test Mode)
</p>
</footer>
);
};

View File

@ -0,0 +1,102 @@
import React from 'react';
import { Sparkles, LogIn, UserPlus, BookOpen, CheckCircle } from 'lucide-react';
import type { UserProfile } from '../../types';
interface StoreHeaderProps {
activeTab: 'storefront' | 'subscriptions';
onSwitchTab: (tab: 'storefront' | 'subscriptions') => void;
loggedInUser: UserProfile | null;
onOpenProfile: () => void;
onOpenAuth: (mode: 'login' | 'register') => void;
}
export const StoreHeader: React.FC<StoreHeaderProps> = ({
activeTab,
onSwitchTab,
loggedInUser,
onOpenProfile,
onOpenAuth,
}) => {
return (
<header className="w-full bg-[#0A0A0E] text-slate-300 border-b border-slate-800 px-6 py-4 flex items-center justify-between shadow-lg flex-shrink-0">
<div className="flex items-center gap-6">
<div
onClick={() => onSwitchTab('storefront')}
className="flex items-center gap-3 cursor-pointer group"
>
<div className="h-10 w-10 rounded-xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-md shadow-indigo-500/20 group-hover:scale-105 transition-transform">
<Sparkles className="h-5 w-5 text-white" />
</div>
<div>
<h1 className="text-base font-black tracking-tight text-white flex items-center gap-1">
ACUPEDIA
</h1>
<p className="text-[9px] text-slate-400 font-bold tracking-widest uppercase">TCM PLATFORM</p>
</div>
</div>
{/* Navigation Tabs */}
<nav className="hidden sm:flex items-center bg-slate-900/80 border border-slate-800 rounded-xl p-1 gap-1">
<button
onClick={() => onSwitchTab('storefront')}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${
activeTab === 'storefront'
? 'bg-indigo-600 text-white shadow-sm'
: 'text-slate-400 hover:text-slate-200'
}`}
>
<BookOpen className="h-3.5 w-3.5" /> Storefront
</button>
<button
onClick={() => onSwitchTab('subscriptions')}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-bold transition-colors ${
activeTab === 'subscriptions'
? 'bg-indigo-600 text-white shadow-sm'
: 'text-slate-400 hover:text-slate-200'
}`}
>
<CheckCircle className="h-3.5 w-3.5" /> My Subscriptions
{loggedInUser?.active_subscriptions && loggedInUser.active_subscriptions.length > 0 && (
<span className="bg-indigo-900 text-indigo-200 text-[10px] px-1.5 py-0.2 rounded-full ml-0.5">
{loggedInUser.active_subscriptions.length}
</span>
)}
</button>
</nav>
</div>
<div className="flex items-center gap-3">
{loggedInUser ? (
<button
onClick={onOpenProfile}
className="flex items-center gap-3 hover:text-white transition-colors group focus:outline-none"
>
<div className="text-right hidden sm:block">
<p className="text-xs font-bold text-white truncate max-w-[150px]">
{loggedInUser.display_name || loggedInUser.email}
</p>
</div>
<div className="h-9 w-9 rounded-lg bg-indigo-950/60 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-bold text-sm group-hover:border-indigo-400 transition-colors">
{(loggedInUser.display_name || loggedInUser.email || 'U')[0].toUpperCase()}
</div>
</button>
) : (
<div className="flex gap-2">
<button
onClick={() => onOpenAuth('login')}
className="flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 transition-colors"
>
<LogIn className="h-3.5 w-3.5" /> Login
</button>
<button
onClick={() => onOpenAuth('register')}
className="flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors shadow shadow-indigo-600/10"
>
<UserPlus className="h-3.5 w-3.5" /> Join
</button>
</div>
)}
</div>
</header>
);
};

View File

@ -0,0 +1,176 @@
import React, { useState } from 'react';
import { CheckCircle } from 'lucide-react';
import { Pagination } from '../common/Pagination';
import type { UserProfile, ModuleItem } from '../../types';
interface SubscriptionsViewProps {
loggedInUser: UserProfile | null;
onOpenAuth: (mode: 'login') => void;
onSwitchTab: (tab: 'storefront') => void;
curriculumModules: ModuleItem[];
}
export const SubscriptionsView: React.FC<SubscriptionsViewProps> = ({
loggedInUser,
onOpenAuth,
onSwitchTab,
curriculumModules,
}) => {
const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(6);
const subscriptions = loggedInUser?.active_subscriptions || [];
const totalCount = subscriptions.length;
const startIndex = (currentPage - 1) * pageSize;
const paginatedSubscriptions = subscriptions.slice(startIndex, startIndex + pageSize);
return (
<div className="max-w-4xl mx-auto space-y-6 flex-1 w-full">
<div className="space-y-2">
<div className="inline-flex items-center gap-1.5 bg-indigo-50 border border-indigo-200 text-indigo-700 text-xs px-3 py-1 rounded-full font-semibold">
<CheckCircle className="h-3.5 w-3.5" /> Entitlements Ledger
</div>
<h2 className="text-3xl font-extrabold text-slate-900 tracking-tight">My Active Subscriptions</h2>
<p className="text-slate-500 text-sm leading-relaxed font-semibold">
Track your active learning passes, their validity periods, and remaining countdowns. All active subscriptions synchronize automatically inside the Acupedia iOS/Android mobile apps.
</p>
</div>
{/* Subscriptions ledger grid */}
{!loggedInUser ? (
<div className="bg-white border border-slate-200 rounded-3xl p-10 text-center space-y-4 shadow-sm">
<p className="text-sm text-slate-500 font-semibold">
Please register or log in to view active entitlements.
</p>
<button
onClick={() => onOpenAuth('login')}
className="bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-xs px-4 py-2.5 rounded-xl shadow-md transition-colors duration-300"
>
Log In
</button>
</div>
) : subscriptions.length === 0 ? (
<div className="bg-white border border-slate-200 rounded-3xl p-12 text-center space-y-4 shadow-sm">
<div className="h-14 w-14 rounded-2xl bg-indigo-50 flex items-center justify-center mx-auto text-indigo-500">
<CheckCircle className="h-6 w-6" />
</div>
<div className="space-y-1">
<h3 className="text-base font-bold text-slate-800">No active subscriptions</h3>
<p className="text-xs text-slate-500 font-semibold max-w-[320px] mx-auto leading-relaxed">
You do not currently possess any active course passes. Visit the Storefront catalog to unlock TCM learning modules.
</p>
</div>
<button
onClick={() => onSwitchTab('storefront')}
className="bg-indigo-600 hover:bg-indigo-500 text-white font-bold text-xs px-5 py-3 rounded-2xl shadow-lg shadow-indigo-600/10 transition-all duration-300 inline-flex items-center gap-1.5"
>
Explore Modules Catalog
</button>
</div>
) : (
<div className="space-y-6">
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
{paginatedSubscriptions.map((sub: any) => {
// Find module metadata matching sub.plan_code
const moduleMeta = curriculumModules.find((m) => m.code === sub.plan_code);
// Calculate days left
let daysLeft = 0;
const hasExpiry = !!sub.expires_at;
if (hasExpiry) {
const expiry = new Date(sub.expires_at);
const now = new Date();
const diffTime = expiry.getTime() - now.getTime();
daysLeft = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
}
return (
<div
key={sub.id}
className="rounded-3xl p-6 bg-white border border-slate-200/80 shadow-sm flex flex-col justify-between space-y-4 hover:border-slate-300 transition-all duration-300"
>
<div className="space-y-2">
<div className="flex justify-between items-center">
<span className="text-[10px] bg-emerald-50 text-emerald-600 border border-emerald-200 font-bold tracking-widest uppercase px-2.5 py-1 rounded-md">
ACTIVE
</span>
{sub.plan_code === 'LIFETIME_ALL' ? (
<span className="text-[10px] bg-amber-50 text-amber-700 border border-amber-200 font-bold tracking-widest uppercase px-2.5 py-1 rounded-md">
👑 10 Years Pass
</span>
) : (
<span className="text-[10px] bg-indigo-50 text-indigo-600 border border-indigo-200 font-bold tracking-widest uppercase px-2.5 py-1 rounded-md">
1 Year Pass
</span>
)}
</div>
<h3 className="text-lg font-bold text-slate-800">
{moduleMeta ? moduleMeta.name : sub.plan_code.replace(/_/g, ' ').toUpperCase()}
</h3>
<p className="text-xs text-slate-500 leading-relaxed font-semibold">
{moduleMeta ? moduleMeta.desc : 'Unlocked subscription access to module contents.'}
</p>
</div>
<div className="pt-4 border-t border-slate-100 flex flex-col gap-2">
<div className="flex justify-between text-xs font-semibold text-slate-500">
<span>Activated:</span>
<span className="text-slate-800 font-bold">
{sub.started_at
? new Date(sub.started_at).toLocaleDateString(undefined, { dateStyle: 'medium' })
: 'N/A'}
</span>
</div>
<div className="flex justify-between text-xs font-semibold text-slate-500">
<span>Expires:</span>
<span className="text-slate-800 font-bold">
{hasExpiry
? new Date(sub.expires_at).toLocaleDateString(undefined, { dateStyle: 'medium' })
: 'Lifetime'}
</span>
</div>
<div className="mt-2 flex justify-between items-center bg-slate-50 p-3 rounded-2xl border border-slate-100">
<span className="text-[11px] text-slate-500 font-bold uppercase tracking-wider">
Validity Remaining:
</span>
{!hasExpiry ? (
<span className="text-xs bg-amber-100 text-amber-800 border border-amber-200 font-extrabold px-3 py-1 rounded-xl shadow-sm animate-pulse">
Lifetime Access
</span>
) : sub.plan_code === 'LIFETIME_ALL' ? (
<span className="text-xs bg-amber-100 text-amber-800 border border-amber-200 font-extrabold px-3 py-1 rounded-xl shadow-sm animate-pulse">
{daysLeft > 0 ? `${(daysLeft / 365).toFixed(1)} Years Left` : 'Expired'}
</span>
) : (
<span className="text-xs bg-emerald-100 text-emerald-800 border border-emerald-200 font-extrabold px-3 py-1 rounded-xl shadow-sm">
{daysLeft > 0 ? `${daysLeft} Days Left` : 'Expired'}
</span>
)}
</div>
</div>
</div>
);
})}
</div>
{/* Pagination Controls */}
{totalCount > 6 && (
<div className="bg-white rounded-2xl border border-slate-200/80 p-2 shadow-sm">
<Pagination
currentPage={currentPage}
totalItems={totalCount}
itemsPerPage={pageSize}
onPageChange={setCurrentPage}
onItemsPerPageChange={(size) => {
setPageSize(size);
setCurrentPage(1);
}}
pageSizeOptions={[6, 12, 24]}
/>
</div>
)}
</div>
)}
</div>
);
};

View File

@ -0,0 +1,23 @@
export interface CountryCode {
code: string;
label: string;
country: string;
}
export const COUNTRY_CODES: CountryCode[] = [
{ code: '+91', label: '🇮🇳 +91', country: 'India' },
{ code: '+1', label: '🇺🇸 +1', country: 'US' },
{ code: '+44', label: '🇬🇧 +44', country: 'UK' },
{ code: '+61', label: '🇦🇺 +61', country: 'AU' },
{ code: '+49', label: '🇩🇪 +49', country: 'DE' },
{ code: '+33', label: '🇫🇷 +33', country: 'FR' },
{ code: '+81', label: '🇯🇵 +81', country: 'JP' },
{ code: '+86', label: '🇨🇳 +86', country: 'CN' },
{ code: '+971', label: '🇦🇪 +971', country: 'UAE' },
{ code: '+65', label: '🇸🇬 +65', country: 'SG' },
{ code: '+55', label: '🇧🇷 +55', country: 'BR' },
{ code: '+82', label: '🇰🇷 +82', country: 'KR' },
{ code: '+7', label: '🇷🇺 +7', country: 'RU' },
{ code: '+27', label: '🇿🇦 +27', country: 'ZA' },
{ code: '+234', label: '🇳🇬 +234', country: 'NG' },
];

43
src/constants/modules.ts Normal file
View File

@ -0,0 +1,43 @@
export interface ModuleItem {
code: string;
name: string;
category: string;
priceInr: number;
priceUsd: number;
priceEur: number;
desc: string;
color: string;
}
export const CURRICULUM_MODULES: ModuleItem[] = [
// 1. Points Category
{ code: 'POINTS_ACU', name: 'Points: Acu (EOV+Cat+Ext+MR)', category: 'Points', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Unlocks Master Acupuncture Points, Extraordinary Vessels, Category/Extension Rules, and Meridian Stimulations.', color: 'from-blue-500 to-indigo-600' },
{ code: 'POINTS_SCALP', name: 'Points: Scalp', category: 'Points', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Unlocks High-Performance Scalp Acupuncture Mapping for specialized clinical neurological disorders.', color: 'from-indigo-500 to-purple-600' },
{ code: 'POINTS_EAR', name: 'Points: Ear / Auricular', category: 'Points', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Unlocks specialized Ear Micro-System Reflex stimulations, anatomy mapping, and reflexes.', color: 'from-purple-500 to-pink-600' },
{ code: 'POINTS_TUNG', name: 'Master Tung', category: 'Points', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Unlocks Master Tung\'s legendary extra points, clinical distals, and unique point properties.', color: 'from-pink-500 to-rose-600' },
{ code: 'POINTS_PACK', name: 'Points: Complete Pack', category: 'Points', priceInr: 2, priceUsd: 2.0, priceEur: 2.0, desc: '1 Year: Unlock all 4 Points modules (Acu, Scalp, Ear, and Master Tung) at once for ultimate master-level access.', color: 'from-indigo-600 to-pink-600' },
// 2. Pattern Category — Individual sub-modules (all map to PATTERN_CORE plan)
{ code: 'PATTERN_CORE', name: 'Eight Principles', category: 'Pattern', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Exterior/Interior, Cold/Heat, Deficiency/Excess, Yin/Yang pattern differentiation.', color: 'from-violet-500 to-purple-600' },
{ code: 'PATTERN_CORE', name: 'Zang-Fu Organs', category: 'Pattern', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Zangfu organ and channel identification across 12 organ systems.', color: 'from-cyan-500 to-blue-600' },
{ code: 'PATTERN_CORE', name: 'Qi, Blood & Body Fluids', category: 'Pattern', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Qi, Blood, and Body Fluid identification of pathological patterns.', color: 'from-blue-500 to-indigo-600' },
{ code: 'PATTERN_CORE', name: 'Pathogenic Factors', category: 'Pattern', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Wind, Cold, Summer-Heat, Dampness, Dryness, Fire pattern identification.', color: 'from-amber-500 to-orange-600' },
{ code: 'PATTERN_CORE', name: 'Six Stages', category: 'Pattern', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Tai Yang, Yang Ming, Shao Yang, Tai Yin, Shao Yin, Jue Yin stage differentiation.', color: 'from-emerald-500 to-green-600' },
{ code: 'PATTERN_CORE', name: 'Four Levels', category: 'Pattern', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Wei, Qi, Ying, Xue level pattern identification for warm diseases.', color: 'from-red-500 to-rose-600' },
{ code: 'PATTERN_CORE', name: 'Three Burners', category: 'Pattern', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Upper, Middle, and Lower Burner (San Jiao) pattern identification.', color: 'from-pink-500 to-fuchsia-600' },
{ code: 'PATTERN_CORE', name: 'Five Elements', category: 'Pattern', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Wood, Fire, Earth, Metal, Water relationships and clinical patterns.', color: 'from-indigo-500 to-violet-600' },
{ code: 'PATTERN_CORE', name: 'Pattern: Complete Pack', category: 'Pattern', priceInr: 2, priceUsd: 2.0, priceEur: 2.0, desc: '1 Year: Unlock all 8 Pattern Diagnosis methodologies at once for complete syndrome differentiation mastery.', color: 'from-rose-600 to-orange-600' },
// 3. Nutrition Category — Individual sub-modules (all map to NUTRITION_CORE plan)
{ code: 'NUTRITION_CORE', name: 'Food Categories', category: 'Nutrition', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Nutritional food category classifications, thermal properties, and dietetic groupings.', color: 'from-emerald-500 to-teal-600' },
{ code: 'NUTRITION_CORE', name: 'Food Items', category: 'Nutrition', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Individual food item properties, indications, and therapeutic applications.', color: 'from-green-500 to-emerald-600' },
{ code: 'NUTRITION_CORE', name: 'Nutrition: Complete Pack', category: 'Nutrition', priceInr: 2, priceUsd: 2.0, priceEur: 2.0, desc: '1 Year: Unlock all Nutrition & Dietetics modules for complete clinical dietary therapy mastery.', color: 'from-teal-500 to-green-600' },
// 4. Therapeutics Category
{ code: 'THERAPEUTICS_GYNAE', name: 'Therapeutics: Gynecology', category: 'Therapeutics', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Unlocks advanced clinical Gynecology treatment protocols, syndromes, and corresponding points.', color: 'from-teal-500 to-cyan-500' },
{ code: 'THERAPEUTICS_EAR', name: 'Therapeutics: Ear reflexology', category: 'Therapeutics', priceInr: 1, priceUsd: 1.0, priceEur: 1.0, desc: '1 Year: Unlocks comprehensive ear micro-system treatment procedures and specific clinical ear protocols.', color: 'from-cyan-500 to-blue-600' },
{ code: 'THERAPEUTICS_CORE', name: 'Therapeutics Complete Bundle', category: 'Therapeutics', priceInr: 2, priceUsd: 2.0, priceEur: 2.0, desc: '1 Year: Unlocks both advanced clinical Gynecology and Ear Reflexology therapeutics treatment protocols.', color: 'from-teal-500 to-blue-600' },
// 5. Lifetime Access
{ code: 'LIFETIME_ALL', name: 'Lifetime Unlimited Access Pass', category: 'Lifetime', priceInr: 2, priceUsd: 2.0, priceEur: 2.0, desc: '10 Years: Unlock all 10 current modules + all future updates. Includes official master clinical certificate.', color: 'from-yellow-500 to-amber-600' }
];

97
src/index.css Normal file
View File

@ -0,0 +1,97 @@
@import "tailwindcss";
@theme {
--color-brand-dark: #0B0B0F;
--color-brand-card: #12121A;
--color-brand-border: #1E1E2C;
--color-brand-accent: #6366F1;
--color-brand-cyan: #06B6D4;
--color-brand-emerald: #10B981;
--color-brand-rose: #EF4444;
}
body {
background-color: #F8FAFC; /* Premium light slate background */
color: #0F172A; /* Dark slate text for maximum high-contrast clinical readability */
font-family: 'Outfit', sans-serif;
background-image:
radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.02) 0%, transparent 45%),
radial-gradient(circle at 90% 80%, rgba(6, 182, 212, 0.02) 0%, transparent 45%);
background-attachment: fixed;
}
/* Custom Scrollbar for Light Theme pages */
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-track {
background: #F8FAFC;
}
::-webkit-scrollbar-thumb {
background: #CBD5E1;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #94A3B8;
}
/* Glassmorphism Classes adapted for Light theme panels */
.glass-panel {
background: rgba(255, 255, 255, 0.8);
backdrop-filter: blur(12px);
border: 1px solid rgba(15, 23, 42, 0.06);
}
.glass-card {
background: rgba(255, 255, 255, 0.5);
backdrop-filter: blur(8px);
border: 1px solid rgba(15, 23, 42, 0.04);
}
/* Premium Gradients */
.gradient-text {
background-clip: text;
-webkit-background-clip: text;
color: transparent;
background-image: linear-gradient(to right, #4F46E5, #0891B2, #059669);
}
.gradient-border-hover {
position: relative;
transition: all 0.3s ease;
}
.gradient-border-hover::before {
content: '';
position: absolute;
inset: 0;
border-radius: inherit;
padding: 1px;
background: linear-gradient(to right, transparent, transparent);
-webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
pointer-events: none;
transition: all 0.3s ease;
}
.gradient-border-hover:hover::before {
background: linear-gradient(to right, #6366F1, #06B6D4);
}
@keyframes slideIn {
from {
transform: translateX(100%);
}
to {
transform: translateX(0);
}
}
.animate-slide-in {
animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

10
src/main.tsx Normal file
View File

@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)

19
src/services/api.ts Normal file
View File

@ -0,0 +1,19 @@
import axios from 'axios';
export const API_BASE = (import.meta.env.VITE_API_BASE !== undefined && import.meta.env.VITE_API_BASE !== null && import.meta.env.VITE_API_BASE !== '')
? import.meta.env.VITE_API_BASE
: (typeof window !== 'undefined' && (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'))
? 'http://localhost:8000'
: '';
export const api = axios.create({
baseURL: API_BASE,
});
api.interceptors.request.use((config) => {
const token = localStorage.getItem('access_token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
}
return config;
});

12
src/services/razorpay.ts Normal file
View File

@ -0,0 +1,12 @@
export const loadRazorpayScript = (): Promise<boolean> => {
return new Promise((resolve) => {
if (typeof window === 'undefined') return resolve(false);
if ((window as any).Razorpay) return resolve(true);
const script = document.createElement('script');
script.src = 'https://checkout.razorpay.com/v1/checkout.js';
script.onload = () => resolve(true);
script.onerror = () => resolve(false);
document.body.appendChild(script);
});
};

88
src/types/index.ts Normal file
View File

@ -0,0 +1,88 @@
export type Currency = 'INR' | 'USD' | 'EUR';
export interface ModuleItem {
code: string;
name: string;
category: string;
priceInr: number;
priceUsd: number;
priceEur: number;
desc: string;
color: string;
}
export interface UserSubscription {
id: string;
user_id: string;
plan_code: string;
started_at?: string;
starts_at?: string;
expires_at?: string;
is_active: boolean;
payment_id?: string;
metadata?: Record<string, any>;
}
export interface UserProfile {
id: string;
email: string;
display_name: string;
full_name?: string;
phone?: string;
phone_number?: string;
country?: string;
roles?: string[];
external_ref?: string;
active_subscriptions: UserSubscription[];
created_at?: string;
}
export interface PricingCalculation {
original_price: number;
discount_amount: number;
taxable_amount: number;
gst_amount: number;
convenience_fee?: number;
convenience_fee_rate?: number;
grand_total: number;
total_amount?: number;
currency: Currency;
applied_coupon?: {
code: string;
discount_type: 'percentage' | 'fixed';
discount_value: number;
discount_amount: number;
} | null;
items?: Array<{
code: string;
name: string;
unit_price: number;
}>;
}
export interface PublicPlan {
code: string;
base_code?: string;
name: string;
price_inr?: number;
price_usd?: number;
price_eur?: number;
is_active?: boolean;
badge_text?: string;
heading?: string;
subtitle?: string;
description?: string;
modules?: Array<{ id?: string; name: string; slug?: string }>;
}
export interface VerificationResult {
status: 'success' | 'error';
paymentId?: string;
orderId?: string;
invoiceNumber?: string;
invoiceUrl?: string;
amount?: number;
currency?: Currency;
items?: string[];
message?: string;
}

24
tsconfig.app.json Normal file
View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "es2023",
"lib": ["ES2023", "DOM"],
"module": "esnext",
"types": ["vite/client"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}

7
tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

23
tsconfig.node.json Normal file
View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "es2023",
"lib": ["ES2023"],
"module": "esnext",
"types": ["node"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["vite.config.ts"]
}

11
vite.config.ts Normal file
View File

@ -0,0 +1,11 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
base: process.env.VITE_BASE_PATH || '/store/',
plugins: [react()],
server: {
port: 3000,
}
})