Skip to content

Commit f5358c6

Browse files
Merge pull request #3916 from OneCommunityGlobal/taariq_fixing_angads_filter_branch_frontend
Taariq: Fix filterColor persistence issue on change and refresh for Individual as well as bulk Selected filterColors Frontend.
2 parents 04a1da0 + aa71a55 commit f5358c6

17 files changed

Lines changed: 11219 additions & 14290 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
"eslint-plugin-react-hooks": "^4.6.2",
185185
"eslint-plugin-testing-library": "^7.11.0",
186186
"eslint-plugin-vitest": "^0.5.4",
187-
"husky": "^7.0.4",
187+
"husky": "^9.1.7",
188188
"joi-browser": "^13.4.0",
189189
"jsdom": "^26.1.0",
190190
"lint-staged": "^16.1.5",

src/actions/weeklySummaries.js

Lines changed: 215 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import axios from 'axios';
2+
import { toast } from 'react-toastify';
23
import * as actions from '../constants/weeklySummaries';
4+
import * as reportActions from '../constants/weeklySummariesReport';
35
import { ENDPOINTS } from '~/utils/URL';
46
import { getUserProfileActionCreator } from './userProfile';
57

@@ -36,7 +38,7 @@ export const fetchWeeklySummariesError = error => ({
3638
* @param {ObjectId} userId The user id.
3739
*/
3840
export const getWeeklySummaries = userId => {
39-
const url = ENDPOINTS.USER_PROFILE(userId);
41+
const url = ENDPOINTS.USER_PROFILE_FIXED(userId);
4042
return async dispatch => {
4143
dispatch(fetchWeeklySummariesBegin());
4244
try {
@@ -112,3 +114,215 @@ export const updateWeeklySummaries = (userId, weeklySummariesData) => {
112114
}
113115
};
114116
};
117+
118+
// ========== WEEKLY SUMMARIES REPORT (from your old file) ==========
119+
120+
/**
121+
* Action to set the 'loading' flag to true for reports.
122+
*/
123+
export const fetchWeeklySummariesReportBegin = () => ({
124+
type: reportActions.FETCH_SUMMARIES_REPORT_BEGIN,
125+
});
126+
127+
/**
128+
* This action is used to set the weekly summaries reports in store.
129+
*
130+
* @param {array} weeklySummariesData An array of all active users.
131+
*/
132+
export const fetchWeeklySummariesReportSuccess = weeklySummariesData => ({
133+
type: reportActions.FETCH_SUMMARIES_REPORT_SUCCESS,
134+
payload: { weeklySummariesData },
135+
});
136+
137+
/**
138+
* Handle the error case for reports.
139+
*
140+
* @param {Object} error The error object.
141+
*/
142+
export const fetchWeeklySummariesReportError = error => ({
143+
type: reportActions.FETCH_SUMMARIES_REPORT_ERROR,
144+
payload: { error },
145+
});
146+
147+
/**
148+
* Update one summary report
149+
*
150+
* @param {Object} updatedField the updated field object, dynamic
151+
*/
152+
export const updateSummaryReport = ({ _id, updatedField }) => ({
153+
type: reportActions.UPDATE_SUMMARY_REPORT,
154+
payload: { _id, updatedField },
155+
});
156+
157+
// write server-truth user object into the store
158+
export const updateSummaryReportFromServerAction = (user) => ({
159+
type: reportActions.UPDATE_SUMMARY_REPORT,
160+
payload: { _id: user._id, updatedField: user },
161+
});
162+
/**
163+
* Gets all active users' summaries + a few other selected fields from the userProfile that
164+
* might be useful for the weekly summary report.
165+
*/
166+
export const getWeeklySummariesReport = (weekIndex = null) => {
167+
return async dispatch => {
168+
dispatch(fetchWeeklySummariesReportBegin());
169+
try {
170+
// Use the APIEndpoint from ENDPOINTS
171+
let url = ENDPOINTS.WEEKLY_SUMMARIES_REPORT();
172+
173+
const timestamp = `ts=${Date.now()}`;
174+
const separator = url.includes('?') ? '&' : '?';
175+
176+
if (weekIndex === null) {
177+
url = `${url}${separator}${timestamp}`;
178+
} else {
179+
const separator = url.includes('?') ? '&' : '?';
180+
url = `${url}${separator}week=${weekIndex}&${timestamp}`;
181+
}
182+
183+
const response = await axios.get(url, {
184+
headers: {
185+
'Cache-Control': 'no-cache',
186+
Pragma: 'no-cache',
187+
Expires: '0',
188+
},
189+
});
190+
// Adding this debug log to check if filterColors are coming back
191+
// eslint-disable-next-line no-console
192+
console.log('API Response:', response.data);
193+
// eslint-disable-next-line no-console
194+
console.log('FilterColors in response:', response.data.map(user => ({
195+
id: user._id,
196+
name: user.firstName + ' ' + user.lastName,
197+
filterColor: user.filterColor
198+
})));
199+
dispatch(fetchWeeklySummariesReportSuccess(response.data));
200+
return { status: response.status, data: response.data };
201+
} catch (error) {
202+
dispatch(fetchWeeklySummariesReportError(error));
203+
return error.response ? error.response.status : 500;
204+
}
205+
};
206+
};
207+
208+
// working
209+
// export const updateOneSummaryReport = (userId, fullUserPayload) => {
210+
// // const url = ENDPOINTS.USER_PROFILE(userId);
211+
// // return async dispatch => {
212+
// // const { data: userProfile } = await axios.get(url);
213+
// // const payload = { ...userProfile, ...updatedField };
214+
// // // eslint-disable-next-line no-console
215+
// // console.log('🛰 PUT payload being sent:', payload);
216+
// // const res = await axios.put(url, {
217+
// // ...userProfile,
218+
// // ...updatedField,
219+
// // });
220+
221+
// // // 🔹 Step 4 debug: log backend response explicitly
222+
// // // eslint-disable-next-line no-console
223+
// // console.log('🔍 Backend returned after PUT:', res.data);
224+
// // // eslint-disable-next-line no-console
225+
// // console.log('✅ PUT response:', res.data);
226+
227+
// // if (res.status === 200) {
228+
// // dispatch(updateSummaryReport({ _id: userId, updatedField }));
229+
// // // eslint-disable-next-line no-console
230+
// // console.log('🟢 Redux state updated with:', updatedField);
231+
// // return res;
232+
// // }
233+
234+
// // throw new Error(`An error occurred while attempting to save the changes to the profile.`);
235+
// // };
236+
// const url = ENDPOINTS.USER_PROFILE(userId);
237+
// return async dispatch => {
238+
// // try {
239+
// // // Optional: fetch current user profile if needed
240+
// // // const { data: userProfile } = await axios.get(url);
241+
// // const state = getState();
242+
// // const allUsers = Array.isArray(state.weeklySummariesReport?.summaries)
243+
// // ? state.weeklySummariesReport.summaries
244+
// // : [];
245+
// // const currentUser = allUsers.find(u => u._id === userId);
246+
247+
// // if (!currentUser) throw new Error('User not found in state');
248+
249+
// // // Merge updatedField (like filterColor) into the full user object
250+
// // const payload = { ...currentUser, ...updatedField };
251+
252+
// // // Send the PUT and get server response (server should return the saved user)
253+
// // // const res = await axios.put(url, {
254+
// // // ...updatedField, // send only updated fields (you already normalized on client)
255+
// // // });
256+
// // const res = await axios.put(url, payload);
257+
// // // Log for debugging
258+
// // // eslint-disable-next-line no-console
259+
// // console.log('✅ PUT response (updateOneSummaryReport):', res.data);
260+
261+
// // if (res.status === 200) {
262+
// // // Dispatch the server-truth into the store.
263+
// // // IMPORTANT: payload should be the full user object (or at least fields the UI needs)
264+
// // dispatch(updateSummaryReport({ _id: userId, updatedField: res.data }));
265+
266+
// // // Return the server response so callers can use res.data
267+
// // return res;
268+
// // }
269+
270+
// // throw new Error('Failed to save profile');
271+
// // } catch (err) {
272+
// // // rethrow so caller's try/catch can handle revert
273+
// // throw err;
274+
// // }
275+
// //above was good byt not working code
276+
// const res = await axios.put(url, fullUserPayload);
277+
// if (res.status === 200) {
278+
// dispatch(updateSummaryReport({ _id: userId, updatedField: res.data }));
279+
// return res;
280+
// }
281+
// throw new Error('Failed to save profile');
282+
// };
283+
// };
284+
export const updateOneSummaryReport = (userId, payload) => {
285+
const url = ENDPOINTS.USER_PROFILE(userId);
286+
return async dispatch => {
287+
const res = await axios.put(url, payload);
288+
if (res.status === 200) {
289+
dispatch(updateSummaryReport({ _id: userId, updatedField: res.data }));
290+
return res;
291+
}
292+
throw new Error('Failed to save profile');
293+
};
294+
};
295+
296+
/**
297+
* Toggle the user's bio status (posted, requested, default).
298+
*/
299+
export const toggleUserBio = (userId, bioPosted) => {
300+
const url = ENDPOINTS.TOGGLE_BIO_STATUS(userId);
301+
return async dispatch => {
302+
try {
303+
const res = await axios.patch(url, { bioPosted });
304+
305+
if (res.status === 200) {
306+
const updatedField = { bioPosted };
307+
308+
// Dispatch an action to update the store
309+
dispatch(updateSummaryReport({ _id: userId, updatedField }));
310+
311+
toast.success(`Bio status updated to "${bioPosted}"`);
312+
}
313+
314+
return res;
315+
} catch (error) {
316+
toast.error('An error occurred while updating bio status.');
317+
throw error;
318+
}
319+
};
320+
};
321+
322+
/**
323+
* Optimistically update filterColor for all users in selected team codes.
324+
*/
325+
export const updateBulkFilterColors = ({ color, teamCodes, newState }) => ({
326+
type: reportActions.UPDATE_BULK_FILTER_COLORS,
327+
payload: { color, teamCodes, newState },
328+
});

src/actions/weeklySummariesReport.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,31 @@ export const updateSummaryReport = ({ _id, updatedField }) => ({
4444
* Gets all active users' summaries + a few other selected fields from the userProfile that
4545
* might be useful for the weekly summary report.
4646
*/
47-
export const getWeeklySummariesReport = (weekIndex = null) => {
47+
export const getWeeklySummariesReport = (weekIndex = null, options = {}) => {
4848
return async dispatch => {
4949
dispatch(fetchWeeklySummariesReportBegin());
5050
try {
5151
// Use the APIEndpoint from ENDPOINTS
5252
let url = ENDPOINTS.WEEKLY_SUMMARIES_REPORT();
5353

54+
const timestamp = options.forceRefresh ? `ts=${Date.now()}` : '';
5455
// Add the week parameter if provided
5556
if (weekIndex !== null) {
5657
// Check if the URL already has parameters
5758
const separator = url.includes('?') ? '&' : '?';
58-
url = `${url}${separator}week=${weekIndex}`;
59+
url = `${url}${separator}week=${weekIndex}${timestamp ? '&' + timestamp : ''}`;
60+
} else if (timestamp) {
61+
const separator = url.includes('?') ? '&' : '?';
62+
url = `${url}${separator}${timestamp}`;
5963
}
6064

61-
const response = await axios.get(url);
65+
const response = await axios.get(url, {
66+
headers: {
67+
'Cache-Control': 'no-cache',
68+
Pragma: 'no-cache',
69+
Expires: '0',
70+
},
71+
});
6272
dispatch(fetchWeeklySummariesReportSuccess(response.data));
6373
return { status: response.status, data: response.data };
6474
} catch (error) {

src/components/BMDashboard/WeeklyProjectSummary/DistributionLaborHours/DistributionLaborHours.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-alert */
12
import React, { useState, useEffect } from 'react';
23
import { useSelector } from 'react-redux';
34
import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer } from 'recharts';

src/components/Timelog/__tests__/TimelogNavbar.test.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable import/no-named-as-default */
12
import React from 'react';
23
import { BrowserRouter as Router , Route } from 'react-router-dom';
34
import { Provider } from 'react-redux';

src/components/TotalOrgSummary/TaskCompleted/TaskCompletedBarChart.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-alert */
12
import TinyBarChart from '../TinyBarChart';
23
import Loading from '../../common/Loading';
34

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import '@testing-library/jest-dom/extend-expect';
55
import moment from 'moment';
66
import { Provider } from 'react-redux';
77
// eslint-disable import/no-named-as-default
8+
// eslint-disable-next-line import/no-named-as-default
89
import configureStore from 'redux-mock-store';
910
import SetUpFinalDayPopUp from '../SetUpFinalDayPopUp.jsx';
1011
const mockStore = configureStore([]);

0 commit comments

Comments
 (0)