Skip to content

Conversation

@marcuscastelo
Copy link
Owner

@marcuscastelo marcuscastelo commented Jul 27, 2025

Summary

Fixes day change modal functionality by ensuring data is refetched from the server after accepting day change. Previously, when users clicked "Ir para [data] (Hoje)" to go to the current day, the target day was updated but day data remained stale, causing the current day to appear as non-existent even if it existed in the database.

Implementation Details

  • Modified acceptDayChange() function: Added bootstrap() call after updating target day to trigger day data refetch
  • Updated test coverage: Enhanced dayChangeDetection.test.ts with proper mocks for showPromise and currentUserId to handle the new bootstrap call
  • Preserved existing behavior: Day change modal still updates target day and clears modal state as before

Root Cause

The acceptDayChange function in src/modules/diet/day-diet/application/dayDiet.ts only updated the target day without refetching day diets from the server, leaving the application with stale data that might not include the current day.

Technical Changes

// Before
export function acceptDayChange() {
  const changeData = dayChangeData()
  if (changeData) {
    setTargetDay(changeData.newDay)
    setDayChangeData(null)
  }
}

// After  
export function acceptDayChange() {
  const changeData = dayChangeData()
  if (changeData) {
    setTargetDay(changeData.newDay)
    setDayChangeData(null)
    bootstrap() // Refetch day diets to ensure current day is available
  }
}

Testing

  • ✅ All existing tests continue to pass
  • ✅ Updated test properly mocks bootstrap dependencies
  • ✅ Verified proper error handling and type safety
  • ✅ Quality checks pass (lint, type-check, tests)

User Impact

  • Before: Day change modal would update to current day but show "DayNotFound" component
  • After: Day change modal correctly displays current day data if it exists in database
  • Improves UX: Seamless day transitions without confusing "day not found" states

Closes #1020

- Add bootstrap() call to acceptDayChange() function to ensure day data is refetched when user accepts day change
- Update test mocks to properly handle bootstrap function dependencies (showPromise and currentUserId)
- Resolves issue where current day appears as non-existent after day change modal acceptance

Fixes #1020
@marcuscastelo marcuscastelo added bug Report a problem or malfunction complexity-low Low implementation complexity ui UI/UX related issue or improvement labels Jul 27, 2025
@vercel
Copy link

vercel bot commented Jul 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
macroflows ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 27, 2025 2:04am

@github-actions github-actions bot added the complexity-medium Medium implementation complexity label Jul 27, 2025
@marcuscastelo marcuscastelo changed the base branch from stable to rc/v0.14.0 July 27, 2025 01:57
@marcuscastelo marcuscastelo merged commit 1cf0cd0 into rc/v0.14.0 Jul 27, 2025
5 checks passed
@marcuscastelo marcuscastelo deleted the marcuscastelo/issue1020 branch July 27, 2025 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Report a problem or malfunction complexity-low Low implementation complexity complexity-medium Medium implementation complexity ui UI/UX related issue or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: day change modal does not refetch data after accepting day change

2 participants