c_agri_trade/project_code/frontend/src/App.tsx

97 lines
4.0 KiB
TypeScript

import React, { useEffect, useState } from 'react';
import { authStore } from './stores/authStore';
import { tenantStore } from './stores/tenantStore';
import { LoginView } from './features/auth/LoginView';
import { SessionView } from './features/auth/SessionView';
import { AccessDeniedView } from './features/auth/AccessDeniedView';
import { HeaderTenantSwitcher } from './features/tenant/HeaderTenantSwitcher';
import { PlatformTenantsView } from './features/tenant/PlatformTenantsView';
import { TenantMembersView } from './features/tenant/TenantMembersView';
import { AuditLogView } from './features/tenant/AuditLogView';
export const App: React.FC = () => {
const [activeTab, setActiveTab] = useState<'sessions' | 'tenants' | 'members' | 'audit'>('sessions');
const [isAuthenticated, setIsAuthenticated] = useState<boolean>(authStore.getState().isAuthenticated);
useEffect(() => {
return authStore.subscribe(() => {
setIsAuthenticated(authStore.getState().isAuthenticated);
});
}, []);
if (!isAuthenticated) {
return <LoginView />;
}
return (
<div className="min-h-screen bg-gray-50 flex flex-col font-sans">
<header className="bg-white border-b border-gray-200 px-6 py-3 flex items-center justify-between shadow-sm">
<div className="flex items-center space-x-6">
<div className="flex items-center space-x-2">
<span className="text-xl font-bold tracking-tight text-emerald-800">ATB Mandi Desk</span>
<span className="text-xs bg-emerald-100 text-emerald-800 px-2 py-0.5 rounded-full font-medium">v1.0.0</span>
</div>
<nav className="flex space-x-2">
<button
onClick={() => setActiveTab('sessions')}
className={`px-3 py-1.5 text-sm font-medium rounded-md ${
activeTab === 'sessions' ? 'bg-emerald-50 text-emerald-700' : 'text-gray-600 hover:text-gray-900'
}`}
>
Session Governance
</button>
<button
onClick={() => setActiveTab('tenants')}
className={`px-3 py-1.5 text-sm font-medium rounded-md ${
activeTab === 'tenants' ? 'bg-emerald-50 text-emerald-700' : 'text-gray-600 hover:text-gray-900'
}`}
>
Platform Tenants
</button>
<button
onClick={() => setActiveTab('members')}
className={`px-3 py-1.5 text-sm font-medium rounded-md ${
activeTab === 'members' ? 'bg-emerald-50 text-emerald-700' : 'text-gray-600 hover:text-gray-900'
}`}
>
Tenant Members
</button>
<button
onClick={() => setActiveTab('audit')}
className={`px-3 py-1.5 text-sm font-medium rounded-md ${
activeTab === 'audit' ? 'bg-emerald-50 text-emerald-700' : 'text-gray-600 hover:text-gray-900'
}`}
>
Security Audit
</button>
</nav>
</div>
<div className="flex items-center space-x-4">
<HeaderTenantSwitcher />
<button
onClick={() => {
authStore.logout();
tenantStore.clearTenant();
}}
className="text-xs text-red-600 hover:text-red-800 font-medium px-2 py-1 rounded border border-red-200 hover:bg-red-50"
>
Logout
</button>
</div>
</header>
<main className="flex-1 p-6 max-w-7xl w-full mx-auto">
{activeTab === 'sessions' && <SessionView />}
{activeTab === 'tenants' && <PlatformTenantsView />}
{activeTab === 'members' && <TenantMembersView />}
{activeTab === 'audit' && <AuditLogView />}
</main>
<footer className="bg-white border-t border-gray-200 px-6 py-3 text-xs text-gray-500 text-center">
Agriculture Trading Backoffice (ATB) &copy; 2026. Built with AI-Native Unified Process (UP-AI v1.5).
</footer>
</div>
);
};