Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/components/Timelog/TimeEntryForm/TimeEntryForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ function TimeEntryForm(props) {
// props from parent
const {
from,
sendStop,
sendPause,
sendClear,
edit,
data,
toggle,
Expand Down Expand Up @@ -370,6 +371,9 @@ function TimeEntryForm(props) {
setSubmitting(false);
return;
}
if (from === 'Timer') {
sendPause();
}

const handleFormReset = () => {
setFormValues(initialFormValues);
Expand All @@ -386,12 +390,7 @@ function TimeEntryForm(props) {
const handlePostSubmitActions = async () => {
switch (from) {
case 'Timer': {
const timerStopped = await sendStop();
if (!timerStopped) {
toast.warning(
'Time was logged, but the timer stop could not be confirmed. Refresh the timer before continuing.',
);
}
sendClear();
clearForm();
// Enhanced callback with additional data
if (onTimeSubmitted) {
Expand Down Expand Up @@ -933,7 +932,8 @@ function TimeEntryForm(props) {

TimeEntryForm.propTypes = {
from: PropTypes.string,
sendStop: PropTypes.func,
sendPause: PropTypes.func,
sendClear: PropTypes.func,
edit: PropTypes.bool.isRequired,
toggle: PropTypes.func.isRequired,
isOpen: PropTypes.bool.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,33 @@ it('should change Project with user input', async () => {
expect(select).toHaveValue(toSelect.projectId);
expect(select).toHaveDisplayValue(toSelect.projectName);
});
it('pauses on timer submit and clears after successful logging', async () => {
const sendPause = vi.fn();
const sendClear = vi.fn();

renderWithProvider(
<TimeEntryForm
from="Timer"
data={data}
edit={false}
toggle={toggle}
isOpen
sendPause={sendPause}
sendClear={sendClear}
timerConnected
/>,
{ store },
);

await userEvent.click(screen.getByRole('button', { name: /submit/i }));

await waitFor(() => {
expect(sendPause).toHaveBeenCalledTimes(1);
expect(sendClear).toHaveBeenCalledTimes(1);
});

expect(sendPause.mock.invocationCallOrder[0]).toBeLessThan(
sendClear.mock.invocationCallOrder[0],
);
});
});
4 changes: 2 additions & 2 deletions src/components/Timer/Timer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ function Timer({ authUser, darkMode, isPopout }) {
sendStart,
sendPause,
sendClear,
sendStop,
sendAckForced,
sendGetTimer,
sendStartChime,
Expand Down Expand Up @@ -816,7 +815,8 @@ function Timer({ authUser, darkMode, isPopout }) {
toggle={toggleLogTimeModal}
isOpen={logTimeEntryModal}
data={logTimer}
sendStop={sendStop}
sendPause={sendPause}
sendClear={sendClear}
timerConnected={customReadyState === ReadyState.OPEN}
onTimeSubmitted={handleTimeSubmitted}
sessionId={sessionId}
Expand Down
Loading