From fff63f5efa7fe95a5675d0776028220259169c19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Thu, 5 Nov 2026 17:27:36 -0300 Subject: [PATCH] feat: add reviews, notifications, notes and account hardening --- App.tsx | 71 +++++---- components/course/CourseReviews.tsx | 137 ++++++++++++++++++ components/shell/Sidebar.tsx | 22 ++- components/ui/ErrorBoundary.tsx | 31 ++++ components/ui/Select.tsx | 63 +++++++- lib/routes.ts | 2 + pages/AccessTokenPage.tsx | 3 +- pages/AuthPage.tsx | 1 + pages/CoursePage.tsx | 20 ++- pages/ForgotPasswordPage.tsx | 40 +++++ pages/LessonPage.tsx | 31 +++- pages/ManageCourses.tsx | 11 +- pages/MyLearning.tsx | 46 +++++- pages/NotFoundPage.tsx | 13 ++ pages/NotificationsPage.tsx | 72 +++++++++ pages/SuperAdmin.tsx | 43 +++++- pages/YouPage.tsx | 4 +- server/migrations/017_account_views_notes.sql | 29 ++++ server/migrations/018_course_reviews.sql | 12 ++ server/migrations/019_notifications.sql | 14 ++ server/src/app.ts | 3 + server/src/auth/plugin.ts | 11 +- server/src/routes/admin.ts | 19 ++- server/src/routes/auth.ts | 45 +++++- server/src/routes/courses.ts | 131 ++++++++++++++++- server/src/routes/learning.ts | 91 ++++++++++++ server/src/routes/notifications.ts | 36 +++++ server/src/services/email.ts | 42 ++++-- services/api.ts | 3 + services/db.ts | 69 +++++++++ services/notifications.ts | 29 ++++ styles/app.css | 49 +++++++ 32 files changed, 1109 insertions(+), 84 deletions(-) create mode 100644 components/course/CourseReviews.tsx create mode 100644 components/ui/ErrorBoundary.tsx create mode 100644 pages/ForgotPasswordPage.tsx create mode 100644 pages/NotFoundPage.tsx create mode 100644 pages/NotificationsPage.tsx create mode 100644 server/migrations/017_account_views_notes.sql create mode 100644 server/migrations/018_course_reviews.sql create mode 100644 server/migrations/019_notifications.sql create mode 100644 server/src/routes/notifications.ts create mode 100644 services/notifications.ts diff --git a/App.tsx b/App.tsx index aeebc41..a26ceb7 100644 --- a/App.tsx +++ b/App.tsx @@ -1,21 +1,22 @@ import React from 'react'; import { BrowserRouter as Router, Routes, Route, Navigate, useLocation, useNavigate } from 'react-router-dom'; -import { ManageCourses } from './pages/ManageCourses'; import { MaterialsPage } from './pages/MaterialsPage'; import { AuthProvider, useAuth } from './context/AuthContext'; import { ToastProvider } from './context/ToastContext'; import { ThemeProvider } from './context/ThemeContext'; import { CatalogProvider } from './context/CatalogContext'; import { AppShell } from './components/shell/AppShell'; +import { ErrorBoundary } from './components/ui/ErrorBoundary'; import { Course, UserRole } from './types'; -import { SuperAdmin } from './pages/SuperAdmin'; import { AccessTokenPage } from './pages/AccessTokenPage'; import { MyLearning } from './pages/MyLearning'; import { ProfilePage } from './pages/ProfilePage'; +import { NotificationsPage } from './pages/NotificationsPage'; import { InstructorProfile } from './pages/InstructorProfile'; -import { TrailDetail } from './pages/TrailDetail'; import { TrailPage } from './pages/TrailPage'; import { AuthPage, homeFor } from './pages/AuthPage'; +import { ForgotPasswordPage } from './pages/ForgotPasswordPage'; +import { NotFoundPage } from './pages/NotFoundPage'; import { paths } from './lib/routes'; import { ExplorePage } from './pages/ExplorePage'; import { SearchPage } from './pages/SearchPage'; @@ -27,6 +28,10 @@ import { YouPage } from './pages/YouPage'; import { ContinueCourse, CoursePage } from './pages/CoursePage'; import { LessonPage } from './pages/LessonPage'; +const ManageCourses = React.lazy(() => import('./pages/ManageCourses').then((module) => ({ default: module.ManageCourses }))); +const SuperAdmin = React.lazy(() => import('./pages/SuperAdmin').then((module) => ({ default: module.SuperAdmin }))); +const TrailDetail = React.lazy(() => import('./pages/TrailDetail').then((module) => ({ default: module.TrailDetail }))); + /** Keeps old /#/... links (invites, password resets, bookmarks) working after moving off HashRouter. */ const LegacyHashRedirect: React.FC = () => { const location = useLocation(); @@ -55,32 +60,36 @@ function AppContent() { return ( - - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> -
} /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - } /> -
+
Carregando…
}> + + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> +
} /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + } /> +
+
); } @@ -93,7 +102,9 @@ function App() { - + + + diff --git a/components/course/CourseReviews.tsx b/components/course/CourseReviews.tsx new file mode 100644 index 0000000..33fe41a --- /dev/null +++ b/components/course/CourseReviews.tsx @@ -0,0 +1,137 @@ +import React, { useEffect, useState } from 'react'; +import { Link } from 'react-router-dom'; +import { StarIcon } from '@phosphor-icons/react'; +import { useAuth } from '../../context/AuthContext'; +import { useToast } from '../../context/ToastContext'; +import { CourseReviewSummary, MyCourseReview, deleteMyCourseReview, getCourseReviews, getMyCourseReview, saveCourseReview } from '../../services/db'; +import { ConfirmDialog } from '../ui/ConfirmDialog'; +import { shortDate } from '../../lib/format'; +import { paths } from '../../lib/routes'; + +const Stars: React.FC<{ value: number; label?: string }> = ({ value, label }) => ( + + {[1, 2, 3, 4, 5].map((star) => )} + +); + +export const CourseReviews: React.FC<{ courseId: string }> = ({ courseId }) => { + const { user } = useAuth(); + const { showToast } = useToast(); + const [summary, setSummary] = useState(null); + const [mine, setMine] = useState(null); + const [rating, setRating] = useState(0); + const [comment, setComment] = useState(''); + const [loading, setLoading] = useState(true); + const [saving, setSaving] = useState(false); + const [deleteOpen, setDeleteOpen] = useState(false); + + const load = async () => { + setLoading(true); + try { + const [publicReviews, myReview] = await Promise.all([ + getCourseReviews(courseId), + user ? getMyCourseReview(courseId).catch(() => null) : Promise.resolve(null), + ]); + setSummary(publicReviews); + setMine(myReview); + setRating(myReview?.rating ?? 0); + setComment(myReview?.comment ?? ''); + } catch { + setSummary(null); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + void load(); + }, [courseId, user?.id]); + + const submit = async (event: React.FormEvent) => { + event.preventDefault(); + if (!rating) { + showToast('Escolha uma nota de 1 a 5 estrelas.', 'error'); + return; + } + setSaving(true); + try { + const result = await saveCourseReview(courseId, rating, comment.trim()); + setMine(result.review); + setSummary(result.summary); + setRating(result.review.rating); + setComment(result.review.comment); + showToast('Avaliação salva.', 'success'); + } catch { + showToast('Não foi possível salvar sua avaliação.', 'error'); + } finally { + setSaving(false); + } + }; + + const remove = async () => { + setDeleteOpen(false); + try { + await deleteMyCourseReview(courseId); + setMine(null); + setRating(0); + setComment(''); + setSummary(await getCourseReviews(courseId)); + showToast('Avaliação removida.', 'success'); + } catch { + showToast('Não foi possível remover sua avaliação.', 'error'); + } + }; + + const average = summary?.average ?? 0; + const count = summary?.count ?? 0; + + return
+
+

Avaliações

+ {count > 0 && {count} {count === 1 ? 'avaliação' : 'avaliações'}} +
+ + {loading ?

Carregando avaliações…

: <> +
+
+ {count ? average.toFixed(1) : '—'} + + {count ? `${count} ${count === 1 ? 'pessoa avaliou' : 'pessoas avaliaram'}` : 'Seja a primeira pessoa a avaliar'} +
+ + {user ?
+
+ {mine ? 'Sua avaliação' : 'Avalie este curso'} +
+ {[1, 2, 3, 4, 5].map((star) => )} +
+
+
+ +