[refactor] Move availability utils + offset into @bluedot/utils#2604
Conversation
Relocate the framework-agnostic weekly-availabilities conversion logic and timezone offset helpers out of apps/availability into @bluedot/utils, so server-side code can consume them without pulling in React. Adds gridToUtcIntervalString / utcIntervalStringToGrid helpers. TimeAvailabilityGrid stays in @bluedot/ui, now importing MINUTES_IN_UNIT + TimeAvailabilityMap from @bluedot/utils. Closes #2603 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
More reviews will be available in 47 minutes and 43 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR consolidates availability conversion utilities and timezone offset helpers into Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
libraries/ui/src/TimeAvailabilityGrid.tsx (1)
5-5: Confirm@bluedot/utilsroot barrel is safe for client imports
libraries/utils/src/index.tsre-exports bothvalidateEnvandslackAlert, butvalidateEnvonly touchesprocess.envin the default parameter (envSource = process.env), so the browser won’t error on import (only ifvalidateEnv()is called).slackNotifications.tshas nonode:*/require/fs-style imports and relies on browser-compatible globals (fetch, timers), so importing the barrel fromTimeAvailabilityGrid.tsxshouldn’t break client bundles.
Optional: still consider subpath exports so server-oriented helpers aren’t exposed to accidental client usage.🤖 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 `@libraries/ui/src/TimeAvailabilityGrid.tsx` at line 5, The import from the root barrel (`@bluedot/utils`) pulls MINUTES_IN_UNIT and TimeAvailabilityMap which currently is safe but exposes server-oriented helpers; to prevent accidental client-side imports of server-only utilities, either switch this file to import the specific client-safe symbol subpath(s) (e.g., the module that exports MINUTES_IN_UNIT/TimeAvailabilityMap) instead of the root barrel, or add a short inline comment in TimeAvailabilityGrid.tsx noting that the root barrel is safe for client use and why (validateEnv only reads process.env in its default arg and slack notifications use browser globals). Update references around MINUTES_IN_UNIT and TimeAvailabilityMap accordingly.
🤖 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.
Nitpick comments:
In `@libraries/ui/src/TimeAvailabilityGrid.tsx`:
- Line 5: The import from the root barrel (`@bluedot/utils`) pulls MINUTES_IN_UNIT
and TimeAvailabilityMap which currently is safe but exposes server-oriented
helpers; to prevent accidental client-side imports of server-only utilities,
either switch this file to import the specific client-safe symbol subpath(s)
(e.g., the module that exports MINUTES_IN_UNIT/TimeAvailabilityMap) instead of
the root barrel, or add a short inline comment in TimeAvailabilityGrid.tsx
noting that the root barrel is safe for client use and why (validateEnv only
reads process.env in its default arg and slack notifications use browser
globals). Update references around MINUTES_IN_UNIT and TimeAvailabilityMap
accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 870f95b5-bb28-43d5-9e6e-9aad41c2b6fe
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (12)
apps/availability/src/components/TimeAvailabilityInput.tsxapps/availability/src/components/TimeOffsetSelector.tsxapps/availability/src/pages/form/[slug].tsxlibraries/ui/src/TimeAvailabilityGrid.stories.tsxlibraries/ui/src/TimeAvailabilityGrid.tsxlibraries/ui/src/index.tslibraries/utils/package.jsonlibraries/utils/src/index.tslibraries/utils/src/timeAvailability.test.tslibraries/utils/src/timeAvailability.tslibraries/utils/src/timezoneOffset.test.tslibraries/utils/src/timezoneOffset.ts
Greptile SummaryThis PR moves timezone-offset helpers and weekly-availability grid utilities out of
Confidence Score: 3/5The refactor is logically correct and well-tested, but a missing type cast in longEnoughInterval is inconsistent with every other call site and may surface as a TypeScript compile error. The conversion logic is unchanged and round-trip tests pass for UTC, positive, and negative offsets. The main risk is in apps/availability/src/pages/form/[slug].tsx line 74, where weeklyTimeAvToIntervals is called with a TimeAvailabilityMap value without the as Record<wa.WeeklyTime, boolean> cast that gridToUtcIntervalString and intervalsToWeeklyTimeAv both rely on — if wa.WeeklyTime is not simply number, this is a hidden compile error on the critical form-submission path. apps/availability/src/pages/form/[slug].tsx (missing cast in longEnoughInterval) and libraries/utils/src/timeAvailability.ts (internal helper signatures still reference Record<wa.WeeklyTime, boolean> instead of TimeAvailabilityMap). Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["apps/availability\nform/[slug].tsx"] -->|"gridToUtcIntervalString(map, tz)"| B["@bluedot/utils\ntimeAvailability.ts"]
A -->|"utcIntervalStringToGrid(str, tz)"| B
B -->|"weeklyTimeAvToIntervals(map)"| C["weekly-availabilities\nwa.unionSchedules / wa.format"]
B -->|"shiftIntervals(intervals, offset)"| C
B -->|"wa.parseIntervals(str)"| C
B -->|"parseOffsetFromStringToMinutes(tz)"| D["@bluedot/utils\ntimezoneOffset.ts"]
E["@bluedot/ui\nTimeAvailabilityGrid.tsx"] -->|"MINUTES_IN_UNIT\nTimeAvailabilityMap"| B
F["apps/availability\nTimeAvailabilityInput.tsx"] -->|"MINUTES_IN_WEEK\nTimeAvailabilityMap"| B
G["apps/availability\nTimeOffsetSelector.tsx"] -->|"offsets"| D
|
Drops the scattered `as Record<wa.WeeklyTime, boolean>` casts: the helpers operate on the canonical TimeAvailabilityMap, so callers no longer need to cast. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Thanks bots. Addressed in 0363b8b. Greptile P2 (internal signatures should use Greptile P1 (missing cast in CodeRabbit (subpath exports for the Typecheck + the 7 |
Relocate the framework-agnostic weekly-availabilities conversion logic and timezone offset helpers out of apps/availability into @bluedot/utils, so server-side code can consume them without pulling in React. Adds
gridToUtcIntervalString/utcIntervalStringToGridhelpers. TimeAvailabilityGrid stays in @bluedot/ui, now importing MINUTES_IN_UNIT + TimeAvailabilityMap from @bluedot/utils.Closes #2603