Skip to content

Commit 1e4d0d5

Browse files
committed
2024-11-11 - search and add-new external-recip
1 parent 9fd2a8a commit 1e4d0d5

File tree

8 files changed

+90
-98
lines changed

8 files changed

+90
-98
lines changed

web-ui/src/components/feedback_external_recipient_selector/FeedbackExternalRecipientSelector.jsx

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { styled } from '@mui/material/styles';
33
import FeedbackExternalRecipientCard from '../feedback_external_recipient_card/FeedbackExternalRecipientCard';
44
import { AppContext } from '../../context/AppContext';
55
import {
6-
selectProfile,
7-
selectCsrfToken,
8-
selectCurrentUser,
9-
selectNormalizedMembers, selectFeedbackExternalRecipient
6+
selectProfile, selectCsrfToken, selectCurrentUser, selectNormalizedMembers,
107
} from '../../context/selectors';
118
import {putExternalRecipientInactivate, getExternalRecipients} from '../../api/feedback';
129
import Typography from '@mui/material/Typography';
@@ -59,7 +56,7 @@ const propTypes = {
5956
};
6057

6158
const FeedbackExternalRecipientSelector = ({ changeQuery, fromQuery, forQuery, addExternalRecipientId }) => {
62-
const { state } = useContext(AppContext);
59+
const { state, dispatch } = useContext(AppContext);
6360
const csrf = selectCsrfToken(state);
6461
const userProfile = selectCurrentUser(state);
6562
const { id } = userProfile;
@@ -96,39 +93,39 @@ const FeedbackExternalRecipientSelector = ({ changeQuery, fromQuery, forQuery, a
9693

9794
useEffect(() => {
9895
function bindFromURL() {
99-
if (
100-
!hasRenewedFromURL.current &&
101-
fromQuery !== null &&
102-
fromQuery !== undefined
103-
) {
104-
let profileCopy = externalRecipients;
105-
if (typeof fromQuery === 'string') {
106-
let newProfile = { id: fromQuery };
107-
if (externalRecipients.filter(externalRecipient => externalRecipient.id === newProfile.id).length === 0) {
108-
profileCopy.push(newProfile);
109-
}
110-
} else if (Array.isArray(fromQuery)) {
111-
for (let i = 0; i < fromQuery.length; ++i) {
112-
let newProfile = { id: fromQuery[i] };
113-
if (externalRecipients.filter(externalRecipient => externalRecipient.id === newProfile.id).length === 0) {
114-
profileCopy.push(newProfile);
96+
if (
97+
!hasRenewedFromURL.current &&
98+
fromQuery !== null &&
99+
fromQuery !== undefined
100+
) {
101+
let profileCopy = externalRecipients;
102+
if (typeof fromQuery === 'string') {
103+
let newProfile = { id: fromQuery };
104+
if (externalRecipients.filter(externalRecipient => externalRecipient.id === newProfile.id).length === 0) {
105+
profileCopy.push(newProfile);
106+
}
107+
} else if (Array.isArray(fromQuery)) {
108+
for (let i = 0; i < fromQuery.length; ++i) {
109+
let newProfile = { id: fromQuery[i] };
110+
if (externalRecipients.filter(externalRecipient => externalRecipient.id === newProfile.id).length === 0) {
111+
profileCopy.push(newProfile);
112+
}
113+
}
114+
}
115+
setExternalRecipients(profileCopy);
116+
hasRenewedFromURL.current = true;
115117
}
116-
}
117-
}
118-
setExternalRecipients(profileCopy);
119-
hasRenewedFromURL.current = true;
120-
}
121118
}
122119

123120
async function getExternalRecipientsForSelector() {
124-
if (forQuery === undefined || forQuery === null) {
125-
return;
126-
}
127-
let res = await getExternalRecipients(csrf);
128-
if (res && res.payload) {
129-
return res.payload.data && !res.error ? res.payload.data : undefined;
130-
}
131-
return null;
121+
if (forQuery === undefined || forQuery === null) {
122+
return;
123+
}
124+
let res = await getExternalRecipients(csrf);
125+
if (res && res.payload) {
126+
return res.payload.data && !res.error ? res.payload.data : undefined;
127+
}
128+
return null;
132129
}
133130

134131
if (csrf && (searchText === '' || searchText.length === 0)) {
@@ -157,7 +154,6 @@ const FeedbackExternalRecipientSelector = ({ changeQuery, fromQuery, forQuery, a
157154
} else {
158155
fromQuery.push(id);
159156
}
160-
console.log("FeedbackExternalRecipientSelector.jsx, cardClickHandler, 02 - fromQuery: ", fromQuery);
161157
changeQuery('from', fromQuery);
162158
hasRenewedFromURL.current = false;
163159
};
@@ -263,8 +259,13 @@ const FeedbackExternalRecipientSelector = ({ changeQuery, fromQuery, forQuery, a
263259
} else if (feedbackExternalRecipientRes.payload && feedbackExternalRecipientRes.payload.data) {
264260
newRecipient.id = feedbackExternalRecipientRes.payload.data.id;
265261
console.log("FeedbackExternalRecipientSelector.jsx, handleNewRecipientSubmit, newRecipient: ", newRecipient);
266-
setExternalRecipients([...externalRecipients, newRecipient]);
262+
//setExternalRecipients([...externalRecipients, newRecipient]);
267263
addExternalRecipientId(newRecipient.id);
264+
const updatedRecipients = await getExternalRecipients(csrf);
265+
console.log("FeedbackExternalRecipientSelector.jsx, handleNewRecipientSubmit, updatedRecipients: ", updatedRecipients);
266+
if (updatedRecipients && updatedRecipients.payload) {
267+
setExternalRecipients(updatedRecipients.payload.data);
268+
}
268269
handleNewRecipientClose();
269270
}
270271
};

web-ui/src/components/feedback_recipient_selector/FeedbackRecipientSelector.jsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,13 @@ const FeedbackRecipientSelector = ({ changeQuery, fromQuery, forQuery }) => {
138138
});
139139
});
140140
let newProfiles = filteredProfileCopy.concat(res);
141-
console.log("FeedbackRecipientSelector, getSuggestions, newProfiles: ", newProfiles);
142141
setProfiles(newProfiles);
143142
}
144143
});
145144
} // eslint-disable-next-line react-hooks/exhaustive-deps
146145
}, [id, csrf, searchText]);
147146

148147
const cardClickHandler = id => {
149-
console.log("FeedbackRecipientSelector, cardClickHandler, id: ", id);
150-
console.log("FeedbackRecipientSelector, cardClickHandler, fromQuery: ", fromQuery);
151148
if (!Array.isArray(fromQuery)) {
152149
fromQuery = fromQuery ? [fromQuery] : [];
153150
}

web-ui/src/components/feedback_request_confirmation/FeedbackRequestConfirmation.jsx

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import CheckCircleIcon from '@mui/icons-material/CheckCircle';
55
import {
66
selectProfile,
77
selectHasCreateFeedbackPermission,
8-
noPermission, selectFeedbackExternalRecipient,
8+
noPermission,
99
} from '../../context/selectors';
1010
import { AppContext } from '../../context/AppContext';
1111
import { Link, useLocation } from 'react-router-dom';
@@ -15,7 +15,8 @@ import './FeedbackRequestConfirmation.css';
1515
import { green } from '@mui/material/colors';
1616
import Button from '@mui/material/Button';
1717
import {getFeedbackTemplate} from "../../api/feedbacktemplate.js";
18-
import {UPDATE_TOAST} from "../../context/actions.js"; // Import the action type
18+
import {UPDATE_TOAST} from "../../context/actions.js";
19+
import {getExternalRecipients} from "../../api/feedback.js"; // Import the action type
1920

2021
const dateUtils = new DateFnsUtils();
2122
const PREFIX = 'FeedbackRequestConfirmation';
@@ -52,11 +53,11 @@ const FeedbackRequestConfirmation = () => {
5253
const templateQuery = query.template?.toString();
5354
const requestee = selectProfile(state, forQuery);
5455
const [templateIsForExternalRecipient, setTemplateIsForExternalRecipient] = useState(false);
56+
const [externalRecipients, setExternalRecipients] = useState([]);
5557

5658
useEffect(() => {
5759
async function fetchTemplateDetails() {
5860
if (!templateQuery) return;
59-
6061
let res = await getFeedbackTemplate(templateQuery);
6162
let templateResponse =
6263
res.payload &&
@@ -78,24 +79,45 @@ const FeedbackRequestConfirmation = () => {
7879
setTemplateIsForExternalRecipient(templateResponse.isForExternalRecipient);
7980
}
8081
}
81-
8282
fetchTemplateDetails();
8383
}, [templateQuery, dispatch]);
8484

85+
useEffect(() => {
86+
async function fetchExternalRecipients() {
87+
let res = await getExternalRecipients();
88+
let externalRecipientsResponse =
89+
res.payload && res.payload.data && res.payload.status === 200 && !res.error
90+
? res.payload.data
91+
: null
92+
;
93+
if (externalRecipientsResponse) {
94+
setExternalRecipients(externalRecipientsResponse);
95+
}
96+
}
97+
fetchExternalRecipients();
98+
}, [templateIsForExternalRecipient]);
99+
85100
function getRecipientNames() {
86-
if (fromQuery !== undefined) {
87-
let fromArray = fromQuery.split(',');
88-
let recipientProfiles = [];
89-
if (fromArray.length !== 0) {
90-
for (let i = 0; i < fromArray.length; ++i) {
91-
let element = fromArray[i];
92-
recipientProfiles.push(element);
93-
}
94-
} else {
95-
recipientProfiles.push(fromQuery);
101+
let recipientProfiles = [];
102+
if (templateIsForExternalRecipient) {
103+
if (fromQuery !== undefined) {
104+
let fromArray = fromQuery.split(',');
105+
fromArray.forEach(id => {
106+
let recipient = externalRecipients.find(recipient => recipient.id === id);
107+
if (recipient) {
108+
recipientProfiles.push(recipient.firstName + ' ' + recipient.lastName + ' (' + recipient.companyName + ')');
109+
}
110+
});
111+
}
112+
} else {
113+
if (fromQuery !== undefined) {
114+
let fromArray = fromQuery.split(',');
115+
fromArray.forEach(id => {
116+
recipientProfiles.push(id);
117+
});
96118
}
97-
return recipientProfiles;
98119
}
120+
return recipientProfiles;
99121
}
100122

101123
let recipientInfo = getRecipientNames();
@@ -122,7 +144,7 @@ const FeedbackRequestConfirmation = () => {
122144
`
123145
${
124146
templateIsForExternalRecipient
125-
? selectFeedbackExternalRecipient(state, recipient)?.firstName + " " + selectFeedbackExternalRecipient(state, recipient)?.lastName + " (" + selectFeedbackExternalRecipient(state, recipient)?.companyName + ") "
147+
? recipient
126148
: selectProfile(state, recipient)?.name
127149
}
128150
${index === recipientInfo.length - 1 ? '' : ', '}

web-ui/src/context/AppContext.jsx

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const AppContextProvider = props => {
6666
teams,
6767
memberSkills,
6868
memberProfiles,
69-
feedbackExternalRecipients,
7069
checkins,
7170
skills,
7271
certifications,
@@ -167,25 +166,6 @@ const AppContextProvider = props => {
167166
, [csrf, memberSkills])
168167
;
169168

170-
useEffect(() => {
171-
async function getAllExternalRecipients() {
172-
let res = await getExternalRecipients(csrf);
173-
let externalRecipients =
174-
res.payload && res.payload.data && !res.error
175-
? res.payload.data
176-
: undefined
177-
;
178-
if (externalRecipients) {
179-
dispatch({ type: UPDATE_EXTERNAL_RECIPIENTS, payload: externalRecipients });
180-
dispatch({ type: UPDATE_EXTERNAL_RECIPIENTS_LOADING, payload: false });
181-
}
182-
}
183-
if (csrf && !feedbackExternalRecipients) {
184-
getAllExternalRecipients();
185-
}
186-
}, [csrf, feedbackExternalRecipients])
187-
;
188-
189169
useEffect(() => {
190170
async function getMemberProfiles() {
191171
let res = await getAllMembers(csrf);

web-ui/src/context/actions.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,3 @@ export const UPDATE_TEAMS_LOADING = '@@check-ins/update_teams_loading';
3434
export const UPDATE_REVIEW_PERIOD = '@@check-ins/update_review_period';
3535
export const UPDATE_REVIEW_PERIODS = '@@check-ins/update_review_periods';
3636
export const ADD_REVIEW_PERIOD = '@@check-ins/add_review_period';
37-
export const UPDATE_EXTERNAL_RECIPIENTS = '@@check-ins/update_external_recipients';
38-
export const UPDATE_EXTERNAL_RECIPIENTS_LOADING = '@@check-ins/update_external_recipients_loading';

web-ui/src/context/reducer.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
UPDATE_TEAMS_LOADING,
3333
UPDATE_REVIEW_PERIOD,
3434
UPDATE_REVIEW_PERIODS,
35-
ADD_REVIEW_PERIOD, UPDATE_EXTERNAL_RECIPIENTS, UPDATE_EXTERNAL_RECIPIENTS_LOADING
35+
ADD_REVIEW_PERIOD
3636
} from './actions';
3737

3838
export const initialState = {
@@ -46,7 +46,6 @@ export const initialState = {
4646
memberProfiles: null,
4747
terminatedMembers: [],
4848
memberSkills: null,
49-
feedbackExternalRecipients: null,
5049
roles: null,
5150
userRoles: null,
5251
skills: null,

web-ui/src/context/selectors.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ export const selectGuilds = state => state.guilds || [];
1515
export const selectLoading = state => state.loading;
1616
export const selectReviewPeriods = state => state.reviewPeriods;
1717
export const selectPermissions = state => state.permissions;
18-
export const selectFeedbackExternalRecipients = state => state.feedbackExternalRecipients || [];
19-
2018
export const noPermission = 'You do not have permission to view this page.';
2119

2220
const hasPermission = permissionName =>
@@ -733,14 +731,3 @@ export const selectReviewPeriod = createSelector(
733731
(state, periodId) => periodId,
734732
(periodMap, periodId) => periodMap[periodId]
735733
);
736-
737-
export const selectFeedbackExternalRecipientIds = createSelector(
738-
selectFeedbackExternalRecipients,
739-
externalRecipients => externalRecipients.map(externalRecipient => externalRecipient.id)
740-
);
741-
742-
export const selectFeedbackExternalRecipient = createSelector(
743-
selectFeedbackExternalRecipients,
744-
(state, feedbackExternalRecipientId) => feedbackExternalRecipientId,
745-
(feedbackExternalRecipients, feedbackExternalRecipientId) => feedbackExternalRecipients.find(feedbackExternalRecipient => feedbackExternalRecipient.id === feedbackExternalRecipientId)
746-
);

web-ui/src/pages/FeedbackRequestPage.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ import FeedbackTemplateSelector from '../components/feedback_template_selector/F
1818
import FeedbackRecipientSelector from '../components/feedback_recipient_selector/FeedbackRecipientSelector';
1919
import SelectDate from '../components/feedback_date_selector/SelectDate';
2020
import { AppContext } from '../context/AppContext';
21-
import { createFeedbackRequest } from '../api/feedback';
21+
import {createFeedbackRequest, getExternalRecipients} from '../api/feedback';
2222
import {
2323
selectProfile,
2424
selectCsrfToken,
2525
selectCurrentUser,
2626
selectCurrentMemberIds,
2727
selectHasCreateFeedbackPermission,
28-
noPermission, selectFeedbackExternalRecipientIds,
28+
noPermission,
2929
} from '../context/selectors';
3030
import DateFnsUtils from '@date-io/date-fns';
3131
import { getFeedbackTemplate, softDeleteAdHocTemplates } from '../api/feedbacktemplate';
@@ -259,7 +259,7 @@ const FeedbackRequestPage = () => {
259259
await softDeleteAdHoc(currentUserId);
260260
const newLocation = {
261261
pathname: '/feedback/request/confirmation',
262-
search: queryString.stringify(query)
262+
search: queryString.stringify(query),
263263
};
264264
history.push(newLocation);
265265
} else if (res.error || data === null) {
@@ -365,10 +365,18 @@ const FeedbackRequestPage = () => {
365365
}, [state]);
366366

367367
useEffect(() => {
368-
const feedbackExternalRecipients = selectFeedbackExternalRecipientIds(state);
369-
if (feedbackExternalRecipients) {
370-
setExternalRecipientIds(feedbackExternalRecipients);
368+
async function fetchExternalRecipients() {
369+
let res = await getExternalRecipients();
370+
let externalRecipientsResponse =
371+
res.payload && res.payload.data && res.payload.status === 200 && !res.error
372+
? res.payload.data
373+
: null
374+
;
375+
if (externalRecipientsResponse) {
376+
setExternalRecipientIds(externalRecipientsResponse.map(recipient => recipient.id));
377+
}
371378
}
379+
fetchExternalRecipients();
372380
}, [state]);
373381

374382
useEffect(() => {

0 commit comments

Comments
 (0)