-
Notifications
You must be signed in to change notification settings - Fork 11.6k
feat(companion): add optimistic updates to EventTypeDetail screen #26935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(companion): add optimistic updates to EventTypeDetail screen #26935
Conversation
- Enhance useUpdateEventType hook with full optimistic update support - Add onMutate callback to update cache immediately - Add onSuccess callback to sync with server response - Add onError callback to rollback on failure - Update both eventTypes.detail(id) and eventTypes.lists() caches - Refactor handleSave in event-type-detail.tsx - Replace direct CalComAPIService.updateEventType() with useUpdateEventType hook - Replace direct CalComAPIService.createEventType() with useCreateEventType hook - Remove manual fetchEventTypeData() call after save (cache updates automatically) - Replace local saving state with mutation hooks' isPending states - Refactor handleDelete in event-type-detail.tsx - Replace direct CalComAPIService.deleteEventType() with useDeleteEventType hook This ensures the event types list updates immediately after save/delete without requiring manual refresh.
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 2 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="companion/hooks/useEventTypes.ts">
<violation number="1" location="companion/hooks/useEventTypes.ts:128">
P2: Widening `updates` to `Record<string, unknown>` removes the compile-time contract with `CreateEventTypeInput`, so callers can now send invalid payload shapes that the API will only reject at runtime. Keep the hook typed as `Partial<CreateEventTypeInput>` (cast for cache merges if needed) to preserve type safety.</violation>
</file>
<file name="companion/app/(tabs)/(event-types)/event-type-detail.tsx">
<violation number="1" location="companion/app/(tabs)/(event-types)/event-type-detail.tsx:1257">
P2: `eventTypeData` is never synced after a successful update anymore, so dirty-checking compares against stale data. After saving once, `isDirty` stays true and reverting a field back to its original value no longer triggers an update because the baseline still matches the old value.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Devin AI is addressing Cubic AI's review feedbackNew feedback has been sent to the existing Devin session. ✅ Pushed commit |
Revert the type from Record<string, unknown> back to Partial<CreateEventTypeInput> to preserve compile-time type checking for callers. Addresses Cubic AI review feedback (confidence 9/10).
93e8d79
into
feat/companion-auto-reload-on-save
What does this PR do?
This PR adds optimistic updates to the EventTypeDetail screen in the companion app, ensuring the event types list updates immediately after save/delete operations without requiring manual refresh.
Note: This is a stacked PR that depends on #26931 (
feat/companion-auto-reload-on-save).Changes:
Enhanced
useUpdateEventTypehook with full optimistic update support:onMutatecallback to update cache immediately before server responseonSuccesscallback to sync cache with server responseonErrorcallback to rollback cache on failureeventTypes.detail(id)andeventTypes.lists()cachesRefactored
handleSavein event-type-detail.tsx:CalComAPIService.updateEventType()withuseUpdateEventTypehookCalComAPIService.createEventType()withuseCreateEventTypehookfetchEventTypeData()call after save (cache updates automatically)Refactored
handleDeletein event-type-detail.tsx:CalComAPIService.deleteEventType()withuseDeleteEventTypehookReplaced local
savingstate with mutation hooks'isPendingstates (isUpdating || isCreating)Mandatory Tasks (DO NOT REMOVE)
How should this be tested?
Test on iOS and Android devices/simulators
Test update flow:
Test delete flow:
Test error rollback:
Human Review Checklist
eventTypeDatalocal state is not synced after update - dirty-checking may compare against stale baseline after first save. This is a known limitation that may need follow-up work if it causes issues.Link to Devin run: https://app.devin.ai/sessions/0e35f5cdab8943dabb66fc182e4241fe
Requested by: Dhairyashil Shinde (@dhairyashiil)