4.0 KiB
4.0 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.tsxfrontend/src/components/safety-quiz/frontend/src/components/frameworks/DirectorDashboard.tsxfrontend/src/components/director-dashboard/DirectorQuizResultsPanel.tsxfrontend/src/components/director-dashboard/DirectorRiskList.tsxfrontend/src/components/safety-quiz/SafetyQuizContentEditorPanel.tsx
Business logic layer:
frontend/src/business/safety-quiz/hooks.tsfrontend/src/business/safety-quiz/mappers.tsfrontend/src/business/safety-quiz/selectors.tsfrontend/src/business/safety-quiz/types.tsfrontend/src/business/director-dashboard/hooks.tsfrontend/src/business/director-dashboard/selectors.ts
API/data access layer:
frontend/src/shared/api/safetyQuizResults.tsfrontend/src/shared/types/safetyQuiz.ts
Constants:
frontend/src/shared/constants/safetyQuiz.ts
Behavior
- Quiz submission uses
POST /api/safety_quiz_results. - Behavior Management is available at organization, school, campus, and class effective
tiers when the user has
READ_QBS. - Result-saving UI and mutation are enabled only in the user's own non-organization scope. A parent user drilled into a child tenant can complete the quiz for immediate feedback, but no "saved" badge is shown and no reportable child-scope result is created.
- The notification dropdown uses
GET /api/safety_quiz_results/mefor the current week. School, campus, and class staff withTAKE_QUIZsee a reminder until their saved database result exists. - Staff completion and leadership dashboard rows load from
GET /api/safety_quiz_results/completion; pending status is derived from missing saved rows in the backend response. - QBS quiz content loads from
GET /api/content-catalog/read/safety-qbs-quiz. - Organization-scope content managers can add, update, and delete the QBS quiz and key reminders through a form-based editor backed by the authenticated content catalog endpoints. The editor is hidden outside the user's own organization scope, and the backend enforces the same rule.
- Editable QBS quiz payloads are typed and validated in the business layer before saving.
- Compliance views render completed and pending staff from the backend report instead of substituting static staff rows.
- Result ownership is derived by the backend from the authenticated session.
- User profile renders the latest saved QBS result from
GET /api/safety_quiz_results/me. QBSSafety.tsxis a thin wrapper that callsuseSafetyQuizPageand 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. - The backend also normalizes submitted
week_ofvalues to the same Sunday-start key before saving, so weekly status, notifications, completion, and dashboard metrics all read the current canonical week. - Weekly focus and key reminders are backend content payload fields, not frontend constants.
- QBS quiz content reads only the active
safety-qbs-quizcatalog row. When organization content managers update the quiz, the backend stores a new active row and keeps previous quiz versions inactive for history. - Safety quiz view components use shared
Button,StatePanel, andModuleHeaderprimitives. - Leadership dashboards derive QBS completion metrics and risk rows from the backend completion summary.
Preset Content
The default safety-qbs-quiz payload is seeded from the backend content catalog defaults for new
organizations. School, campus, and classroom scopes read the organization-owned payload. The
frontend does not keep fallback quiz questions or reminder copy in constants.