Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jiayu fix bug manual add lost volunteer time #2319

Merged
7 changes: 4 additions & 3 deletions src/actions/timeEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ export const deleteTimeEntry = timeEntry => {
const url = ENDPOINTS.TIME_ENTRY_CHANGE(timeEntry._id);
return async dispatch => {
try {
await axios.delete(url);
const res = await axios.delete(url);
if (timeEntry.entryType === 'default') {
dispatch(updateTimeEntries(timeEntry));
}
} catch (error) {
return error;
return res.status;
} catch (e) {
return e.response.status;
}
};
};
Expand Down
12 changes: 4 additions & 8 deletions src/components/Reports/LostTime/AddLostTime.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ const AddLostTime = props => {
const { isTangible, personId } = timeEntry;
const volunteerTime = parseFloat(hours) + parseFloat(minutes) / 60;

if (isTangible !== 'true') {
if (!isTangible) {
userProfile.totalIntangibleHrs += volunteerTime;
} else {
hoursByCategory['unassigned'] += volunteerTime;
Expand All @@ -254,18 +254,14 @@ const AddLostTime = props => {
const timeEntry = {
personId: inputs.personId,
dateOfWork: inputs.dateOfWork,
hours: parseInt(inputs.hours),
minutes: parseInt(inputs.minutes),
projectId: inputs.projectId,
teamId: inputs.teamId,
isTangible: inputs.isTangible.toString(),
isTangible: inputs.isTangible,
entryType: entryType,
};

timeEntry.timeSpent = `${inputs.hours}:${inputs.minutes}:00`;

if(inputs.personId) {
updateHours(props.userProfile, timeEntry, inputs.hours, inputs.minutes);
}

setSubmitting(true);
let timeEntryStatus;
timeEntryStatus = await dispatch(postTimeEntry(timeEntry));
Expand Down
22 changes: 7 additions & 15 deletions src/components/Reports/LostTime/EditHistoryModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ const EditHistoryModal = props => {
const currEntryTime = parseFloat(hours) + parseFloat(minutes) / 60;
const timeDifference = currEntryTime - oldEntryTime;

if (initialForm.isTangible == 'true' && isTangible == 'true') {
if (initialForm.isTangible && isTangible) {
hoursByCategory['unassigned'] += timeDifference;
} else if (initialForm.isTangible == 'false' && isTangible == 'false') {
} else if (!initialForm.isTangible && !isTangible) {
userProfile.totalIntangibleHrs += timeDifference;
} else if (initialForm.isTangible == 'true' && isTangible == 'false') {
} else if (initialForm.isTangible && !isTangible) {
hoursByCategory['unassigned'] -= oldEntryTime;
userProfile.totalIntangibleHrs += currEntryTime;
} else {
Expand All @@ -218,8 +218,8 @@ const EditHistoryModal = props => {
const { isTangible, personId } = timeEntry;

const entryTime = parseFloat(initialForm.hours) + parseFloat(initialForm.minutes) / 60;

if (isTangible == 'true') {
if (isTangible) {
hoursByCategory['unassigned'] -= entryTime;
} else {
userProfile.totalIntangibleHrs -= entryTime;
Expand Down Expand Up @@ -263,16 +263,12 @@ const EditHistoryModal = props => {
projectId: inputs.projectId,
teamId: inputs.teamId,
dateOfWork: inputs.dateOfWork,
isTangible: inputs.isTangible.toString(),
isTangible: inputs.isTangible,
entryType: props.entryType,
hours: parseInt(inputs.hours),
minutes: parseInt(inputs.minutes),
};

if(inputs.personId) {
updateHours(props.userProfile, timeEntry, inputs.hours, inputs.minutes);
}

setSubmitting(true);
let timeEntryStatus;
timeEntryStatus = await dispatch(editTimeEntry(props._id, timeEntry, initialForm.dateOfWork));
Expand Down Expand Up @@ -302,16 +298,12 @@ const EditHistoryModal = props => {
projectId: inputs.projectId,
teamId: inputs.teamId,
dateOfWork: inputs.dateOfWork,
isTangible: inputs.isTangible.toString(),
isTangible: inputs.isTangible,
entryType: props.entryType,
hours: parseInt(inputs.hours),
minutes: parseInt(inputs.minutes),
};

if(inputs.personId) {
deleteHours(props.userProfile, timeEntry);
}

const timeEntryStatus = await dispatch(deleteTimeEntry(timeEntry));
if (timeEntryStatus !== 200) {
toggleDelete();
Expand Down
Loading