40227-vm/frontend/docs/campus-attendance-integration.md
2026-06-25 16:10:48 +02:00

5.6 KiB

Campus Attendance Frontend Integration

Purpose

Attendance now tracks staff attendance only. The page still reads legacy campus attendance config/summary endpoints where existing report plumbing requires them, but visible entry, rollups, details, and dashboard-facing metrics use staff_attendance_records.

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

Files

View layer:

  • frontend/src/components/frameworks/CampusAttendance.tsx
  • frontend/src/components/campus-attendance/AttendanceSummaryCard.tsx
  • frontend/src/components/campus-attendance/CampusAttendanceEntryForm.tsx
  • frontend/src/components/campus-attendance/CampusAttendanceHeader.tsx
  • frontend/src/components/campus-attendance/CampusAttendanceLinkConfig.tsx
  • frontend/src/components/campus-attendance/CampusAttendanceStatus.tsx
  • frontend/src/components/campus-attendance/IndividualCampusAttendanceView.tsx
  • frontend/src/components/campus-attendance/SuperintendentAttendanceView.tsx
  • frontend/src/components/campus-attendance/styles.ts
  • frontend/src/components/campus-attendance/types.ts

Business logic layer:

  • frontend/src/business/campus-attendance/hooks.ts
  • frontend/src/business/campus-attendance/mappers.ts
  • frontend/src/business/campus-attendance/printReport.ts
  • frontend/src/business/campus-attendance/selectors.ts
  • frontend/src/business/campus-attendance/types.ts

API/data access layer:

  • frontend/src/shared/api/campusAttendance.ts
  • frontend/src/shared/api/staffAttendance.ts (staff summary and office/staff attendance entry)
  • frontend/src/shared/types/campusAttendance.ts
  • frontend/src/shared/constants/campusAttendance.ts

Behavior

  • Attendance links load from GET /api/campus_attendance/configs.
  • Attendance links save through PUT /api/campus_attendance/configs/:campusKey.
  • The active UI no longer reads or writes GET /api/campus_attendance/summaries; those backend endpoints remain legacy plumbing outside the staff-only attendance workflow.
  • Staff attendance records load from GET /api/staff_attendance/records when the user has READ_STAFF_ATTENDANCE_REPORTS. Campus views group these records by campus and date.
  • The page derives its mode from the effective scope, not from the signed-in role label:
    • campus effective scope shows campus staff attendance.
    • class effective scope is read-only for attendance entry.
    • school effective scope aggregates scoped campus staff attendance plus school staff attendance.
    • organization effective scope aggregates scoped school/campus staff attendance plus organization staff attendance.
  • Users with FILL_ATTENDANCE can enter daily staff attendance from organization, school, or campus effective scope. Class effective scope no longer renders attendance entry controls.
  • Organization office attendance targets organization-owned users without school/campus assignment. School office attendance targets school-owned users without campus assignment. Campus attendance targets campus-bound and class-scoped staff inside the campus.
  • School and organization percentage cards use staff attendance only. Campus attendance entered by office managers appears in school-level rollups; school-level staff attendance appears in organization-level rollups with staff records from other schools and campuses.
  • The top-bar notification uses the current staff summary as a completion signal. Users with FILL_ATTENDANCE or READ_STAFF_ATTENDANCE_REPORTS are nudged at organization, school, or campus effective scope until today's staff attendance record count reaches the current scope's staff count. Class effective scope does not receive this attendance reminder.
  • Aggregate cards follow the tenant hierarchy: organization scope shows school cards, and school scope shows campus cards. Clicking a child card opens /attendance/details/:level/:tenantId. The details page shows staff attendance records for that child scope.
  • Each staff row has Present/Late/Absent controls, and saving writes one record per user through PUT /api/staff_attendance/records/:userId/:date. Late staff count as present for attendance percentage and remain visible as late exceptions.
  • Attendance page staff summary cards load from GET /api/staff_attendance/summary?startDate=today&endDate=today when the user has READ_STAFF_ATTENDANCE_REPORTS; the top-bar completion reminder uses the same summary endpoint for users with FILL_ATTENDANCE or READ_STAFF_ATTENDANCE_REPORTS.
  • Campus screens show staff-only summary cards and recent staff attendance history.
  • Aggregate views render only campus cards represented by scoped campus tenants or attendance config rows, because the campus catalog endpoint is not the source of scoped reporting data.
  • The backend calculates the attendance percentage.
  • CampusAttendance.tsx is a thin composition wrapper.
  • CampusAttendance uses typed business hooks/selectors for access, form state, today, weekly staff rollups, campus summary calculations, and print report generation.
  • Print report generation escapes dynamic strings before writing report HTML.
  • Blocked print popups return an explicit print result and show a visible attendance status error.

Verification

  • frontend/src/business/campus-attendance/selectors.test.ts covers attendance calculations, scope titles, staff daily summaries, and staff-only summary selectors.
  • frontend/src/business/campus-attendance/printReport.test.ts covers printable staff-attendance report generation and no-data labels.
  • frontend/src/business/campus-attendance/printReport.test.ts covers blocked-popup handling for attendance report printing.
  • frontend/src/business/campus-attendance/mappers.test.ts covers API DTO mapping.