Repository navigation
Mahika - fix: stop the timer before saving the time log [FE] - #5788
mahikakakkad wants to merge 4 commits into
Conversation
…e local countdown
… close the log form on success
The axios get mock repeated an identical ~23-line if/else block already present in TimeEntryForm.test.jsx and TimeEntryForm_edit.test.jsx, pushing SonarQube's new-code duplication to 6.0% (gate requires <=3%). Expressing the same URL->response mapping as a lookup table instead keeps the behavior identical while no longer matching those files' duplicate block.
234cb18 to
b998c3f
Compare
|
There was a problem hiding this comment.
Reviewed at b998c3f by reading the code against HGNRest development plus OneCommunityGlobal/HGNRest#2474, and by running the Timer tests. I couldn't test it in the browser tonight because apidev returns 500 on every endpoint, so everything below comes from the code and a unit test.
What works:
- Stopping before saving fixes the main report: the timer can no longer keep running while a slow save is in flight.
- All 9 tests in
TimeEntryForm.timerStop.test.jsxpass locally.
Requesting changes:
-
If the save fails, the retry can't log the time, so the session's time is lost. The flow is GET_TIMER, then STOP_TIMER, then save. If the save fails, the form stays open for a retry (as the comment says). But on retry,
submitTimeEntryruns GET_TIMER again. The server stopped the timer on the first attempt, so it now answersstarted: false. The form then shows "This timer session was already stopped or logged elsewhere", closes, and saves nothing. The timer is already stopped with the leftover time, so the worked time is gone.
I reproduced this with one extra test inTimeEntryForm.timerStop.test.jsx, using a fake server that remembers its state:sendStopsetsstarted = false, the firstpostTimeEntryrejects, the second resolves. After two Submit clicks,postTimeEntryran only once and the form closed. The existing "if saving fails after a confirmed stop" test passes because itssendGetTimerAndConfirmmock always returnsstarted: true, so it never hits the second GET_TIMER.
This only happens once OneCommunityGlobal/HGNRest#2474 is merged, and the merge order puts it first. Without it, GET_TIMER times out, returns null, and the retry goes through after a 5-second wait. One fix: once this tab's own stop is confirmed, store the confirmed elapsed time in a ref and skip the GET_TIMER and stop steps on a retry, so the retry only re-sends the save. -
This PR and #5778 fix the same bug in conflicting ways. #5778 (Ansh) pauses on submit and sends CLEAR_TIMER after the save. This PR stops first and keeps STOP_TIMER, so the timer keeps the leftover time instead of resetting.
git merge-treeshows the two branches conflict inTimeEntryForm.jsxandTimer.jsx. Only one can merge, so please agree on one with Ansh and Jae.
Not blocking:
- The saved hours and minutes now come from the server's elapsed time, which includes the time spent filling in the form (as your note says). The form can show a smaller number than what gets saved, and the user doesn't see the final value before it's saved.
- The stop-confirm timeout drops from 10 s to 5 s. That's fine, but on a slow connection more submits will now fail with "time was NOT logged".
- (From the code, and seen live on #5778.)
postTimeEntrycatches HTTP errors and returns the status code instead of throwing, so if the save returns a 500, this PR'scatchnever runs. The timer is already stopped, and the form closes with "Time logged successfully!". I saw exactly this on #5778 with a mocked 500. Checking the returned status before treating the save as done would fix it.



Description
Fixes Jae's report: submitting a time log from the Timer took 10-15 seconds, and the timer kept running and didn't clear. The timer was only stopped AFTER the time entry finished saving, so during a slow save it kept ticking and could be logged twice.
Now the timer stops first, then saves. It also logs the server's exact elapsed time, and a tab whose session was already logged in another tab won't log it again.
Related PRS (if any):
Merge order: backend PR first, then Mahika - 🔥 : timer auto-reconnect and stop false chimes [FE] #5751, then this PR.
Main changes explained:
How to test:
Screenshots or videos of changes:
Note:
The logged time is the server's time at submit, so it includes the time spent filling in the form.