Files
Convivo/apps/convivo/src/screens/Feedback.tsx
T
Lago 22f5f1d317 Redesign Phases 3-6: multi-event model, APPE Admin, Convivo App behaviors, APPE branding
- Phase 3: new migration 20260824000000_redesign.sql (contacts/events/registrations/sponsors, slot types, session speakers + feedback/material), seed rewrite
- Phase 4: APPE Admin rebrand + Contacts/Registrations/Sponsors/Schedule/Activity/Events views
- Phase 5: Convivo App (24h login, 5s polling, QR type badge, red dot, speaker material)
- Phase 6: APPE favicon + PWA icons for both apps
- Docs: schema/rpcs/rls/seed/screens/api-client/admin-app/architecture/next-steps/README/roadmap updated
2026-08-23 02:53:16 +02:00

87 lines
2.7 KiB
TypeScript

import { useState } from 'react';
import { useAuth } from '../context/AuthContext';
import { useEvent } from '../lib/useEvent';
import { submitFeedback } from '../lib/api';
import { Spinner } from '../components/ui';
import { useToast } from '../context/ToastContext';
export function Feedback({ sessionId, onDone }: { sessionId: string; onDone: () => void }) {
const { contact } = useAuth();
const { sessionById, loading } = useEvent();
const [rating, setRating] = useState(0);
const [comment, setComment] = useState('');
const [busy, setBusy] = useState(false);
const { toast } = useToast();
const session = sessionById.get(sessionId);
if (loading || !session) {
return (
<section className="screen no-tab">
<div className="center" style={{ flex: 1 }}>
<Spinner />
</div>
</section>
);
}
async function submit() {
if (rating === 0) return;
setBusy(true);
try {
const res = await submitFeedback(sessionId, rating, comment.trim());
toast(`Thanks! +${res.earned} pts ⭐`, 'ok');
onDone();
} catch (e) {
toast(e instanceof Error ? e.message : 'Could not submit feedback', 'err');
} finally {
setBusy(false);
}
}
return (
<section className="screen no-tab">
<div className="row" style={{ marginBottom: 14 }}>
<button className="btn ghost small" onClick={onDone}>← Back</button>
<div className="grow" style={{ textAlign: 'center' }}>
<div className="h2">Rate this session</div>
</div>
<span style={{ width: 60 }} />
</div>
<div className="card" style={{ textAlign: 'center' }}>
<div className="h2">{session.title}</div>
<div className="muted small" style={{ marginTop: 4 }}>{session.room} · {session.speakers}</div>
</div>
<div className="stars" style={{ justifyContent: 'center', margin: '20px 0' }}>
{[1, 2, 3, 4, 5].map((n) => (
<button
key={n}
className={`star ${n <= rating ? 'on' : ''}`}
onClick={() => setRating(n)}
aria-label={`${n} star${n > 1 ? 's' : ''}`}
>
★
</button>
))}
</div>
<textarea
className="input"
placeholder="Add a comment (optional) — comments earn bonus points"
value={comment}
onChange={(e) => setComment(e.target.value)}
rows={4}
/>
<button className="btn primary" disabled={busy || rating === 0} onClick={submit}>
{busy ? 'Submitting…' : 'Submit feedback'}
</button>
<div className="muted small" style={{ textAlign: 'center', marginTop: 8 }}>
{contact ? `Signing in as ${contact.full_name}` : ''}
</div>
</section>
);
}