40227-vm/frontend/docs/safety-quiz-integration.md
2026-06-12 10:56:13 +02:00

2.6 KiB

Safety Quiz Frontend Integration

Purpose

Safety/QBS quiz results follow the frontend three-layer architecture.

View -> Business Logic -> API/Data Access -> Backend

Files

View layer:

  • frontend/src/components/frameworks/QBSSafety.tsx
  • frontend/src/components/safety-quiz/
  • frontend/src/components/frameworks/DirectorDashboard.tsx
  • frontend/src/components/director-dashboard/DirectorQuizResultsPanel.tsx
  • frontend/src/components/director-dashboard/DirectorRiskList.tsx
  • frontend/src/components/safety-quiz/SafetyQuizContentEditorPanel.tsx

Business logic layer:

  • frontend/src/business/safety-quiz/hooks.ts
  • frontend/src/business/safety-quiz/mappers.ts
  • frontend/src/business/safety-quiz/selectors.ts
  • frontend/src/business/safety-quiz/types.ts
  • frontend/src/business/director-dashboard/hooks.ts
  • frontend/src/business/director-dashboard/selectors.ts

API/data access layer:

  • frontend/src/shared/api/safetyQuizResults.ts
  • frontend/src/shared/types/safetyQuiz.ts

Constants:

  • frontend/src/shared/constants/safetyQuiz.ts

Behavior

  • Quiz submission uses POST /api/safety_quiz_results.
  • Staff completion and director dashboard rows load from GET /api/safety_quiz_results.
  • QBS quiz content loads from GET /api/public/content-catalog/safety-qbs-quiz.
  • Directors and superintendents can edit the QBS quiz content through the authenticated content catalog endpoint PUT /api/content-catalog/safety-qbs-quiz.
  • Editable QBS quiz payloads are JSON-validated in the business layer before saving.
  • Compliance views render empty and error states explicitly instead of substituting static staff rows.
  • Result ownership is derived by the backend from the authenticated session.
  • QBSSafety.tsx is a thin wrapper that calls useSafetyQuizPage and renders focused safety quiz view components.
  • Quiz score, progress, result feedback, and compliance summary are derived in business selectors.
  • The "current week" key (getCurrentSafetyQuizWeek) uses the shared American (Sunday-start) week util (shared/business/week.ts) — consistent with the dashboard hero and F.R.A.M.E.
  • Weekly focus and key reminders are backend content payload fields, not frontend constants.
  • Safety quiz view components use shared Button, StatePanel, and ModuleHeader primitives.
  • Director dashboard derives QBS completion metrics and risk rows in business selectors.

If compliance needs pending/overdue rows for all staff, add a backend summary endpoint that joins staff membership with submitted results. Do not recreate pending staff rows in frontend static data.