40227-vm/frontend/docs/personality-integration.md

91 lines
6.0 KiB
Markdown

# Personality Frontend Integration
## Purpose
EI/personality content, result loading, saving, completion reporting, and aggregate distribution follow the frontend three-layer architecture.
```text
View -> Business Logic -> API/Data Access -> Backend
```
## Files
View layer:
- `frontend/src/components/frameworks/EmotionalIntelligence.tsx`
- `frontend/src/components/emotional-intelligence/AssessmentTab.tsx`
- `frontend/src/components/emotional-intelligence/EmotionalIntelligenceQuizEditorPanel.tsx`
- `frontend/src/components/emotional-intelligence/EmotionalIntelligenceHeader.tsx`
- `frontend/src/components/emotional-intelligence/EmotionalIntelligenceTabs.tsx`
- `frontend/src/components/emotional-intelligence/PersonalityDistributionPanel.tsx`
- `frontend/src/components/emotional-intelligence/PersonalityQuizTab.tsx`
- `frontend/src/components/emotional-intelligence/SavedPersonalityBanner.tsx`
- `frontend/src/components/emotional-intelligence/WeeklyFocusBanner.tsx`
- `frontend/src/components/emotional-intelligence/groupStyles.ts`
- `frontend/src/components/emotional-intelligence/types.ts`
- `frontend/src/components/frameworks/PersonalityQuiz.tsx`
- `frontend/src/components/personality-quiz/`
- `frontend/src/components/frameworks/PersonalityDirectory.tsx`
- `frontend/src/components/personality-directory/`
Business logic layer:
- `frontend/src/business/personality/queryHooks.ts`
- `frontend/src/business/personality/directoryHooks.ts`
- `frontend/src/business/personality/emotionalIntelligenceHooks.ts`
- `frontend/src/business/personality/quizWorkflowHooks.ts`
- `frontend/src/business/personality/mappers.ts`
- `frontend/src/business/personality/selectors.ts`
- `frontend/src/business/personality/types.ts`
- `frontend/src/shared/types/emotionalIntelligence.ts` (EI content itself is backend-owned via the content catalog)
API/data access layer:
- `frontend/src/shared/api/personality.ts`
- `frontend/src/shared/types/personality.ts`
## Behavior
- The current user's latest saved result for each quiz kind loads from
`GET /api/personality_quiz_results/me`.
- The profile page loads the current user's persisted EI and personality history from
`GET /api/personality_quiz_results/me/history`, ordered by completion date. This keeps previous
EI weekly results and personality type completions visible after weekly EI windows roll forward.
- EI self-assessment and personality quiz content load from backend content catalog rows. Existing
quiz content is preset for each organization, and organization-scope users with
`MANAGE_CONTENT_CATALOG` manage it from the Emotional Intelligence page.
- Quiz completion saves through `PUT /api/personality_quiz_results/me`. The database is the single
source of truth for completion badges, profile history, completion reporting, and notifications.
- Saved-result loading, saved-result badges, and result mutations are enabled
only in the user's own scope. A parent user drilled into a child tenant may
complete the quiz for immediate review, but the UI does not claim that the
result was saved and the backend does not create reportable child-scope rows.
- Director and superintendent aggregate distribution loads from `GET /api/personality_quiz_results/distribution`.
- Team wellness completion reporting loads from `GET /api/personality_quiz_results/completion`.
The report combines current-week EI self-assessment results and latest personality type results,
grouped by quiz category. Personality rows show each user's current type.
- EI self-assessment is a weekly workflow. Notifications for missing EI completion are evaluated
for the current Sunday-start week. The Personality Type quiz and Personality Directory are not
weekly workflows and do not reset weekly.
- The user profile page renders Behavior Management, EI Self-Assessment, and Personality Type Quiz
results in one quiz-results table. The EI/personality rows come from the persisted history
endpoint; the QBS row comes from the safety quiz status endpoint.
- Leadership dashboards render the same quiz categories in one quiz-results table and include EI
self-assessment and Personality Type pending counts in the risk list.
- Backend errors are surfaced as UI error states instead of being swallowed.
- `EmotionalIntelligence.tsx` is a thin composition wrapper.
- `PersonalityQuiz.tsx` is a thin composition wrapper.
- `PersonalityDirectory.tsx` is a thin composition wrapper.
- EI self-assessment state, score calculation, level selection, personality distribution grouping, and personality save coordination live in `frontend/src/business/personality/`.
- Personality quiz flow state, saved-result hydration, result tab state, progress calculation, relationship tips, workplace language strengths, and result formatting live in `frontend/src/business/personality/`.
- Personality directory search, group filtering, expanded type state, and active detail section state live in `frontend/src/business/personality/`.
- Personality business hooks are split by workflow: backend query/mutation hooks, directory workflow, EI page workflow, and quiz workflow. Imports use the workflow-specific files directly; there is no legacy re-export surface.
- EI questions and Personality Type quiz questions are backend-owned organization content.
Personality type directory records, dimensions, and workplace tips are product-static and are not
weekly-updated quiz content.
- The frontend does not write personality type to user employment fields.
## Verification
Focused personality selector and mapper tests cover distribution totals/grouping, EI level thresholds, saved-date formatting, quiz progress, dimension progress, type breakdowns, relationship tips, communication strengths, communication growth guidance, personality directory filtering, persisted result mapping, profile history API wiring, and completion API wiring. Profile and director-dashboard selector tests cover the unified Behavior Management / EI Self-Assessment / Personality Type quiz result tables. Top-bar selector tests cover EI self-assessment and personality quiz completion reminders. These tests also guard the S/J and S/P grouping behavior.