feat: initial commit for standalone acupedia admin portal
This commit is contained in:
commit
b4718ec41f
|
|
@ -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., /admin/ or / if using a subdomain like admin.acupedia.in)
|
||||
VITE_BASE_PATH=/admin/
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
# Acupedia Admin Console
|
||||
|
||||
Administrative web portal for managing curriculum modules, subscription pricing, coupons, practitioners, transaction ledgers, and database backups.
|
||||
|
||||
## Tech Stack
|
||||
- **Framework**: React 19 + TypeScript + Vite
|
||||
- **Styling**: TailwindCSS v4
|
||||
- **Icons**: Lucide React
|
||||
- **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:3001/admin/`.
|
||||
|
||||
## 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: `/admin/`).
|
||||
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
])
|
||||
|
|
@ -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 Administrative Suite - Backoffice controls, ledger, payment verification, and curriculum manager." />
|
||||
|
||||
<!-- 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 Admin Console</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>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "panacea-admin-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"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
export default {
|
||||
plugins: {
|
||||
'@tailwindcss/postcss': {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
|
|
@ -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 |
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,101 @@
|
|||
import React from 'react';
|
||||
import { Sparkles, AlertCircle, Shield, Eye, EyeOff } from 'lucide-react';
|
||||
|
||||
interface AdminLoginFormProps {
|
||||
email: string;
|
||||
password: string;
|
||||
showPassword: boolean;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
loggedInUser: any;
|
||||
isAdmin: boolean;
|
||||
onEmailChange: (v: string) => void;
|
||||
onPasswordChange: (v: string) => void;
|
||||
onToggleShowPassword: () => void;
|
||||
onSubmit: (e: React.FormEvent) => void;
|
||||
}
|
||||
|
||||
export const AdminLoginForm: React.FC<AdminLoginFormProps> = ({
|
||||
email,
|
||||
password,
|
||||
showPassword,
|
||||
loading,
|
||||
error,
|
||||
loggedInUser,
|
||||
isAdmin,
|
||||
onEmailChange,
|
||||
onPasswordChange,
|
||||
onToggleShowPassword,
|
||||
onSubmit,
|
||||
}) => {
|
||||
return (
|
||||
<div className="min-h-screen bg-[#08080C] text-slate-100 flex items-center justify-center p-4 selection:bg-indigo-500 selection:text-white">
|
||||
<div className="w-full max-w-md bg-slate-900/90 border border-slate-800 rounded-3xl p-8 shadow-2xl backdrop-blur-xl space-y-6">
|
||||
<div className="text-center space-y-2">
|
||||
<div className="h-12 w-12 rounded-2xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center mx-auto shadow-lg shadow-indigo-500/20">
|
||||
<Sparkles className="h-6 w-6 text-white" />
|
||||
</div>
|
||||
<h1 className="text-xl font-black tracking-tight text-white">ACUPEDIA BACKOFFICE</h1>
|
||||
<p className="text-xs text-slate-400 font-semibold">Clinical Platform Administrative Suite</p>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="p-3 bg-rose-500/10 border border-rose-500/30 text-rose-400 text-xs rounded-xl font-bold flex items-center gap-2">
|
||||
<AlertCircle className="h-4 w-4 shrink-0" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{loggedInUser && !isAdmin && (
|
||||
<div className="p-3 bg-amber-500/10 border border-amber-500/30 text-amber-400 text-xs rounded-xl font-bold flex items-center gap-2">
|
||||
<Shield className="h-4 w-4 shrink-0" />
|
||||
<span>Account {loggedInUser.email} lacks administrative privileges.</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={onSubmit} className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-400">Admin Email</label>
|
||||
<input
|
||||
type="email"
|
||||
required
|
||||
value={email}
|
||||
onChange={(e) => onEmailChange(e.target.value)}
|
||||
placeholder="admin@acupedia.in"
|
||||
className="w-full px-4 py-3 rounded-xl bg-slate-800/80 border border-slate-700 text-white text-xs font-semibold focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<label className="text-[10px] uppercase font-black tracking-wider text-slate-400">Password</label>
|
||||
<div className="relative">
|
||||
<input
|
||||
type={showPassword ? 'text' : 'password'}
|
||||
required
|
||||
value={password}
|
||||
onChange={(e) => onPasswordChange(e.target.value)}
|
||||
placeholder="••••••••"
|
||||
className="w-full px-4 py-3 rounded-xl bg-slate-800/80 border border-slate-700 text-white text-xs font-semibold focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleShowPassword}
|
||||
className="absolute right-3 top-3 text-slate-400 hover:text-white cursor-pointer"
|
||||
>
|
||||
{showPassword ? <EyeOff className="h-4 w-4" /> : <Eye className="h-4 w-4" />}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full py-3 bg-indigo-600 hover:bg-indigo-500 disabled:bg-slate-800 text-white text-xs font-black rounded-xl transition-all shadow-lg shadow-indigo-600/20 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{loading ? 'Authenticating...' : 'Sign In to Console'}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
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 = [5, 10, 20, 50],
|
||||
}) => {
|
||||
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;
|
||||
}
|
||||
|
||||
// Calculate page numbers to display with smart ellipsis
|
||||
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-4 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>entries</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> entries
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,342 @@
|
|||
import React from 'react';
|
||||
import { Ticket, Edit, Percent, Calendar, Tag, DollarSign, RefreshCw } from 'lucide-react';
|
||||
|
||||
export interface CouponFormData {
|
||||
code: string;
|
||||
category: string;
|
||||
discountType: 'percentage' | 'flat';
|
||||
discountValue: string;
|
||||
maxDiscountCap: string;
|
||||
description: string;
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
scope: 'storewide' | 'specific';
|
||||
applicablePlanIds: string[];
|
||||
applicableModuleIds: string[];
|
||||
minSpend: string;
|
||||
usageLimit: string;
|
||||
firstOnly: boolean;
|
||||
}
|
||||
|
||||
interface CouponModalProps {
|
||||
mode: 'create' | 'edit' | null;
|
||||
data: CouponFormData;
|
||||
plans: any[];
|
||||
modules: any[];
|
||||
saving: boolean;
|
||||
onChange: (field: keyof CouponFormData, val: any) => void;
|
||||
onSave: (e: React.FormEvent) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const CouponModal: React.FC<CouponModalProps> = ({
|
||||
mode,
|
||||
data,
|
||||
plans,
|
||||
modules,
|
||||
saving,
|
||||
onChange,
|
||||
onSave,
|
||||
onClose,
|
||||
}) => {
|
||||
if (!mode) return null;
|
||||
|
||||
const isEdit = mode === 'edit';
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4">
|
||||
<div className="bg-white rounded-3xl border border-slate-200 shadow-2xl max-w-xl w-full p-6 space-y-5 max-h-[90vh] overflow-y-auto animate-in fade-in zoom-in duration-150">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between border-b border-slate-100 pb-3">
|
||||
<div>
|
||||
<h3 className="text-base font-bold text-slate-800 flex items-center gap-2">
|
||||
{isEdit ? <Edit className="h-4 w-4 text-indigo-600" /> : <Ticket className="h-4 w-4 text-indigo-600" />}
|
||||
{isEdit ? `Edit Coupon: ${data.code}` : 'Create Promotional Coupon'}
|
||||
</h3>
|
||||
<p className="text-xs text-slate-400">
|
||||
Configure discount rules, date schedule, scope, and cart thresholds.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="text-slate-400 hover:text-slate-600 p-1 cursor-pointer"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form onSubmit={onSave} className="space-y-4">
|
||||
{/* BLOCK 1: Code & Discount Value */}
|
||||
<div className="bg-slate-50/80 border border-slate-200/80 rounded-2xl p-4 space-y-3">
|
||||
<div className="flex items-center gap-1.5 border-b border-slate-200/60 pb-2">
|
||||
<Percent className="h-3.5 w-3.5 text-indigo-600" />
|
||||
<span className="text-xs font-bold text-slate-700">Block 1: Promo Code & Discount Value</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Coupon Code *</label>
|
||||
<input
|
||||
type="text"
|
||||
required
|
||||
placeholder="e.g. FLASH50"
|
||||
disabled={isEdit}
|
||||
value={data.code}
|
||||
onChange={(e) => onChange('code', e.target.value.toUpperCase())}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-mono font-bold text-slate-800 uppercase focus:outline-none focus:border-indigo-500 disabled:bg-slate-100"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Category</label>
|
||||
<select
|
||||
value={data.category}
|
||||
onChange={(e) => onChange('category', e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="general">General Promo</option>
|
||||
<option value="introductory">Introductory (New User)</option>
|
||||
<option value="seasonal">Seasonal / Flash Sale</option>
|
||||
<option value="loyalty">Loyalty / Staggered</option>
|
||||
<option value="referral">Referral Partner</option>
|
||||
<option value="institutional">Institutional / Student</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-3 gap-3">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Discount Type</label>
|
||||
<select
|
||||
value={data.discountType}
|
||||
onChange={(e) => onChange('discountType', e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="percentage">Percentage (%)</option>
|
||||
<option value="flat">Flat Amount (₹/$)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">
|
||||
{data.discountType === 'percentage' ? 'Percentage (%) *' : 'Flat Amount *'}
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0.01"
|
||||
required
|
||||
value={data.discountValue}
|
||||
onChange={(e) => onChange('discountValue', e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Max Cap (0=None)</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
disabled={data.discountType !== 'percentage'}
|
||||
value={data.maxDiscountCap}
|
||||
onChange={(e) => onChange('maxDiscountCap', e.target.value)}
|
||||
placeholder="0"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 disabled:opacity-50"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Description / Campaign Note</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. Festival 50% discount up to ₹1,000"
|
||||
value={data.description}
|
||||
onChange={(e) => onChange('description', e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BLOCK 2: Schedule & Validity */}
|
||||
<div className="bg-slate-50/80 border border-slate-200/80 rounded-2xl p-4 space-y-3">
|
||||
<div className="flex items-center gap-1.5 border-b border-slate-200/60 pb-2">
|
||||
<Calendar className="h-3.5 w-3.5 text-indigo-600" />
|
||||
<span className="text-xs font-bold text-slate-700">Block 2: Schedule & Date Window</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Start Date</label>
|
||||
<input
|
||||
type="date"
|
||||
value={data.startDate}
|
||||
onChange={(e) => onChange('startDate', e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Expiration Date</label>
|
||||
<input
|
||||
type="date"
|
||||
value={data.endDate}
|
||||
onChange={(e) => onChange('endDate', e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* BLOCK 3: Scope & Item Restrictions */}
|
||||
<div className="bg-slate-50/80 border border-slate-200/80 rounded-2xl p-4 space-y-3">
|
||||
<div className="flex items-center gap-1.5 border-b border-slate-200/60 pb-2">
|
||||
<Tag className="h-3.5 w-3.5 text-indigo-600" />
|
||||
<span className="text-xs font-bold text-slate-700">Block 3: Scope & Applicability</span>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-4">
|
||||
<label className="flex items-center gap-2 cursor-pointer text-xs font-bold text-slate-700">
|
||||
<input
|
||||
type="radio"
|
||||
name="couponScope"
|
||||
checked={data.scope === 'storewide'}
|
||||
onChange={() => onChange('scope', 'storewide')}
|
||||
className="accent-indigo-600"
|
||||
/>
|
||||
Entire Storefront (All Items)
|
||||
</label>
|
||||
<label className="flex items-center gap-2 cursor-pointer text-xs font-bold text-slate-700">
|
||||
<input
|
||||
type="radio"
|
||||
name="couponScope"
|
||||
checked={data.scope === 'specific'}
|
||||
onChange={() => onChange('scope', 'specific')}
|
||||
className="accent-indigo-600"
|
||||
/>
|
||||
Specific Plans & Modules Only
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{data.scope === 'specific' && (
|
||||
<div className="space-y-2 pt-2 border-t border-slate-200/60">
|
||||
<div>
|
||||
<label className="block text-[10px] font-bold text-slate-500 uppercase tracking-wider mb-1">
|
||||
Qualifying Plans
|
||||
</label>
|
||||
<div className="max-h-28 overflow-y-auto bg-white border border-slate-200 rounded-xl p-2 space-y-1.5">
|
||||
{plans.map((p) => {
|
||||
const pid = p.inr_plan_id || p.id;
|
||||
const checked = data.applicablePlanIds.includes(pid);
|
||||
return (
|
||||
<label key={p.base_code || p.code} className="flex items-center gap-2 text-xs text-slate-700 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) onChange('applicablePlanIds', [...data.applicablePlanIds, pid]);
|
||||
else onChange('applicablePlanIds', data.applicablePlanIds.filter((x) => x !== pid));
|
||||
}}
|
||||
className="accent-indigo-600 rounded"
|
||||
/>
|
||||
<span className="font-semibold">{p.name} ({p.base_code || p.code})</span>
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-[10px] font-bold text-slate-500 uppercase tracking-wider mb-1">
|
||||
Qualifying Modules
|
||||
</label>
|
||||
<div className="max-h-28 overflow-y-auto bg-white border border-slate-200 rounded-xl p-2 space-y-1.5">
|
||||
{modules.map((m) => {
|
||||
const checked = data.applicableModuleIds.includes(m.id);
|
||||
return (
|
||||
<label key={m.id} className="flex items-center gap-2 text-xs text-slate-700 cursor-pointer">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={checked}
|
||||
onChange={(e) => {
|
||||
if (e.target.checked) onChange('applicableModuleIds', [...data.applicableModuleIds, m.id]);
|
||||
else onChange('applicableModuleIds', data.applicableModuleIds.filter((x) => x !== m.id));
|
||||
}}
|
||||
className="accent-indigo-600 rounded"
|
||||
/>
|
||||
<span className="font-semibold">{m.name}</span>
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* BLOCK 4: Conditions & Thresholds */}
|
||||
<div className="bg-slate-50/80 border border-slate-200/80 rounded-2xl p-4 space-y-3">
|
||||
<div className="flex items-center gap-1.5 border-b border-slate-200/60 pb-2">
|
||||
<DollarSign className="h-3.5 w-3.5 text-indigo-600" />
|
||||
<span className="text-xs font-bold text-slate-700">Block 4: Conditions & Usage Limits</span>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Min Spend (0=None)</label>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
value={data.minSpend}
|
||||
onChange={(e) => onChange('minSpend', e.target.value)}
|
||||
placeholder="0"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Global Usage Limit (0=None)</label>
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
value={data.usageLimit}
|
||||
onChange={(e) => onChange('usageLimit', e.target.value)}
|
||||
placeholder="0"
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label className="flex items-center gap-2 cursor-pointer pt-1">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={data.firstOnly}
|
||||
onChange={(e) => onChange('firstOnly', e.target.checked)}
|
||||
className="accent-indigo-600 rounded"
|
||||
/>
|
||||
<span className="text-xs font-bold text-slate-700">
|
||||
First Purchase Only (Exclusive to new customers with 0 prior subscriptions)
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex gap-3 pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="flex-1 py-2.5 rounded-xl text-xs font-bold bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors cursor-pointer"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="flex-1 py-2.5 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors flex items-center justify-center gap-1.5 shadow-md shadow-indigo-600/20 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{saving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : isEdit ? 'Save Changes' : 'Save & Publish Coupon'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,328 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Ticket, Plus, Check, Copy, Edit, Trash2 } from 'lucide-react';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
|
||||
interface CouponsTabProps {
|
||||
coupons: any[];
|
||||
filterStatus: 'all' | 'active' | 'scheduled' | 'expired';
|
||||
searchQuery: string;
|
||||
currentPage: number;
|
||||
perPage: number;
|
||||
onFilterStatusChange: (status: 'all' | 'active' | 'scheduled' | 'expired') => void;
|
||||
onSearchChange: (query: string) => void;
|
||||
onPageChange: (page: number) => void;
|
||||
onPerPageChange: (perPage: number) => void;
|
||||
onOpenCreateCoupon: () => void;
|
||||
onOpenEditCoupon: (coupon: any) => void;
|
||||
onToggleStatus: (coupon: any) => void;
|
||||
onDeleteCoupon: (coupon: any) => void;
|
||||
}
|
||||
|
||||
export const CouponsTab: React.FC<CouponsTabProps> = ({
|
||||
coupons,
|
||||
filterStatus,
|
||||
searchQuery,
|
||||
currentPage,
|
||||
perPage,
|
||||
onFilterStatusChange,
|
||||
onSearchChange,
|
||||
onPageChange,
|
||||
onPerPageChange,
|
||||
onOpenCreateCoupon,
|
||||
onOpenEditCoupon,
|
||||
onToggleStatus,
|
||||
onDeleteCoupon,
|
||||
}) => {
|
||||
const [copiedCode, setCopiedCode] = useState<string | null>(null);
|
||||
|
||||
const handleCopyCode = (code: string) => {
|
||||
navigator.clipboard.writeText(code);
|
||||
setCopiedCode(code);
|
||||
setTimeout(() => setCopiedCode(null), 2000);
|
||||
};
|
||||
|
||||
const filteredCoupons = coupons.filter((c) => {
|
||||
if (filterStatus !== 'all' && c.schedule_status !== filterStatus) return false;
|
||||
if (searchQuery.trim()) {
|
||||
const q = searchQuery.toLowerCase();
|
||||
return (
|
||||
c.code.toLowerCase().includes(q) ||
|
||||
(c.description && c.description.toLowerCase().includes(q))
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
const totalFiltered = filteredCoupons.length;
|
||||
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
||||
const safePage = Math.min(currentPage, totalPages);
|
||||
const startIndex = (safePage - 1) * perPage;
|
||||
const paginatedCoupons = filteredCoupons.slice(startIndex, startIndex + perPage);
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Top KPI Cards */}
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-slate-800">{coupons.length}</p>
|
||||
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mt-1">Total Promo Codes</p>
|
||||
</div>
|
||||
<div className="bg-emerald-50/60 border border-emerald-200/60 rounded-2xl p-4 text-center">
|
||||
<div className="flex items-center justify-center gap-1.5">
|
||||
<div className="h-2 w-2 rounded-full bg-emerald-500 animate-pulse" />
|
||||
<p className="text-2xl font-black text-emerald-700">
|
||||
{coupons.filter((c) => c.schedule_status === 'active').length}
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-[10px] font-bold text-emerald-600 uppercase tracking-wider mt-1">Active Now</p>
|
||||
</div>
|
||||
<div className="bg-amber-50/60 border border-amber-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-amber-700">
|
||||
{coupons.filter((c) => c.schedule_status === 'scheduled').length}
|
||||
</p>
|
||||
<p className="text-[10px] font-bold text-amber-600 uppercase tracking-wider mt-1">Scheduled / Upcoming</p>
|
||||
</div>
|
||||
<div className="bg-indigo-50/60 border border-indigo-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-indigo-700">
|
||||
{coupons.reduce((acc, c) => acc + (c.usage_count || 0), 0)}
|
||||
</p>
|
||||
<p className="text-[10px] font-bold text-indigo-600 uppercase tracking-wider mt-1">Total Redemptions</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Filter & Action Controls */}
|
||||
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4 bg-slate-50/80 border border-slate-200/60 rounded-2xl p-4">
|
||||
{/* Filter Pills */}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{(['all', 'active', 'scheduled', 'expired'] as const).map((status) => (
|
||||
<button
|
||||
key={status}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onFilterStatusChange(status);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-bold capitalize transition-all cursor-pointer ${
|
||||
filterStatus === status
|
||||
? 'bg-indigo-600 text-white shadow-sm'
|
||||
: 'bg-white text-slate-600 border border-slate-200 hover:bg-slate-100 shadow-sm'
|
||||
}`}
|
||||
>
|
||||
{status === 'all'
|
||||
? `All (${coupons.length})`
|
||||
: `${status} (${coupons.filter((c) => c.schedule_status === status).length})`}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 w-full sm:w-auto">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search code or description..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => {
|
||||
onSearchChange(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 placeholder:text-slate-400 focus:outline-none focus:border-indigo-500 w-full sm:w-56 shadow-sm"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpenCreateCoupon}
|
||||
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white shadow-md shadow-indigo-600/20 transition-all cursor-pointer whitespace-nowrap"
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5" /> Create Coupon
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Coupons Table */}
|
||||
{filteredCoupons.length === 0 ? (
|
||||
<div className="text-center py-16 bg-slate-50/50 rounded-2xl border border-slate-200/60">
|
||||
<Ticket className="h-10 w-10 text-slate-300 mx-auto mb-2" />
|
||||
<p className="text-sm font-bold text-slate-600">No promotional coupons found</p>
|
||||
<p className="text-xs text-slate-400 mt-0.5">Click "+ Create Coupon" above to launch a new discount code.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left text-xs">
|
||||
<thead className="bg-slate-50 border-b border-slate-200 text-slate-500 uppercase tracking-wider text-[10px] font-extrabold">
|
||||
<tr>
|
||||
<th className="py-3 px-4">Coupon Code</th>
|
||||
<th className="py-3 px-4">Discount Value</th>
|
||||
<th className="py-3 px-4">Schedule / Status</th>
|
||||
<th className="py-3 px-4">Redemptions</th>
|
||||
<th className="py-3 px-4">Scope & Conditions</th>
|
||||
<th className="py-3 px-4 text-center">Active</th>
|
||||
<th className="py-3 px-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100">
|
||||
{paginatedCoupons.map((c) => {
|
||||
const isPercent = c.discount_type === 'percentage';
|
||||
const hasCap = isPercent && c.max_discount_limit > 0;
|
||||
const usageLimit = c.usage_limit || 0;
|
||||
const usageCount = c.usage_count || 0;
|
||||
const hasSpecific =
|
||||
(c.applicable_plan_ids && c.applicable_plan_ids.length > 0) ||
|
||||
(c.applicable_module_ids && c.applicable_module_ids.length > 0);
|
||||
|
||||
return (
|
||||
<tr key={c.id} className="hover:bg-slate-50/70 transition-colors">
|
||||
{/* Code */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="font-mono font-black text-indigo-700 bg-indigo-50 border border-indigo-200/80 px-2.5 py-1 rounded-lg text-xs tracking-wider">
|
||||
{c.code}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleCopyCode(c.code)}
|
||||
title="Copy promo code"
|
||||
className="text-slate-400 hover:text-indigo-600 p-1 transition-colors cursor-pointer"
|
||||
>
|
||||
{copiedCode === c.code ? (
|
||||
<Check className="h-3.5 w-3.5 text-emerald-500" />
|
||||
) : (
|
||||
<Copy className="h-3.5 w-3.5" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
{c.description && (
|
||||
<p className="text-[10px] text-slate-400 font-semibold mt-1 max-w-[200px] truncate">
|
||||
{c.description}
|
||||
</p>
|
||||
)}
|
||||
</td>
|
||||
|
||||
{/* Value */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
<div className="inline-flex items-center gap-1 font-extrabold text-slate-800 text-xs">
|
||||
{isPercent ? `${c.value}% OFF` : `₹${c.value} FLAT`}
|
||||
</div>
|
||||
{hasCap && (
|
||||
<p className="text-[10px] text-slate-400 font-semibold mt-0.5">
|
||||
Cap: ₹{c.max_discount_limit}
|
||||
</p>
|
||||
)}
|
||||
<span className="block text-[9px] font-bold text-slate-400 capitalize mt-0.5">
|
||||
Category: {c.coupon_category || 'General'}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* Schedule */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
<span
|
||||
className={`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-extrabold tracking-wider uppercase border ${
|
||||
c.schedule_status === 'active'
|
||||
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
||||
: c.schedule_status === 'scheduled'
|
||||
? 'bg-amber-50 text-amber-700 border-amber-200'
|
||||
: c.schedule_status === 'expired'
|
||||
? 'bg-rose-50 text-rose-700 border-rose-200'
|
||||
: 'bg-slate-100 text-slate-500 border-slate-200'
|
||||
}`}
|
||||
>
|
||||
{c.schedule_status === 'active' && (
|
||||
<span className="h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse" />
|
||||
)}
|
||||
{c.schedule_status}
|
||||
</span>
|
||||
<p className="text-[10px] text-slate-400 font-medium mt-1">
|
||||
{c.start_date?.split('T')[0] || '—'} → {c.end_date?.split('T')[0] || '—'}
|
||||
</p>
|
||||
</td>
|
||||
|
||||
{/* Usage */}
|
||||
<td className="py-3.5 px-4 whitespace-nowrap">
|
||||
<p className="font-bold text-slate-700 text-xs">
|
||||
{usageCount} {usageLimit > 0 ? `/ ${usageLimit}` : 'uses'}
|
||||
</p>
|
||||
{usageLimit > 0 ? (
|
||||
<div className="w-24 bg-slate-100 rounded-full h-1.5 mt-1.5 overflow-hidden">
|
||||
<div
|
||||
className="bg-indigo-600 h-1.5 rounded-full transition-all"
|
||||
style={{ width: `${Math.min(100, (usageCount / usageLimit) * 100)}%` }}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-[9px] text-slate-400 font-semibold">Unlimited</span>
|
||||
)}
|
||||
</td>
|
||||
|
||||
{/* Scope & Conditions */}
|
||||
<td className="py-3.5 px-4">
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<span className="text-[9px] font-extrabold px-1.5 py-0.5 rounded bg-slate-100 text-slate-600 border border-slate-200">
|
||||
{hasSpecific ? 'Targeted Items' : 'Storewide'}
|
||||
</span>
|
||||
{c.min_purchase_amount > 0 && (
|
||||
<span className="text-[9px] font-bold px-1.5 py-0.5 rounded bg-blue-50 text-blue-700 border border-blue-200">
|
||||
Min: ₹{c.min_purchase_amount}
|
||||
</span>
|
||||
)}
|
||||
{c.is_first_purchase_only && (
|
||||
<span className="text-[9px] font-bold px-1.5 py-0.5 rounded bg-purple-50 text-purple-700 border border-purple-200">
|
||||
1st Order Only
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Active Switch */}
|
||||
<td className="py-3.5 px-4 text-center whitespace-nowrap">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onToggleStatus(c)}
|
||||
className={`relative inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${
|
||||
c.is_active ? 'bg-indigo-600' : 'bg-slate-200'
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${
|
||||
c.is_active ? 'translate-x-4' : 'translate-x-0'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
</td>
|
||||
|
||||
{/* Actions */}
|
||||
<td className="py-3.5 px-4 text-right whitespace-nowrap">
|
||||
<div className="flex items-center justify-end gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onOpenEditCoupon(c)}
|
||||
className="inline-flex items-center gap-1 px-2.5 py-1 rounded-lg text-xs font-bold bg-slate-100 hover:bg-indigo-50 hover:text-indigo-600 text-slate-600 transition-colors border border-slate-200 cursor-pointer shadow-sm"
|
||||
>
|
||||
<Edit className="h-3 w-3" /> Edit
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDeleteCoupon(c)}
|
||||
className="inline-flex items-center p-1 rounded-lg text-slate-400 hover:bg-rose-50 hover:text-rose-600 transition-colors border border-slate-200 cursor-pointer shadow-sm"
|
||||
title="Delete coupon"
|
||||
>
|
||||
<Trash2 className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<Pagination
|
||||
currentPage={safePage}
|
||||
totalItems={totalFiltered}
|
||||
itemsPerPage={perPage}
|
||||
onPageChange={onPageChange}
|
||||
onItemsPerPageChange={onPerPageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
import React from 'react';
|
||||
import { Database, BookOpen, Download, RefreshCw, CheckCircle, AlertCircle, ShieldCheck } from 'lucide-react';
|
||||
|
||||
interface DatabaseBackupTabProps {
|
||||
dbInfo: any | null;
|
||||
downloadingType: 'full' | 'content' | null;
|
||||
successMessage: string | null;
|
||||
errorMessage: string | null;
|
||||
loading: boolean;
|
||||
onRefresh: () => void;
|
||||
onDownloadBackup: (type: 'full' | 'content') => void;
|
||||
}
|
||||
|
||||
export const DatabaseBackupTab: React.FC<DatabaseBackupTabProps> = ({
|
||||
dbInfo,
|
||||
downloadingType,
|
||||
successMessage,
|
||||
errorMessage,
|
||||
loading,
|
||||
onRefresh,
|
||||
onDownloadBackup,
|
||||
}) => {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Top Header Card */}
|
||||
<div className="bg-gradient-to-r from-slate-900 via-indigo-950 to-slate-900 rounded-3xl p-6 text-white shadow-xl relative overflow-hidden">
|
||||
<div className="absolute right-0 top-0 w-96 h-full bg-indigo-500/10 rounded-full blur-3xl pointer-events-none" />
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 relative z-10">
|
||||
<div className="space-y-1">
|
||||
<div className="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-emerald-500/20 text-emerald-400 border border-emerald-500/30 text-[11px] font-black uppercase tracking-wider">
|
||||
<div className="h-2 w-2 rounded-full bg-emerald-400 animate-pulse" /> Live PostgreSQL Database
|
||||
</div>
|
||||
<h2 className="text-xl font-black text-white flex items-center gap-2.5 mt-2">
|
||||
<Database className="h-5 w-5 text-indigo-400" /> Database Backup & Snapshot Engine
|
||||
</h2>
|
||||
<p className="text-xs text-slate-300 max-w-2xl font-medium leading-relaxed">
|
||||
Generate and stream native, compressed PostgreSQL snapshots (.sql.gz) with 100% relational integrity. Backups include all schemas, constraints, sequences, foreign keys, triggers, and live application data.
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onRefresh}
|
||||
disabled={loading}
|
||||
className="inline-flex items-center gap-2 px-4 py-2.5 rounded-xl text-xs font-bold bg-white/10 hover:bg-white/20 border border-white/20 text-white transition-all cursor-pointer backdrop-blur-xs whitespace-nowrap"
|
||||
>
|
||||
<RefreshCw className={`h-3.5 w-3.5 ${loading ? 'animate-spin' : ''}`} /> Refresh Diagnostics
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Notifications */}
|
||||
{successMessage && (
|
||||
<div className="bg-emerald-50 border border-emerald-200 text-emerald-800 px-4 py-3 rounded-2xl text-xs font-semibold flex items-center gap-2 shadow-xs">
|
||||
<CheckCircle className="h-4 w-4 text-emerald-600 shrink-0" />
|
||||
{successMessage}
|
||||
</div>
|
||||
)}
|
||||
{errorMessage && (
|
||||
<div className="bg-rose-50 border border-rose-200 text-rose-800 px-4 py-3 rounded-2xl text-xs font-semibold flex items-center gap-2 shadow-xs">
|
||||
<AlertCircle className="h-4 w-4 text-rose-600 shrink-0" />
|
||||
{errorMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* KPI Metrics */}
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-slate-800">{dbInfo?.database_name || 'panaceadb'}</p>
|
||||
<p className="text-[10px] font-bold text-slate-400 uppercase tracking-wider mt-1">Database Name</p>
|
||||
</div>
|
||||
<div className="bg-indigo-50/60 border border-indigo-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-indigo-700">{dbInfo?.size_human || '23 MB'}</p>
|
||||
<p className="text-[10px] font-bold text-indigo-600 uppercase tracking-wider mt-1">Total Database Size</p>
|
||||
</div>
|
||||
<div className="bg-emerald-50/60 border border-emerald-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-emerald-700">{dbInfo?.total_tables || '42'}</p>
|
||||
<p className="text-[10px] font-bold text-emerald-600 uppercase tracking-wider mt-1">Relational Tables</p>
|
||||
</div>
|
||||
<div className="bg-purple-50/60 border border-purple-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-purple-700">acu_content</p>
|
||||
<p className="text-[10px] font-bold text-purple-600 uppercase tracking-wider mt-1">Primary Schema</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Action Cards */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
{/* Full Database */}
|
||||
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-indigo-300 transition-all space-y-4">
|
||||
<div className="space-y-3">
|
||||
<div className="h-10 w-10 rounded-2xl bg-indigo-50 border border-indigo-200 flex items-center justify-center text-indigo-600">
|
||||
<Database className="h-5 w-5" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-base font-black text-slate-800">Full Database Snapshot</h3>
|
||||
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
||||
Downloads a complete SQL dump of all database schemas, including clinical data, user profiles, authentication records, subscriptions, transactions, and coupons.
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Format:</span>
|
||||
<span className="font-mono font-bold text-slate-700">Compressed .sql.gz (gzip -9)</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Estimated Download Size:</span>
|
||||
<span className="font-mono font-bold text-indigo-600">~1.4 MB</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Relational Integrity:</span>
|
||||
<span className="font-bold text-emerald-600">ACID Consistent (pg_dump)</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDownloadBackup('full')}
|
||||
disabled={downloadingType !== null}
|
||||
className="w-full py-3 px-4 rounded-xl text-xs font-black bg-indigo-600 hover:bg-indigo-500 text-white shadow-md shadow-indigo-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{downloadingType === 'full' ? (
|
||||
<>
|
||||
<RefreshCw className="h-4 w-4 animate-spin" /> Generating & Streaming Backup...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-4 w-4" /> Download Full Database (.sql.gz)
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Clinical Content Only */}
|
||||
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-emerald-300 transition-all space-y-4">
|
||||
<div className="space-y-3">
|
||||
<div className="h-10 w-10 rounded-2xl bg-emerald-50 border border-emerald-200 flex items-center justify-center text-emerald-600">
|
||||
<BookOpen className="h-5 w-5" />
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-base font-black text-slate-800">Clinical Content Only Snapshot</h3>
|
||||
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
||||
Exports strictly the <code className="text-emerald-700 bg-emerald-50 px-1 py-0.5 rounded font-mono font-bold">acu_content</code> schema. Includes acupuncture points, clinical modules, questions bank, protocols, and taxonomy data without user accounts or payment data.
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Target Schema:</span>
|
||||
<span className="font-mono font-bold text-slate-700">acu_content</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Target Entities:</span>
|
||||
<span className="font-bold text-slate-700">Modules, Points, Channels, Quizzes</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Use Case:</span>
|
||||
<span className="font-bold text-emerald-600">Content Staging & Seed Distribution</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDownloadBackup('content')}
|
||||
disabled={downloadingType !== null}
|
||||
className="w-full py-3 px-4 rounded-xl text-xs font-black bg-emerald-600 hover:bg-emerald-500 text-white shadow-md shadow-emerald-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{downloadingType === 'content' ? (
|
||||
<>
|
||||
<RefreshCw className="h-4 w-4 animate-spin" /> Generating & Streaming Backup...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-4 w-4" /> Download Clinical Content (.sql.gz)
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Recovery Instructions */}
|
||||
<div className="bg-slate-50/80 border border-slate-200 rounded-3xl p-6 space-y-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<ShieldCheck className="h-5 w-5 text-indigo-600" />
|
||||
<h3 className="text-sm font-black text-slate-800">Disaster Recovery & Restore Instructions</h3>
|
||||
</div>
|
||||
<p className="text-xs text-slate-500 font-medium">
|
||||
In the event of a system rebuild or migration, you can restore any downloaded snapshot file directly using standard PostgreSQL CLI utilities:
|
||||
</p>
|
||||
|
||||
<div className="bg-slate-900 rounded-2xl p-4 font-mono text-xs text-slate-200 space-y-2 overflow-x-auto shadow-inner">
|
||||
<div className="text-slate-400 text-[11px] font-semibold"># 1. Restore directly via pipeline into Docker or host database:</div>
|
||||
<div className="text-emerald-400 font-bold">
|
||||
gunzip -c panaceadb_backup_full_latest.sql.gz | docker exec -i panacea-postgres psql -U postgres -d panaceadb
|
||||
</div>
|
||||
<div className="text-slate-400 text-[11px] font-semibold pt-1"># 2. Or uncompress first and inspect the raw SQL statements:</div>
|
||||
<div className="text-indigo-300">
|
||||
gunzip panaceadb_backup_full_latest.sql.gz
|
||||
</div>
|
||||
<div className="text-indigo-300">
|
||||
head -n 40 panaceadb_backup_full_latest.sql
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between text-[11px] text-slate-400 font-semibold pt-1">
|
||||
<span>PostgreSQL Engine: {dbInfo?.postgres_version || '16.14'}</span>
|
||||
<span>Internal Host: {dbInfo?.host || 'db'}:{dbInfo?.port || 5432}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,317 @@
|
|||
import React from 'react';
|
||||
import { FileText, CheckCircle, AlertCircle, Calendar, Users, Receipt, Ticket, Download, RefreshCw } from 'lucide-react';
|
||||
|
||||
interface ReportsExportTabProps {
|
||||
dateFilter: 'all' | 'this_month' | 'last_30_days' | 'custom';
|
||||
startDate: string;
|
||||
endDate: string;
|
||||
downloadingReport: string | null;
|
||||
successMessage: string | null;
|
||||
errorMessage: string | null;
|
||||
totalUsers: number;
|
||||
totalPayments: number;
|
||||
totalSubscriptions: number;
|
||||
totalCoupons: number;
|
||||
onDateFilterChange: (filter: 'all' | 'this_month' | 'last_30_days' | 'custom') => void;
|
||||
onStartDateChange: (val: string) => void;
|
||||
onEndDateChange: (val: string) => void;
|
||||
onDownloadReport: (reportKey: string) => void;
|
||||
}
|
||||
|
||||
export const ReportsExportTab: React.FC<ReportsExportTabProps> = ({
|
||||
dateFilter,
|
||||
startDate,
|
||||
endDate,
|
||||
downloadingReport,
|
||||
successMessage,
|
||||
errorMessage,
|
||||
totalUsers,
|
||||
totalPayments,
|
||||
totalSubscriptions,
|
||||
totalCoupons,
|
||||
onDateFilterChange,
|
||||
onStartDateChange,
|
||||
onEndDateChange,
|
||||
onDownloadReport,
|
||||
}) => {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Top Header Card */}
|
||||
<div className="bg-gradient-to-r from-slate-900 via-indigo-950 to-slate-900 rounded-3xl p-6 text-white shadow-xl relative overflow-hidden">
|
||||
<div className="absolute right-0 top-0 w-96 h-full bg-indigo-500/10 rounded-full blur-3xl pointer-events-none" />
|
||||
<div className="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 relative z-10">
|
||||
<div className="space-y-1">
|
||||
<div className="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-indigo-500/20 text-indigo-300 border border-indigo-500/30 text-[11px] font-black uppercase tracking-wider">
|
||||
<FileText className="h-3.5 w-3.5 text-indigo-400" /> Export Utilities & Financial Ledgers
|
||||
</div>
|
||||
<h2 className="text-xl font-black text-white flex items-center gap-2.5 mt-2">
|
||||
Reports & Financial Export Hub
|
||||
</h2>
|
||||
<p className="text-xs text-slate-300 max-w-2xl font-medium leading-relaxed">
|
||||
Generate and download audit-compliant CSV spreadsheets for registered customers, Razorpay payment transactions with GST tax splits (CGST 9% / SGST 9%), active subscriber entitlements, and promotional coupon redemptions.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Notifications */}
|
||||
{successMessage && (
|
||||
<div className="bg-emerald-50 border border-emerald-200 text-emerald-800 px-4 py-3 rounded-2xl text-xs font-semibold flex items-center gap-2 shadow-xs animate-in fade-in">
|
||||
<CheckCircle className="h-4 w-4 text-emerald-600 shrink-0" />
|
||||
{successMessage}
|
||||
</div>
|
||||
)}
|
||||
{errorMessage && (
|
||||
<div className="bg-rose-50 border border-rose-200 text-rose-800 px-4 py-3 rounded-2xl text-xs font-semibold flex items-center gap-2 shadow-xs animate-in fade-in">
|
||||
<AlertCircle className="h-4 w-4 text-rose-600 shrink-0" />
|
||||
{errorMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Filter Bar: Date Range Selector */}
|
||||
<div className="bg-slate-50/80 border border-slate-200/80 rounded-2xl p-4 flex flex-col md:flex-row justify-between items-start md:items-center gap-4 shadow-xs">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-[11px] font-bold text-slate-500 uppercase tracking-wider mr-1 flex items-center gap-1.5">
|
||||
<Calendar className="h-3.5 w-3.5 text-indigo-600" /> Date Window:
|
||||
</span>
|
||||
{[
|
||||
{ id: 'all' as const, label: 'All Time' },
|
||||
{ id: 'this_month' as const, label: 'This Month' },
|
||||
{ id: 'last_30_days' as const, label: 'Last 30 Days' },
|
||||
{ id: 'custom' as const, label: 'Custom Range' },
|
||||
].map((f) => (
|
||||
<button
|
||||
key={f.id}
|
||||
type="button"
|
||||
onClick={() => onDateFilterChange(f.id)}
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-bold transition-all cursor-pointer ${
|
||||
dateFilter === f.id
|
||||
? 'bg-indigo-600 text-white shadow-sm'
|
||||
: 'bg-white text-slate-600 border border-slate-200 hover:bg-slate-100 shadow-sm'
|
||||
}`}
|
||||
>
|
||||
{f.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{dateFilter === 'custom' && (
|
||||
<div className="flex items-center gap-2 w-full md:w-auto animate-in fade-in">
|
||||
<input
|
||||
type="date"
|
||||
value={startDate}
|
||||
onChange={(e) => onStartDateChange(e.target.value)}
|
||||
className="bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 shadow-sm cursor-pointer"
|
||||
/>
|
||||
<span className="text-xs text-slate-400 font-bold">to</span>
|
||||
<input
|
||||
type="date"
|
||||
value={endDate}
|
||||
onChange={(e) => onEndDateChange(e.target.value)}
|
||||
className="bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 shadow-sm cursor-pointer"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 4 Report Cards Grid */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
{/* Report 1: Customers Ledger */}
|
||||
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-indigo-300 transition-all space-y-4">
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="h-10 w-10 rounded-2xl bg-indigo-50 border border-indigo-200 flex items-center justify-center text-indigo-600">
|
||||
<Users className="h-5 w-5" />
|
||||
</div>
|
||||
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-indigo-50 text-indigo-700 border border-indigo-100">
|
||||
{totalUsers} Total Users
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-base font-black text-slate-800">Customers & Practitioners Ledger</h3>
|
||||
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
||||
Export complete customer database with contact details, country, active subscription counts, active plans, total order counts, and cumulative lifetime spend.
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Included Columns:</span>
|
||||
<span className="font-semibold text-slate-700">User ID, Email, Name, Phone, Role, Spend</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Target Audience:</span>
|
||||
<span className="font-semibold text-indigo-600">CRM & Growth Audits</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDownloadReport('customers')}
|
||||
disabled={downloadingReport !== null}
|
||||
className="w-full py-2.5 px-4 rounded-xl text-xs font-black bg-indigo-600 hover:bg-indigo-500 text-white shadow-md shadow-indigo-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{downloadingReport === 'customers' ? (
|
||||
<>
|
||||
<RefreshCw className="h-3.5 w-3.5 animate-spin" /> Generating CSV...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-3.5 w-3.5" /> Export Customers (.csv)
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Report 2: Financial & GST Tax Ledger */}
|
||||
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-emerald-300 transition-all space-y-4">
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="h-10 w-10 rounded-2xl bg-emerald-50 border border-emerald-200 flex items-center justify-center text-emerald-600">
|
||||
<Receipt className="h-5 w-5" />
|
||||
</div>
|
||||
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-emerald-50 text-emerald-700 border border-emerald-100">
|
||||
{totalPayments} Total Orders
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-base font-black text-slate-800">Payments & GST Tax Ledger</h3>
|
||||
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
||||
Accounting & taxation ledger containing Razorpay Payment IDs, invoice numbers, base plan fees, coupon discounts, taxable subtotal, CGST (9%), SGST (9%), and net total paid.
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Tax Compliance:</span>
|
||||
<span className="font-semibold text-emerald-600">CGST (9%) + SGST (9%) Breakdown</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
||||
<span className="font-semibold text-slate-700">Monthly GST Filing & Bookkeeping</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDownloadReport('payments')}
|
||||
disabled={downloadingReport !== null}
|
||||
className="w-full py-2.5 px-4 rounded-xl text-xs font-black bg-emerald-600 hover:bg-emerald-500 text-white shadow-md shadow-emerald-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{downloadingReport === 'payments' ? (
|
||||
<>
|
||||
<RefreshCw className="h-3.5 w-3.5 animate-spin" /> Generating CSV...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-3.5 w-3.5" /> Export Tax & Revenue Ledger (.csv)
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Report 3: Subscriptions Ledger */}
|
||||
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-blue-300 transition-all space-y-4">
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="h-10 w-10 rounded-2xl bg-blue-50 border border-blue-200 flex items-center justify-center text-blue-600">
|
||||
<CheckCircle className="h-5 w-5" />
|
||||
</div>
|
||||
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-blue-50 text-blue-700 border border-blue-100">
|
||||
{totalSubscriptions} Subscriptions
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-base font-black text-slate-800">Subscriptions & Entitlements Ledger</h3>
|
||||
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
||||
Export clinical plan access records, customer identities, subscription status, billing cycle, auto-renewal flag, activation dates, expiration dates, and remaining days.
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Metrics Included:</span>
|
||||
<span className="font-semibold text-slate-700">Remaining Days, Expiration, Plan Code</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
||||
<span className="font-semibold text-blue-600">Churn & Expiration Tracking</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDownloadReport('subscriptions')}
|
||||
disabled={downloadingReport !== null}
|
||||
className="w-full py-2.5 px-4 rounded-xl text-xs font-black bg-blue-600 hover:bg-blue-500 text-white shadow-md shadow-blue-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{downloadingReport === 'subscriptions' ? (
|
||||
<>
|
||||
<RefreshCw className="h-3.5 w-3.5 animate-spin" /> Generating CSV...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-3.5 w-3.5" /> Export Subscriptions (.csv)
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Report 4: Coupon Redemptions */}
|
||||
<div className="bg-white border border-slate-200 rounded-3xl p-6 shadow-sm flex flex-col justify-between hover:border-purple-300 transition-all space-y-4">
|
||||
<div className="space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="h-10 w-10 rounded-2xl bg-purple-50 border border-purple-200 flex items-center justify-center text-purple-600">
|
||||
<Ticket className="h-5 w-5" />
|
||||
</div>
|
||||
<span className="text-[10px] font-bold px-2.5 py-1 rounded-full bg-purple-50 text-purple-700 border border-purple-100">
|
||||
{totalCoupons} Promo Codes
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-base font-black text-slate-800">Promotions & Coupon Redemptions</h3>
|
||||
<p className="text-xs text-slate-500 mt-1 font-medium leading-relaxed">
|
||||
Track coupon performance and redemptions across orders, including discount rates, caps, customer emails, associated invoices, and total discount value granted.
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-slate-50 border border-slate-200/60 rounded-xl p-3 text-[11px] text-slate-600 space-y-1">
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Campaign Metrics:</span>
|
||||
<span className="font-semibold text-slate-700">Code, Category, Discount INR, User</span>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<span className="text-slate-400 font-semibold">Primary Use:</span>
|
||||
<span className="font-semibold text-purple-600">Marketing & Partner ROI</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDownloadReport('coupons')}
|
||||
disabled={downloadingReport !== null}
|
||||
className="w-full py-2.5 px-4 rounded-xl text-xs font-black bg-purple-600 hover:bg-purple-500 text-white shadow-md shadow-purple-600/20 transition-all flex items-center justify-center gap-2 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{downloadingReport === 'coupons' ? (
|
||||
<>
|
||||
<RefreshCw className="h-3.5 w-3.5 animate-spin" /> Generating CSV...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Download className="h-3.5 w-3.5" /> Export Redemptions (.csv)
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,176 @@
|
|||
import React from 'react';
|
||||
import {
|
||||
Sparkles, ChevronLeft, ChevronRight, LogOut,
|
||||
List, BookOpen, Tag, Ticket, Users, CheckCircle,
|
||||
Receipt, Shield, Database, FileText
|
||||
} from 'lucide-react';
|
||||
import type { LoggedInUser, AdminTabType } from '../../types';
|
||||
|
||||
interface TabItem {
|
||||
key: AdminTabType;
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
count?: number;
|
||||
}
|
||||
|
||||
interface AdminSidebarProps {
|
||||
loggedInUser: LoggedInUser | null;
|
||||
activeTab: AdminTabType;
|
||||
onSelectTab: (tab: AdminTabType) => void;
|
||||
counts: {
|
||||
modules: number;
|
||||
plans: number;
|
||||
coupons: number;
|
||||
customers: number;
|
||||
subscriptions: number;
|
||||
payments: number;
|
||||
admins: number;
|
||||
};
|
||||
isCollapsed: boolean;
|
||||
onToggleCollapse: () => void;
|
||||
onLogout: () => void;
|
||||
}
|
||||
|
||||
export const AdminSidebar: React.FC<AdminSidebarProps> = ({
|
||||
loggedInUser,
|
||||
activeTab,
|
||||
onSelectTab,
|
||||
counts,
|
||||
isCollapsed,
|
||||
onToggleCollapse,
|
||||
onLogout,
|
||||
}) => {
|
||||
const tabs: TabItem[] = [
|
||||
{ key: 'overview', label: 'Overview & Logs', icon: <List className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'modules', label: 'Modules', count: counts.modules, icon: <BookOpen className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'plans', label: 'Plans & Pricing', count: counts.plans, icon: <Tag className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'coupons', label: 'Coupons', count: counts.coupons, icon: <Ticket className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'customers', label: 'Customers', count: counts.customers, icon: <Users className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'users_subscriptions', label: 'Subscriptions', count: counts.subscriptions, icon: <CheckCircle className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'payments', label: 'Payments', count: counts.payments, icon: <Receipt className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'admins', label: 'Manage Admins', count: counts.admins, icon: <Shield className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'database', label: 'DB & Backups', icon: <Database className="h-4 w-4 shrink-0" /> },
|
||||
{ key: 'reports', label: 'Reports & Exports', icon: <FileText className="h-4 w-4 shrink-0" /> },
|
||||
];
|
||||
|
||||
return (
|
||||
<aside
|
||||
className={`bg-[#0A0A0E] border-b md:border-b-0 md:border-r border-slate-800/80 flex flex-col justify-between py-4 transition-all duration-300 ease-in-out flex-shrink-0 text-slate-300 shadow-2xl select-none relative z-30 ${
|
||||
isCollapsed ? 'w-full md:w-[68px] px-2' : 'w-full md:w-60 px-3'
|
||||
}`}
|
||||
>
|
||||
<div className="space-y-4">
|
||||
{/* Brand & Collapse Header */}
|
||||
<div className={`flex items-center ${isCollapsed ? 'justify-center' : 'justify-between'} gap-2 px-1`}>
|
||||
<div className="flex items-center gap-2.5 min-w-0">
|
||||
<div className="h-8 w-8 rounded-xl bg-gradient-to-tr from-indigo-500 to-cyan-400 flex items-center justify-center shadow-md shadow-indigo-500/20 shrink-0">
|
||||
<Sparkles className="h-4 w-4 text-white" />
|
||||
</div>
|
||||
{!isCollapsed && (
|
||||
<div className="min-w-0">
|
||||
<h1 className="text-sm font-black tracking-tight text-white truncate">
|
||||
ACUPEDIA
|
||||
</h1>
|
||||
<p className="text-[8px] text-slate-400 font-bold tracking-widest uppercase">ADMIN CONSOLE</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleCollapse}
|
||||
className="hidden md:flex h-7 w-7 rounded-lg bg-slate-800/80 hover:bg-slate-700 text-slate-400 hover:text-white items-center justify-center transition-colors cursor-pointer border border-slate-700/60"
|
||||
title={isCollapsed ? 'Expand sidebar' : 'Collapse sidebar'}
|
||||
>
|
||||
{isCollapsed ? <ChevronRight className="h-3.5 w-3.5" /> : <ChevronLeft className="h-3.5 w-3.5" />}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Navigation Tabs */}
|
||||
<nav className="space-y-1">
|
||||
{tabs.map((tab) => {
|
||||
const isActive = activeTab === tab.key;
|
||||
return (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => onSelectTab(tab.key)}
|
||||
className={`w-full flex items-center gap-3 px-3 py-2.5 rounded-xl text-xs font-bold transition-all cursor-pointer relative group ${
|
||||
isActive
|
||||
? 'bg-indigo-600 text-white shadow-lg shadow-indigo-600/30'
|
||||
: 'text-slate-400 hover:text-slate-100 hover:bg-slate-800/60'
|
||||
} ${isCollapsed ? 'justify-center px-0' : ''}`}
|
||||
title={isCollapsed ? `${tab.label} ${tab.count !== undefined ? `(${tab.count})` : ''}` : undefined}
|
||||
>
|
||||
{tab.icon}
|
||||
{!isCollapsed && (
|
||||
<>
|
||||
<span className="truncate flex-1 text-left">{tab.label}</span>
|
||||
{tab.count !== undefined && (
|
||||
<span
|
||||
className={`text-[10px] font-black px-1.5 py-0.5 rounded-full ${
|
||||
isActive
|
||||
? 'bg-white/20 text-white'
|
||||
: 'bg-slate-800 text-slate-400 group-hover:text-slate-200'
|
||||
}`}
|
||||
>
|
||||
{tab.count}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
{/* Collapsed active dot */}
|
||||
{isCollapsed && isActive && (
|
||||
<span className="absolute right-1.5 top-1/2 -translate-y-1/2 w-1.5 h-1.5 bg-white rounded-full shadow-xs" />
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{/* User Footer */}
|
||||
<div className="pt-3 border-t border-slate-800/80 mt-4">
|
||||
{!isCollapsed ? (
|
||||
<div className="space-y-2.5 px-1">
|
||||
<div className="flex items-center gap-2.5">
|
||||
<div className="h-8 w-8 rounded-xl bg-gradient-to-tr from-indigo-950 to-indigo-900 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-black text-xs shrink-0 shadow-inner">
|
||||
{loggedInUser?.display_name ? loggedInUser.display_name[0].toUpperCase() : 'A'}
|
||||
</div>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="text-xs font-bold text-white truncate">
|
||||
{loggedInUser?.display_name || 'Admin'}
|
||||
</p>
|
||||
<p className="text-[10px] text-slate-400 truncate">{loggedInUser?.email}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onLogout}
|
||||
className="w-full flex items-center justify-center gap-2 py-2 rounded-xl text-xs font-bold bg-slate-800 hover:bg-slate-700 text-slate-300 hover:text-white transition-colors cursor-pointer border border-slate-700/60"
|
||||
>
|
||||
<LogOut className="h-3.5 w-3.5" /> Log Out
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<div
|
||||
className="h-8 w-8 rounded-xl bg-indigo-950/60 border border-indigo-500/30 flex items-center justify-center text-indigo-400 font-bold text-xs shrink-0"
|
||||
title={`${loggedInUser?.display_name || 'Admin'} (${loggedInUser?.email})`}
|
||||
>
|
||||
{loggedInUser?.display_name ? loggedInUser.display_name[0].toUpperCase() : 'A'}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onLogout}
|
||||
className="h-8 w-8 flex items-center justify-center rounded-xl bg-slate-800 hover:bg-slate-700 text-slate-400 hover:text-white transition-colors cursor-pointer border border-slate-700/60"
|
||||
title="Log Out"
|
||||
>
|
||||
<LogOut className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
import React from 'react';
|
||||
import {
|
||||
List, BookOpen, Tag, Ticket, Users, CheckCircle,
|
||||
Receipt, Shield, Database, FileText, RefreshCw
|
||||
} from 'lucide-react';
|
||||
import type { AdminTabType } from '../../types';
|
||||
|
||||
interface TabItem {
|
||||
key: AdminTabType;
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
}
|
||||
|
||||
interface AdminTabNavProps {
|
||||
activeTab: AdminTabType;
|
||||
onSelectTab: (tab: AdminTabType) => void;
|
||||
counts: {
|
||||
modules: number;
|
||||
plans: number;
|
||||
coupons: number;
|
||||
customers: number;
|
||||
subscriptions: number;
|
||||
payments: number;
|
||||
admins: number;
|
||||
};
|
||||
onRefresh: () => void;
|
||||
loading: boolean;
|
||||
}
|
||||
|
||||
export const AdminTabNav: React.FC<AdminTabNavProps> = ({
|
||||
activeTab,
|
||||
onSelectTab,
|
||||
counts,
|
||||
onRefresh,
|
||||
loading,
|
||||
}) => {
|
||||
const tabs: TabItem[] = [
|
||||
{ key: 'overview', label: 'Overview & Logs', icon: <List className="h-3.5 w-3.5" /> },
|
||||
{ key: 'modules', label: `Modules (${counts.modules})`, icon: <BookOpen className="h-3.5 w-3.5" /> },
|
||||
{ key: 'plans', label: `Plans & Pricing (${counts.plans})`, icon: <Tag className="h-3.5 w-3.5" /> },
|
||||
{ key: 'coupons', label: `Coupons (${counts.coupons})`, icon: <Ticket className="h-3.5 w-3.5" /> },
|
||||
{ key: 'customers', label: `Customers (${counts.customers})`, icon: <Users className="h-3.5 w-3.5" /> },
|
||||
{ key: 'users_subscriptions', label: `Users Subscriptions (${counts.subscriptions})`, icon: <CheckCircle className="h-3.5 w-3.5" /> },
|
||||
{ key: 'payments', label: `Payments (${counts.payments})`, icon: <Receipt className="h-3.5 w-3.5" /> },
|
||||
{ key: 'admins', label: `Manage Admins (${counts.admins})`, icon: <Shield className="h-3.5 w-3.5" /> },
|
||||
{ key: 'database', label: 'DB & Backups', icon: <Database className="h-3.5 w-3.5" /> },
|
||||
{ key: 'reports', label: 'Reports & Exports', icon: <FileText className="h-3.5 w-3.5" /> },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="bg-slate-50 border-b border-slate-200 px-4 py-2.5 flex items-center gap-1.5 overflow-x-auto select-none">
|
||||
{tabs.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => onSelectTab(tab.key)}
|
||||
className={`flex items-center gap-1.5 px-3.5 py-1.5 rounded-xl text-xs font-bold transition-all whitespace-nowrap cursor-pointer ${
|
||||
activeTab === tab.key
|
||||
? 'bg-indigo-600 text-white shadow-md shadow-indigo-600/20'
|
||||
: 'text-slate-500 hover:bg-slate-200/70 hover:text-slate-800'
|
||||
}`}
|
||||
>
|
||||
{tab.icon}
|
||||
<span>{tab.label}</span>
|
||||
</button>
|
||||
))}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={onRefresh}
|
||||
disabled={loading}
|
||||
className="ml-auto shrink-0 flex items-center gap-1 px-3 py-1.5 rounded-lg text-xs font-bold bg-white border border-slate-200 hover:bg-slate-100 text-slate-600 transition-colors disabled:opacity-40 cursor-pointer shadow-sm"
|
||||
>
|
||||
<RefreshCw className={`h-3 w-3 ${loading ? 'animate-spin' : ''}`} /> Refresh
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
import React from 'react';
|
||||
import { XCircle, RefreshCw } from 'lucide-react';
|
||||
import type { ModuleItem } from '../../types';
|
||||
|
||||
interface EditModuleModalProps {
|
||||
module: ModuleItem | null;
|
||||
name: string;
|
||||
description: string;
|
||||
category: string;
|
||||
saving: boolean;
|
||||
onNameChange: (val: string) => void;
|
||||
onDescriptionChange: (val: string) => void;
|
||||
onCategoryChange: (val: string) => void;
|
||||
onSave: (e: React.FormEvent) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const EditModuleModal: React.FC<EditModuleModalProps> = ({
|
||||
module,
|
||||
name,
|
||||
description,
|
||||
category,
|
||||
saving,
|
||||
onNameChange,
|
||||
onDescriptionChange,
|
||||
onCategoryChange,
|
||||
onSave,
|
||||
onClose,
|
||||
}) => {
|
||||
if (!module) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-[150] flex items-center justify-center p-4 bg-slate-950/70 backdrop-blur-sm">
|
||||
<div className="bg-white border border-slate-200 rounded-3xl p-6 w-full max-w-lg shadow-2xl space-y-5 animate-in fade-in duration-200">
|
||||
<div className="flex items-center justify-between border-b border-slate-100 pb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<div
|
||||
className="h-8 w-8 rounded-lg flex items-center justify-center font-bold text-white text-xs"
|
||||
style={{ backgroundColor: (module as any).color || '#6366F1' }}
|
||||
>
|
||||
{(module.name || 'M')[0].toUpperCase()}
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-sm font-bold text-slate-800">Edit Clinical Module</h3>
|
||||
<p className="text-[10px] text-slate-400 font-mono">{module.slug}</p>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="text-slate-400 hover:text-slate-600 p-1 cursor-pointer transition-colors"
|
||||
>
|
||||
<XCircle className="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<form onSubmit={onSave} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Display Name</label>
|
||||
<input
|
||||
type="text"
|
||||
required
|
||||
value={name}
|
||||
onChange={(e) => onNameChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Category</label>
|
||||
<select
|
||||
value={category}
|
||||
onChange={(e) => onCategoryChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="point">Points</option>
|
||||
<option value="Patterns">Patterns</option>
|
||||
<option value="Nutrition">Nutrition</option>
|
||||
<option value="Therapeutics">Therapeutics</option>
|
||||
<option value="General">General</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Clinical Description</label>
|
||||
<textarea
|
||||
rows={3}
|
||||
value={description}
|
||||
onChange={(e) => onDescriptionChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs font-medium text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="flex-1 py-2 rounded-xl text-xs font-bold bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors cursor-pointer"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="flex-1 py-2 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors flex items-center justify-center gap-1.5 shadow-sm cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{saving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : 'Save Changes'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,276 @@
|
|||
import React from 'react';
|
||||
import { Edit } from 'lucide-react';
|
||||
import type { ModuleItem } from '../../types';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
|
||||
interface ModulesTabProps {
|
||||
modules: ModuleItem[];
|
||||
searchQuery: string;
|
||||
statusFilter: string;
|
||||
categoryFilter: string;
|
||||
currentPage: number;
|
||||
perPage: number;
|
||||
onSearchChange: (query: string) => void;
|
||||
onStatusFilterChange: (status: string) => void;
|
||||
onCategoryFilterChange: (cat: string) => void;
|
||||
onPageChange: (page: number) => void;
|
||||
onPerPageChange: (perPage: number) => void;
|
||||
onToggleStatus: (mod: ModuleItem) => void;
|
||||
onEditModule: (mod: ModuleItem) => void;
|
||||
}
|
||||
|
||||
export const ModulesTab: React.FC<ModulesTabProps> = ({
|
||||
modules,
|
||||
searchQuery,
|
||||
statusFilter,
|
||||
categoryFilter,
|
||||
currentPage,
|
||||
perPage,
|
||||
onSearchChange,
|
||||
onStatusFilterChange,
|
||||
onCategoryFilterChange,
|
||||
onPageChange,
|
||||
onPerPageChange,
|
||||
onToggleStatus,
|
||||
onEditModule,
|
||||
}) => {
|
||||
const filtered = modules.filter((m) => {
|
||||
const matchesSearch =
|
||||
!searchQuery ||
|
||||
(m.name || '').toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
(m.slug || '').toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
(m.code || '').toLowerCase().includes(searchQuery.toLowerCase()) ||
|
||||
(m.description || '').toLowerCase().includes(searchQuery.toLowerCase());
|
||||
|
||||
const matchesStatus =
|
||||
statusFilter === 'all' ||
|
||||
(statusFilter === 'active' && m.is_active) ||
|
||||
(statusFilter === 'inactive' && !m.is_active);
|
||||
|
||||
const matchesCategory =
|
||||
categoryFilter === 'all' ||
|
||||
(m.category || '').toLowerCase() === categoryFilter.toLowerCase();
|
||||
|
||||
return matchesSearch && matchesStatus && matchesCategory;
|
||||
});
|
||||
|
||||
const totalFiltered = filtered.length;
|
||||
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
||||
const safePage = Math.min(currentPage, totalPages);
|
||||
const startIndex = (safePage - 1) * perPage;
|
||||
const paginatedModules = filtered.slice(startIndex, startIndex + perPage);
|
||||
|
||||
const categories = [
|
||||
{ key: 'all', label: 'All Categories' },
|
||||
{ key: 'point', label: 'Points' },
|
||||
{ key: 'Patterns', label: 'Patterns' },
|
||||
{ key: 'Nutrition', label: 'Nutrition' },
|
||||
{ key: 'Therapeutics', label: 'Therapeutics' },
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Search & Status Bar */}
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 space-y-3.5">
|
||||
<div className="flex flex-col sm:flex-row gap-3 items-stretch sm:items-center justify-between">
|
||||
{/* Search Box */}
|
||||
<div className="flex-1 max-w-md relative">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search by name, slug, or code..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => {
|
||||
onSearchChange(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-9 pr-4 py-2 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 shadow-sm"
|
||||
/>
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 text-xs">🔍</span>
|
||||
</div>
|
||||
|
||||
{/* Status Filter Segmented Control (Fixed Alignment) */}
|
||||
<div className="flex items-center gap-1 bg-slate-200/70 p-1 rounded-xl shrink-0 flex-nowrap overflow-x-auto shadow-inner">
|
||||
<span className="text-[10px] uppercase font-bold text-slate-500 px-1.5 hidden sm:inline whitespace-nowrap">
|
||||
Status:
|
||||
</span>
|
||||
{[
|
||||
{ key: 'all', label: `All (${modules.length})` },
|
||||
{ key: 'active', label: `Active (${modules.filter((m) => m.is_active).length})` },
|
||||
{ key: 'inactive', label: `Inactive (${modules.filter((m) => !m.is_active).length})` },
|
||||
].map((f) => (
|
||||
<button
|
||||
key={f.key}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onStatusFilterChange(f.key);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className={`px-3 py-1 rounded-lg text-xs font-bold transition-all cursor-pointer whitespace-nowrap ${
|
||||
statusFilter === f.key
|
||||
? 'bg-indigo-600 text-white shadow-sm'
|
||||
: 'text-slate-600 hover:text-slate-900 hover:bg-white/60'
|
||||
}`}
|
||||
>
|
||||
{f.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Category Filter Pills */}
|
||||
<div className="flex items-center gap-1.5 flex-wrap border-t border-slate-200/60 pt-3">
|
||||
<span className="text-[10px] uppercase font-bold text-slate-400 mr-1">Category:</span>
|
||||
{categories.map((cat) => {
|
||||
const count =
|
||||
cat.key === 'all'
|
||||
? modules.length
|
||||
: modules.filter((m) => (m.category || '').toLowerCase() === cat.key.toLowerCase()).length;
|
||||
const isSelected = categoryFilter.toLowerCase() === cat.key.toLowerCase();
|
||||
return (
|
||||
<button
|
||||
key={cat.key}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onCategoryFilterChange(cat.key);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className={`px-2.5 py-1 rounded-lg text-xs font-bold transition-colors cursor-pointer whitespace-nowrap ${
|
||||
isSelected
|
||||
? 'bg-slate-900 text-white shadow-sm'
|
||||
: 'bg-white border border-slate-200 text-slate-600 hover:bg-slate-100 shadow-sm'
|
||||
}`}
|
||||
>
|
||||
{cat.label} ({count})
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Modules Table */}
|
||||
{filtered.length === 0 ? (
|
||||
<div className="text-center py-12 bg-slate-50 border border-slate-200/60 rounded-2xl space-y-2">
|
||||
<p className="text-sm font-bold text-slate-600">No modules match the selected filters.</p>
|
||||
<p className="text-xs text-slate-400">Try changing your search keywords or filter pills.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="bg-white border border-slate-200 rounded-2xl overflow-hidden shadow-sm p-4">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left border-collapse text-xs">
|
||||
<thead>
|
||||
<tr className="bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider border-b border-slate-200">
|
||||
<th className="py-3 px-3.5">Module Name & Details</th>
|
||||
<th className="py-3 px-3.5">Identifier / Code</th>
|
||||
<th className="py-3 px-3.5">Category</th>
|
||||
<th className="py-3 px-3.5">Linked Plans</th>
|
||||
<th className="py-3 px-3.5">Catalog Status</th>
|
||||
<th className="py-3 px-3.5 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100">
|
||||
{paginatedModules.map((mod) => (
|
||||
<tr
|
||||
key={mod.id}
|
||||
className={`hover:bg-slate-50/80 transition-colors ${
|
||||
!mod.is_active ? 'bg-slate-50/40 text-slate-500' : 'text-slate-800'
|
||||
}`}
|
||||
>
|
||||
{/* Column 1: Module & Details */}
|
||||
<td className="py-3.5 px-3.5">
|
||||
<div className="flex items-center gap-3">
|
||||
<div
|
||||
className="h-8 w-8 rounded-xl flex items-center justify-center font-black text-xs text-white shadow-sm shrink-0"
|
||||
style={{ backgroundColor: (mod as any).color || '#6366F1' }}
|
||||
>
|
||||
{(mod.name || 'M')[0].toUpperCase()}
|
||||
</div>
|
||||
<div className="min-w-0 max-w-xs md:max-w-md">
|
||||
<p className="font-bold text-slate-800 text-xs truncate">{mod.name}</p>
|
||||
<p className="text-[11px] text-slate-400 truncate mt-0.5 font-medium">
|
||||
{mod.description || 'No description provided.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Column 2: Code / Slug */}
|
||||
<td className="py-3.5 px-3.5 font-mono">
|
||||
<div className="flex items-center gap-1.5 flex-wrap">
|
||||
{mod.code && (
|
||||
<span className="text-[9px] font-black uppercase px-1.5 py-0.5 rounded bg-slate-100 text-slate-700 border border-slate-200">
|
||||
{mod.code}
|
||||
</span>
|
||||
)}
|
||||
<span className="text-[11px] text-slate-500">{mod.slug}</span>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Column 3: Category */}
|
||||
<td className="py-3.5 px-3.5">
|
||||
<span className="text-[10px] font-bold text-indigo-600 bg-indigo-50 px-2.5 py-1 rounded-lg border border-indigo-100 uppercase tracking-wider">
|
||||
{mod.category || 'General'}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* Column 4: Linked Plans */}
|
||||
<td className="py-3.5 px-3.5 font-semibold text-slate-600">
|
||||
<span className="bg-slate-100 text-slate-700 px-2 py-0.5 rounded-md text-[10px] font-bold border border-slate-200">
|
||||
{mod.linked_plans_count || 0} {mod.linked_plans_count === 1 ? 'Plan' : 'Plans'}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* Column 5: Status */}
|
||||
<td className="py-3.5 px-3.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<span
|
||||
className={`px-2.5 py-0.5 rounded-full text-[10px] font-black uppercase border whitespace-nowrap ${
|
||||
mod.is_active
|
||||
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
||||
: 'bg-slate-100 text-slate-500 border-slate-200'
|
||||
}`}
|
||||
>
|
||||
{mod.is_active ? '● Active' : '○ Inactive'}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onToggleStatus(mod)}
|
||||
className={`text-[10px] font-bold px-2 py-1 rounded-lg transition-colors cursor-pointer border whitespace-nowrap ${
|
||||
mod.is_active
|
||||
? 'bg-white hover:bg-rose-50 text-slate-500 hover:text-rose-600 border-slate-200'
|
||||
: 'bg-emerald-600 hover:bg-emerald-500 text-white border-transparent shadow-sm'
|
||||
}`}
|
||||
>
|
||||
{mod.is_active ? 'Deactivate' : 'Activate'}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Column 6: Actions */}
|
||||
<td className="py-3.5 px-3.5 text-right">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onEditModule(mod)}
|
||||
className="py-1 px-2.5 bg-white hover:bg-slate-100 border border-slate-200 rounded-lg text-xs font-bold text-slate-700 transition-colors inline-flex items-center gap-1 cursor-pointer shadow-sm"
|
||||
>
|
||||
<Edit className="h-3.5 w-3.5 text-slate-400" /> Edit
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
{/* Unified Pagination */}
|
||||
<Pagination
|
||||
currentPage={safePage}
|
||||
totalItems={totalFiltered}
|
||||
itemsPerPage={perPage}
|
||||
onPageChange={onPageChange}
|
||||
onItemsPerPageChange={onPerPageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
import React, { useState, useMemo } from 'react';
|
||||
import { Receipt, Download, Mail, RefreshCw, Search, ArrowUpDown, ArrowDown, ArrowUp, X } from 'lucide-react';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
|
||||
interface PaymentsTabProps {
|
||||
payments: any[];
|
||||
currentPage: number;
|
||||
perPage: number;
|
||||
downloadingId: string | null;
|
||||
sharingId: string | null;
|
||||
onPageChange: (p: number) => void;
|
||||
onPerPageChange: (pp: number) => void;
|
||||
onDownloadInvoice: (id: string) => void;
|
||||
onShareInvoice: (id: string) => void;
|
||||
}
|
||||
|
||||
export const PaymentsTab: React.FC<PaymentsTabProps> = ({
|
||||
payments,
|
||||
currentPage,
|
||||
perPage,
|
||||
downloadingId,
|
||||
sharingId,
|
||||
onPageChange,
|
||||
onPerPageChange,
|
||||
onDownloadInvoice,
|
||||
onShareInvoice,
|
||||
}) => {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [sortOrder, setSortOrder] = useState<'desc' | 'asc'>('desc');
|
||||
|
||||
// Filter and Sort payments
|
||||
const processedPayments = useMemo(() => {
|
||||
let result = [...payments];
|
||||
|
||||
// Filter
|
||||
if (searchQuery.trim()) {
|
||||
const q = searchQuery.toLowerCase().trim();
|
||||
result = result.filter((p: any) => {
|
||||
const id = (p.id || '').toLowerCase();
|
||||
const email = (p.email || '').toLowerCase();
|
||||
const orderId = (p.order_id || '').toLowerCase();
|
||||
const contact = (p.contact || '').toLowerCase();
|
||||
const method = (p.method || '').toLowerCase();
|
||||
const invoiceNum = (p.invoice_number || '').toLowerCase();
|
||||
const status = (p.status || '').toLowerCase();
|
||||
|
||||
return (
|
||||
id.includes(q) ||
|
||||
email.includes(q) ||
|
||||
orderId.includes(q) ||
|
||||
contact.includes(q) ||
|
||||
method.includes(q) ||
|
||||
invoiceNum.includes(q) ||
|
||||
status.includes(q)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// Sort by created_at (default newest first)
|
||||
result.sort((a: any, b: any) => {
|
||||
const timeA = typeof a.created_at === 'number' ? a.created_at * 1000 : new Date(a.created_at || 0).getTime();
|
||||
const timeB = typeof b.created_at === 'number' ? b.created_at * 1000 : new Date(b.created_at || 0).getTime();
|
||||
return sortOrder === 'desc' ? timeB - timeA : timeA - timeB;
|
||||
});
|
||||
|
||||
return result;
|
||||
}, [payments, searchQuery, sortOrder]);
|
||||
|
||||
const totalFiltered = processedPayments.length;
|
||||
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
||||
const safePage = Math.min(currentPage, totalPages);
|
||||
const startIndex = (safePage - 1) * perPage;
|
||||
const paginatedPayments = processedPayments.slice(startIndex, startIndex + perPage);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Search & Sort Controls Header */}
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 flex flex-col sm:flex-row justify-between items-stretch sm:items-center gap-3">
|
||||
{/* Search Input */}
|
||||
<div className="flex-1 max-w-md relative">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search payment ID, order ID, email, method, invoice..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => {
|
||||
setSearchQuery(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-9 pr-8 py-2 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 shadow-sm"
|
||||
/>
|
||||
<Search className="h-3.5 w-3.5 absolute left-3 top-1/2 -translate-y-1/2 text-slate-400" />
|
||||
{searchQuery && (
|
||||
<button
|
||||
onClick={() => {
|
||||
setSearchQuery('');
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600 p-0.5"
|
||||
>
|
||||
<X className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Sort & Count Controls */}
|
||||
<div className="flex items-center gap-3 justify-between sm:justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSortOrder(prev => prev === 'desc' ? 'asc' : 'desc')}
|
||||
className="flex items-center gap-1.5 px-3 py-2 rounded-xl text-xs font-bold bg-white border border-slate-200 text-slate-700 hover:bg-slate-100 hover:border-slate-300 transition-colors shadow-2xs cursor-pointer"
|
||||
title={`Toggle sort order (current: ${sortOrder === 'desc' ? 'Latest first' : 'Oldest first'})`}
|
||||
>
|
||||
<ArrowUpDown className="h-3.5 w-3.5 text-indigo-600" />
|
||||
<span>Sort: {sortOrder === 'desc' ? 'Newest First' : 'Oldest First'}</span>
|
||||
{sortOrder === 'desc' ? (
|
||||
<ArrowDown className="h-3 w-3 text-slate-400" />
|
||||
) : (
|
||||
<ArrowUp className="h-3 w-3 text-slate-400" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="text-xs font-bold text-slate-500 whitespace-nowrap">
|
||||
Showing <span className="text-slate-800">{totalFiltered}</span> of{' '}
|
||||
<span className="text-slate-800">{payments.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{payments.length === 0 ? (
|
||||
<p className="text-sm text-slate-400 italic text-center py-10 font-semibold">
|
||||
No payments captured on Razorpay gateway yet.
|
||||
</p>
|
||||
) : processedPayments.length === 0 ? (
|
||||
<div className="border border-slate-200 rounded-2xl p-10 bg-white text-center space-y-2">
|
||||
<p className="text-sm font-bold text-slate-700">No matching payments found</p>
|
||||
<p className="text-xs text-slate-400">
|
||||
No payments match your search query "{searchQuery}".
|
||||
</p>
|
||||
<button
|
||||
onClick={() => setSearchQuery('')}
|
||||
className="text-xs text-indigo-600 font-bold hover:underline mt-2 inline-block"
|
||||
>
|
||||
Clear search query
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-xs">
|
||||
<thead>
|
||||
<tr className="border-b border-slate-200 bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider">
|
||||
<th className="text-left py-3 px-3">Payment ID</th>
|
||||
<th className="text-left py-3 px-3">Date</th>
|
||||
<th className="text-left py-3 px-3">Amount</th>
|
||||
<th className="text-left py-3 px-3">Status</th>
|
||||
<th className="text-left py-3 px-3">Method</th>
|
||||
<th className="text-left py-3 px-3">Email</th>
|
||||
<th className="text-left py-3 px-3">Order ID</th>
|
||||
<th className="text-left py-3 px-3">Invoice</th>
|
||||
<th className="text-center py-3 px-3">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{paginatedPayments.map((p: any, i: number) => {
|
||||
const paymentDate = p.created_at
|
||||
? typeof p.created_at === 'number'
|
||||
? new Date(p.created_at * 1000).toLocaleDateString(undefined, { dateStyle: 'medium' })
|
||||
: new Date(p.created_at).toLocaleDateString(undefined, { dateStyle: 'medium' })
|
||||
: '—';
|
||||
|
||||
return (
|
||||
<tr key={p.id || i} className="border-b border-slate-100 hover:bg-slate-50 transition-colors">
|
||||
<td className="py-2.5 px-3 font-mono text-indigo-600 font-bold">{p.id}</td>
|
||||
<td className="py-2.5 px-3 text-slate-500 whitespace-nowrap">{paymentDate}</td>
|
||||
<td className="py-2.5 px-3 font-bold text-slate-800 whitespace-nowrap">
|
||||
{p.currency === 'USD' ? '$' : p.currency === 'EUR' ? '€' : '₹'}
|
||||
{p.amount ? (p.amount / 100).toFixed(2) : '—'}
|
||||
</td>
|
||||
<td className="py-2.5 px-3">
|
||||
<span
|
||||
className={`px-2 py-0.5 rounded-full text-[10px] font-bold ${
|
||||
p.status === 'captured'
|
||||
? 'bg-emerald-50 text-emerald-700 border border-emerald-200'
|
||||
: p.status === 'authorized'
|
||||
? 'bg-blue-50 text-blue-700 border border-blue-200'
|
||||
: p.status === 'failed'
|
||||
? 'bg-rose-50 text-rose-700 border border-rose-200'
|
||||
: 'bg-slate-100 text-slate-600 border border-slate-200'
|
||||
}`}
|
||||
>
|
||||
{p.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="py-2.5 px-3 text-slate-600 capitalize">{p.method || '—'}</td>
|
||||
<td className="py-2.5 px-3 text-slate-600 truncate max-w-[160px]">{p.email || '—'}</td>
|
||||
<td className="py-2.5 px-3 font-mono text-slate-500 text-[10px]">{p.order_id || '—'}</td>
|
||||
<td className="py-2.5 px-3">
|
||||
{p.invoice_number ? (
|
||||
<span
|
||||
className={`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md text-[10px] font-black font-mono shadow-xs ${
|
||||
p.invoice_number.startsWith('inv_')
|
||||
? 'bg-indigo-50/70 border border-indigo-200 text-indigo-700'
|
||||
: 'bg-amber-50/70 border border-amber-200 text-amber-700'
|
||||
}`}
|
||||
>
|
||||
<Receipt
|
||||
className={`h-3 w-3 ${
|
||||
p.invoice_number.startsWith('inv_') ? 'text-indigo-500' : 'text-amber-500'
|
||||
}`}
|
||||
/>
|
||||
{p.invoice_number}
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-slate-300 italic text-[10px]">Not generated</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-2.5 px-3">
|
||||
{p.status === 'captured' && (
|
||||
<div className="flex items-center justify-center gap-1.5">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDownloadInvoice(p.id)}
|
||||
disabled={downloadingId === p.id}
|
||||
className="h-7 w-7 flex items-center justify-center bg-indigo-50 hover:bg-indigo-100 disabled:bg-slate-100 disabled:text-slate-400 border border-indigo-200 text-indigo-700 rounded-lg cursor-pointer transition-colors shadow-xs"
|
||||
title="Download Invoice PDF"
|
||||
>
|
||||
{downloadingId === p.id ? (
|
||||
<RefreshCw className="h-3.5 w-3.5 animate-spin" />
|
||||
) : (
|
||||
<Download className="h-3.5 w-3.5" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onShareInvoice(p.id)}
|
||||
disabled={sharingId === p.id}
|
||||
className="h-7 w-7 flex items-center justify-center bg-slate-900 hover:bg-slate-800 disabled:bg-slate-100 disabled:text-slate-400 border border-slate-800 text-white rounded-lg cursor-pointer transition-colors shadow-xs"
|
||||
title="Share Invoice via Email"
|
||||
>
|
||||
{sharingId === p.id ? (
|
||||
<RefreshCw className="h-3.5 w-3.5 animate-spin text-indigo-400" />
|
||||
) : (
|
||||
<Mail className="h-3.5 w-3.5 text-indigo-400" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<Pagination
|
||||
currentPage={safePage}
|
||||
totalItems={totalFiltered}
|
||||
itemsPerPage={perPage}
|
||||
onPageChange={onPageChange}
|
||||
onItemsPerPageChange={onPerPageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,303 @@
|
|||
import React from 'react';
|
||||
import { AlertCircle, RefreshCw } from 'lucide-react';
|
||||
|
||||
interface CreatePlanModalProps {
|
||||
show: boolean;
|
||||
code: string;
|
||||
name: string;
|
||||
desc: string;
|
||||
badge: string;
|
||||
heading: string;
|
||||
subtitle: string;
|
||||
type: string;
|
||||
duration: string;
|
||||
priceInr: string;
|
||||
priceUsd: string;
|
||||
selectedModuleIds: string[];
|
||||
allModules: any[];
|
||||
saving: boolean;
|
||||
error: string | null;
|
||||
onCodeChange: (v: string) => void;
|
||||
onNameChange: (v: string) => void;
|
||||
onDescChange: (v: string) => void;
|
||||
onBadgeChange: (v: string) => void;
|
||||
onHeadingChange: (v: string) => void;
|
||||
onSubtitleChange: (v: string) => void;
|
||||
onTypeChange: (v: string) => void;
|
||||
onDurationChange: (v: string) => void;
|
||||
onPriceInrChange: (v: string) => void;
|
||||
onPriceUsdChange: (v: string) => void;
|
||||
onToggleModule: (id: string) => void;
|
||||
onSelectAllModules: () => void;
|
||||
onClearAllModules: () => void;
|
||||
onSave: (e: React.FormEvent) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const CreatePlanModal: React.FC<CreatePlanModalProps> = ({
|
||||
show,
|
||||
code,
|
||||
name,
|
||||
desc,
|
||||
badge,
|
||||
heading,
|
||||
subtitle,
|
||||
type,
|
||||
duration,
|
||||
priceInr,
|
||||
priceUsd,
|
||||
selectedModuleIds,
|
||||
allModules,
|
||||
saving,
|
||||
error,
|
||||
onCodeChange,
|
||||
onNameChange,
|
||||
onDescChange,
|
||||
onBadgeChange,
|
||||
onHeadingChange,
|
||||
onSubtitleChange,
|
||||
onTypeChange,
|
||||
onDurationChange,
|
||||
onPriceInrChange,
|
||||
onPriceUsdChange,
|
||||
onToggleModule,
|
||||
onSelectAllModules,
|
||||
onClearAllModules,
|
||||
onSave,
|
||||
onClose,
|
||||
}) => {
|
||||
if (!show) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4">
|
||||
<div className="bg-white rounded-3xl border border-slate-200 shadow-2xl max-w-xl w-full p-6 space-y-5 max-h-[90vh] overflow-y-auto animate-in fade-in zoom-in duration-150">
|
||||
<div className="flex items-center justify-between border-b border-slate-100 pb-3">
|
||||
<div>
|
||||
<h3 className="text-base font-bold text-slate-800">Create Custom Plan / Bundle</h3>
|
||||
<p className="text-xs text-slate-400">Assemble arbitrary modules into a brand-new package.</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="text-slate-400 hover:text-slate-600 text-sm font-bold p-1 cursor-pointer"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<div className="bg-rose-50 border border-rose-200 rounded-xl p-3 text-xs text-rose-700 font-bold flex items-center gap-2">
|
||||
<AlertCircle className="h-4 w-4 shrink-0" />
|
||||
<span>{error}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<form onSubmit={onSave} className="space-y-4">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Plan Code (Unique)</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. PAIN_CLINICAL_PACK"
|
||||
required
|
||||
value={code}
|
||||
onChange={(e) => onCodeChange(e.target.value.toUpperCase().replace(/\s+/g, '_'))}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-mono font-bold text-slate-800 focus:outline-none focus:border-indigo-500 uppercase"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Display Title</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. Pain Management Specialist Pack"
|
||||
required
|
||||
value={name}
|
||||
onChange={(e) => onNameChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Description</label>
|
||||
<textarea
|
||||
rows={2}
|
||||
placeholder="Details regarding clinical contents unlocked by this pack..."
|
||||
value={desc}
|
||||
onChange={(e) => onDescChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Storefront Presentation Fields */}
|
||||
<div className="bg-indigo-50/60 border border-indigo-100 rounded-2xl p-3.5 space-y-3">
|
||||
<span className="text-xs font-bold text-indigo-900 block">🎨 Storefront Presentation & Headlines (Optional)</span>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Badge Pill Text</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="✨ CUSTOM PACKAGES & BUNDLES"
|
||||
value={badge}
|
||||
onChange={(e) => onBadgeChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Card Heading</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Special Curated Bundles"
|
||||
value={heading}
|
||||
onChange={(e) => onHeadingChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Card Subtitle / Description</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Custom curriculum collections created exclusively for practitioners."
|
||||
value={subtitle}
|
||||
onChange={(e) => onSubtitleChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Type & Duration */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Plan Type</label>
|
||||
<select
|
||||
value={type}
|
||||
onChange={(e) => onTypeChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="bundle">Bundle (Multi-module pack)</option>
|
||||
<option value="one_time">One-time / Standalone</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Billing Duration</label>
|
||||
<select
|
||||
value={duration}
|
||||
onChange={(e) => onDurationChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-semibold text-slate-800 focus:outline-none focus:border-indigo-500 cursor-pointer"
|
||||
>
|
||||
<option value="yearly">1 Year Access</option>
|
||||
<option value="monthly">1 Month Access</option>
|
||||
<option value="quarterly">3 Months Access</option>
|
||||
<option value="lifetime">Lifetime Access (10 Years)</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Dual Currency Pricing */}
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs">₹</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
placeholder="1499.00"
|
||||
required
|
||||
value={priceInr}
|
||||
onChange={(e) => onPriceInrChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price ($ USD)</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs">$</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
placeholder="19.99"
|
||||
required
|
||||
value={priceUsd}
|
||||
onChange={(e) => onPriceUsdChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Module Selection */}
|
||||
<div className="space-y-2 border-t border-slate-100 pt-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<label className="text-xs font-bold text-slate-700">
|
||||
Select Included Modules ({selectedModuleIds.length} selected)
|
||||
</label>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSelectAllModules}
|
||||
className="text-[10px] font-bold text-indigo-600 hover:text-indigo-800 cursor-pointer"
|
||||
>
|
||||
Select All
|
||||
</button>
|
||||
<span className="text-slate-300">•</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClearAllModules}
|
||||
className="text-[10px] font-bold text-slate-500 hover:text-slate-700 cursor-pointer"
|
||||
>
|
||||
Clear All
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2 max-h-48 overflow-y-auto p-2 bg-slate-50 border border-slate-200 rounded-xl">
|
||||
{allModules.map((mod) => {
|
||||
const isSelected = selectedModuleIds.includes(mod.id);
|
||||
return (
|
||||
<label
|
||||
key={mod.id}
|
||||
className={`flex items-center gap-2.5 p-2 rounded-lg border text-xs cursor-pointer transition-colors ${
|
||||
isSelected
|
||||
? 'bg-indigo-50/80 border-indigo-300 text-indigo-950 font-bold'
|
||||
: 'bg-white border-slate-200 text-slate-700 hover:bg-slate-100/60'
|
||||
}`}
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={isSelected}
|
||||
onChange={() => onToggleModule(mod.id)}
|
||||
className="rounded text-indigo-600 focus:ring-indigo-500 h-3.5 w-3.5 cursor-pointer"
|
||||
/>
|
||||
<div className="truncate flex-1">
|
||||
<p className="truncate text-xs">{mod.name}</p>
|
||||
<span className="text-[9px] text-slate-400 font-semibold">{mod.category || 'General'}</span>
|
||||
</div>
|
||||
</label>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 pt-3 border-t border-slate-100">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="flex-1 py-2.5 rounded-xl text-xs font-bold bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors cursor-pointer"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="flex-1 py-2.5 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors flex items-center justify-center gap-1.5 shadow-md shadow-indigo-600/20 cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{saving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : 'Create & Publish Plan'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,171 @@
|
|||
import React from 'react';
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
|
||||
interface EditPriceModalProps {
|
||||
plan: any | null;
|
||||
name: string;
|
||||
desc: string;
|
||||
badge: string;
|
||||
heading: string;
|
||||
subtitle: string;
|
||||
priceInr: string;
|
||||
priceUsd: string;
|
||||
saving: boolean;
|
||||
onNameChange: (v: string) => void;
|
||||
onDescChange: (v: string) => void;
|
||||
onBadgeChange: (v: string) => void;
|
||||
onHeadingChange: (v: string) => void;
|
||||
onSubtitleChange: (v: string) => void;
|
||||
onPriceInrChange: (v: string) => void;
|
||||
onPriceUsdChange: (v: string) => void;
|
||||
onSave: (e: React.FormEvent) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
export const EditPriceModal: React.FC<EditPriceModalProps> = ({
|
||||
plan,
|
||||
name,
|
||||
desc,
|
||||
badge,
|
||||
heading,
|
||||
subtitle,
|
||||
priceInr,
|
||||
priceUsd,
|
||||
saving,
|
||||
onNameChange,
|
||||
onDescChange,
|
||||
onBadgeChange,
|
||||
onHeadingChange,
|
||||
onSubtitleChange,
|
||||
onPriceInrChange,
|
||||
onPriceUsdChange,
|
||||
onSave,
|
||||
onClose,
|
||||
}) => {
|
||||
if (!plan) return null;
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4">
|
||||
<div className="bg-white rounded-3xl border border-slate-200 shadow-2xl max-w-lg w-full p-6 space-y-5 max-h-[90vh] overflow-y-auto animate-in fade-in zoom-in duration-150">
|
||||
<div className="flex items-center justify-between border-b border-slate-100 pb-3">
|
||||
<div>
|
||||
<h3 className="text-base font-bold text-slate-800">Edit Plan Details & Pricing</h3>
|
||||
<p className="text-xs text-slate-400">Update rates and storefront presentation.</p>
|
||||
</div>
|
||||
<span className="px-2 py-0.5 rounded text-[10px] font-mono font-bold bg-indigo-50 text-indigo-600 border border-indigo-100">
|
||||
{plan.base_code || plan.code}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<form onSubmit={onSave} className="space-y-4">
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Plan Display Name</label>
|
||||
<input
|
||||
type="text"
|
||||
required
|
||||
value={name}
|
||||
onChange={(e) => onNameChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Plan Description</label>
|
||||
<textarea
|
||||
rows={2}
|
||||
value={desc}
|
||||
onChange={(e) => onDescChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Storefront Presentation */}
|
||||
<div className="bg-indigo-50/60 border border-indigo-100 rounded-2xl p-3.5 space-y-3">
|
||||
<span className="text-xs font-bold text-indigo-900 block">🎨 Storefront Presentation (Optional)</span>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Badge Pill Text</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="✨ CUSTOM PACKAGES & BUNDLES"
|
||||
value={badge}
|
||||
onChange={(e) => onBadgeChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Card Heading</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Special Curated Bundles"
|
||||
value={heading}
|
||||
onChange={(e) => onHeadingChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[11px] font-bold text-slate-600 mb-1">Card Subtitle / Description</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Custom curriculum collections created exclusively for practitioners."
|
||||
value={subtitle}
|
||||
onChange={(e) => onSubtitleChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-1.5 text-xs text-slate-800 focus:outline-none focus:border-indigo-500 placeholder:text-slate-400"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price (₹ INR)</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs">₹</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
required
|
||||
value={priceInr}
|
||||
onChange={(e) => onPriceInrChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className="block text-xs font-bold text-slate-600 mb-1">Price ($ USD)</label>
|
||||
<div className="relative">
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 font-bold text-xs">$</span>
|
||||
<input
|
||||
type="number"
|
||||
step="0.01"
|
||||
min="0"
|
||||
required
|
||||
value={priceUsd}
|
||||
onChange={(e) => onPriceUsdChange(e.target.value)}
|
||||
className="w-full bg-slate-50 border border-slate-200 rounded-xl pl-7 pr-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 pt-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="flex-1 py-2 rounded-xl text-xs font-bold bg-slate-100 hover:bg-slate-200 text-slate-600 transition-colors cursor-pointer"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={saving}
|
||||
className="flex-1 py-2 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white transition-colors flex items-center justify-center gap-1.5 shadow-sm cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{saving ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : 'Save Changes'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,329 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Plus, Tag, Users, Edit, Sparkles } from 'lucide-react';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
|
||||
interface PlansTabProps {
|
||||
plans: any[];
|
||||
searchQuery: string;
|
||||
typeFilter: string;
|
||||
currentPage: number;
|
||||
perPage: number;
|
||||
onSearchChange: (q: string) => void;
|
||||
onTypeFilterChange: (f: string) => void;
|
||||
onPageChange: (p: number) => void;
|
||||
onPerPageChange: (pp: number) => void;
|
||||
onOpenCreatePlan: () => void;
|
||||
onTogglePlanStatus: (plan: any) => void;
|
||||
onOpenEditPrice: (plan: any) => void;
|
||||
}
|
||||
|
||||
export const PlansTab: React.FC<PlansTabProps> = ({
|
||||
plans,
|
||||
searchQuery,
|
||||
typeFilter,
|
||||
currentPage,
|
||||
perPage,
|
||||
onSearchChange,
|
||||
onTypeFilterChange,
|
||||
onPageChange,
|
||||
onPerPageChange,
|
||||
onOpenCreatePlan,
|
||||
onTogglePlanStatus,
|
||||
onOpenEditPrice,
|
||||
}) => {
|
||||
const [expandedModules, setExpandedModules] = useState<Record<string, boolean>>({});
|
||||
|
||||
const toggleExpandModules = (planKey: string) => {
|
||||
setExpandedModules((prev) => ({ ...prev, [planKey]: !prev[planKey] }));
|
||||
};
|
||||
|
||||
const filteredPlans = plans.filter((plan) => {
|
||||
const q = searchQuery.toLowerCase().trim();
|
||||
const matchesSearch =
|
||||
!q ||
|
||||
plan.base_code?.toLowerCase().includes(q) ||
|
||||
plan.name?.toLowerCase().includes(q) ||
|
||||
plan.description?.toLowerCase().includes(q) ||
|
||||
(plan.modules &&
|
||||
plan.modules.some(
|
||||
(m: any) => m.name?.toLowerCase().includes(q) || m.slug?.toLowerCase().includes(q)
|
||||
));
|
||||
|
||||
if (!matchesSearch) return false;
|
||||
|
||||
if (typeFilter === 'bundle') return plan.plan_type === 'bundle';
|
||||
if (typeFilter === 'one_time') return plan.plan_type !== 'bundle';
|
||||
if (typeFilter === 'active') return plan.is_active === true;
|
||||
if (typeFilter === 'inactive') return plan.is_active === false;
|
||||
return true;
|
||||
});
|
||||
|
||||
const totalFiltered = filteredPlans.length;
|
||||
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
||||
const safePage = Math.min(currentPage, totalPages);
|
||||
const startIndex = (safePage - 1) * perPage;
|
||||
const paginatedPlans = filteredPlans.slice(startIndex, startIndex + perPage);
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Header & Filter Bar */}
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 space-y-3.5">
|
||||
<div className="flex flex-col sm:flex-row gap-3 items-center justify-between">
|
||||
<div className="w-full sm:w-80 relative">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search plan code, name, or module..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => {
|
||||
onSearchChange(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-9 pr-4 py-2 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 shadow-sm"
|
||||
/>
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 text-xs">🔍</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 w-full sm:w-auto justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={onOpenCreatePlan}
|
||||
className="flex items-center gap-1.5 px-4 py-2 rounded-xl text-xs font-bold bg-indigo-600 hover:bg-indigo-500 text-white shadow-md shadow-indigo-600/20 transition-all cursor-pointer whitespace-nowrap"
|
||||
>
|
||||
<Plus className="h-3.5 w-3.5" /> Create Custom Plan
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Filter Pills */}
|
||||
<div className="flex items-center gap-1.5 flex-wrap border-t border-slate-200/60 pt-3">
|
||||
<span className="text-[10px] uppercase font-bold text-slate-400 mr-1">Filter:</span>
|
||||
{[
|
||||
{ key: 'all', label: `All Plans (${plans.length})` },
|
||||
{ key: 'bundle', label: `Bundles (${plans.filter((p) => p.plan_type === 'bundle').length})` },
|
||||
{ key: 'one_time', label: `Single Modules (${plans.filter((p) => p.plan_type !== 'bundle').length})` },
|
||||
{ key: 'active', label: `Active (${plans.filter((p) => p.is_active).length})` },
|
||||
{ key: 'inactive', label: `Inactive (${plans.filter((p) => !p.is_active).length})` },
|
||||
].map((f) => (
|
||||
<button
|
||||
key={f.key}
|
||||
type="button"
|
||||
onClick={() => {
|
||||
onTypeFilterChange(f.key);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className={`px-3 py-1 rounded-lg text-xs font-bold transition-colors cursor-pointer ${
|
||||
typeFilter === f.key
|
||||
? 'bg-indigo-600 text-white shadow-sm'
|
||||
: 'bg-white border border-slate-200 text-slate-600 hover:bg-slate-100 shadow-sm'
|
||||
}`}
|
||||
>
|
||||
{f.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Plans Ledger Table */}
|
||||
{filteredPlans.length === 0 ? (
|
||||
<div className="bg-slate-50 border border-slate-200 rounded-2xl p-10 text-center space-y-2">
|
||||
<Tag className="h-8 w-8 text-slate-300 mx-auto" />
|
||||
<p className="text-sm font-bold text-slate-600">No subscription plans found</p>
|
||||
<p className="text-xs text-slate-400">Try adjusting your search query or filter settings.</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-sm bg-white p-4">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-left border-collapse">
|
||||
<thead>
|
||||
<tr className="bg-slate-50 border-b border-slate-200 text-[11px] uppercase font-bold text-slate-400 tracking-wider">
|
||||
<th className="py-3.5 px-4">Plan Details</th>
|
||||
<th className="py-3.5 px-3">Type & Duration</th>
|
||||
<th className="py-3.5 px-3">Included Modules</th>
|
||||
<th className="py-3.5 px-3">Live Pricing (INR / USD)</th>
|
||||
<th className="py-3.5 px-3 text-center">Subscribers</th>
|
||||
<th className="py-3.5 px-3 text-center">Status</th>
|
||||
<th className="py-3.5 px-4 text-right">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-slate-100 text-xs">
|
||||
{paginatedPlans.map((plan) => (
|
||||
<tr
|
||||
key={plan.base_code || plan.code || plan.id}
|
||||
className={`hover:bg-slate-50/80 transition-colors ${
|
||||
!plan.is_active ? 'opacity-65 bg-slate-50/30' : ''
|
||||
}`}
|
||||
>
|
||||
{/* Plan Details */}
|
||||
<td className="py-3.5 px-4">
|
||||
<div className="space-y-0.5 max-w-xs">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="font-bold text-slate-800">{plan.name}</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<code className="text-[10px] font-mono text-indigo-600 bg-indigo-50 px-1.5 py-0.5 rounded border border-indigo-100 font-bold">
|
||||
{plan.base_code || plan.code}
|
||||
</code>
|
||||
</div>
|
||||
{plan.description && (
|
||||
<p className="text-[11px] text-slate-400 truncate max-w-xs">{plan.description}</p>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Type & Duration */}
|
||||
<td className="py-3.5 px-3 whitespace-nowrap">
|
||||
<div className="space-y-1">
|
||||
<span
|
||||
className={`inline-block px-2 py-0.5 rounded-md text-[10px] font-bold ${
|
||||
plan.plan_type === 'bundle'
|
||||
? 'bg-purple-100 text-purple-700 border border-purple-200'
|
||||
: 'bg-blue-100 text-blue-700 border border-blue-200'
|
||||
}`}
|
||||
>
|
||||
{plan.plan_type === 'bundle' ? 'Package Bundle' : 'Single Module'}
|
||||
</span>
|
||||
<p className="text-[10px] text-slate-500 capitalize">
|
||||
{plan.billing_period === 'lifetime'
|
||||
? 'Lifetime Access'
|
||||
: `${plan.billing_period || 'yearly'} Billing`}
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Included Modules */}
|
||||
<td className="py-3.5 px-3">
|
||||
{plan.modules && plan.modules.length > 0 ? (
|
||||
<div className="max-w-xs">
|
||||
{plan.code === 'LIFETIME_ALL' || plan.base_code === 'LIFETIME_ALL' ? (
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[10px] font-black bg-gradient-to-r from-amber-50 to-orange-50 text-amber-800 border border-amber-300 shadow-xs">
|
||||
<Sparkles className="h-3 w-3 text-amber-500 shrink-0" />
|
||||
All Modules ({plan.modules.length})
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => toggleExpandModules(plan.base_code || plan.code || plan.id)}
|
||||
className="text-[10px] font-bold text-indigo-600 hover:text-indigo-800 underline cursor-pointer"
|
||||
>
|
||||
{expandedModules[plan.base_code || plan.code || plan.id] ? 'Hide' : 'View all'}
|
||||
</button>
|
||||
</div>
|
||||
{expandedModules[plan.base_code || plan.code || plan.id] && (
|
||||
<div className="flex flex-wrap gap-1 mt-1.5 p-2 bg-slate-50 border border-slate-200 rounded-lg max-h-36 overflow-y-auto">
|
||||
{plan.modules.map((m: any, i: number) => (
|
||||
<span
|
||||
key={m.id || i}
|
||||
className="text-[10px] font-bold px-1.5 py-0.5 rounded bg-white text-slate-700 border border-slate-200 whitespace-nowrap"
|
||||
>
|
||||
{m.name || m.slug}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<div className="flex flex-wrap gap-1 items-center">
|
||||
{(expandedModules[plan.base_code || plan.code || plan.id]
|
||||
? plan.modules
|
||||
: plan.modules.slice(0, 3)
|
||||
).map((m: any, i: number) => (
|
||||
<span
|
||||
key={m.id || i}
|
||||
className="text-[10px] font-bold px-1.5 py-0.5 rounded bg-slate-100 text-slate-700 border border-slate-200 whitespace-nowrap"
|
||||
>
|
||||
{m.name || m.slug}
|
||||
</span>
|
||||
))}
|
||||
{plan.modules.length > 3 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => toggleExpandModules(plan.base_code || plan.code || plan.id)}
|
||||
className="text-[10px] font-bold px-1.5 py-0.5 rounded bg-indigo-50 text-indigo-700 border border-indigo-200 hover:bg-indigo-100 transition-colors cursor-pointer whitespace-nowrap"
|
||||
>
|
||||
{expandedModules[plan.base_code || plan.code || plan.id]
|
||||
? 'Show less'
|
||||
: `+${plan.modules.length - 3} more`}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<span className="text-[10px] text-slate-400 italic">No modules attached</span>
|
||||
)}
|
||||
</td>
|
||||
|
||||
{/* Pricing */}
|
||||
<td className="py-3.5 px-3 whitespace-nowrap">
|
||||
<div className="space-y-0.5 font-bold">
|
||||
<p className="text-xs text-slate-800 font-mono">₹{plan.price_inr ?? '—'}</p>
|
||||
<p className="text-[10px] text-slate-400 font-mono">${plan.price_usd ?? '—'}</p>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
{/* Subscribers */}
|
||||
<td className="py-3.5 px-3 text-center whitespace-nowrap">
|
||||
<span
|
||||
className={`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-[10px] font-bold ${
|
||||
(plan.subscribers_count || 0) > 0
|
||||
? 'bg-indigo-50 text-indigo-700 border border-indigo-200'
|
||||
: 'bg-slate-50 text-slate-400 border border-slate-200'
|
||||
}`}
|
||||
>
|
||||
<Users className="h-3 w-3" />
|
||||
{plan.subscribers_count || 0}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* Live Status Toggle */}
|
||||
<td className="py-3.5 px-3 text-center whitespace-nowrap">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onTogglePlanStatus(plan)}
|
||||
className={`relative inline-flex h-5 w-9 shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none ${
|
||||
plan.is_active ? 'bg-indigo-600' : 'bg-slate-300'
|
||||
}`}
|
||||
title={plan.is_active ? 'Click to deactivate' : 'Click to activate'}
|
||||
>
|
||||
<span
|
||||
className={`pointer-events-none inline-block h-4 w-4 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out ${
|
||||
plan.is_active ? 'translate-x-4' : 'translate-x-0'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
<span className="block text-[9px] font-bold text-slate-400 mt-0.5">
|
||||
{plan.is_active ? 'Active' : 'Inactive'}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
{/* Actions */}
|
||||
<td className="py-3.5 px-4 text-right whitespace-nowrap">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onOpenEditPrice(plan)}
|
||||
className="inline-flex items-center gap-1 px-3 py-1.5 rounded-lg text-xs font-bold bg-slate-100 hover:bg-indigo-50 hover:text-indigo-600 text-slate-600 transition-colors border border-slate-200 cursor-pointer shadow-sm"
|
||||
>
|
||||
<Edit className="h-3 w-3" /> Edit Info & Price
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<Pagination
|
||||
currentPage={safePage}
|
||||
totalItems={totalFiltered}
|
||||
itemsPerPage={perPage}
|
||||
onPageChange={onPageChange}
|
||||
onItemsPerPageChange={onPerPageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
import React, { useState, useMemo } from 'react';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
import { ArrowUpDown, ArrowDown, ArrowUp } from 'lucide-react';
|
||||
|
||||
interface SubscriptionsTabProps {
|
||||
subscriptions: any[];
|
||||
filterCustomerName: string;
|
||||
filterModuleName: string;
|
||||
currentPage: number;
|
||||
perPage: number;
|
||||
onFilterCustomerChange: (v: string) => void;
|
||||
onFilterModuleChange: (v: string) => void;
|
||||
onPageChange: (p: number) => void;
|
||||
onPerPageChange: (pp: number) => void;
|
||||
}
|
||||
|
||||
export const SubscriptionsTab: React.FC<SubscriptionsTabProps> = ({
|
||||
subscriptions,
|
||||
filterCustomerName,
|
||||
filterModuleName,
|
||||
currentPage,
|
||||
perPage,
|
||||
onFilterCustomerChange,
|
||||
onFilterModuleChange,
|
||||
onPageChange,
|
||||
onPerPageChange,
|
||||
}) => {
|
||||
const [sortOrder, setSortOrder] = useState<'desc' | 'asc'>('desc');
|
||||
|
||||
const processedSubs = useMemo(() => {
|
||||
let result = subscriptions.filter((sub: any) => {
|
||||
const custName = (sub.user_name || '').toLowerCase();
|
||||
const custEmail = (sub.user_email || '').toLowerCase();
|
||||
const modName = (sub.plan_name || '').toLowerCase();
|
||||
const modCode = (sub.plan_code || '').toLowerCase();
|
||||
|
||||
const queryCust = filterCustomerName.toLowerCase();
|
||||
const queryMod = filterModuleName.toLowerCase();
|
||||
|
||||
const matchCust = !queryCust || custName.includes(queryCust) || custEmail.includes(queryCust);
|
||||
const matchMod = !queryMod || modName.includes(queryMod) || modCode.includes(queryMod);
|
||||
|
||||
return matchCust && matchMod;
|
||||
});
|
||||
|
||||
result.sort((a: any, b: any) => {
|
||||
const timeA = a.started_at ? new Date(a.started_at).getTime() : 0;
|
||||
const timeB = b.started_at ? new Date(b.started_at).getTime() : 0;
|
||||
return sortOrder === 'desc' ? timeB - timeA : timeA - timeB;
|
||||
});
|
||||
|
||||
return result;
|
||||
}, [subscriptions, filterCustomerName, filterModuleName, sortOrder]);
|
||||
|
||||
const totalFiltered = processedSubs.length;
|
||||
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
||||
const safePage = Math.min(currentPage, totalPages);
|
||||
const startIndex = (safePage - 1) * perPage;
|
||||
const paginatedSubs = processedSubs.slice(startIndex, startIndex + perPage);
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Search Filters & Sort Controls */}
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 space-y-3">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1.5">
|
||||
Filter by Customer (Name / Email)
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search customer name or email..."
|
||||
value={filterCustomerName}
|
||||
onChange={(e) => {
|
||||
onFilterCustomerChange(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3.5 py-2 text-xs text-slate-800 font-bold focus:outline-none focus:border-indigo-500 transition-all placeholder:text-slate-400 shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1.5">
|
||||
Filter by Module (Name / Code)
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search plan name or code..."
|
||||
value={filterModuleName}
|
||||
onChange={(e) => {
|
||||
onFilterModuleChange(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3.5 py-2 text-xs text-slate-800 font-bold focus:outline-none focus:border-indigo-500 transition-all placeholder:text-slate-400 shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Sort & Count Bar */}
|
||||
<div className="flex justify-between items-center pt-2 border-t border-slate-200/60">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSortOrder(prev => prev === 'desc' ? 'asc' : 'desc')}
|
||||
className="flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-bold bg-white border border-slate-200 text-slate-700 hover:bg-slate-100 hover:border-slate-300 transition-colors shadow-2xs cursor-pointer"
|
||||
title={`Toggle sort order (current: ${sortOrder === 'desc' ? 'Latest first' : 'Oldest first'})`}
|
||||
>
|
||||
<ArrowUpDown className="h-3.5 w-3.5 text-indigo-600" />
|
||||
<span>Sort: {sortOrder === 'desc' ? 'Newest Activated First' : 'Oldest Activated First'}</span>
|
||||
{sortOrder === 'desc' ? (
|
||||
<ArrowDown className="h-3 w-3 text-slate-400" />
|
||||
) : (
|
||||
<ArrowUp className="h-3 w-3 text-slate-400" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<span className="text-xs font-bold text-slate-500">
|
||||
Showing <span className="text-slate-800">{totalFiltered}</span> of{' '}
|
||||
<span className="text-slate-800">{subscriptions.length}</span> subscriptions
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{totalFiltered === 0 ? (
|
||||
<p className="text-sm text-slate-400 italic text-center py-10 font-semibold">
|
||||
No subscriptions match the active filters.
|
||||
</p>
|
||||
) : (
|
||||
<div className="border border-slate-200 rounded-2xl overflow-hidden shadow-xs p-4 bg-white">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-xs">
|
||||
<thead>
|
||||
<tr className="border-b border-slate-200 bg-slate-50/80 text-[10px] uppercase font-bold text-slate-400 tracking-wider">
|
||||
<th className="text-left py-3 px-3">Subscriber</th>
|
||||
<th className="text-left py-3 px-3">Phone</th>
|
||||
<th className="text-left py-3 px-3">Access Plan</th>
|
||||
<th className="text-left py-3 px-3">Status</th>
|
||||
<th className="text-left py-3 px-3">Activated</th>
|
||||
<th className="text-left py-3 px-3">Expires</th>
|
||||
<th className="text-left py-3 px-3">Time Left</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{paginatedSubs.map((sub: any, i: number) => {
|
||||
const daysLeft = sub.days_left;
|
||||
return (
|
||||
<tr key={sub.id || i} className="border-b border-slate-100 hover:bg-slate-50 transition-colors">
|
||||
<td className="py-3 px-3">
|
||||
<p className="font-bold text-slate-800">{sub.user_name || 'Subscriber'}</p>
|
||||
<p className="text-[10px] text-slate-400 font-mono mt-0.5">{sub.user_email}</p>
|
||||
{sub.user_external_ref && (
|
||||
<p className="text-[9px] text-slate-400 font-mono mt-0.5">
|
||||
Cust:{' '}
|
||||
<span className="bg-slate-100 text-slate-600 px-1 py-0.2 rounded font-bold">
|
||||
{sub.user_external_ref}
|
||||
</span>
|
||||
</p>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-3 px-3 text-slate-600 font-semibold">{sub.user_phone || '—'}</td>
|
||||
<td className="py-3 px-3">
|
||||
<p className="font-bold text-slate-800">{sub.plan_name}</p>
|
||||
<p className="text-[9px] text-indigo-500 font-bold uppercase tracking-wider mt-0.5">
|
||||
{sub.plan_code}
|
||||
</p>
|
||||
{sub.payment_reference && (
|
||||
<p className="text-[9px] text-slate-400 font-mono mt-0.5">
|
||||
Order:{' '}
|
||||
<span className="bg-slate-100 text-slate-600 px-1 py-0.2 rounded font-bold">
|
||||
{sub.payment_reference}
|
||||
</span>
|
||||
</p>
|
||||
)}
|
||||
</td>
|
||||
<td className="py-3 px-3">
|
||||
<span
|
||||
className={`px-2 py-0.5 rounded-full text-[10px] font-black uppercase ${
|
||||
sub.status === 'active'
|
||||
? 'bg-emerald-50 text-emerald-700 border border-emerald-200'
|
||||
: sub.status === 'refunded'
|
||||
? 'bg-rose-50 text-rose-700 border border-rose-200'
|
||||
: 'bg-slate-100 text-slate-600 border border-slate-200'
|
||||
}`}
|
||||
>
|
||||
{sub.status}
|
||||
</span>
|
||||
</td>
|
||||
<td className="py-3 px-3 text-slate-600 font-semibold">
|
||||
{sub.started_at
|
||||
? new Date(sub.started_at).toLocaleDateString(undefined, { dateStyle: 'medium' })
|
||||
: '—'}
|
||||
</td>
|
||||
<td className="py-3 px-3 text-slate-600 font-semibold">
|
||||
{sub.expires_at
|
||||
? new Date(sub.expires_at).toLocaleDateString(undefined, { dateStyle: 'medium' })
|
||||
: sub.status === 'active'
|
||||
? 'Lifetime'
|
||||
: '—'}
|
||||
</td>
|
||||
<td className="py-3 px-3">
|
||||
{sub.status === 'active' ? (
|
||||
!sub.expires_at ? (
|
||||
<span className="text-[10px] font-bold text-emerald-600">Lifetime</span>
|
||||
) : daysLeft !== undefined && daysLeft !== null ? (
|
||||
<span
|
||||
className={`text-[10px] font-bold px-2 py-0.5 rounded-full ${
|
||||
daysLeft > 30
|
||||
? 'bg-emerald-50 text-emerald-700'
|
||||
: daysLeft > 7
|
||||
? 'bg-amber-50 text-amber-700'
|
||||
: 'bg-rose-50 text-rose-700'
|
||||
}`}
|
||||
>
|
||||
{daysLeft}d left
|
||||
</span>
|
||||
) : (
|
||||
<span className="text-[10px] text-slate-400">Active</span>
|
||||
)
|
||||
) : (
|
||||
<span className="text-[10px] text-slate-400">Expired</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<Pagination
|
||||
currentPage={safePage}
|
||||
totalItems={totalFiltered}
|
||||
itemsPerPage={perPage}
|
||||
onPageChange={onPageChange}
|
||||
onItemsPerPageChange={onPerPageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
import React from 'react';
|
||||
import { RefreshCcw, RefreshCw, Users, Shield } from 'lucide-react';
|
||||
import type { LoggedInUser } from '../../types';
|
||||
|
||||
interface SyncOverviewProps {
|
||||
stats: {
|
||||
totalUsers: number;
|
||||
subscriptions: number;
|
||||
superAdmins: number;
|
||||
payments: number;
|
||||
};
|
||||
adminLogs: string[];
|
||||
onClearLogs: () => void;
|
||||
}
|
||||
|
||||
export const SyncOverview: React.FC<SyncOverviewProps> = ({
|
||||
stats,
|
||||
adminLogs,
|
||||
onClearLogs,
|
||||
}) => {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* 4 Summary Metric Cards */}
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||||
<div className="bg-gradient-to-br from-blue-50 to-indigo-50 border border-blue-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-indigo-600">{stats.totalUsers}</p>
|
||||
<p className="text-[10px] font-bold text-slate-500 uppercase tracking-wider mt-1">Total Users</p>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-purple-50 to-pink-50 border border-purple-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-purple-600">{stats.subscriptions}</p>
|
||||
<p className="text-[10px] font-bold text-slate-500 uppercase tracking-wider mt-1">Subscriptions</p>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-emerald-50 to-teal-50 border border-emerald-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-emerald-600">{stats.superAdmins}</p>
|
||||
<p className="text-[10px] font-bold text-slate-500 uppercase tracking-wider mt-1">Super Admins</p>
|
||||
</div>
|
||||
<div className="bg-gradient-to-br from-amber-50 to-orange-50 border border-amber-200/60 rounded-2xl p-4 text-center">
|
||||
<p className="text-2xl font-black text-amber-600">{stats.payments}</p>
|
||||
<p className="text-[10px] font-bold text-slate-500 uppercase tracking-wider mt-1">Payments</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Terminal Log Console */}
|
||||
<div className="bg-slate-950 rounded-2xl overflow-hidden shadow-md">
|
||||
<div className="px-4 py-2.5 border-b border-slate-800 flex justify-between items-center text-slate-400">
|
||||
<span className="text-xs font-bold uppercase tracking-wider">System Event Logging Ledger</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClearLogs}
|
||||
className="text-[10px] text-slate-400 hover:text-white font-bold cursor-pointer transition-colors"
|
||||
>
|
||||
Clear Console
|
||||
</button>
|
||||
</div>
|
||||
<div className="p-4 font-mono text-[11px] leading-relaxed h-[220px] overflow-y-auto space-y-1 shadow-inner">
|
||||
{adminLogs.length === 0 ? (
|
||||
<p className="text-slate-600 italic">No admin actions performed in this session. Logs will print here...</p>
|
||||
) : (
|
||||
adminLogs.map((log, index) => {
|
||||
const isError = log.includes('FAILED') || log.includes('Error');
|
||||
const isSuccess = log.includes('SUCCESS');
|
||||
return (
|
||||
<p
|
||||
key={index}
|
||||
className={isError ? 'text-rose-400' : isSuccess ? 'text-emerald-400' : 'text-cyan-400/90'}
|
||||
>
|
||||
{log}
|
||||
</p>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const SyncTopCards: React.FC<{
|
||||
loggedInUser: LoggedInUser | null;
|
||||
adminSyncing: boolean;
|
||||
onForceSync: () => void;
|
||||
}> = ({ loggedInUser, adminSyncing, onForceSync }) => {
|
||||
return (
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-5">
|
||||
{/* Force Sync Box */}
|
||||
<div className="bg-white border border-slate-200 rounded-2xl p-5 shadow-sm space-y-3">
|
||||
<h3 className="text-sm font-bold text-slate-800 flex items-center gap-2">
|
||||
<RefreshCcw className="h-4 w-4 text-cyan-500" /> Database Sync
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500 leading-relaxed font-semibold">
|
||||
Pulls active payment states from the Razorpay API and resolves pending database rows.
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onForceSync}
|
||||
disabled={adminSyncing || !loggedInUser}
|
||||
className="w-full py-2 rounded-xl bg-cyan-600 hover:bg-cyan-500 disabled:bg-slate-200 disabled:text-slate-400 text-xs font-bold text-white transition-colors flex items-center justify-center gap-2 cursor-pointer shadow-sm"
|
||||
>
|
||||
{adminSyncing ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : <RefreshCcw className="h-3.5 w-3.5" />}
|
||||
<span>Force-Sync Gateway</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Status Box */}
|
||||
<div className="bg-white border border-slate-200 rounded-2xl p-5 shadow-sm space-y-3">
|
||||
<h3 className="text-sm font-bold text-slate-800 flex items-center gap-2">
|
||||
<Users className="h-4 w-4 text-indigo-500" /> User Session
|
||||
</h3>
|
||||
{loggedInUser ? (
|
||||
<div className="text-[11px] text-slate-700 space-y-1 font-bold leading-relaxed">
|
||||
<p>✓ Email: <span className="text-indigo-600 font-bold">{loggedInUser.email}</span></p>
|
||||
<p>✓ Country: {loggedInUser.country || 'N/A'}</p>
|
||||
<p>✓ Roles: {(loggedInUser.roles || []).join(', ')}</p>
|
||||
</div>
|
||||
) : (
|
||||
<p className="text-xs text-slate-400 italic font-semibold">No session active. Register on storefront.</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Compliance Box */}
|
||||
<div className="bg-white border border-slate-200 rounded-2xl p-5 shadow-sm space-y-3">
|
||||
<h3 className="text-sm font-bold text-slate-800 flex items-center gap-2">
|
||||
<Shield className="h-4 w-4 text-emerald-500" /> Tax Compliance
|
||||
</h3>
|
||||
<div className="text-[10px] text-slate-400 space-y-1 font-bold">
|
||||
<p>✓ CGST: 9% split</p>
|
||||
<p>✓ SGST: 9% split</p>
|
||||
<p>✓ ISO compliance generated automatically</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
import React from 'react';
|
||||
import { Shield, RefreshCw, UserPlus } from 'lucide-react';
|
||||
|
||||
interface AdminsTabProps {
|
||||
admins: any[];
|
||||
name: string;
|
||||
email: string;
|
||||
password: string;
|
||||
loading: boolean;
|
||||
onNameChange: (v: string) => void;
|
||||
onEmailChange: (v: string) => void;
|
||||
onPasswordChange: (v: string) => void;
|
||||
onCreateAdmin: (e: React.FormEvent) => void;
|
||||
}
|
||||
|
||||
export const AdminsTab: React.FC<AdminsTabProps> = ({
|
||||
admins,
|
||||
name,
|
||||
email,
|
||||
password,
|
||||
loading,
|
||||
onNameChange,
|
||||
onEmailChange,
|
||||
onPasswordChange,
|
||||
onCreateAdmin,
|
||||
}) => {
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Onboard System Administrator Form */}
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-5 shadow-xs">
|
||||
<h3 className="text-sm font-black text-slate-800 uppercase tracking-wider mb-1 flex items-center gap-1.5">
|
||||
<UserPlus className="h-4 w-4 text-indigo-600" /> Onboard System Administrator
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500 font-semibold mb-5">
|
||||
Instantly register a new administrative account with super_admin privileges.
|
||||
</p>
|
||||
|
||||
<form onSubmit={onCreateAdmin} className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-3 items-end">
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Full Name</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="e.g. Dr. Jane Smith"
|
||||
value={name}
|
||||
onChange={(e) => onNameChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 font-bold focus:outline-none focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 placeholder:text-slate-300 shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Email Address *</label>
|
||||
<input
|
||||
type="email"
|
||||
required
|
||||
placeholder="admin@acupedia.in"
|
||||
value={email}
|
||||
onChange={(e) => onEmailChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 font-bold focus:outline-none focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 placeholder:text-slate-300 shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-[10px] uppercase font-bold text-slate-500 mb-1">Password *</label>
|
||||
<input
|
||||
type="password"
|
||||
required
|
||||
placeholder="••••••••"
|
||||
value={password}
|
||||
onChange={(e) => onPasswordChange(e.target.value)}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-3 py-2 text-xs text-slate-800 font-bold focus:outline-none focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 placeholder:text-slate-300 shadow-sm"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={loading}
|
||||
className="w-full py-2 bg-indigo-600 hover:bg-indigo-500 text-white rounded-xl text-xs font-bold transition-all flex items-center justify-center gap-1.5 shadow-md shadow-indigo-600/10 disabled:bg-slate-200 disabled:text-slate-400 cursor-pointer"
|
||||
>
|
||||
{loading ? <RefreshCw className="h-3.5 w-3.5 animate-spin" /> : <UserPlus className="h-3.5 w-3.5" />}
|
||||
<span>Create Admin</span>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{/* Active Administrators Ledger */}
|
||||
<div className="bg-white border border-slate-200 rounded-2xl p-5 shadow-sm space-y-3.5">
|
||||
<h4 className="text-xs font-black text-indigo-600 uppercase tracking-wider flex items-center gap-1.5">
|
||||
<Shield className="h-4 w-4" /> Active Administrators ({admins.length})
|
||||
</h4>
|
||||
|
||||
<div className="max-h-[300px] overflow-y-auto space-y-2 pr-1">
|
||||
{admins.length === 0 ? (
|
||||
<p className="text-xs text-slate-400 italic py-4 font-semibold">No admins loaded.</p>
|
||||
) : (
|
||||
admins.map((adminItem: any, idx: number) => (
|
||||
<div
|
||||
key={idx}
|
||||
className="flex justify-between items-center border border-slate-100 bg-slate-50/60 hover:bg-slate-50 rounded-xl p-3 text-xs transition-colors"
|
||||
>
|
||||
<div>
|
||||
<p className="font-bold text-slate-800">{adminItem.display_name || 'System Admin'}</p>
|
||||
<p className="text-[10px] text-slate-500 font-mono mt-0.5">{adminItem.email}</p>
|
||||
</div>
|
||||
<span className="bg-emerald-50 text-emerald-700 text-[10px] font-black uppercase px-2.5 py-1 rounded-lg border border-emerald-100">
|
||||
{adminItem.roles && adminItem.roles.includes('super_admin') ? 'Super Admin' : 'Admin'}
|
||||
</span>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,338 @@
|
|||
import React from 'react';
|
||||
import { Shield, RefreshCw, Download, CheckCircle } from 'lucide-react';
|
||||
|
||||
interface CustomerDrawerProps {
|
||||
customerId: string | null;
|
||||
customerData: any | null;
|
||||
loading: boolean;
|
||||
statusToggling: boolean;
|
||||
activeTab: 'overview' | 'subscriptions' | 'invoices';
|
||||
onTabChange: (tab: 'overview' | 'subscriptions' | 'invoices') => void;
|
||||
onToggleStatus: () => void;
|
||||
onClose: () => void;
|
||||
onDownloadInvoice?: (paymentId: string) => void;
|
||||
}
|
||||
|
||||
export const CustomerDrawer: React.FC<CustomerDrawerProps> = ({
|
||||
customerId,
|
||||
customerData,
|
||||
loading,
|
||||
statusToggling,
|
||||
activeTab,
|
||||
onTabChange,
|
||||
onToggleStatus,
|
||||
onClose,
|
||||
onDownloadInvoice,
|
||||
}) => {
|
||||
if (!customerId) return null;
|
||||
|
||||
const formatCurrency = (amount: number, currency: string = 'INR') => {
|
||||
const sym = currency === 'USD' ? '$' : currency === 'EUR' ? '€' : '₹';
|
||||
return `${sym}${Number(amount || 0).toFixed(2)}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 bg-slate-950/60 backdrop-blur-xs flex justify-end animate-in fade-in duration-200">
|
||||
<div className="w-full max-w-xl bg-white h-full shadow-2xl flex flex-col justify-between overflow-hidden animate-in slide-in-from-right duration-200">
|
||||
{/* Drawer Top Bar */}
|
||||
<div className="p-5 border-b border-slate-200 bg-slate-50 flex items-center justify-between shrink-0">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-11 w-11 rounded-2xl bg-indigo-600 text-white font-black text-base flex items-center justify-center shadow-md">
|
||||
{customerData?.display_name ? customerData.display_name[0].toUpperCase() : 'U'}
|
||||
</div>
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<h3 className="text-base font-black text-slate-800">
|
||||
{customerData?.display_name || 'Customer Account'}
|
||||
</h3>
|
||||
{customerData && (
|
||||
<span
|
||||
className={`text-[10px] font-black uppercase px-2 py-0.5 rounded-full border ${
|
||||
customerData.is_active
|
||||
? 'bg-emerald-50 text-emerald-700 border-emerald-200'
|
||||
: 'bg-rose-50 text-rose-700 border-rose-200'
|
||||
}`}
|
||||
>
|
||||
{customerData.is_active ? 'Active' : 'Suspended'}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-slate-400 font-semibold">{customerData?.email || 'Loading...'}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="h-8 w-8 rounded-full bg-slate-200/80 hover:bg-slate-300 text-slate-600 flex items-center justify-center text-sm font-black transition-colors cursor-pointer"
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Drawer Body */}
|
||||
<div className="flex-1 overflow-y-auto p-6 space-y-6">
|
||||
{loading ? (
|
||||
<div className="flex flex-col items-center justify-center py-20 space-y-3">
|
||||
<RefreshCw className="h-8 w-8 animate-spin text-indigo-600" />
|
||||
<p className="text-xs font-bold text-slate-400">Loading customer profile & entitlements...</p>
|
||||
</div>
|
||||
) : customerData ? (
|
||||
<>
|
||||
{/* Account Status Control */}
|
||||
<div className="bg-slate-50 border border-slate-200 rounded-2xl p-4 flex items-center justify-between shadow-2xs">
|
||||
<div className="space-y-0.5">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Shield className="h-3.5 w-3.5 text-indigo-600" />
|
||||
<span className="text-xs font-bold text-slate-800">Account Access Control</span>
|
||||
</div>
|
||||
<p className="text-[11px] text-slate-500 font-medium">
|
||||
{customerData.is_active
|
||||
? 'Account is active. Customer has login access to Web and Mobile.'
|
||||
: 'Account is suspended. Customer is blocked from logging in.'}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={onToggleStatus}
|
||||
disabled={statusToggling}
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-black transition-all flex items-center gap-1.5 cursor-pointer shadow-xs disabled:opacity-50 ${
|
||||
customerData.is_active
|
||||
? 'bg-rose-50 hover:bg-rose-100 text-rose-700 border border-rose-200'
|
||||
: 'bg-emerald-600 hover:bg-emerald-500 text-white shadow-emerald-600/20'
|
||||
}`}
|
||||
>
|
||||
{statusToggling ? (
|
||||
<RefreshCw className="h-3 w-3 animate-spin" />
|
||||
) : customerData.is_active ? (
|
||||
'Suspend Account'
|
||||
) : (
|
||||
'Re-Activate Account'
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Drawer Sub-Tabs */}
|
||||
<div className="flex border-b border-slate-200 gap-1 pb-1">
|
||||
{[
|
||||
{ id: 'overview' as const, label: 'Overview' },
|
||||
{
|
||||
id: 'subscriptions' as const,
|
||||
label: `Plans & Modules (${customerData.subscriptions?.length || 0})`,
|
||||
},
|
||||
{
|
||||
id: 'invoices' as const,
|
||||
label: `Invoices (${customerData.transactions?.length || 0})`,
|
||||
},
|
||||
].map((tab) => (
|
||||
<button
|
||||
key={tab.id}
|
||||
type="button"
|
||||
onClick={() => onTabChange(tab.id)}
|
||||
className={`px-3 py-2 text-xs font-bold rounded-xl transition-all cursor-pointer ${
|
||||
activeTab === tab.id
|
||||
? 'bg-indigo-600 text-white shadow-xs'
|
||||
: 'text-slate-500 hover:text-slate-800 hover:bg-slate-100'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* TAB 1: OVERVIEW */}
|
||||
{activeTab === 'overview' && (
|
||||
<div className="space-y-4">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="bg-slate-50 rounded-2xl p-3 border border-slate-200/60">
|
||||
<span className="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Total Spent</span>
|
||||
<p className="text-xl font-black text-slate-800 mt-0.5">
|
||||
{customerData.total_spent_formatted ||
|
||||
formatCurrency(
|
||||
customerData.total_spent ?? customerData.total_spent_inr ?? 0,
|
||||
customerData.currency || 'INR'
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
<div className="bg-slate-50 rounded-2xl p-3 border border-slate-200/60">
|
||||
<span className="text-[10px] font-bold text-slate-400 uppercase tracking-wider">Total Orders</span>
|
||||
<p className="text-xl font-black text-slate-800 mt-0.5">{customerData.total_orders || 0}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="bg-white border border-slate-200 rounded-2xl p-4 space-y-3">
|
||||
<h4 className="text-xs font-bold text-slate-700 uppercase tracking-wider border-b border-slate-100 pb-2">
|
||||
Contact & Account Information
|
||||
</h4>
|
||||
<div className="grid grid-cols-2 gap-y-2.5 text-xs">
|
||||
<div>
|
||||
<span className="text-slate-400 font-semibold block text-[10px]">Email Address</span>
|
||||
<span className="font-bold text-slate-700">{customerData.email}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-400 font-semibold block text-[10px]">Phone Number</span>
|
||||
<span className="font-bold text-slate-700">{customerData.phone_number || 'Not provided'}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-400 font-semibold block text-[10px]">Country</span>
|
||||
<span className="font-bold text-slate-700">{customerData.country || 'India'}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-400 font-semibold block text-[10px]">Assigned Roles</span>
|
||||
<span className="font-bold text-indigo-600 capitalize">
|
||||
{customerData.roles?.join(', ') || 'user'}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<span className="text-slate-400 font-semibold block text-[10px]">Member Since</span>
|
||||
<span className="font-bold text-slate-700">
|
||||
{customerData.created_at ? customerData.created_at.split('T')[0] : 'N/A'}
|
||||
</span>
|
||||
</div>
|
||||
{customerData.external_ref && (
|
||||
<div>
|
||||
<span className="text-slate-400 font-semibold block text-[10px]">Gateway Ref</span>
|
||||
<span className="font-bold font-mono text-[10px] text-slate-600">{customerData.external_ref}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* TAB 2: SUBSCRIPTIONS */}
|
||||
{activeTab === 'subscriptions' && (
|
||||
<div className="space-y-3">
|
||||
{(!customerData.subscriptions || customerData.subscriptions.length === 0) ? (
|
||||
<p className="text-xs text-slate-400 italic py-6 text-center">No active or past plan subscriptions found.</p>
|
||||
) : (
|
||||
customerData.subscriptions.map((sub: any, idx: number) => {
|
||||
const planName = sub.plan?.name || sub.plan_name || sub.plan?.code || sub.plan_code || 'Subscribed Plan';
|
||||
const planCode = sub.plan?.code || sub.plan_code;
|
||||
const modules = sub.plan?.modules || [];
|
||||
|
||||
return (
|
||||
<div key={idx} className="bg-slate-50 border border-slate-200 rounded-xl p-4 text-xs space-y-2">
|
||||
<div className="flex justify-between items-start gap-2">
|
||||
<div>
|
||||
<h5 className="font-bold text-slate-800 text-sm">{planName}</h5>
|
||||
{planCode && (
|
||||
<span className="text-[9px] font-mono font-bold text-indigo-600 bg-indigo-50 border border-indigo-200 px-1.5 py-0.5 rounded uppercase mt-0.5 inline-block">
|
||||
{planCode}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span
|
||||
className={`px-2 py-0.5 rounded text-[10px] font-bold ${
|
||||
sub.status === 'active'
|
||||
? 'bg-emerald-50 text-emerald-700 border border-emerald-200'
|
||||
: 'bg-slate-200 text-slate-600'
|
||||
}`}
|
||||
>
|
||||
{sub.status}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{modules.length > 0 && (
|
||||
<div className="flex flex-wrap gap-1 pt-1">
|
||||
{modules.map((m: any, mIdx: number) => (
|
||||
<span
|
||||
key={mIdx}
|
||||
className="bg-white border border-slate-200 text-slate-600 text-[9px] font-semibold px-2 py-0.5 rounded-md flex items-center gap-1 shadow-2xs"
|
||||
>
|
||||
<CheckCircle className="h-2.5 w-2.5 text-emerald-500" />
|
||||
{m.name || m.code}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="pt-2 border-t border-slate-200/60 flex justify-between text-[10px] text-slate-400">
|
||||
<span>
|
||||
Valid: {sub.started_at ? sub.started_at.split('T')[0] : 'N/A'} →{' '}
|
||||
{sub.expires_at ? sub.expires_at.split('T')[0] : 'Lifetime'}
|
||||
</span>
|
||||
{sub.remaining_days !== null && sub.remaining_days !== undefined && (
|
||||
<span className={sub.is_expired ? 'text-rose-500 font-bold' : 'text-emerald-600 font-bold'}>
|
||||
{sub.is_expired ? 'Expired' : `${sub.remaining_days} days left`}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* TAB 3: INVOICES */}
|
||||
{activeTab === 'invoices' && (
|
||||
<div className="space-y-3">
|
||||
{(!customerData.transactions || customerData.transactions.length === 0) ? (
|
||||
<p className="text-xs text-slate-400 italic py-6 text-center">No payment transactions found.</p>
|
||||
) : (
|
||||
customerData.transactions.map((tx: any, idx: number) => {
|
||||
const invNumber = tx.invoice?.invoice_number || (tx.gateway_transaction_id ? `Tx: ${tx.gateway_transaction_id}` : tx.id);
|
||||
const paymentId = tx.gateway_transaction_id || tx.id;
|
||||
const amount = tx.invoice?.total_amount !== undefined ? tx.invoice.total_amount : tx.amount;
|
||||
const curr = tx.currency || tx.invoice?.currency || 'INR';
|
||||
|
||||
return (
|
||||
<div
|
||||
key={idx}
|
||||
className="flex justify-between items-center bg-slate-50 border border-slate-200 rounded-xl p-3.5 text-xs shadow-2xs"
|
||||
>
|
||||
<div className="space-y-0.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-mono font-bold text-slate-800">{invNumber}</span>
|
||||
{tx.invoice?.invoice_number && (
|
||||
<span className="text-[9px] bg-indigo-50 border border-indigo-200 text-indigo-700 font-bold px-1.5 py-0.2 rounded">
|
||||
Invoice
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-[10px] text-slate-400">
|
||||
{tx.created_at?.split('T')[0] || '—'}
|
||||
{tx.gateway_transaction_id && ` • ${tx.gateway_transaction_id}`}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="text-right">
|
||||
<p className="font-bold text-slate-800">{formatCurrency(amount, curr)}</p>
|
||||
<span
|
||||
className={`text-[10px] font-bold ${
|
||||
tx.status === 'success' || tx.status === 'captured'
|
||||
? 'text-emerald-600'
|
||||
: 'text-rose-600'
|
||||
}`}
|
||||
>
|
||||
{tx.status}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{onDownloadInvoice && paymentId && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onDownloadInvoice(paymentId)}
|
||||
className="h-7 w-7 flex items-center justify-center bg-indigo-50 hover:bg-indigo-100 border border-indigo-200 text-indigo-700 rounded-lg cursor-pointer transition-colors shadow-xs"
|
||||
title="Download Invoice PDF"
|
||||
>
|
||||
<Download className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -0,0 +1,169 @@
|
|||
import React, { useState, useMemo } from 'react';
|
||||
import { CreditCard, Eye, ChevronRight, ArrowUpDown, ArrowDown, ArrowUp } from 'lucide-react';
|
||||
import { Pagination } from '../common/Pagination';
|
||||
|
||||
interface CustomersTabProps {
|
||||
customers: any[];
|
||||
currentPage: number;
|
||||
perPage: number;
|
||||
onPageChange: (page: number) => void;
|
||||
onPerPageChange: (perPage: number) => void;
|
||||
onOpenCustomerDrawer: (id: string) => void;
|
||||
}
|
||||
|
||||
export const CustomersTab: React.FC<CustomersTabProps> = ({
|
||||
customers,
|
||||
currentPage,
|
||||
perPage,
|
||||
onPageChange,
|
||||
onPerPageChange,
|
||||
onOpenCustomerDrawer,
|
||||
}) => {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [sortOrder, setSortOrder] = useState<'desc' | 'asc'>('desc');
|
||||
|
||||
const processedCustomers = useMemo(() => {
|
||||
let result = customers.filter((c) => {
|
||||
if (!searchQuery.trim()) return true;
|
||||
const q = searchQuery.toLowerCase();
|
||||
return (
|
||||
(c.display_name || '').toLowerCase().includes(q) ||
|
||||
(c.email || '').toLowerCase().includes(q) ||
|
||||
(c.phone_number || '').toLowerCase().includes(q) ||
|
||||
(c.external_ref || '').toLowerCase().includes(q)
|
||||
);
|
||||
});
|
||||
|
||||
result.sort((a, b) => {
|
||||
const timeA = a.created_at ? new Date(a.created_at).getTime() : 0;
|
||||
const timeB = b.created_at ? new Date(b.created_at).getTime() : 0;
|
||||
return sortOrder === 'desc' ? timeB - timeA : timeA - timeB;
|
||||
});
|
||||
|
||||
return result;
|
||||
}, [customers, searchQuery, sortOrder]);
|
||||
|
||||
const totalFiltered = processedCustomers.length;
|
||||
const totalPages = Math.max(1, Math.ceil(totalFiltered / perPage));
|
||||
const safePage = Math.min(currentPage, totalPages);
|
||||
const startIndex = (safePage - 1) * perPage;
|
||||
const paginatedCustomers = processedCustomers.slice(startIndex, startIndex + perPage);
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Search & Sort Header */}
|
||||
<div className="bg-slate-50 border border-slate-200/80 rounded-2xl p-4 flex flex-col sm:flex-row justify-between items-stretch sm:items-center gap-3">
|
||||
<div className="flex-1 max-w-md relative">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search by customer name, email, phone, or gateway ID..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => {
|
||||
setSearchQuery(e.target.value);
|
||||
onPageChange(1);
|
||||
}}
|
||||
className="w-full bg-white border border-slate-200 rounded-xl pl-9 pr-4 py-2 text-xs text-slate-800 font-semibold focus:outline-none focus:border-indigo-500 placeholder:text-slate-400 shadow-sm"
|
||||
/>
|
||||
<span className="absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 text-xs">🔍</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 justify-between sm:justify-end">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setSortOrder((prev) => (prev === 'desc' ? 'asc' : 'desc'))}
|
||||
className="flex items-center gap-1.5 px-3 py-2 rounded-xl text-xs font-bold bg-white border border-slate-200 text-slate-700 hover:bg-slate-100 hover:border-slate-300 transition-colors shadow-2xs cursor-pointer"
|
||||
title={`Toggle sort order (current: ${sortOrder === 'desc' ? 'Latest first' : 'Oldest first'})`}
|
||||
>
|
||||
<ArrowUpDown className="h-3.5 w-3.5 text-indigo-600" />
|
||||
<span>Sort: {sortOrder === 'desc' ? 'Newest First' : 'Oldest First'}</span>
|
||||
{sortOrder === 'desc' ? (
|
||||
<ArrowDown className="h-3 w-3 text-slate-400" />
|
||||
) : (
|
||||
<ArrowUp className="h-3 w-3 text-slate-400" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="text-xs font-bold text-slate-500 text-right whitespace-nowrap">
|
||||
Total Customers: <span className="text-slate-800">{customers.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{processedCustomers.length === 0 ? (
|
||||
<p className="text-sm text-slate-400 italic text-center py-10 font-semibold">
|
||||
No registered practitioners or customers found matching your filter.
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-3">
|
||||
{paginatedCustomers.map((prac: any, i: number) => (
|
||||
<div
|
||||
key={prac.id || i}
|
||||
className="bg-slate-50 border border-slate-200/70 rounded-2xl p-4 hover:border-slate-300 transition-all shadow-xs"
|
||||
>
|
||||
{/* Customer Header */}
|
||||
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="h-10 w-10 rounded-2xl bg-indigo-100 border border-indigo-200 flex items-center justify-center text-indigo-600 font-black text-sm shrink-0">
|
||||
{prac.display_name ? prac.display_name[0].toUpperCase() : 'U'}
|
||||
</div>
|
||||
<div>
|
||||
<h4 className="text-sm font-bold text-slate-800">
|
||||
{prac.display_name || 'Practitioner User'}
|
||||
</h4>
|
||||
<p className="text-xs text-slate-400 font-semibold">{prac.email}</p>
|
||||
{prac.external_ref && (
|
||||
<p className="text-[10px] text-slate-400 font-mono mt-0.5 flex items-center gap-1">
|
||||
<CreditCard className="h-3 w-3 text-slate-400" />
|
||||
<span>Razorpay Cust: </span>
|
||||
<span className="bg-slate-100 border border-slate-200 text-slate-600 px-1.5 py-0.2 rounded text-[9px] font-bold">
|
||||
{prac.external_ref}
|
||||
</span>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-[10px] bg-slate-200/80 text-slate-600 font-bold uppercase tracking-wider px-2.5 py-1 rounded-lg">
|
||||
🌐 {prac.country || 'India'}
|
||||
</span>
|
||||
{prac.phone_number && (
|
||||
<span className="text-[10px] bg-slate-200/80 text-slate-600 font-bold uppercase tracking-wider px-2.5 py-1 rounded-lg">
|
||||
📞 {prac.phone_number}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
className={`text-[10px] font-black uppercase tracking-wider px-2.5 py-1 rounded-lg ${
|
||||
prac.is_active
|
||||
? 'bg-emerald-50 text-emerald-700 border border-emerald-200'
|
||||
: 'bg-rose-50 text-rose-700 border border-rose-200'
|
||||
}`}
|
||||
>
|
||||
{prac.is_active ? 'Active Account' : 'Inactive'}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onOpenCustomerDrawer(prac.id)}
|
||||
className="inline-flex items-center gap-1 px-3 py-1 rounded-lg text-[11px] font-bold bg-indigo-50 hover:bg-indigo-600 text-indigo-700 hover:text-white border border-indigo-200 hover:border-indigo-600 transition-all cursor-pointer shadow-xs"
|
||||
>
|
||||
<Eye className="h-3 w-3" /> View Profile & Access <ChevronRight className="h-3 w-3" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<Pagination
|
||||
currentPage={safePage}
|
||||
totalItems={totalFiltered}
|
||||
itemsPerPage={perPage}
|
||||
onPageChange={onPageChange}
|
||||
onItemsPerPageChange={onPerPageChange}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
@ -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' },
|
||||
];
|
||||
|
|
@ -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' }
|
||||
];
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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>,
|
||||
)
|
||||
|
|
@ -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;
|
||||
});
|
||||
|
|
@ -0,0 +1,142 @@
|
|||
export type AdminTabType =
|
||||
| 'overview'
|
||||
| 'modules'
|
||||
| 'plans'
|
||||
| 'coupons'
|
||||
| 'customers'
|
||||
| 'payments'
|
||||
| 'admins'
|
||||
| 'users_subscriptions'
|
||||
| 'database'
|
||||
| 'reports';
|
||||
|
||||
export interface LoggedInUser {
|
||||
id?: string;
|
||||
email?: string;
|
||||
display_name?: string;
|
||||
full_name?: string;
|
||||
roles?: string[];
|
||||
country?: string;
|
||||
}
|
||||
|
||||
export interface ModuleItem {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
description?: string;
|
||||
category: string;
|
||||
is_active: boolean;
|
||||
linked_plans_count?: number;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface PlanPrice {
|
||||
inr?: number;
|
||||
usd?: number;
|
||||
}
|
||||
|
||||
export interface PlanItem {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
badge?: string;
|
||||
heading?: string;
|
||||
subtitle?: string;
|
||||
plan_type: 'bundle' | 'one_time' | string;
|
||||
duration: 'yearly' | 'monthly' | 'lifetime' | string;
|
||||
is_active: boolean;
|
||||
prices?: PlanPrice;
|
||||
price_inr?: number;
|
||||
price_usd?: number;
|
||||
subscriber_count?: number;
|
||||
module_ids?: string[];
|
||||
modules?: ModuleItem[];
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
export interface CouponItem {
|
||||
id: string;
|
||||
code: string;
|
||||
discount_type: 'percentage' | 'flat';
|
||||
discount_value: number;
|
||||
max_discount_cap?: number;
|
||||
category: string;
|
||||
start_date?: string;
|
||||
end_date?: string;
|
||||
usage_limit?: number;
|
||||
usage_count?: number;
|
||||
min_spend?: number;
|
||||
first_order_only?: boolean;
|
||||
scope: 'storewide' | 'specific';
|
||||
applicable_plan_ids?: string[];
|
||||
applicable_module_ids?: string[];
|
||||
description?: string;
|
||||
is_active: boolean;
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
export interface CustomerItem {
|
||||
id: string;
|
||||
email: string;
|
||||
full_name?: string;
|
||||
phone_number?: string;
|
||||
is_active: boolean;
|
||||
roles?: string[];
|
||||
created_at?: string;
|
||||
subscription_count?: number;
|
||||
active_subscriptions?: number;
|
||||
total_spent?: number;
|
||||
}
|
||||
|
||||
export interface SubscriptionItem {
|
||||
id: string;
|
||||
user_id: string;
|
||||
user_email?: string;
|
||||
user_name?: string;
|
||||
plan_id?: string;
|
||||
plan_name?: string;
|
||||
module_id?: string;
|
||||
module_name?: string;
|
||||
status: 'active' | 'expired' | 'canceled' | 'pending';
|
||||
start_date: string;
|
||||
end_date: string;
|
||||
amount_paid?: number;
|
||||
currency?: string;
|
||||
rzp_payment_id?: string;
|
||||
}
|
||||
|
||||
export interface PaymentItem {
|
||||
id: string;
|
||||
rzp_payment_id: string;
|
||||
rzp_order_id?: string;
|
||||
user_email?: string;
|
||||
amount: number;
|
||||
currency: string;
|
||||
status: 'captured' | 'failed' | 'refunded' | 'pending';
|
||||
method?: string;
|
||||
invoice_number?: string;
|
||||
created_at: string;
|
||||
notes?: Record<string, any>;
|
||||
}
|
||||
|
||||
export interface AdminUserItem {
|
||||
id: string;
|
||||
email: string;
|
||||
full_name?: string;
|
||||
phone_number?: string;
|
||||
role: 'super_admin' | 'finance_admin' | 'content_admin' | string;
|
||||
is_active: boolean;
|
||||
created_at?: string;
|
||||
}
|
||||
|
||||
export interface DbInfoItem {
|
||||
version?: string;
|
||||
database_name?: string;
|
||||
size_bytes?: number;
|
||||
size_formatted?: string;
|
||||
tables?: Array<{ name: string; rows: number; size_bytes?: number }>;
|
||||
last_backup?: string;
|
||||
}
|
||||
|
|
@ -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"]
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
|
|
@ -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"]
|
||||
}
|
||||
|
|
@ -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 || '/admin/',
|
||||
plugins: [react()],
|
||||
server: {
|
||||
port: 3001,
|
||||
}
|
||||
})
|
||||
Loading…
Reference in New Issue