Skip to content

Commit fbb1124

Browse files
committed
Merge branch 'development' of https://github.com/OneCommunityGlobal/HighestGoodNetworkApp into Ramakrishna_Fix_dashboard_view
2 parents ee13050 + 8ae9902 commit fbb1124

31 files changed

Lines changed: 5140 additions & 16908 deletions

File tree

package-lock.json

Lines changed: 711 additions & 14234 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/actions/allTeamsAction.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,14 @@ export const updateTeam = (teamName, teamId, isActive, teamCode) => {
183183
return async dispatch => {
184184
try {
185185
const updateTeamResponse = await axios.put(url, requestData);
186-
dispatch(updateTeamAction(teamId, isActive, teamName, teamCode));
186+
if (updateTeamResponse.status === 200) {
187+
// Use the actual response data from the backend
188+
const updatedTeam = updateTeamResponse.data;
189+
dispatch(updateTeamAction(teamId, updatedTeam.isActive, updatedTeam.teamName, updatedTeam.teamCode));
190+
}
187191
return updateTeamResponse;
188192
} catch (error) {
189-
return error.response.data.error;
193+
return error.response?.data?.error || error.message;
190194
}
191195
};
192196
};

src/actions/projectMembers.js

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,44 @@ export const getAllUserProfiles = () => {
3737

3838
/**
3939
* Call API to find a user profile
40+
* FIX: Ensure API response is always an array and handle backend variations
4041
*/
41-
export const findUserProfiles = keyword => {
42-
// Creates an array containing the first and last name and filters out whitespace
43-
const fullNameRegex = keyword.replace(/[-\\/\\^$*+?.()|[\]{}]/g, '\\$&'); // Escape special characters
44-
42+
export const findUserProfiles = (keyword, activeOnly = true) => {
4543
return async (dispatch, getState) => {
4644
try {
47-
// Dispatch loading action immediately
4845
dispatch(findUsersStart());
49-
const response = await axios.get(ENDPOINTS.USER_PROFILE_BY_FULL_NAME(fullNameRegex));
50-
51-
// await dispatch(findUsersStart());
5246

53-
if (keyword !== '') {
54-
let users = response.data;
55-
const { members } = getState().projectMembers;
56-
// set for insatnt lookups
57-
const memberIds = new Set(members.map(member => member._id));
58-
users = users.map(user => ({
59-
...user,
60-
assigned: memberIds.has(user._id),
61-
}));
62-
dispatch(foundUsers(users));
63-
} else {
47+
const q = keyword.trim();
48+
if (!q) {
6449
dispatch(foundUsers([]));
50+
return;
6551
}
52+
53+
const url = ENDPOINTS.USER_PROFILE_BY_FULL_NAME(encodeURIComponent(q), activeOnly);
54+
const { data } = await axios.get(url);
55+
56+
// DEBUG: Log the API response for troubleshooting
57+
console.log('findUserProfiles API response:', data);
58+
59+
// FIX: Support both array and object with 'users' property
60+
let userList = [];
61+
if (Array.isArray(data)) {
62+
userList = data;
63+
} else if (Array.isArray(data?.users)) {
64+
userList = data.users;
65+
} else if (Array.isArray(data?.result)) {
66+
userList = data.result;
67+
}
68+
69+
const { members } = getState().projectMembers;
70+
const memberIds = new Set(members.map(m => m._id));
71+
72+
const users = userList.map(u => ({
73+
...u,
74+
assigned: memberIds.has(u._id),
75+
}));
76+
77+
dispatch(foundUsers(users));
6678
} catch (error) {
6779
dispatch(foundUsers([]));
6880
dispatch(findUsersError(error));
@@ -162,26 +174,33 @@ export const assignProject = (projectId, userId, operation, firstName, lastName)
162174
/**
163175
* Call API to find project members
164176
*/
165-
export const findProjectMembers = (projectId, query) => {
166-
// Escape special characters in the query
167-
const queryRegex = query.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
168-
177+
export const findProjectMembers = (_projectId, query) => {
169178
return async (dispatch, getState) => {
179+
dispatch(findUsersStart());
180+
181+
const q = (query || '').trim();
182+
if (!q) {
183+
dispatch(foundUsers([]));
184+
return;
185+
}
186+
170187
try {
171-
// Dispatch loading action immediately
172-
dispatch(findProjectMembersStart());
173-
const response = await axios.get(ENDPOINTS.PROJECT_MEMBER_SEARCH(projectId, queryRegex));
188+
// backend expects ?search=... not /search/...
189+
const { data } = await axios.get(
190+
ENDPOINTS.USER_PROFILE_BY_FULL_NAME(encodeURIComponent(q))
191+
);
174192

175-
if (query !== '') {
176-
const members = response.data;
193+
const list = Array.isArray(data) ? data
194+
: Array.isArray(data?.users) ? data.users
195+
: [];
177196

178-
dispatch(foundProjectMembers(members));
179-
} else {
180-
dispatch(foundProjectMembers([]));
181-
}
182-
} catch (error) {
183-
dispatch(foundProjectMembers([]));
184-
dispatch(findProjectMembersError(error));
197+
const assigned = new Set(getState().projectMembers.members.map(m => m._id));
198+
const users = list.map(u => ({ ...u, assigned: assigned.has(u._id) }));
199+
200+
dispatch(foundUsers(users));
201+
} catch (err) {
202+
dispatch(foundUsers([]));
203+
dispatch(findUsersError(err));
185204
}
186205
};
187206
};

0 commit comments

Comments
 (0)