Skip to content

feat(availability): add preset hours dropdown to new schedule dialog#29661

Draft
veronikal24 wants to merge 1 commit into
calcom:mainfrom
ranUser01:feature/availability-schedule-presets
Draft

feat(availability): add preset hours dropdown to new schedule dialog#29661
veronikal24 wants to merge 1 commit into
calcom:mainfrom
ranUser01:feature/availability-schedule-presets

Conversation

@veronikal24

Copy link
Copy Markdown

Adds a "Starting hours" select field to the Add New Schedule dialog with three options: Custom (no preset), Morning (6 AM–12 PM Mon–Fri), and Evening (5 PM–10 PM Mon–Fri). Selected preset is passed as the initial schedule time ranges when creating the schedule.

What does this PR do?

  • Fixes #XXXX (GitHub issue number)

Visual Demo (For contributors especially)

A visual demonstration is strongly recommended, for both the original and new change (video / image - any one).

Video Demo (if applicable):

  • Show screen recordings of the issue or feature.
  • Demonstrate how to reproduce the issue, the behavior before and after the change.

Image Demo (if applicable):

  • Add side-by-side screenshots of the original and updated change.
  • Highlight any significant change(s).

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
  • What are the minimal test data to have?
  • What is expected (happy path) to have (input and output)?
  • Any other important info that could help to test that PR

Checklist

  • I haven't read the contributing guide
  • My code doesn't follow the style guidelines of this project
  • I haven't commented my code, particularly in hard-to-understand areas
  • I haven't checked if my changes generate no new warnings
  • My PR is too large (>500 lines or >10 files) and should be split into smaller PRs

Adds a "Starting hours" select field to the Add New Schedule dialog with
three options: Custom (no preset), Morning (6 AM–12 PM Mon–Fri), and
Evening (5 PM–10 PM Mon–Fri). Selected preset is passed as the initial
schedule time ranges when creating the schedule.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Welcome to Cal.diy, @veronikal24! Thanks for opening this pull request.

A few things to keep in mind:

  • This is Cal.diy, not Cal.com. Cal.diy is a community-driven, fully open-source fork of Cal.com licensed under MIT. Your changes here will be part of Cal.diy — they will not be deployed to the Cal.com production app.
  • Please review our Contributing Guidelines if you haven't already.
  • Make sure your PR title follows the Conventional Commits format.

A maintainer will review your PR soon. Thanks for contributing!

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

NewScheduleButton gains a "starting hours" preset selector. A SchedulePreset type and SCHEDULE_PRESETS map are added, defining custom, morning (6 AM–12 PM Mon–Fri), and evening (5 PM–10 PM Mon–Fri) as UTC weekday date ranges. The form gains a preset field defaulting to "custom". On submit, the selected preset's schedule is passed to the create mutation. The UI uses Controller + SelectField to render the preset options. Four new i18n keys are added to en/common.json for the labels.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: adding preset hours dropdown options to the new schedule dialog.
Description check ✅ Passed The description directly explains the new starting-hours presets and how they affect schedule creation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/web/modules/schedules/components/NewScheduleButton.tsx (2)

11-12: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid the @calcom/ui/components/form barrel here.

This change reintroduces a barrel import for the touched form components. Please switch these to direct source imports so the file stays aligned with the UI package import contract. As per coding guidelines, "Import directly from source files, not barrel files" and "Never use barrel imports from index.ts files".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/modules/schedules/components/NewScheduleButton.tsx` around lines 11
- 12, The touched form imports in NewScheduleButton should not use the
`@calcom/ui/components/form` barrel. Update the Form, SelectField, and InputField
imports to come from their direct source modules instead of the barrel so the
file follows the UI package import contract and avoids index-based reexports.

Source: Coding guidelines


17-25: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rewrite or drop these comments.

These additions describe the implementation rather than the reason for it. If the helper needs documentation, capture why UTC anchoring/weekday ordering matters; otherwise remove the comments. As per coding guidelines, "Only add code comments that explain why, not what" and "Never add comments that simply restate what the code does".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/modules/schedules/components/NewScheduleButton.tsx` around lines 17
- 25, The comments in buildWeekdayRanges are implementation notes rather than
rationale, so either remove them or rewrite them to explain why UTC anchoring
and weekday ordering are necessary. Update the documentation near the
buildWeekdayRanges helper in NewScheduleButton so it captures the intent behind
the UTC Date construction and the Mon-Fri mapping, without restating what the
code does.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/modules/schedules/components/NewScheduleButton.tsx`:
- Around line 33-35: The `custom` option in `NewScheduleButton` still ends up
using `DEFAULT_SCHEDULE` because the create flow treats a missing `schedule` as
fallback, so make `custom` represent an explicit blank schedule instead. Update
the `scheduleOptions` entry for `custom` and the related create handler logic so
the `createSchedule` path can distinguish “no preset” from “use default,” using
the unique `buildWeekdayRanges`, `DEFAULT_SCHEDULE`, and `input.schedule`
handling in `NewScheduleButton` as the place to fix it.

---

Nitpick comments:
In `@apps/web/modules/schedules/components/NewScheduleButton.tsx`:
- Around line 11-12: The touched form imports in NewScheduleButton should not
use the `@calcom/ui/components/form` barrel. Update the Form, SelectField, and
InputField imports to come from their direct source modules instead of the
barrel so the file follows the UI package import contract and avoids index-based
reexports.
- Around line 17-25: The comments in buildWeekdayRanges are implementation notes
rather than rationale, so either remove them or rewrite them to explain why UTC
anchoring and weekday ordering are necessary. Update the documentation near the
buildWeekdayRanges helper in NewScheduleButton so it captures the intent behind
the UTC Date construction and the Mon-Fri mapping, without restating what the
code does.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 41d2384b-65a5-4825-be46-fd1149da15c4

📥 Commits

Reviewing files that changed from the base of the PR and between b97cd62 and 8e2e24d.

📒 Files selected for processing (2)
  • apps/web/modules/schedules/components/NewScheduleButton.tsx
  • packages/i18n/locales/en/common.json

Comment on lines +33 to +35
custom: { label: "custom_hours", schedule: undefined },
morning: { label: "morning_hours", schedule: buildWeekdayRanges(6, 12) },
evening: { label: "evening_hours", schedule: buildWeekdayRanges(17, 22) },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

custom still creates the default schedule.

custom maps to undefined, but the create handler falls back to DEFAULT_SCHEDULE whenever input.schedule is missing. So this option does not behave like "no preset"—it silently creates the standard default hours instead. Send an explicit empty 7-day schedule here if the intent is a blank starting point.

Proposed fix
+const EMPTY_SCHEDULE = Array.from({ length: 7 }, () => [] as { start: Date; end: Date }[]);
+
 const SCHEDULE_PRESETS: Record<
   SchedulePreset,
   { label: string; schedule: { start: Date; end: Date }[][] | undefined }
 > = {
-  custom: { label: "custom_hours", schedule: undefined },
+  custom: { label: "custom_hours", schedule: EMPTY_SCHEDULE },
   morning: { label: "morning_hours", schedule: buildWeekdayRanges(6, 12) },
   evening: { label: "evening_hours", schedule: buildWeekdayRanges(17, 22) },
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
custom: { label: "custom_hours", schedule: undefined },
morning: { label: "morning_hours", schedule: buildWeekdayRanges(6, 12) },
evening: { label: "evening_hours", schedule: buildWeekdayRanges(17, 22) },
const EMPTY_SCHEDULE = Array.from({ length: 7 }, () => [] as { start: Date; end: Date }[]);
const SCHEDULE_PRESETS: Record<
SchedulePreset,
{ label: string; schedule: { start: Date; end: Date }[][] | undefined }
> = {
custom: { label: "custom_hours", schedule: EMPTY_SCHEDULE },
morning: { label: "morning_hours", schedule: buildWeekdayRanges(6, 12) },
evening: { label: "evening_hours", schedule: buildWeekdayRanges(17, 22) },
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/modules/schedules/components/NewScheduleButton.tsx` around lines 33
- 35, The `custom` option in `NewScheduleButton` still ends up using
`DEFAULT_SCHEDULE` because the create flow treats a missing `schedule` as
fallback, so make `custom` represent an explicit blank schedule instead. Update
the `scheduleOptions` entry for `custom` and the related create handler logic so
the `createSchedule` path can distinguish “no preset” from “use default,” using
the unique `buildWeekdayRanges`, `DEFAULT_SCHEDULE`, and `input.schedule`
handling in `NewScheduleButton` as the place to fix it.

@bandhan-majumder bandhan-majumder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

for feature requests, please create an issue first!

@bandhan-majumder bandhan-majumder marked this pull request as draft June 27, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants