remove demo code
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useEffectiveDriverId } from '@/hooks/useEffectiveDriverId';
|
||||
import { useNotifications } from '@/components/notifications/NotificationProvider';
|
||||
import type { NotificationVariant } from '@/components/notifications/notificationTypes';
|
||||
import { Wrench, ChevronDown, ChevronUp, X, MessageSquare, Activity, LogIn, AlertTriangle } from 'lucide-react';
|
||||
import { Wrench, ChevronDown, ChevronUp, X, MessageSquare, Activity, AlertTriangle } from 'lucide-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { ApiConnectionMonitor } from '@/lib/api/base/ApiConnectionMonitor';
|
||||
@@ -16,10 +16,9 @@ import { NotificationTypeSection } from './sections/NotificationTypeSection';
|
||||
import { UrgencySection } from './sections/UrgencySection';
|
||||
import { NotificationSendSection } from './sections/NotificationSendSection';
|
||||
import { APIStatusSection } from './sections/APIStatusSection';
|
||||
import { LoginSection } from './sections/LoginSection';
|
||||
|
||||
// Import types
|
||||
import type { DemoNotificationType, DemoUrgency, LoginMode } from './types';
|
||||
import type { DemoNotificationType, DemoUrgency } from './types';
|
||||
|
||||
export default function DevToolbar() {
|
||||
const router = useRouter();
|
||||
@@ -30,8 +29,6 @@ export default function DevToolbar() {
|
||||
const [selectedUrgency, setSelectedUrgency] = useState<DemoUrgency>('toast');
|
||||
const [sending, setSending] = useState(false);
|
||||
const [lastSent, setLastSent] = useState<string | null>(null);
|
||||
const [loginMode, setLoginMode] = useState<LoginMode>('none');
|
||||
const [loggingIn, setLoggingIn] = useState(false);
|
||||
|
||||
// API Status Monitoring State
|
||||
const [apiStatus, setApiStatus] = useState(() => ApiConnectionMonitor.getInstance().getStatus());
|
||||
@@ -47,77 +44,6 @@ export default function DevToolbar() {
|
||||
|
||||
const currentDriverId = useEffectiveDriverId();
|
||||
|
||||
// Sync login mode with actual session state on mount
|
||||
useEffect(() => {
|
||||
if (typeof document !== 'undefined') {
|
||||
// Check for actual session cookie first
|
||||
const cookies = document.cookie.split(';');
|
||||
const sessionCookie = cookies.find(c => c.trim().startsWith('gp_session='));
|
||||
|
||||
if (sessionCookie) {
|
||||
// User has a session cookie, check if it's valid by calling the API
|
||||
fetch('/api/auth/session', {
|
||||
method: 'GET',
|
||||
credentials: 'include'
|
||||
})
|
||||
.then(res => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
}
|
||||
throw new Error('No valid session');
|
||||
})
|
||||
.then(session => {
|
||||
if (session && session.user) {
|
||||
// Determine login mode based on user email patterns
|
||||
const email = session.user.email?.toLowerCase() || '';
|
||||
const displayName = session.user.displayName?.toLowerCase() || '';
|
||||
const role = (session.user as any).role;
|
||||
|
||||
let mode: LoginMode = 'none';
|
||||
|
||||
// First check session.role if available
|
||||
if (role) {
|
||||
if (role === 'sponsor') mode = 'sponsor';
|
||||
else if (role === 'league-owner') mode = 'league-owner';
|
||||
else if (role === 'league-steward') mode = 'league-steward';
|
||||
else if (role === 'league-admin') mode = 'league-admin';
|
||||
else if (role === 'system-owner') mode = 'system-owner';
|
||||
else if (role === 'super-admin') mode = 'super-admin';
|
||||
else if (role === 'driver') mode = 'driver';
|
||||
}
|
||||
// Fallback to email patterns
|
||||
else if (email.includes('sponsor') || displayName.includes('sponsor')) {
|
||||
mode = 'sponsor';
|
||||
} else if (email.includes('league-owner') || displayName.includes('owner')) {
|
||||
mode = 'league-owner';
|
||||
} else if (email.includes('league-steward') || displayName.includes('steward')) {
|
||||
mode = 'league-steward';
|
||||
} else if (email.includes('league-admin') || displayName.includes('admin')) {
|
||||
mode = 'league-admin';
|
||||
} else if (email.includes('system-owner') || displayName.includes('system owner')) {
|
||||
mode = 'system-owner';
|
||||
} else if (email.includes('super-admin') || displayName.includes('super admin')) {
|
||||
mode = 'super-admin';
|
||||
} else if (email.includes('driver') || displayName.includes('demo')) {
|
||||
mode = 'driver';
|
||||
}
|
||||
|
||||
setLoginMode(mode);
|
||||
} else {
|
||||
setLoginMode('none');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// Session invalid or expired
|
||||
setLoginMode('none');
|
||||
});
|
||||
} else {
|
||||
// No session cookie means not logged in
|
||||
setLoginMode('none');
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
// API Status Monitoring Effects
|
||||
useEffect(() => {
|
||||
const monitor = ApiConnectionMonitor.getInstance();
|
||||
@@ -235,54 +161,6 @@ export default function DevToolbar() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDemoLogin = async (role: LoginMode) => {
|
||||
if (role === 'none') return;
|
||||
|
||||
setLoggingIn(true);
|
||||
try {
|
||||
// Use the demo login API
|
||||
const response = await fetch('/api/auth/demo-login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ role }),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Demo login failed');
|
||||
}
|
||||
|
||||
setLoginMode(role);
|
||||
|
||||
// Navigate based on role
|
||||
if (role === 'sponsor') {
|
||||
window.location.href = '/sponsor/dashboard';
|
||||
} else {
|
||||
// For driver and league roles, go to dashboard
|
||||
window.location.href = '/dashboard';
|
||||
}
|
||||
} catch (error) {
|
||||
alert('Demo login failed. Please check the API server status.');
|
||||
} finally {
|
||||
setLoggingIn(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleLogout = async () => {
|
||||
setLoggingIn(true);
|
||||
try {
|
||||
// Call logout API
|
||||
await fetch('/api/auth/logout', { method: 'POST' });
|
||||
|
||||
setLoginMode('none');
|
||||
// Refresh to update all components
|
||||
window.location.href = '/';
|
||||
} catch (error) {
|
||||
alert('Logout failed. Please check the API server status.');
|
||||
} finally {
|
||||
setLoggingIn(false);
|
||||
}
|
||||
};
|
||||
|
||||
// Only show in development
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
return null;
|
||||
@@ -435,21 +313,6 @@ export default function DevToolbar() {
|
||||
/>
|
||||
</Accordion>
|
||||
|
||||
{/* Login Section - Accordion */}
|
||||
<Accordion
|
||||
title="Demo Login"
|
||||
icon={<LogIn className="w-4 h-4 text-gray-400" />}
|
||||
isOpen={openAccordion === 'login'}
|
||||
onToggle={() => setOpenAccordion(openAccordion === 'login' ? null : 'login')}
|
||||
>
|
||||
<LoginSection
|
||||
loginMode={loginMode}
|
||||
loggingIn={loggingIn}
|
||||
onDemoLogin={handleDemoLogin}
|
||||
onLogout={handleLogout}
|
||||
/>
|
||||
</Accordion>
|
||||
|
||||
{/* Error Stats Section - Accordion */}
|
||||
<Accordion
|
||||
title="Error Stats"
|
||||
|
||||
Reference in New Issue
Block a user