From 7377c5e32d873a22ecf4f9de0a6cd1d08d8435af Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Wed, 20 Aug 2025 01:11:04 -0700 Subject: [PATCH 1/2] fix(weekly-summary-email): update Assignment, BCC Action, and Bcc Constants to resolve task issues --- src/actions/weeklySummaryEmailBCCAction.js | 9 ++++++++- src/constants/WeeklySummaryEmailBccConstants.js | 1 + src/reducers/WeeklySummaryEmailAssignment.js | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/actions/weeklySummaryEmailBCCAction.js b/src/actions/weeklySummaryEmailBCCAction.js index d8d0a05751..259536f68e 100644 --- a/src/actions/weeklySummaryEmailBCCAction.js +++ b/src/actions/weeklySummaryEmailBCCAction.js @@ -24,6 +24,11 @@ const weeklySummaryEmailBccError = error => ({ payload: error, }); +const updateWeeklySummaryEmailBcc = (id, email) => ({ + type: types.UPDATE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT, + payload: { _id: id, email }, +}); + // fetch all assignments export const getAllWeeklySummaryEmailAssignments = () => { const url = ENDPOINTS.WEEKLY_SUMMARY_EMAIL_BCC(); @@ -79,7 +84,8 @@ export const updateWeeklySummaryEmailAssignment = (id, email) => async dispatch try { const response = await axios.put(ENDPOINTS.UPDATE_WEEKLY_SUMMARY_EMAIL_BCC(id), { email }); if (response.status === 200) { - dispatch(getAllWeeklySummaryEmailAssignments()); + const updated = response?.data?.assignment || { _id: id, email }; + dispatch(updateWeeklySummaryEmailBcc(updated._id, updated.email)); } else { dispatch(weeklySummaryEmailBccError(response.data)); } @@ -87,3 +93,4 @@ export const updateWeeklySummaryEmailAssignment = (id, email) => async dispatch dispatch(weeklySummaryEmailBccError(error)); } }; + diff --git a/src/constants/WeeklySummaryEmailBccConstants.js b/src/constants/WeeklySummaryEmailBccConstants.js index 4e1d98f298..8148a583d7 100644 --- a/src/constants/WeeklySummaryEmailBccConstants.js +++ b/src/constants/WeeklySummaryEmailBccConstants.js @@ -2,3 +2,4 @@ export const GET_WEEKLY_SUMMARY_EMAIL_ASSIGNMENTS = 'GET_WEEKLY_SUMMARY_EMAIL_AS export const SET_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT = 'SET_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT'; export const DELETE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT = 'DELETE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT'; export const WEEKLY_SUMMARY_EMAIL_ASSIGNMENT_ERROR = 'WEEKLY_SUMMARY_EMAIL_ASSIGNMENT_ERROR'; +export const UPDATE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT = 'UPDATE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT'; diff --git a/src/reducers/WeeklySummaryEmailAssignment.js b/src/reducers/WeeklySummaryEmailAssignment.js index 0a19850cb0..bda8b98eb0 100644 --- a/src/reducers/WeeklySummaryEmailAssignment.js +++ b/src/reducers/WeeklySummaryEmailAssignment.js @@ -25,6 +25,14 @@ const WeeklySummaryEmailAssignment = (state = initialState, action = {}) => { emailAssignment: state.emailAssignment.filter(ele => ele._id !== action.payload), error: null, }; + case types.UPDATE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT: + return { + ...state, + emailAssignment: state.emailAssignment.map(item => + item._id === action.payload._id ? { ...item, email: action.payload.email } : item, + ), + error: null, + }; case types.WEEKLY_SUMMARY_EMAIL_ASSIGNMENT_ERROR: return { ...state, From 314b20576c0f0ff0f72fca29f69b1fb77d924e65 Mon Sep 17 00:00:00 2001 From: Linh Huynh Date: Tue, 24 Feb 2026 22:48:42 -0800 Subject: [PATCH 2/2] fix(frontend): make weekly summary email edits update UI immediately --- .../weeklySummaryEmailBCCAction.js.test.js | 67 +++++++++++++++++++ src/actions/weeklySummaryEmailBCCAction.js | 12 ++-- .../WeeklySummaryEmailAssignmentPopUp.jsx | 4 +- src/reducers/WeeklySummaryEmailAssignment.js | 2 +- 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 src/actions/__tests__/weeklySummaryEmailBCCAction.js.test.js diff --git a/src/actions/__tests__/weeklySummaryEmailBCCAction.js.test.js b/src/actions/__tests__/weeklySummaryEmailBCCAction.js.test.js new file mode 100644 index 0000000000..41662d9bcf --- /dev/null +++ b/src/actions/__tests__/weeklySummaryEmailBCCAction.js.test.js @@ -0,0 +1,67 @@ +import axios from 'axios'; +import configureMockStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; + +import * as types from '../../constants/WeeklySummaryEmailBccConstants'; +import { updateWeeklySummaryEmailAssignment } from '../weeklySummaryEmailBCCAction'; + +vi.mock('axios'); + +const mockStore = configureMockStore([thunk]); + +describe('updateWeeklySummaryEmailAssignment action creator', () => { + it('dispatches updated assignment when API returns wrapped assignment payload', async () => { + const store = mockStore({}); + const updatedAssignment = { + _id: 'assignment-id', + email: 'updated@example.com', + assignedTo: { _id: 'user-id', firstName: 'Updated', lastName: 'User' }, + }; + + axios.put.mockResolvedValue({ + status: 200, + data: { assignment: updatedAssignment }, + }); + + await store.dispatch(updateWeeklySummaryEmailAssignment('assignment-id', 'updated@example.com')); + + expect(store.getActions()).toContainEqual({ + type: types.UPDATE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT, + payload: updatedAssignment, + }); + }); + + it('dispatches updated assignment when API returns assignment directly', async () => { + const store = mockStore({}); + const updatedAssignment = { + _id: 'assignment-id', + email: 'updated@example.com', + }; + + axios.put.mockResolvedValue({ + status: 200, + data: updatedAssignment, + }); + + await store.dispatch(updateWeeklySummaryEmailAssignment('assignment-id', 'updated@example.com')); + + expect(store.getActions()).toContainEqual({ + type: types.UPDATE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT, + payload: updatedAssignment, + }); + }); + + it('dispatches error action when update fails', async () => { + const store = mockStore({}); + const error = new Error('Network Error'); + + axios.put.mockRejectedValue(error); + + await store.dispatch(updateWeeklySummaryEmailAssignment('assignment-id', 'updated@example.com')); + + expect(store.getActions()).toContainEqual({ + type: types.WEEKLY_SUMMARY_EMAIL_ASSIGNMENT_ERROR, + payload: error, + }); + }); +}); diff --git a/src/actions/weeklySummaryEmailBCCAction.js b/src/actions/weeklySummaryEmailBCCAction.js index 259536f68e..7c9b814f3c 100644 --- a/src/actions/weeklySummaryEmailBCCAction.js +++ b/src/actions/weeklySummaryEmailBCCAction.js @@ -24,9 +24,9 @@ const weeklySummaryEmailBccError = error => ({ payload: error, }); -const updateWeeklySummaryEmailBcc = (id, email) => ({ +const updateWeeklySummaryEmailBcc = assignment => ({ type: types.UPDATE_WEEKLY_SUMMARY_EMAIL_ASSIGNMENT, - payload: { _id: id, email }, + payload: assignment, }); // fetch all assignments @@ -84,8 +84,12 @@ export const updateWeeklySummaryEmailAssignment = (id, email) => async dispatch try { const response = await axios.put(ENDPOINTS.UPDATE_WEEKLY_SUMMARY_EMAIL_BCC(id), { email }); if (response.status === 200) { - const updated = response?.data?.assignment || { _id: id, email }; - dispatch(updateWeeklySummaryEmailBcc(updated._id, updated.email)); + const updated = response?.data?.assignment || response?.data || { _id: id, email }; + if (updated && updated._id) { + dispatch(updateWeeklySummaryEmailBcc(updated)); + } else { + dispatch(getAllWeeklySummaryEmailAssignments()); + } } else { dispatch(weeklySummaryEmailBccError(response.data)); } diff --git a/src/components/VolunteerweeklysummaryBBC/WeeklySummaryEmailAssignmentPopUp.jsx b/src/components/VolunteerweeklysummaryBBC/WeeklySummaryEmailAssignmentPopUp.jsx index 5598221d58..f4f4f684e5 100644 --- a/src/components/VolunteerweeklysummaryBBC/WeeklySummaryEmailAssignmentPopUp.jsx +++ b/src/components/VolunteerweeklysummaryBBC/WeeklySummaryEmailAssignmentPopUp.jsx @@ -89,9 +89,9 @@ const WeeklySummaryEmailAssignmentPopUp = React.memo(props => { setEditingEmail(email); }; - const handleEditSave = id => { + const handleEditSave = async id => { if (editingEmail && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(editingEmail)) { - dispatch(updateWeeklySummaryEmailAssignment(id, editingEmail)); + await dispatch(updateWeeklySummaryEmailAssignment(id, editingEmail)); setEditingId(null); setEditingEmail(''); } diff --git a/src/reducers/WeeklySummaryEmailAssignment.js b/src/reducers/WeeklySummaryEmailAssignment.js index bda8b98eb0..e0fc360bf8 100644 --- a/src/reducers/WeeklySummaryEmailAssignment.js +++ b/src/reducers/WeeklySummaryEmailAssignment.js @@ -29,7 +29,7 @@ const WeeklySummaryEmailAssignment = (state = initialState, action = {}) => { return { ...state, emailAssignment: state.emailAssignment.map(item => - item._id === action.payload._id ? { ...item, email: action.payload.email } : item, + item._id === action.payload._id ? { ...item, ...action.payload } : item, ), error: null, };