Skip to content

Commit d290a9e

Browse files
committed
Factored review assignment API calls into a separate file.
1 parent ee5fa80 commit d290a9e

File tree

2 files changed

+57
-69
lines changed

2 files changed

+57
-69
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { resolve } from './api.js';
2+
3+
const reviewAssignmentsUrl = '/services/review-assignments';
4+
5+
export const getReviewAssignments = async (id, cookie) => {
6+
return resolve({
7+
url: `${reviewAssignmentsUrl}/period/${id}`,
8+
headers: { 'X-CSRF-Header': cookie, Accept: 'application/json' }
9+
});
10+
};
11+
12+
export const createReviewAssignments = async (id, assignments, cookie) => {
13+
return resolve({
14+
method: 'POST',
15+
url: `${reviewAssignmentsUrl}/${id}`,
16+
data: assignments,
17+
headers: {
18+
'X-CSRF-Header': cookie,
19+
Accept: 'application/json',
20+
'Content-Type': 'application/json;charset=UTF-8'
21+
}
22+
});
23+
};
24+
25+
export const updateReviewAssignment = async (assignment, cookie) => {
26+
return resolve({
27+
method: assignment.id === null ? 'POST' : 'PUT',
28+
url: reviewAssignmentsUrl,
29+
data: assignment,
30+
headers: {
31+
'X-CSRF-Header': cookie,
32+
Accept: 'application/json',
33+
'Content-Type': 'application/json;charset=UTF-8'
34+
}
35+
});
36+
};
37+
38+
export const removeReviewAssignment = async (id, cookie) => {
39+
return resolve({
40+
method: 'DELETE',
41+
url: `${reviewAssignmentsUrl}/${id}`,
42+
headers: { 'X-CSRF-Header': cookie }
43+
});
44+
};

web-ui/src/components/reviews/TeamReviews.jsx

Lines changed: 13 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ import {
3434
import { styled } from '@mui/material/styles';
3535

3636
import ConfirmationDialog from '../dialogs/ConfirmationDialog';
37-
import { resolve } from '../../api/api.js';
37+
import {
38+
getReviewAssignments,
39+
createReviewAssignments,
40+
updateReviewAssignment,
41+
removeReviewAssignment,
42+
} from '../../api/reviewassignments.js';
3843
import {
3944
findReviewRequestsByPeriod,
4045
findSelfReviewRequestsByPeriodAndTeamMembers
@@ -158,8 +163,6 @@ const TeamReviews = ({ onBack, periodId }) => {
158163
const isAdmin = selectIsAdmin(state);
159164
const period = selectReviewPeriod(state, periodId);
160165

161-
const reviewAssignmentsUrl = '/services/review-assignments';
162-
163166
useEffect(() => {
164167
loadAssignments();
165168
}, [currentMembers]);
@@ -192,15 +195,7 @@ const TeamReviews = ({ onBack, periodId }) => {
192195
};
193196

194197
const loadAssignments = async () => {
195-
const res = await resolve({
196-
method: 'GET',
197-
url: `${reviewAssignmentsUrl}/period/${periodId}`,
198-
headers: {
199-
'X-CSRF-Header': csrf,
200-
Accept: 'application/json',
201-
'Content-Type': 'application/json;charset=UTF-8'
202-
}
203-
});
198+
const res = await getReviewAssignments(periodId, csrf);
204199
if (res.error) return;
205200

206201
const assignments = res.payload.data;
@@ -243,29 +238,12 @@ const TeamReviews = ({ onBack, periodId }) => {
243238
}));
244239

245240
// Set those on the server as the review assignments.
246-
let res = await resolve({
247-
method: 'POST',
248-
url: reviewAssignmentsUrl + '/' + periodId,
249-
data,
250-
headers: {
251-
'X-CSRF-Header': csrf,
252-
Accept: 'application/json',
253-
'Content-Type': 'application/json;charset=UTF-8'
254-
}
255-
});
241+
let res = await createReviewAssignments(periodId, data, csrf);
256242
if (res.error) return;
257243

258244
// Get the list of review assignments from the server to ensure that we are
259245
// reflecting what was actually created.
260-
res = await resolve({
261-
method: 'GET',
262-
url: `${reviewAssignmentsUrl}/period/${periodId}`,
263-
headers: {
264-
'X-CSRF-Header': csrf,
265-
Accept: 'application/json',
266-
'Content-Type': 'application/json;charset=UTF-8'
267-
}
268-
});
246+
res = await getReviewAssignments(periodId, csrf);
269247
const assignments = res.error ? [] : res.payload.data;
270248

271249
// Update our reactive assignment and member lists.
@@ -614,11 +592,7 @@ const TeamReviews = ({ onBack, periodId }) => {
614592

615593
const { id, revieweeId, reviewerId } = assignment;
616594
if (id) {
617-
const res = await resolve({
618-
method: 'DELETE',
619-
url: `${reviewAssignmentsUrl}/${id}`,
620-
headers: { 'X-CSRF-Header': csrf }
621-
});
595+
const res = await removeReviewAssignment(id, csrf);
622596

623597
if (res.error) {
624598
console.error('Error deleting assignment:', res.error);
@@ -650,19 +624,7 @@ const TeamReviews = ({ onBack, periodId }) => {
650624
};
651625

652626
const updateReviewPeriodStatus = async reviewStatus => {
653-
const res = await resolve({
654-
method: 'PUT',
655-
url: '/services/review-periods',
656-
headers: {
657-
Accept: 'application/json',
658-
'Content-Type': 'application/json;charset=UTF-8',
659-
'X-CSRF-Header': csrf
660-
},
661-
data: {
662-
...period,
663-
reviewStatus
664-
}
665-
});
627+
const res = await updateReviewPeriod({ ...period, reviewStatus }, csrf);
666628
if (res.error) return;
667629

668630
onBack();
@@ -730,16 +692,7 @@ const TeamReviews = ({ onBack, periodId }) => {
730692
}
731693
}
732694

733-
const res = await resolve({
734-
method: 'POST',
735-
url: `${reviewAssignmentsUrl}/${periodId}`,
736-
data: newAssignments,
737-
headers: {
738-
'X-CSRF-Header': csrf,
739-
Accept: 'application/json',
740-
'Content-Type': 'application/json;charset=UTF-8'
741-
}
742-
});
695+
const res = await createReviewAssignments(periodId, newAssignments, csrf);
743696
if (res.error) return;
744697

745698
newAssignments = sortMembers(res.payload.data);
@@ -949,16 +902,7 @@ const TeamReviews = ({ onBack, periodId }) => {
949902
};
950903

951904
const approveReviewAssignment = async (assignment, approved) => {
952-
const res = await resolve({
953-
method: assignment.id === null ? 'POST' : 'PUT',
954-
url: reviewAssignmentsUrl,
955-
headers: {
956-
Accept: 'application/json',
957-
'Content-Type': 'application/json;charset=UTF-8',
958-
'X-CSRF-Header': csrf
959-
},
960-
data: { ...assignment, approved }
961-
});
905+
await updateReviewAssignment({ ...assignment, approved }, csrf);
962906
};
963907

964908
const visibleTeamMembers = () => {

0 commit comments

Comments
 (0)