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
2 changes: 1 addition & 1 deletion src/actions/__tests__/userManagement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('User Management Actions', () => {
{ type: 'RECEIVE_USER_PROFILE_BASIC_INFO', payload: mockBasicInfo }
];

await store.dispatch(actions.getUserProfileBasicInfo({source: mockSource}));
await store.dispatch(actions.getUserProfileBasicInfo({ source: mockSource }));
expect(store.getActions()).toEqual(expectedActions);
expect(axios.get).toHaveBeenCalledWith(ENDPOINTS.USER_PROFILE_BASIC_INFO(mockSource));
});
Expand Down
17 changes: 12 additions & 5 deletions src/actions/userManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
DISABLE_USER_PROFILE_EDIT,
CHANGE_USER_PROFILE_PAGE,
START_USER_INFO_UPDATE,
CLEAR_USER_INFO_UPDATE
} from '../constants/userManagement';
import { ENDPOINTS } from '~/utils/URL';
import { UserStatus, UserStatusOperations, InactiveReason } from '~/utils/enums';
Expand Down Expand Up @@ -109,7 +110,9 @@
export const getAllUserProfile = () => {
const userProfilesPromise = axios.get(ENDPOINTS.USER_PROFILES);
return async dispatch => {

await dispatch(userProfilesFetchStartAction());

if (!userProfilesPromise || typeof userProfilesPromise.then !== 'function') {
return Promise.resolve([]);
}
Expand Down Expand Up @@ -139,18 +142,18 @@

//2) if no lastActivityAt, use createdDate (if present)
// format createdDate to real datetime in COMPANY_TZ
if(!user?.lastActivityAt && user?.createdDate) {
if (!user?.lastActivityAt && user?.createdDate) {
const created = moment.tz(user.createdDate, 'YYYY-MM-DD', COMPANY_TZ).startOf('day');
return created.toISOString();
}

//3) if no createdDate -> endDate will be set as passed
if(user?.endDate) {
if (user?.endDate) {
return moment(user.endDate).toISOString();
}

// optional: if lastActivityAt is present, use that
if(user?.lastActivityAt) {
if (user?.lastActivityAt) {
return moment(user.lastActivityAt).toISOString();
}

Expand All @@ -159,7 +162,7 @@
}

export const buildUpdatedUserLifecycleDetails = (user, payload) => {
const {action, endDate, reactivationDate} = payload;
const { action, endDate, reactivationDate } = payload;
switch (action) {
case UserStatusOperations.ACTIVATE:
return {
Expand Down Expand Up @@ -203,8 +206,8 @@
};

const buildBackendPayload = (userDetails, action) => {
console.log('Building backend payload with:', { userDetails, action });

Check warning on line 209 in src/actions/userManagement.js

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
switch (action){
switch (action) {
case UserStatusOperations.ACTIVATE:
return {
action: action,
Expand Down Expand Up @@ -406,4 +409,8 @@

export const updateUserInfomation = value => dispatch => {
dispatch({ type: START_USER_INFO_UPDATE, payload: value });
};

export const clearUserInformation = () => dispatch => {
dispatch({ type: CLEAR_USER_INFO_UPDATE });
};
15 changes: 13 additions & 2 deletions src/components/UserManagement/UserTableHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { faEdit, faSave } from '@fortawesome/free-solid-svg-icons';
import axios from 'axios';
import { toast } from 'react-toastify';
import { getAllUserProfile } from '../../actions/userManagement';
import { getAllUserProfile , clearUserInformation} from '../../actions/userManagement';
import { ENDPOINTS } from '~/utils/URL';
import userTableDataPermissions from '../../utils/userTableDataPermissions';
import PropTypes from 'prop-types';
Expand All @@ -29,13 +29,24 @@
*/
const UserTableHeaderComponent = ({ authRole, roleSearchText, darkMode, editUser, enableEditUserInfo, disableEditUserInfo, isMobile, mobileFontSize }) => {
const dispatch = useDispatch();
const [editFlag, setEditFlag] = useState(editUser);
const defaultEditFlags = {
first: 1,
last: 1,
role: 1,
jobTitle: 1,
email: 1,
weeklycommittedHours: 1,
startDate: 1,
endDate: 1,
};
const [editFlag, setEditFlag] = useState(editUser ? editUser : defaultEditFlags);

Check warning on line 42 in src/components/UserManagement/UserTableHeader.jsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Unnecessary use of conditional expression for default assignment.

See more on https://sonarcloud.io/project/issues?id=OneCommunityGlobal_HighestGoodNetworkApp&issues=AZ2N7__7rpw_FOb5QkJQ&open=AZ2N7__7rpw_FOb5QkJQ&pullRequest=5147
const updatedUserData = useSelector(state => state.userProfileEdit.newUserData);
const saveUserInformation = async updatedData => {
try {
const response = await axios.patch(ENDPOINTS.USER_PROFILE_UPDATE, updatedData);
if (response.status === 200) {
const toastId = toast.success(' Saving Data...', { autoClose: false });
await dispatch(clearUserInformation());
await dispatch(getAllUserProfile());
toast.update(toastId, {
render: 'Data Updated successfully !',
Expand Down
1 change: 1 addition & 0 deletions src/constants/userManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export const CHANGE_USER_PROFILE_PAGE = 'CHANGE_USER_PROFILE_PAGE';
export const START_USER_INFO_UPDATE = 'START_USER_INFO_UPDATE';
export const FINISH_USER_INFO_UPDATE = 'FINISH_USER_INFO_UPDATE';
export const ERROR_USER_INFO_UPDATE = 'ERROR_USER_INFO_UPDATE';
export const CLEAR_USER_INFO_UPDATE = 'CLEAR_USER_INFO_UPDATE';
2 changes: 2 additions & 0 deletions src/reducers/allUserProfilesReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ export const enableUserInfoEditReducer = (userProfile = userProfilesInitial, act
return updateObject(userProfile, { editable: action.payload });
case 'START_USER_INFO_UPDATE':
return { ...userProfile, newUserData: userProfile.newUserData.concat(action.payload) };
case 'CLEAR_USER_INFO_UPDATE':
return { ...userProfile, newUserData: [] };
default:
return userProfile;
}
Expand Down
Loading