Skip to content

Feature/82 make coach selection mandatory for private lessons#96

Open
maxiDeee wants to merge 2 commits into
developfrom
feature/82-make-coach-selection-mandatory-for-private-lessons
Open

Feature/82 make coach selection mandatory for private lessons#96
maxiDeee wants to merge 2 commits into
developfrom
feature/82-make-coach-selection-mandatory-for-private-lessons

Conversation

@maxiDeee
Copy link
Copy Markdown

@maxiDeee maxiDeee commented Jun 6, 2026

Overview

Private lessons could be created without a coach (the form validated coach_id but never saved it, and the column was nullable). This makes a coach mandatory for private lessons end to end, lets admins reassign the coach when editing, and prevents deleting a coach who is still assigned to a private lesson.

  • Schema: coach_id FK set nullrestrict, plus a partial CHECK (type <> 'private_lessons' OR coach_id IS NOT NULL) so private lessons require a coach while programs stay coachless.
  • Create/edit: createService now persists coachId; updateService supports reassignment while keeping the coach required. The dialog submits the coach via a hidden input (a Radix Select with name silently falls back to its first option) and pre-selects the current coach when editing.
  • Delete: new deleteUserAdmin action blocks deleting a coach assigned to a private lesson; surfaced in the Users tab via a delete button, confirm dialog, and error toast.
  • Also fixes a pre-existing bug that blocked reassignment: updateService recreated the Stripe price on every edit, which archives the product's default price (rejected by Stripe). It now swaps the price only when the amount changes.

Testing

  • Unit: pnpm test passes 18/18 (11 new) covering the create, update, and delete actions; pnpm lint and tsc --noEmit are clean.
  • Manual: verified creating a private lesson with no coach is rejected, reassigning the coach on edit saves successfully, and deleting an assigned coach shows an error.

Screenshots / Screencasts

Creating a private lesson without a coach is rejected:
Screenshot 2026-06-06 at 5 31 31 PM

Deleting a user assigned as coach to a private lesson is blocked:
Screenshot 2026-06-06 at 12 32 50 PM

Checklist

  • Code is neat, readable, and works
  • Code is commented where appropriate and w
  • Commit messages follow our guidelines
  • Issue number is linked
  • Branch is linked
  • Reviewers are assigned

Notes

The schema change isn't applied to the DB yet — run pnpm db:push. The CHECK constraint will fail to create if any existing private_lessons row has coach_id IS NULL, so backfill those rows with a coach (or soft-delete them) first.

Out of scope follow-up: editing a service's price still hits the Stripe "default price cannot be archived" error on a genuine price change; only the unchanged-price path is fixed here.

Copy link
Copy Markdown
Member

@RenaudBernier RenaudBernier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message just shows on first try to create service. It should show on every unsuccessful try.

Screen.Recording.2026-06-06.at.3.50.25.PM.mov

@maxiDeee
Copy link
Copy Markdown
Author

maxiDeee commented Jun 6, 2026

Fixed bug for error message only showing up once, updated screenshot.
Please check the Notes section in PR description.

@maxiDeee maxiDeee changed the title feat(services): make coach selection mandatory for private lessons Feature/82 make coach selection mandatory for private lessons Jun 6, 2026
@maxiDeee maxiDeee requested a review from RenaudBernier June 6, 2026 21:37
Copy link
Copy Markdown
Member

@RenaudBernier RenaudBernier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants