Skip to content

Split ScheduleFormBloc responsibilities across defaults, persistence, preparation, and analytics #539

Description

@jjoonleo

Problem

ScheduleFormBloc is carrying too much orchestration for the schedule form. It handles create/edit loading, auth-derived defaults, UUID/time defaults, preparation comparison and persistence, schedule create/update mutations, submission error mapping, and analytics event construction.

This makes schedule-form changes high-risk because unrelated concerns all require edits to the same Bloc and the same broad test setup.

Evidence

  • lib/presentation/schedule_create/bloc/schedule_form_bloc.dart constructs the Bloc with many inputs, including schedule use cases, preparation use cases, analytics tracking, and AuthBloc.
  • Create setup fetches default preparation, reads AuthBloc.state.user.spareTimeOrNull, generates IDs, and computes initial schedule time.
  • Update/create handlers own mutation ordering plus conditional preparation persistence.
  • The Bloc builds and tracks the schedule_created analytics payload directly.
  • test/presentation/schedule_create/bloc/schedule_form_bloc_test.dart defines stubs for every collaborator and wires all of them for most Bloc tests.

Proposed direction

Introduce narrower orchestration seams so the Bloc only coordinates form events and state:

  • Move create/edit loading defaults into a schedule-form preparation service/use case.
  • Move create/update schedule plus conditional custom-preparation persistence into dedicated submit use cases.
  • Replace direct AuthBloc dependency with an explicit current-user/defaults input or resolver.
  • Move schedule_created payload construction behind a schedule analytics tracker called after successful create submission.

Acceptance criteria

  • ScheduleFormBloc no longer depends directly on AuthBloc or ProductUsageEventTracker.
  • Create and edit flows preserve current behavior for default preparation, user spare time, initial date seeding, schedule mutation, conditional preparation persistence, and create analytics.
  • Bloc tests no longer require stubbing every schedule, preparation, auth, and analytics collaborator for basic state behavior.
  • Focused tests cover the new preparation/defaults and submit orchestration seams, including unchanged preparation, changed preparation, create success analytics, and failure handling.

Source: Codex codebase audit on 2026-06-28.

Metadata

Metadata

Assignees

No one assigned

    Labels

    codex-readyCan be started independently by a Codex thread nowpreparationrelated to preparation featurerefactorschedulerelated to schedule featuretest

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions