Skip to content

Commit f4e6452

Browse files
Merge pull request #3155 from OneCommunityGlobal/Koushica_Time_Entry_Task_Hours_Update
Koushica - Fix delay in the hour count update for the individual task
2 parents 60d06fe + 0b5f54c commit f4e6452

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

src/components/TeamMemberTasks/actions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const fetchTeamMembersTaskSuccess = createAction('FETCH_TEAM_MEMBERS_TASK
55
export const fetchTeamMembersTimeEntriesSuccess = createAction('FETCH_TEAM_MEMBERS_TIMEENTRIES_SUCCESS');
66
export const updateTeamMembersTimeEntrySuccess = createAction('UPDATE_TEAM_MEMBERS_TIMEENTRY_SUCCESS');
77
export const fetchTeamMembersDataError = createAction('FETCH_TEAM_MEMBERS_DATA_ERROR');
8+
export const updateIndividualTaskTime = createAction('UPDATE_TEAM_MEMBERS_TASK_TIME');
89

910
export const createOrUpdateTaskNotificationBegin = createAction(
1011
'CREATE_OR_UPDATE_TASK_NOTIFICATION_BEGIN',

src/components/TeamMemberTasks/reducer.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ export const teamMemberTasksReducer = (state = initialState, action) => {
2626
return timeentry
2727
})
2828
return { ...state, usersWithTimeEntries: updatedTimeEntries }
29+
case 'UPDATE_TEAM_MEMBERS_TASK_TIME':
30+
const {usersWithTasks} = state;
31+
const {newTime, taskId, personId} = action.payload;
32+
const updatedusersWithTasks = usersWithTasks.map((user,index)=>{
33+
if(user.personId === personId){
34+
let newTotalTime = Number(newTime.hours) + (Number(newTime.minutes)/60)
35+
user.totaltangibletime_hrs += newTotalTime;
36+
user.totaltime_hrs += newTotalTime;
37+
if(taskId) {
38+
let {tasks} = user;
39+
tasks = tasks.map((task)=>{
40+
if(task._id === taskId){
41+
task.hoursLogged += newTotalTime;
42+
}
43+
return task
44+
})
45+
}
46+
}
47+
return user
48+
})
49+
return {...state, usersWithTasks : updatedusersWithTasks}
2950
case 'DELETE_TASK_NOTIFICATION_SUCCESS':
3051
return {
3152
...state,

src/components/Timelog/TimeEntryForm/TimeEntryForm.jsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ import { getUserProfile } from 'actions/userProfile';
2727
import axios from 'axios';
2828
import hasPermission from 'utils/permissions';
2929
import { boxStyle, boxStyleDark } from 'styles';
30+
import { useDispatch } from 'react-redux';
3031
import { postTimeEntry, editTimeEntry, getTimeEntriesForWeek } from '../../../actions/timeEntries';
3132
import AboutModal from './AboutModal';
3233
import TangibleInfoModal from './TangibleInfoModal';
3334
import ReminderModal from './ReminderModal';
3435
import TimeLogConfirmationModal from './TimeLogConfirmationModal';
3536
import { ENDPOINTS } from '../../../utils/URL';
3637
import '../../Header/DarkMode.css';
38+
import { updateIndividualTaskTime } from '../../TeamMemberTasks/actions';
3739

3840
// Images are not allowed in timelog
3941
const customImageUploadHandler = () =>
@@ -67,6 +69,7 @@ function TimeEntryForm(props) {
6769
const { from, sendStop, edit, data, toggle, isOpen, tab, darkMode } = props;
6870
// props from store
6971
const { authUser } = props;
72+
const dispatch = useDispatch();
7073

7174
const viewingUser = JSON.parse(sessionStorage.getItem('viewingUser') ?? '{}');
7275

@@ -311,7 +314,7 @@ function TimeEntryForm(props) {
311314
};
312315

313316
const submitTimeEntry = async () => {
314-
const { hours: formHours, minutes: formMinutes } = formValues;
317+
const { hours: formHours, minutes: formMinutes, personId, taskId } = formValues;
315318
const timeEntry = { ...formValues };
316319
const isTimeModified = edit && (initialHours !== formHours || initialMinutes !== formMinutes);
317320

@@ -337,6 +340,13 @@ function TimeEntryForm(props) {
337340
case 'Timer':
338341
sendStop();
339342
clearForm();
343+
dispatch(
344+
updateIndividualTaskTime({
345+
newTime: { hours: formHours, minutes: formMinutes },
346+
taskId,
347+
personId,
348+
}),
349+
);
340350
break;
341351
case 'TimeLog': {
342352
const date = moment(formValues.dateOfWork);

0 commit comments

Comments
 (0)