cal.com icon indicating copy to clipboard operation
cal.com copied to clipboard

fix: prevent empty availability schedule names

Open xDipzz opened this issue 2 months ago • 6 comments

What does this PR do?

  • Add frontend validation with error toast and i18n support
  • Add backend validation with .trim().min(1) in Zod schemas
  • Add i18n translation for schedule_name_cannot_be_empty
  • Add comprehensive tests for validation (9 tests, all passing)
  • Sync previousValue with prop changes in EditableHeading
  • Follow PR #24044 approach with all reviewer feedback addressed

Fixes #21709

Visual Demo (For contributors especially)

Before (Bug)

https://github.com/user-attachments/assets/aba0a5d3-141b-45bf-b60c-f7792ac8bc68

After (Fixed)

https://github.com/user-attachments/assets/c6b83737-fe51-4810-9a96-22cd12948411

Tests Added

create.schema.test.ts - 4 tests covering:

  • Valid schedule names
  • Trimming whitespace
  • Rejecting empty strings
  • Rejecting whitespace-only strings

update.schema.test.ts - 5 tests covering:

  • Valid schedule names
  • Trimming whitespace
  • Rejecting empty strings
  • Rejecting whitespace-only strings
  • Optional name handling

All 9 tests passing

Approach (Following PR #24044)

Frontend

  • Shows error toast when user tries to save empty name
  • Uses i18n for multi-language support
  • Silent auto-revert in EditableHeading for better UX
  • Syncs previousValue with prop changes to prevent stale state

Backend

  • Zod schemas use .trim().min(1) validation
  • Prevents empty/whitespace-only names at API level
  • Consistent error messages

Reviewer Feedback Addressed

  • @coderabbitai: Added trimming + min-length check to schemas
  • @volnei: Added comprehensive tests
  • @Pallava-Joshi: Fixed i18n translation properly
  • cubic-dev-ai: Fixed previousValue sync issue in EditableHeading

Mandatory Tasks (DO NOT REMOVE)

  • [x] I have self-reviewed the code
  • [x] I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. N/A - No documentation changes needed
  • [x] I confirm automated tests are in place that prove my fix is effective or that my feature works

How should this be tested?

  1. Go to Availability and click on any availability schedule
  2. Click on edit heading
  3. Delete all text or type only spaces
  4. Click save
  5. Expected: Error toast appears "Schedule name cannot be empty"
  6. Run tests: yarn test create.schema.test.ts update.schema.test.ts

Checklist

  • [x] I have read the contributing guide
  • [x] My code follows the style guidelines of this project
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I have checked if my changes generate no new warnings

xDipzz avatar Nov 27 '25 15:11 xDipzz

@xDipzz is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Nov 27 '25 15:11 vercel[bot]

Can you refer to a similar approach as in PR #24044 and make sure to add tests as well? Please also consider the reviewer’s comments from that PR. Thanks.

@dhairyashiil Thank you for the feedback! I've updated the PR to follow PR #24044's approach:

  • Frontend validation with error toast and i18n support
  • Backend validation using .trim().min(1) in Zod schemas
  • Added schedule_name_cannot_be_empty translation
  • Added comprehensive tests (9 tests, all passing)
  • Addressed all reviewer comments from PR #24044
  • Fixed cubic-dev-ai bot issue regarding previousValue sync

The tests cover:

  • Valid schedule names
  • Trimming whitespace
  • Rejecting empty strings
  • Rejecting whitespace

xDipzz avatar Nov 27 '25 16:11 xDipzz

@cubic-dev-ai leave a review.

Pallava-Joshi avatar Dec 04 '25 17:12 Pallava-Joshi

@cubic-dev-ai leave a review.

@Pallava-Joshi I've started the AI code review. It'll take a few minutes to complete.

cubic-dev-ai[bot] avatar Dec 04 '25 17:12 cubic-dev-ai[bot]

This doesn’t look like a frontend issue. The API is missing proper validation, so the backend is accepting invalid input. The frontend can add checks for better UX, but the backend still needs to enforce the rules. Please add the necessary validation on the server side.

Kannan112 avatar Dec 09 '25 05:12 Kannan112

can you also resolve the merge conflicts here, thank you!

Ryukemeister avatar Dec 10 '25 09:12 Ryukemeister