Files
Convivo/apps/convivo/src/App.tsx
T
5886de9d19 Staff exclusions + contact-password auth sync
- contacts.password now auto-syncs to auth.users.encrypted_password via
  trg_contact_password_sync, so setting a password on the contact row in the
  Supabase UI makes it work with signInWithPassword immediately (fixes staff
  like Bruno not being able to log in with a UI-set password). One-time
  reconciliation in the migration.
- Staff excluded from the leaderboard: _sync_leaderboard skips/removes staff
  rows, get_leaderboard() filters type='staff', seed no longer inserts staff.
  Affects the attendee Leaderboard and the admin Dashboard 'Top points'.
- Home/Agenda/Profile identical for all roles: Home quick-action always
  'Scan & connect' (no 'Check-in' relabel), footer role badge removed, tab
  label always 'Scan' (staff keep check-in via the Scan screen mode toggle).
- Profile: removed the duplicate Staff pill (type pill already shows Staff).
- Agenda session sheet: 'Download material' moved to the bottom of the button
  stack with spacing.
- Docs updated (schema, rpcs, seed, screens, architecture, next-steps).

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
2026-08-23 18:27:01 +02:00

128 lines
4.0 KiB
TypeScript

import { useCallback, useEffect, useState } from 'react';
import { AuthProvider, useAuth } from './context/AuthContext';
import { ToastProvider } from './context/ToastContext';
import { Login } from './screens/Login';
import { Home } from './screens/Home';
import { Agenda } from './screens/Agenda';
import { Scan } from './screens/Scan';
import { Connections } from './screens/Connections';
import { Leaderboard } from './screens/Leaderboard';
import { Profile } from './screens/Profile';
import { Feedback } from './screens/Feedback';
import { Spinner } from './components/ui';
import { getMyConnections } from './lib/api';
import { usePolling } from './lib/usePolling';
type Tab = 'home' | 'agenda' | 'scan' | 'connections' | 'profile' | 'leaderboard';
const TABS: { id: Tab; ico: string; label: string }[] = [
{ id: 'home', ico: '🏠', label: 'Home' },
{ id: 'agenda', ico: '📅', label: 'Agenda' },
{ id: 'scan', ico: '📷', label: 'Scan' },
{ id: 'connections', ico: '🤝', label: 'Connect' },
{ id: 'profile', ico: '👤', label: 'Profile' },
];
function Shell() {
const { session, contact, loading } = useAuth();
const [tab, setTab] = useState<Tab>('home');
const [feedbackSession, setFeedbackSession] = useState<string | null>(null);
const [pendingIncoming, setPendingIncoming] = useState(0);
const email = contact?.email ?? '';
const loadPending = useCallback(async () => {
try {
const conns = await getMyConnections();
setPendingIncoming(conns.filter((c) => c.status === 'pending' && c.to_email === email).length);
} catch {
/* non-fatal */
}
}, [email]);
useEffect(() => {
if (email) void loadPending();
}, [email, loadPending]);
// Keep the Connect red-dot fresh: poll every 5s while visible.
usePolling(() => void loadPending(), 5000, !!email);
// Recalc immediately when a connection is accepted/declined/sent.
useEffect(() => {
const onChanged = () => void loadPending();
window.addEventListener('connections-changed', onChanged);
return () => window.removeEventListener('connections-changed', onChanged);
}, [loadPending]);
if (loading) {
return (
<div className="app">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</div>
);
}
if (!session || !contact) {
return (
<div className="app">
<Login />
</div>
);
}
// Feedback is a full-screen takeover (no tab bar).
if (feedbackSession) {
return (
<div className="app">
<Feedback sessionId={feedbackSession} onDone={() => { setFeedbackSession(null); setTab('home'); }} />
</div>
);
}
// The home page (incl. the tab bar) is identical for every role. Staff keep
// their check-in capability inside the Scan screen (Attendee/Staff toggle).
const scanLabel = 'Scan';
return (
<div className="app">
{tab === 'home' && <Home go={(t) => setTab(t as Tab)} />}
{tab === 'agenda' && <Agenda openFeedback={(id) => setFeedbackSession(id)} />}
{tab === 'scan' && <Scan />}
{tab === 'connections' && <Connections />}
{tab === 'profile' && <Profile />}
{tab === 'leaderboard' && <Leaderboard />}
<nav className="tabbar">
{TABS.map((t) => (
<button
key={t.id}
className={`tab ${t.id === 'scan' ? 'tab-scan' : ''} ${tab === t.id ? 'active' : ''}`}
onClick={() => setTab(t.id)}
>
{t.id === 'scan' ? (
<span className="scan-btn">📷</span>
) : (
<span className="ico">
{t.ico}
{t.id === 'connections' && pendingIncoming > 0 && <span className="dot" />}
</span>
)}
<span>{t.id === 'scan' ? scanLabel : t.label}</span>
</button>
))}
</nav>
</div>
);
}
export default function App() {
return (
<ToastProvider>
<AuthProvider>
<Shell />
</AuthProvider>
</ToastProvider>
);
}