Skip to content

Commit 6757429

Browse files
Merge pull request #4578 from OneCommunityGlobal/Diya_Fix_FinalDay
Diya fix(finalDay): Final Day Changes
2 parents 9fdef11 + ee69926 commit 6757429

9 files changed

Lines changed: 60 additions & 33 deletions

File tree

src/actions/userManagement.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,7 @@ export const updateUserFinalDayStatusIsSet = (user, status, finalDayDate, isSet)
263263
// Prepare patch data
264264
const patchData = {
265265
status,
266-
endDate: finalDayDate
267-
? moment.utc(finalDayDate).format('YYYY-MM-DD')
268-
: undefined,
266+
endDate: finalDayDate ? new Date(finalDayDate) : undefined,
269267
isSet,
270268
};
271269

@@ -286,6 +284,29 @@ export const updateUserFinalDayStatusIsSet = (user, status, finalDayDate, isSet)
286284
};
287285
};
288286

287+
export const updateUserFinalDay = (user, finalDayDate, isSet) => {
288+
return async dispatch => {
289+
try {
290+
const patchData = {
291+
endDate: finalDayDate ? new Date(finalDayDate) : undefined,
292+
isSet,
293+
};
294+
const response = await axios.patch(ENDPOINTS.UPDATE_USER_FINAL_DAY(user._id), patchData);
295+
296+
const updatedUserProfile = {
297+
...user,
298+
...response.data,
299+
};
300+
301+
dispatch(userProfileUpdateAction(updatedUserProfile));
302+
} catch (error) {
303+
toast.error('Error updating user profile:', error);
304+
throw new Error('Failed to update user profile.');
305+
}
306+
};
307+
};
308+
309+
289310
/**
290311
* fetching all user profiles basic info
291312
*/

src/components/LeaderBoard/Leaderboard.jsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ function useDeepEffect(effectFunc, deps) {
5959
}
6060

6161
function displayDaysLeft(lastDay) {
62-
if (lastDay) {
63-
const today = new Date();
64-
const endDate = new Date(lastDay);
65-
const differenceInTime = endDate.getTime() - today.getTime();
66-
const differenceInDays = Math.ceil(differenceInTime / (1000 * 3600 * 24));
67-
return -differenceInDays;
68-
}
69-
return null; // or any other appropriate default value
62+
if (!lastDay) return null;
63+
const ORG_TZ = 'America/Los_Angeles';
64+
const today = moment()
65+
.tz(ORG_TZ)
66+
.startOf('day');
67+
const endDate = moment(lastDay)
68+
.tz(ORG_TZ)
69+
.startOf('day');
70+
const differenceInDays = endDate.diff(today, 'days');
71+
return -differenceInDays;
7072
}
7173

7274
function LeaderBoard({

src/components/UserManagement/SetUpFinalDayButton.jsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState } from 'react';
22
import { useDispatch } from 'react-redux';
33
import { toast } from 'react-toastify';
4-
import { updateUserFinalDayStatusIsSet } from '../../actions/userManagement';
4+
import { updateUserFinalDay } from '../../actions/userManagement';
55
import { boxStyle } from '../../styles';
66
import SetUpFinalDayPopUp from './SetUpFinalDayPopUp';
77
import { SET_FINAL_DAY, CANCEL } from '../../languages/en/ui';
@@ -17,13 +17,14 @@ function SetUpFinalDayButton(props) {
1717
if (isSet) {
1818
// Delete the final day
1919
try {
20-
await updateUserFinalDayStatusIsSet(
20+
await updateUserFinalDay(
2121
userProfile,
22-
userProfile.isActive ? 'Active' : 'Inactive',
2322
undefined,
24-
FinalDay.NotSetFinalDay,
23+
FinalDay.RemoveFinalDay,
2524
)(dispatch);
2625

26+
if (props.loadUserProfile) await props.loadUserProfile(userProfile._id);
27+
2728
setIsSet(false);
2829
// eslint-disable-next-line no-unused-expressions
2930
onFinalDaySave && onFinalDaySave({ ...userProfile, endDate: undefined });
@@ -41,12 +42,13 @@ function SetUpFinalDayButton(props) {
4142

4243
const handleSaveFinalDay = async (finalDayDate) => {
4344
try {
44-
await updateUserFinalDayStatusIsSet(
45+
await updateUserFinalDay(
4546
userProfile,
46-
'Active',
4747
finalDayDate,
4848
FinalDay.FinalDay,
4949
)(dispatch);
50+
51+
if (props.loadUserProfile) await props.loadUserProfile(userProfile._id);
5052

5153
setIsSet(true);
5254
setFinalDayDateOpen(false);

src/components/UserManagement/UserManagement.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,8 @@ class UserManagement extends React.PureComponent {
487487
}
488488
return;
489489
}
490-
if (status === FinalDay.NotSetFinalDay) {
491-
this.props.updateUserFinalDayStatusIsSet(user, 'Active', undefined, FinalDay.NotSetFinalDay);
490+
if (status === FinalDay.RemoveFinalDay) {
491+
this.props.updateUserFinalDayStatusIsSet(user, 'Active', undefined, FinalDay.RemoveFinalDay);
492492
} else {
493493
this.setState({
494494
finalDayDateOpen: true,

src/components/UserManagement/UserTableData.jsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { UserStatus } from '../../utils/enums';
1414
import ActiveCell from './ActiveCell';
1515
import TimeDifference from './TimeDifference';
1616
import { boxStyle } from '../../styles';
17-
import { formatDateLocal, formatDateUtcYYYYMMDD } from '../../utils/formatDate';
17+
import { formatDate, formatDateLocal, formatDateUtcYYYYMMDD } from '../../utils/formatDate';
1818
import hasPermission, {cantUpdateDevAdminDetails } from '../../utils/permissions';
1919
import SetUpFinalDayButton from './SetUpFinalDayButton';
2020

@@ -41,8 +41,8 @@ const UserTableDataComponent = (props) => {
4141
jobTitle: props.user.jobTitle,
4242
email: props.user.email,
4343
weeklycommittedHours: props.user.weeklycommittedHours,
44-
startDate: formatDateUtcYYYYMMDD(props.user.startDate) || '',
45-
endDate: formatDateUtcYYYYMMDD(props.user.endDate) || '',
44+
startDate: formatDate(props.user.startDate) || '',
45+
endDate: formatDate(props.user.endDate) || '',
4646
});
4747
const dispatch = useDispatch();
4848
const history = useHistory();
@@ -97,8 +97,8 @@ const UserTableDataComponent = (props) => {
9797
jobTitle: props.user.jobTitle,
9898
email: props.user.email,
9999
weeklycommittedHours: props.user.weeklycommittedHours,
100-
startDate: formatDateUtcYYYYMMDD(props.user.startDate),
101-
endDate: formatDateUtcYYYYMMDD(props.user.endDate),
100+
startDate: formatDate(props.user.startDate),
101+
endDate: formatDate(props.user.endDate),
102102
});
103103
}, [props.user]);
104104

@@ -543,13 +543,13 @@ const UserTableDataComponent = (props) => {
543543
<td className="email_cell">
544544
{editUser?.endDate ? (
545545
<div>
546-
{props.user.endDate ? formatDateLocal(props.user.endDate) : 'N/A'}
546+
{props.user.endDate ? formatDate(props.user.endDate) : 'N/A'}
547547
<FontAwesomeIcon
548548
className="copy_icon"
549549
icon={faCopy}
550550
onClick={() => {
551551
navigator.clipboard.writeText(
552-
props.user.endDate ? formatDateLocal(formData.endDate) : 'N/A',
552+
props.user.endDate ? formatDate(formData.endDate) : 'N/A',
553553
);
554554
toast.success('End Date Copied!');
555555
}}

src/components/UserManagement/__tests__/UserManagement.test.jsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
updateUserFinalDayStatusIsSet,
1010
deleteUser,
1111
} from '../../../actions/userManagement';
12+
import { FinalDay } from '../../../utils/enums';
1213

1314
// Mock the actions
1415
vi.mock('../../../actions/userManagement', () => ({
@@ -65,14 +66,14 @@ vi.mock('../UserTableData', () => ({
6566
<button
6667
type="button"
6768
data-testid={`final-day-button-${index}`}
68-
onClick={() => onFinalDayClick(user, MOCK_FINAL_DAY)}
69+
onClick={() => onFinalDayClick(user, FinalDay.SetFinalDay)}
6970
>
7071
Set Final Day
7172
</button>
7273
<button
7374
type="button"
7475
data-testid={`not-final-day-button-${index}`}
75-
onClick={() => onFinalDayClick(user, MOCK_NOT_FINAL_DAY)}
76+
onClick={() => onFinalDayClick(user, FinalDay.RemoveFinalDay)}
7677
>
7778
Remove Final Day
7879
</button>
@@ -328,15 +329,15 @@ describe('UserManagement Component', () => {
328329
render(<UnconnectedUserManagement {...props} />);
329330

330331
// Find and click the not final day button for the first user
331-
const notFinalDayButton = screen.getByTestId('not-final-day-button-0');
332-
fireEvent.click(notFinalDayButton);
332+
const removeFinalDayButton = screen.getByTestId('not-final-day-button-0');
333+
fireEvent.click(removeFinalDayButton);
333334

334335
// Verify the API call
335336
expect(updateUserFinalDayStatusIsSet).toHaveBeenCalledWith(
336337
expect.objectContaining({ _id: '1' }),
337338
'Active',
338339
undefined,
339-
MOCK_NOT_FINAL_DAY,
340+
FinalDay.RemoveFinalDay,
340341
);
341342
});
342343
});

src/components/UserProfile/BasicInformationTab/BasicInformationTab.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ const BasicInformationTab = props => {
499499
rolesAllowedToEditStatusFinalDay.includes(role) || dispatch(hasPermission('pauseUserActivity'));
500500

501501
const canEditEndDate =
502-
rolesAllowedToEditStatusFinalDay.includes(role) || dispatch(hasPermission('setUserFinalDay'));
502+
rolesAllowedToEditStatusFinalDay.includes(role) || dispatch(hasPermission('setFinalDay'));
503503

504504

505505
let topMargin = '6px';

src/utils/URL.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const ENDPOINTS = {
66
USER_PROFILE: userId => `${APIEndpoint}/userprofile/${userId}`,
77
USER_PROFILE_PROPERTY: userId => `${APIEndpoint}/userprofile/${userId}/property`,
88
USER_PROFILES: `${APIEndpoint}/userprofile/`,
9+
UPDATE_USER_FINAL_DAY: userId => `${APIEndpoint}/userprofile/${userId}/updateFinalDay`,
910
UPDATE_REHIREABLE_STATUS: userId => `${APIEndpoint}/userprofile/${userId}/rehireable`,
1011
TOGGLE_VISIBILITY: userId => `${APIEndpoint}/userprofile/${userId}/toggleInvisibility`,
1112
USER_PROFILE_UPDATE: `${APIEndpoint}/userprofile/update`,

src/utils/enums.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export const UserStatus = {
77
};
88
export const FinalDay = {
99
FinalDay: 'FinalDay',
10-
NotSetFinalDay: 'NotSetFinalDay',
10+
RemoveFinalDay: 'RemoveFinalDay',
1111
};
1212
/**
1313
* Enum representing the different roles of a user

0 commit comments

Comments
 (0)