Skip to content

Conversation

@dhairyashiil
Copy link
Member

@dhairyashiil dhairyashiil commented Jan 16, 2026

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:

  1. Enhanced useUpdateEventType hook with full optimistic update support:

    • Added onMutate callback to update cache immediately before server response
    • Added onSuccess callback to sync cache with server response
    • Added onError callback to rollback cache on failure
    • Updates both eventTypes.detail(id) and eventTypes.lists() caches
  2. Refactored handleSave in event-type-detail.tsx:

    • Replaced direct CalComAPIService.updateEventType() with useUpdateEventType hook
    • Replaced direct CalComAPIService.createEventType() with useCreateEventType hook
    • Removed manual fetchEventTypeData() call after save (cache updates automatically)
  3. Refactored handleDelete in event-type-detail.tsx:

    • Replaced direct CalComAPIService.deleteEventType() with useDeleteEventType hook
  4. Replaced local saving state with mutation hooks' isPending states (isUpdating || isCreating)

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. N/A - internal companion app changes only.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  1. Test on iOS and Android devices/simulators

  2. Test update flow:

    • Go to Event Types list
    • Tap an event type to open detail screen
    • Make changes (e.g., change title, duration, etc.)
    • Save changes
    • Navigate back to list
    • Expected: List should show updated values immediately without manual refresh
  3. Test delete flow:

    • Go to Event Types list
    • Tap an event type to open detail screen
    • Delete the event type
    • Expected: Should navigate back and list should update immediately
  4. Test error rollback:

    • Simulate a network error during save
    • Expected: UI should rollback to previous state

Human Review Checklist

  • Test optimistic updates work correctly on both iOS and Android
  • Verify error rollback restores previous cache state
  • Note: eventTypeData local 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)

- 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-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@dhairyashiil dhairyashiil marked this pull request as ready for review January 16, 2026 13:50
@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jan 16, 2026
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.

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.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2026

Devin AI is addressing Cubic AI's review feedback

New feedback has been sent to the existing Devin session.

View Devin Session


✅ Pushed commit 711cf29

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).
@dhairyashiil dhairyashiil merged commit 93e8d79 into feat/companion-auto-reload-on-save Jan 16, 2026
15 checks passed
@dhairyashiil dhairyashiil deleted the feat/companion-event-type-optimistic-updates branch January 16, 2026 18:08
@dhairyashiil dhairyashiil restored the feat/companion-event-type-optimistic-updates branch January 16, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Created by Linear-GitHub Sync size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants