Skip to content

Comments

fix: type error in the EventAvailabilityTabPlatformWrapper component#21983

Merged
keithwillcode merged 7 commits intocalcom:mainfrom
apsinghdev:fix/type-error-schedule
Aug 28, 2025
Merged

fix: type error in the EventAvailabilityTabPlatformWrapper component#21983
keithwillcode merged 7 commits intocalcom:mainfrom
apsinghdev:fix/type-error-schedule

Conversation

@apsinghdev
Copy link
Contributor

@apsinghdev apsinghdev commented Jun 23, 2025

What does this PR do?

Visual Demo (For contributors especially)

Screenshot 2025-06-23 at 5 21 57 PM

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 in /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?

Pls check the Problems section in the terminal.


Summary by cubic

Fixed a type error in the EventAvailabilityTabPlatformWrapper component by updating the structure of the schedule prop. This ensures correct typing and prevents runtime errors.

@apsinghdev apsinghdev requested a review from a team June 23, 2025 11:53
@apsinghdev apsinghdev requested a review from a team as a code owner June 23, 2025 11:53
@vercel
Copy link

vercel bot commented Jun 23, 2025

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

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jun 23, 2025
@graphite-app graphite-app bot requested a review from a team June 23, 2025 11:53
@github-actions github-actions bot added 🐛 bug Something isn't working 💻 refactor labels Jun 23, 2025
@dosubot dosubot bot added the platform Anything related to our platform plan label Jun 23, 2025
@apsinghdev apsinghdev changed the title fix: fix type error in the EventAvailabilityTabPlatformWrapper component fix: type error in the EventAvailabilityTabPlatformWrapper component Jun 23, 2025
@graphite-app
Copy link

graphite-app bot commented Jun 23, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (06/23/25)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (06/23/25)

1 label was added to this PR based on Keith Williams's automation.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

cubic found 1 issue across 1 file. Review it in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

],
[]
) || [],
schedule: atomSchedule.schedule.map((avail: any) => ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Using any here removes all compile-time type checking for availability items and can hide bugs. Provide the correct interface or let TypeScript infer the type instead of forcing any.

Suggested change
schedule: atomSchedule.schedule.map((avail: any) => ({
schedule: atomSchedule.schedule.map((avail) => ({

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM, please try to address this small cubic suggestion.

@apsinghdev
Copy link
Contributor Author

@Devanshusharma2005 done. please take a look!

Copy link
Contributor

@Devanshusharma2005 Devanshusharma2005 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the pr.

Comment on lines 62 to 71
schedule: atomSchedule.schedule.map((avail: ScheduleQueryData["schedule"][number]) => ({
id: avail.id ?? null,
startTime: new Date(avail.startTime),
endTime: new Date(avail.endTime),
userId: avail.userId ?? null,
eventTypeId: avail.eventTypeId ?? null,
scheduleId: avail.scheduleId ?? null,
date: avail.date ? new Date(avail.date) : null,
days: avail.days,
})),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be (atomSchedule.schedule || []).map

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense! This fallback can save runtime issues. Fixed it. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be (atomSchedule.schedule || []).map

ahh coz atomSchedule.schedule might be undefined or null if no schedule is present.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly!

Copy link
Contributor

@Devanshusharma2005 Devanshusharma2005 left a comment

Choose a reason for hiding this comment

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

LGTM

@anikdhabal anikdhabal added the Low priority Created by Linear-GitHub Sync label Jul 4, 2025
Copy link
Contributor

@Devanshusharma2005 Devanshusharma2005 left a comment

Choose a reason for hiding this comment

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

@apsinghdev can you please fix the tests. Marking it draft until then.

@Devanshusharma2005 Devanshusharma2005 marked this pull request as draft July 9, 2025 14:54
@github-actions
Copy link
Contributor

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Jul 24, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 24, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

  • Exported type alias ScheduleQueryData from EventAvailabilityTab.tsx.
  • EventAvailabilityTabPlatformWrapper now imports ScheduleQueryData as a type.
  • scheduleQueryData is built by spreading atomSchedule and explicitly setting isManaged, readOnly, id, and timeZone.
  • Replaced reduce-based transformation of atomSchedule.schedule with a map that produces entries typed as ScheduleQueryData["schedule"][number], including id, startTime, endTime, userId, eventTypeId, scheduleId, date, and days, with Date conversions.

Assessment against linked issues

Objective Addressed Explanation
Resolve type mismatch in scheduleQueryData.schedule (\#21981, CAL-5971)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Exporting ScheduleQueryData type alias (packages/features/eventtypes/components/tabs/availability/EventAvailabilityTab.tsx) Appears directly related to enabling type reuse for fixing the wrapper’s type error; not clearly out of scope.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 13, 2025

E2E results are ready!

@kart1ka kart1ka marked this pull request as ready for review August 22, 2025 05:15
@dosubot dosubot bot added the event-types area: event types, event-types label Aug 22, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx (1)

62-62: Past bot comment resolved: no more any.

You removed the any in the schedule mapping and aligned with ScheduleQueryData["schedule"][number]. Good resolution of the earlier bot suggestion.

🧹 Nitpick comments (4)
packages/features/eventtypes/components/tabs/availability/EventAvailabilityTab.tsx (1)

38-38: Type-only export is appropriate and low-risk.

Exporting ScheduleQueryData with export type avoids runtime coupling and makes the type available to platform wrappers. LGTM.

If you anticipate broader reuse, consider relocating this alias to a small co-located types.ts (or a domain-level types module) to reduce chances of accidental component-level import cycles in the future.

packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx (3)

57-61: Redundant property overwrites after spreading.

You spread ...atomSchedule and then immediately reassign the same properties (isManaged, readOnly, id, timeZone) to the same values. This is noise and risks accidental divergence later.

Apply this diff to simplify:

-      scheduleQueryData={{
-        ...atomSchedule,
-        isManaged: atomSchedule.isManaged,
-        readOnly: atomSchedule.readOnly,
-        id: atomSchedule.id,
-        timeZone: atomSchedule.timeZone,
+      scheduleQueryData={{
+        ...atomSchedule,

62-71: Strengthen typing at the result, not the callback param; prefer nullish coalescing.

  • Avoid typing the .map callback parameter to the target element type; it can mask mismatches between the source shape and the desired shape. Instead, make the mapping’s result satisfy the intended type.
  • Prefer ?? [] over || [] for optional arrays to avoid treating non-null falsy values as absent (even if unlikely here).

Consider this focused change:

-        schedule: (atomSchedule.schedule || []).map((avail: ScheduleQueryData["schedule"][number]) => ({
+        schedule: ((atomSchedule.schedule ?? []).map((avail): ScheduleQueryData["schedule"][number] => ({
           id: avail.id ?? null,
           startTime: new Date(avail.startTime),
           endTime: new Date(avail.endTime),
           userId: avail.userId ?? null,
           eventTypeId: avail.eventTypeId ?? null,
           scheduleId: avail.scheduleId ?? null,
           date: avail.date ? new Date(avail.date) : null,
           days: avail.days,
-        })),
+        })) as ScheduleQueryData["schedule"]),

Follow-up:

  • If any of the nullable fields (e.g., id, userId) are actually non-nullable in ScheduleQueryData["schedule"][number], drop the ?? null defaults accordingly. Please run your local type-check to confirm the constraints across environments.

56-72: Optional: memoize normalization to avoid remapping on every render.

Date normalization is pure but will re-run on each render causing a new array identity. If downstream components rely on referential equality for memoization, this can trigger extra renders. Memoizing on atomSchedule.schedule keeps renders lean.

Add this above the return and use it in place of the inline mapping:

import { useMemo } from "react";

// ...
const normalizedSchedule = useMemo<ScheduleQueryData["schedule"]>(() => {
  return ((atomSchedule.schedule ?? []).map((avail): ScheduleQueryData["schedule"][number] => ({
    id: avail.id ?? null,
    startTime: new Date(avail.startTime),
    endTime: new Date(avail.endTime),
    userId: avail.userId ?? null,
    eventTypeId: avail.eventTypeId ?? null,
    scheduleId: avail.scheduleId ?? null,
    date: avail.date ? new Date(avail.date) : null,
    days: avail.days,
  })) as ScheduleQueryData["schedule"]);
}, [atomSchedule.schedule]);

// ...
scheduleQueryData={{
  ...atomSchedule,
  schedule: normalizedSchedule,
}}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 30b0012 and 342f6e7.

📒 Files selected for processing (2)
  • packages/features/eventtypes/components/tabs/availability/EventAvailabilityTab.tsx (1 hunks)
  • packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.tsx

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Always use t() for text localization in frontend code; direct text embedding should trigger a warning

Files:

  • packages/features/eventtypes/components/tabs/availability/EventAvailabilityTab.tsx
  • packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/review.mdc)

Flag excessive Day.js use in performance-critical code; prefer native Date or Day.js .utc() in hot paths like loops

Files:

  • packages/features/eventtypes/components/tabs/availability/EventAvailabilityTab.tsx
  • packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx
**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit configuration file

Flag default exports and encourage named exports. Named exports provide better tree-shaking, easier refactoring, and clearer imports. Exempt main components like pages, layouts, and components that serve as the primary export of a module.

Files:

  • packages/features/eventtypes/components/tabs/availability/EventAvailabilityTab.tsx
  • packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx
🧠 Learnings (1)
📚 Learning: 2025-08-20T17:34:34.906Z
Learnt from: mdm317
PR: calcom/cal.com#23221
File: packages/features/schedules/components/NewScheduleButton.tsx:1-1
Timestamp: 2025-08-20T17:34:34.906Z
Learning: In the Cal.com codebase, server actions like `revalidateAvailabilityList()` from `app/(use-page-wrapper)/(main-nav)/availability/actions` are imported and called directly in client components within mutation `onSuccess` callbacks. This pattern is consistently used across availability-related components (both in availability-view.tsx for updates and NewScheduleButton.tsx for creates) to ensure the availability list cache is fresh after mutations.

Applied to files:

  • packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx
🧬 Code graph analysis (1)
packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx (1)
packages/features/eventtypes/components/tabs/availability/EventAvailabilityTab.tsx (1)
  • ScheduleQueryData (38-38)
⏰ Context from checks skipped due to timeout of 180000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Install dependencies / Yarn install & cache
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (1)
packages/platform/atoms/event-types/wrappers/EventAvailabilityTabPlatformWrapper.tsx (1)

5-5: Good: type-only import prevents runtime cycles.

Using import type { ScheduleQueryData } ensures the wrapper doesn’t pull the component module at runtime. Nice.

Copy link
Contributor

@kart1ka kart1ka left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Ryukemeister Ryukemeister left a comment

Choose a reason for hiding this comment

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

LGTM!

@Ryukemeister Ryukemeister dismissed Devanshusharma2005’s stale review August 26, 2025 17:04

maybe some flaky tests, dont think theres anything here that should actually make em fail

Copy link
Contributor

@Devanshusharma2005 Devanshusharma2005 left a comment

Choose a reason for hiding this comment

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

LGTM

@keithwillcode keithwillcode enabled auto-merge (squash) August 28, 2025 16:02
@keithwillcode keithwillcode merged commit 724e3f2 into calcom:main Aug 28, 2025
30 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛 bug Something isn't working community Created by Linear-GitHub Sync event-types area: event types, event-types Low priority Created by Linear-GitHub Sync platform Anything related to our platform plan ready-for-e2e 💻 refactor Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Type error in the EventAvailabilityTabPlatformWrapper component

8 participants