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: 9 additions & 7 deletions src/actions/timeEntries.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ export const getTimeStartDateEntriesByPeriod = (userId, fromDate, toDate) => {
}
};
};
export const postTimeEntry = timeEntry => {
export const postTimeEntry = (timeEntry, { displayedUserId } = {}) => {
const url = ENDPOINTS.TIME_ENTRY();
return async dispatch => {
try {
const res = await axios.post(url, timeEntry);
if (timeEntry.entryType === 'default' || timeEntry.entryType === 'person') {
dispatch(updateTimeEntries(timeEntry));
dispatch(updateTimeEntries(timeEntry, undefined, displayedUserId));
}
return res.status;
} catch (e) {
Expand All @@ -212,13 +212,13 @@ export const postTimeEntry = timeEntry => {
};
};

export const editTimeEntry = (timeEntryId, timeEntry, oldDateOfWork) => {
export const editTimeEntry = (timeEntryId, timeEntry, oldDateOfWork, { displayedUserId } = {}) => {
const url = ENDPOINTS.TIME_ENTRY_CHANGE(timeEntryId);
return async dispatch => {
try {
const res = await axios.put(url, timeEntry);
if (timeEntry.entryType === 'default' || timeEntry.entryType === 'person') {
dispatch(updateTimeEntries(timeEntry, oldDateOfWork));
dispatch(updateTimeEntries(timeEntry, oldDateOfWork, displayedUserId));
}
return res.status;
} catch (e) {
Expand All @@ -227,13 +227,13 @@ export const editTimeEntry = (timeEntryId, timeEntry, oldDateOfWork) => {
};
};

export const deleteTimeEntry = timeEntry => {
export const deleteTimeEntry = (timeEntry, { displayedUserId } = {}) => {
const url = ENDPOINTS.TIME_ENTRY_CHANGE(timeEntry._id);
return async dispatch => {
try {
const res = await axios.delete(url);
if (timeEntry.entryType === 'default' || timeEntry.entryType === 'person') {
dispatch(updateTimeEntries(timeEntry));
dispatch(updateTimeEntries(timeEntry, undefined, displayedUserId));
}
return res.status;
} catch (e) {
Expand All @@ -242,10 +242,12 @@ export const deleteTimeEntry = timeEntry => {
};
};

const updateTimeEntries = (timeEntry, oldDateOfWork) => {
const updateTimeEntries = (timeEntry, oldDateOfWork, displayedUserId) => {
const startOfWeek = moment().startOf('week');

return async dispatch => {
if (displayedUserId && timeEntry.personId !== displayedUserId) return;

if (oldDateOfWork) {
const oldOffset = Math.ceil(startOfWeek.diff(oldDateOfWork, 'week', true));
dispatch(getTimeEntriesForWeek(timeEntry.personId, oldOffset));
Expand Down
3 changes: 2 additions & 1 deletion src/components/Timelog/TimeEntryForm/TimeEntryForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@
if (edit) {
await props.editTimeEntry(data._id, timeEntry, initialDateOfWork);
} else {
await props.postTimeEntry(timeEntry);
await props.postTimeEntry(timeEntry, { displayedUserId: props.displayedUserId });

Check warning on line 453 in src/components/Timelog/TimeEntryForm/TimeEntryForm.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

'displayedUserId' is missing in props validation

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ4HVO6UZS5iFPNz-f-i&open=AZ4HVO6UZS5iFPNz-f-i&pullRequest=5245
}

await handlePostSubmitActions();
Expand Down Expand Up @@ -719,7 +719,7 @@
id="dateOfWork"
value={formValues.dateOfWork}
onChange={handleInputChange}
// min={userProfile?.isFirstTimelog === true ? moment().toISOString().split('T')[0] : userProfile?.startDate.split('T')[0]}

Check warning on line 722 in src/components/Timelog/TimeEntryForm/TimeEntryForm.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this commented out code.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ4HVO6VZS5iFPNz-f-j&open=AZ4HVO6VZS5iFPNz-f-j&pullRequest=5245
disabled={!canEditTimeEntryDate}
className={
darkMode ? 'bg-darkmode-liblack text-light border-0 calendar-icon-dark' : ''
Expand Down Expand Up @@ -928,6 +928,7 @@
authUser: state.auth.user,
darkMode: state.theme.darkMode,
userProjects: state.userProjects.projects,
displayedUserId: state.userProfile?._id,
});

export default connect(mapStateToProps, {
Expand Down
Loading