Skip to content

Commit b9767f8

Browse files
committed
2024-11-12 - routes
1 parent 2387c4d commit b9767f8

File tree

5 files changed

+197
-16
lines changed

5 files changed

+197
-16
lines changed

web-ui/src/components/routes/Routes.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import KudosPage from '../../pages/KudosPage';
4343
import ManageKudosPage from '../../pages/ManageKudosPage';
4444
import SkillCategoriesPage from '../../pages/SkillCategoriesPage';
4545
import SkillCategoryEditPage from '../../pages/SkillCategoryEditPage';
46-
import FeedbackRequestForExternalRecipientPage from "../../pages/FeedbackRequestForExternalRecipientPage.jsx";
4746

4847
export default function Routes() {
4948
const { state } = useContext(AppContext);
@@ -200,9 +199,6 @@ export default function Routes() {
200199
<Route path="/feedback/submit">
201200
<FeedbackSubmitPage />
202201
</Route>
203-
<Route path="/feedbackExternalRecipient">
204-
<FeedbackRequestForExternalRecipientPage />
205-
</Route>
206202
<Route exact path="/admin/manage-kudos">
207203
<Header title="Manage Kudos"></Header>
208204
<ManageKudosPage />

web-ui/src/components/routes/RoutesFeedbackExternalRecipient.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React, { useContext } from 'react';
22
import { Switch, Route } from 'react-router-dom';
3-
import FeedbackRequestForExternalRecipientPage from "../../pages/FeedbackRequestForExternalRecipientPage.jsx";
43
import {AppFeedbackExternalRecipientContext} from "../../context/AppFeedbackExternalRecipientContext.jsx";
4+
import FeedbackSubmitForExternalRecipientPage from "../../pages/FeedbackSubmitPageForExternalRecipient.jsx";
55

66
export default function RoutesFeedbackExternalRecipient() {
77
const { state } = useContext(AppFeedbackExternalRecipientContext);
88

99
return (
1010
<Switch>
1111
<Route path="/feedbackExternalRecipient">
12-
<FeedbackRequestForExternalRecipientPage />
12+
<FeedbackSubmitForExternalRecipientPage />
1313
</Route>
1414
</Switch>
1515
);

web-ui/src/pages/FeedbackRequestForExternalRecipientPage.jsx

Lines changed: 0 additions & 9 deletions
This file was deleted.

web-ui/src/pages/FeedbackRequestPage.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import DateFnsUtils from '@date-io/date-fns';
3131
import { getFeedbackTemplate, softDeleteAdHocTemplates } from '../api/feedbacktemplate';
3232

3333
import './FeedbackRequestPage.css';
34-
import FeedbackRequestForExternalRecipientPage from "./FeedbackRequestForExternalRecipientPage.jsx";
3534
import FeedbackExternalRecipientSelector from "../components/feedback_external_recipient_selector/FeedbackExternalRecipientSelector.jsx";
3635

3736
const dateUtils = new DateFnsUtils();
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import React, { useContext, useEffect, useRef, useState } from 'react';
2+
import { styled } from '@mui/material/styles';
3+
import FeedbackSubmissionTips from '../components/feedback_submission_tips/FeedbackSubmissionTips';
4+
import FeedbackSubmitForm from '../components/feedback_submit_form/FeedbackSubmitForm';
5+
import TeamMemberReview from '../components/reviews/TeamMemberReview';
6+
import { useHistory, useLocation } from 'react-router-dom';
7+
import {
8+
selectCsrfToken,
9+
selectCurrentUser,
10+
selectProfile
11+
} from '../context/selectors';
12+
import { AppContext } from '../context/AppContext';
13+
import { getFeedbackRequestById } from '../api/feedback';
14+
import Typography from '@mui/material/Typography';
15+
import { UPDATE_TOAST } from '../context/actions';
16+
import * as queryString from 'query-string';
17+
18+
import './FeedbackRequestPage.css';
19+
20+
const PREFIX = 'FeedbackSubmitForExternalRecipientPage';
21+
const classes = {
22+
announcement: `${PREFIX}-announcement`
23+
};
24+
25+
const Root = styled('div')({
26+
[`& .${classes.announcement}`]: {
27+
textAlign: 'center',
28+
marginTop: '3em',
29+
['@media (max-width: 800px)']: {
30+
// eslint-disable-line no-useless-computed-key
31+
fontSize: '22px'
32+
}
33+
}
34+
});
35+
36+
const FeedbackSubmitForExternalRecipientPage = () => {
37+
const { state } = useContext(AppContext);
38+
const csrf = selectCsrfToken(state);
39+
const currentUserId = selectCurrentUser(state)?.id;
40+
const location = useLocation();
41+
const history = useHistory();
42+
const query = queryString.parse(location?.search);
43+
const tabs = query.tabs?.toString();
44+
const requestQuery = query.request?.toString();
45+
const selfRequestQuery = query.selfrequest?.toString();
46+
const [showTips, setShowTips] = useState(true);
47+
const [feedbackRequest, setFeedbackRequest] = useState(null);
48+
const [selfReviewRequest, setSelfReviewRequest] = useState(null);
49+
const [requestee, setRequestee] = useState(null);
50+
const [recipient, setRecipient] = useState(null);
51+
const [requestSubmitted, setRequestSubmitted] = useState(false);
52+
const [requestCanceled, setRequestCanceled] = useState(false);
53+
const feedbackRequestFetched = useRef(false);
54+
55+
function isManager(revieweeProfile) {
56+
const supervisorId = revieweeProfile?.supervisorid;
57+
return supervisorId === currentUserId;
58+
}
59+
60+
useEffect(() => {
61+
if (!requestQuery && !selfRequestQuery) {
62+
history.push('/checkins');
63+
window.snackDispatch({
64+
type: UPDATE_TOAST,
65+
payload: {
66+
severity: 'error',
67+
toast: 'No request present'
68+
}
69+
});
70+
}
71+
72+
async function getFeedbackRequest(query, cookie) {
73+
if (!currentUserId || !cookie || feedbackRequestFetched.current) {
74+
return null;
75+
}
76+
77+
// make call to the API
78+
let res = await getFeedbackRequestById(query, cookie);
79+
return res.payload &&
80+
res.payload.data &&
81+
res.payload.status === 200 &&
82+
!res.error
83+
? res.payload.data
84+
: null;
85+
}
86+
87+
if (csrf && currentUserId && requestQuery && !feedbackRequestFetched.current) {
88+
getFeedbackRequest(requestQuery, csrf).then(request => {
89+
if (request) {
90+
// Permission to view this feedback request will be checked later.
91+
if (
92+
request.status.toLowerCase() === 'submitted' ||
93+
request.submitDate
94+
) {
95+
setRequestSubmitted(true);
96+
setFeedbackRequest(request);
97+
} else if (request.status.toLowerCase() === 'canceled') {
98+
setRequestCanceled(true);
99+
} else {
100+
setFeedbackRequest(request);
101+
}
102+
} else {
103+
history.push('/checkins');
104+
window.snackDispatch({
105+
type: UPDATE_TOAST,
106+
payload: {
107+
severity: 'error',
108+
toast: "Can't find feedback request with that ID"
109+
}
110+
});
111+
}
112+
});
113+
}
114+
115+
if (csrf && currentUserId && selfRequestQuery) {
116+
getFeedbackRequest(selfRequestQuery, csrf).then(request => {
117+
if (request) {
118+
setSelfReviewRequest(request);
119+
}
120+
});
121+
}
122+
}, [csrf, currentUserId, requestQuery, history]);
123+
124+
useEffect(() => {
125+
if (feedbackRequest) {
126+
feedbackRequestFetched.current = true;
127+
}
128+
129+
if (feedbackRequestFetched.current) {
130+
const requesteeProfile = selectProfile(
131+
state,
132+
feedbackRequest?.requesteeId
133+
);
134+
setRequestee(requesteeProfile);
135+
136+
const recipientProfile = selectProfile(
137+
state,
138+
feedbackRequest?.recipientId
139+
);
140+
141+
// If this is our review or we are the manager of the reviewer we are
142+
// allowed to view this review.
143+
if (recipientProfile?.id != currentUserId &&
144+
!isManager(recipientProfile)) {
145+
// The current user is not the recipients's manager, we need to leave.
146+
history.push('/checkins');
147+
window.snackDispatch({
148+
type: UPDATE_TOAST,
149+
payload: {
150+
severity: 'error',
151+
toast: 'You are not authorized to perform this operation.'
152+
}
153+
});
154+
}
155+
}
156+
157+
if (selfReviewRequest) {
158+
const recipientProfile = selectProfile(
159+
state,
160+
selfReviewRequest?.recipientId
161+
);
162+
setRecipient(recipientProfile);
163+
}
164+
}, [feedbackRequest, selfReviewRequest, state]);
165+
166+
return (
167+
<Root className="feedback-submit-page">
168+
{requestCanceled ? (
169+
<Typography className={classes.announcement} variant="h3">
170+
This feedback request has been canceled.
171+
</Typography>
172+
) : tabs || requestSubmitted || selfReviewRequest ? (
173+
<TeamMemberReview
174+
reviews={[feedbackRequest]}
175+
selfReview={selfReviewRequest}
176+
memberProfile={recipient ?? requestee}
177+
/>
178+
) : (
179+
<>
180+
{feedbackRequest &&
181+
(showTips ? (
182+
<FeedbackSubmissionTips onNextClick={() => setShowTips(false)} />
183+
) : (
184+
<FeedbackSubmitForm
185+
requesteeName={requestee?.name}
186+
requestId={requestQuery}
187+
request={feedbackRequest}
188+
/>
189+
))}
190+
</>
191+
)}
192+
</Root>
193+
);
194+
};
195+
export default FeedbackSubmitForExternalRecipientPage;

0 commit comments

Comments
 (0)