Scaffold Scenario Configuration Screen layout
epic-scenario-based-follow-up-prompts-scheduler-and-ui-task-011 — Create the ScenarioConfigurationScreen Flutter widget as a full-page coordinator-only screen. Use Design System v3 sidebar layout via HtmlGenerationUtils.generateSidebarPage equivalent in Flutter. Display a list of scenario templates with enable/disable toggle switches, scenario name, description, and last modified metadata.
Acceptance Criteria
Technical Requirements
Implementation Notes
Define ScenarioConfigurationScreen as a ConsumerWidget. Create a ScenarioTemplateListItem as a separate widget file — do not inline it in the screen file. For the route guard, use the existing role-based route protection pattern already in the router (check go_router or equivalent). For relative/absolute time display, create a pure helper formatLastModified(DateTime dt) -> String to keep the widget clean and testable.
The Toggle Switch should accept an enabled bool and an onChanged VoidCallback — set onChanged to (_) {} placeholder. Use ListView.builder with itemCount and itemBuilder. Category grouping (used in task-012) should be anticipated in the list item data model now: define a ScenarioTemplateViewModel with fields: id, name, description, category, isEnabled, lastModified. Keep this task strictly to layout scaffolding — resist the urge to wire data here.
Testing Requirements
Write widget tests using flutter_test. Widget test 1: Screen renders page header with correct title and subtitle. Widget test 2: ListView renders one ScenarioTemplateListItem per template in the input list. Widget test 3: Each list item shows name, truncated description (2 lines), formatted last modified date, and a Switch.
Widget test 4: Empty state widget shown when template list is empty. Widget test 5: Coordinator role renders screen normally; non-coordinator role triggers route guard redirect. Widget test 6: Toggle switches are visible and interactive (tappable) but do not change any state yet (no-op). Golden test for list item layout at 1.0x and 1.3x font scale.
Aim for 80%+ widget coverage.
If the scheduler runs concurrently (e.g., two overlapping cron invocations due to edge function retry), duplicate prompts could be dispatched before the first run's history records are committed, breaking the deduplication guarantee.
Mitigation & Contingency
Mitigation: Use a Postgres advisory lock or unique constraint on (user_id, scenario_id, activity_ref) in the prompt history table to make concurrent writes idempotent; design the scheduler to check history inside a transaction.
Contingency: If concurrency issues persist in production, add a distributed lock via Supabase Edge Function concurrency limit (max_instances=1) for the evaluation function as a hard guard.
Coordinators may find scenario configuration unclear if trigger conditions are expressed as raw JSON or technical terminology, leading to misconfiguration and irrelevant prompts being sent to peer mentors.
Mitigation & Contingency
Mitigation: Design the ScenarioConfigurationScreen to display human-readable descriptions of each template's trigger condition (e.g., 'Send 3 days after first contact if wellbeing concern was flagged') rather than raw rule properties; validate with an HLF coordinator in a design review before implementation.
Contingency: If coordinators still misconfigure rules after launch, add a preview mode that shows a simulated prompt based on a test activity before the rule is enabled.