Skip to content

Commit bb8edfb

Browse files
committed
Finish polish on facilitator messages
1 parent dc430a6 commit bb8edfb

File tree

3 files changed

+73
-14
lines changed

3 files changed

+73
-14
lines changed

backend/services/implementations/notificationService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ class NotificationService implements INotificationService {
4242
);
4343
populatedNotification = await notification.populate(
4444
"helpRequest.unit",
45-
"title",
45+
"title displayIndex",
4646
);
4747
populatedNotification = await notification.populate(
4848
"helpRequest.module",
49-
"title",
49+
"title pages",
5050
);
5151
populatedNotification = await notification.populate(
5252
"helpRequest.page",

frontend/src/components/user_management/chat-with-learner/ChatMessageItem.tsx

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import { Document, Thumbnail } from "react-pdf";
44
import { Link } from "react-router-dom";
55
import { Notification } from "../../../types/NotificationTypes";
66
import { formatTimeElasped } from "../../../utils/DateUtils";
7-
import { isLessonPage } from "../../../types/CourseTypes";
7+
import { isActivityPage, isLessonPage } from "../../../types/CourseTypes";
88
import * as Routes from "../../../constants/Routes";
99
import NotificationAPIClient from "../../../APIClients/NotificationAPIClient";
10+
import { useCourseUnits } from "../../../contexts/CourseUnitsContext";
11+
import { questionTypeIcons } from "../../../constants/ActivityLabels";
1012

1113
export default function ChatMessageItem({
1214
message,
@@ -16,6 +18,7 @@ export default function ChatMessageItem({
1618
refreshNotifs: () => void;
1719
}) {
1820
const theme = useTheme();
21+
const { courseUnits } = useCourseUnits();
1922

2023
const handleMarkAsRead = async (
2124
event: React.MouseEvent<HTMLButtonElement>,
@@ -26,6 +29,21 @@ export default function ChatMessageItem({
2629
refreshNotifs();
2730
};
2831

32+
// @ts-expect-error populate gives _id instead of id
33+
// eslint-disable-next-line no-underscore-dangle
34+
const unit = courseUnits.find((u) => u.id === message.helpRequest.unit._id);
35+
const moduleIndex =
36+
// @ts-expect-error populate gives _id instead of id
37+
// eslint-disable-next-line no-underscore-dangle
38+
(unit?.modules.findIndex((m) => m.id === message.helpRequest.module._id) ??
39+
-1) + 1;
40+
const pageIndex =
41+
(message.helpRequest.module.pages.findIndex(
42+
// @ts-expect-error populate gives _id instead of id
43+
// eslint-disable-next-line no-underscore-dangle
44+
(p) => p === message.helpRequest.page._id,
45+
) ?? -1) + 1;
46+
2947
return (
3048
<Link
3149
// @ts-expect-error populate gives _id instead of id
@@ -110,17 +128,57 @@ export default function ChatMessageItem({
110128
)}
111129
</Box>
112130
<Typography variant="bodySmall">{message.message}</Typography>
113-
{isLessonPage(message.helpRequest.page) && (
114-
<Document
115-
file={message.helpRequest.page.pdfUrl}
116-
loading="Loading..."
117-
>
118-
<Thumbnail
119-
pageNumber={message.helpRequest.page.pageIndex}
120-
width={330}
121-
/>
122-
</Document>
123-
)}
131+
<Box
132+
sx={{
133+
width: "300px",
134+
height: "183px",
135+
border: "1px solid",
136+
borderColor: theme.palette.Neutral[400],
137+
borderRadius: "7.252px",
138+
overflow: "hidden",
139+
display: "flex",
140+
flexDirection: "column",
141+
alignItems: "center",
142+
justifyContent: "center",
143+
}}
144+
>
145+
<>
146+
<Box
147+
sx={{
148+
width: "100%",
149+
height: "156px",
150+
overflow: "hidden",
151+
display: "flex",
152+
alignItems: "center",
153+
justifyContent: "center",
154+
}}
155+
>
156+
{isLessonPage(message.helpRequest.page) && (
157+
<Document
158+
file={message.helpRequest.page.pdfUrl}
159+
loading="Loading..."
160+
>
161+
<Thumbnail
162+
pageNumber={message.helpRequest.page.pageIndex}
163+
width={300}
164+
/>
165+
</Document>
166+
)}
167+
{isActivityPage(message.helpRequest.page) &&
168+
questionTypeIcons[message.helpRequest.page.questionType]}
169+
</Box>
170+
<Box width="100%" height="27px">
171+
<Typography
172+
variant="labelLarge"
173+
color={theme.palette.Facilitator.Dark.Default}
174+
sx={{ ml: 1 }}
175+
>
176+
MODULE {message.helpRequest.unit.displayIndex}.{moduleIndex}:{" "}
177+
{message.helpRequest.module.title} &gt; PAGE {pageIndex}
178+
</Typography>
179+
</Box>
180+
</>
181+
</Box>
124182
</Box>
125183
</Box>
126184
</Link>

frontend/src/types/HelpRequestType.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface HelpRequest {
1515
id: string;
1616
displayIndex: number;
1717
title: string;
18+
pages: string[]; // array of CoursePage IDs
1819
};
1920
page: CoursePage;
2021
completed: boolean;

0 commit comments

Comments
 (0)