Skip to content

refactor: extract duplicated slug auto-generation state machine from admin dialogs #167

Description

@chiptus

Problem

src/lib/slug.ts supplies primitives only (generateSlug/isValidSlug/sanitizeSlug). The stateful "auto-derive slug while name changes, but stop once the user edits slug directly" behavior was never factored into a hook, so it's hand-copied (including the same comment) into two admin dialogs:

  • src/pages/admin/festivals/FestivalDialog.tsx:55, 82-104 (255 lines total)
  • src/pages/admin/festivals/FestivalEditionManagement.tsx:80, 138-162 (458 lines total)

Both dialogs also mix fetch, form state, validation, and dialog/table JSX in one file with no unit test coverage — FestivalEditionManagement.tsx in particular is a god component (fetch + form state + slug logic + delete confirmation + table, all in one file), a repeated template across the admin area rather than a one-off.

Note: distinct from #135 (duplicate slugs bug on set creation — a uniqueness/collision issue). This ticket is about the duplicated state machine code, not slug collisions.

Fix

Extract a useSlugField(name) hook that absorbs the auto-derive/validate state machine; both dialogs call it instead of carrying their own copy. Splitting FestivalEditionManagement.tsx further (form-state hook / presentational dialog / presentational table) is a larger follow-up, not required for this ticket.

Architecture note

Filed from an architecture review (module/interface/depth vocabulary, see /codebase-design).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions