134 lines
6.0 KiB
TypeScript
134 lines
6.0 KiB
TypeScript
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 & Transaction Processing 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" /> Gateway & Transaction Processing
|
|
</h3>
|
|
<div className="text-[10px] text-slate-500 space-y-1 font-semibold">
|
|
<p>✓ All-inclusive customer pricing (no tax markup)</p>
|
|
<p>✓ Merchant gateway fees handled directly via Razorpay</p>
|
|
<p>✓ Automated invoice & payment receipt generation</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|