Skip to content

Commit 3793684

Browse files
committed
Implement archive room functionality
1 parent d9f1893 commit 3793684

File tree

12 files changed

+269
-100
lines changed

12 files changed

+269
-100
lines changed

bootstrap/modheaders.json

+50-50
Large diffs are not rendered by default.

src/client/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { __prod__ } from "../constants";
1616
const hostname = __prod__
1717
? window.location.hostname +
1818
(window.location.port ? ":" + window.location.port : "")
19-
: "localhost:5000";
19+
: `${window.location.hostname}:5000`;
2020

2121
const httpLink = new HttpLink({
2222
uri: `http${__prod__ ? "s" : ""}://${hostname}/graphql`,

src/client/components/queue/Queue.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
Tooltip,
1212
UnorderedList,
1313
useColorModeValue,
14-
useMediaQuery,
1514
} from "@chakra-ui/react";
1615
import React from "react";
1716
import {

src/client/components/queue/RoomSelector.tsx

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ type Props = {
55
isStaff: boolean;
66
selected: string;
77
onSelect: (roomId: string) => void;
8-
rooms: [roomId: string, roomName: string, isActive: boolean][];
8+
rooms: [
9+
roomId: string,
10+
roomName: string,
11+
isActive: boolean,
12+
archived: boolean
13+
][];
914
};
1015

1116
export const RoomSelector: React.FC<Props> = ({
@@ -27,10 +32,14 @@ export const RoomSelector: React.FC<Props> = ({
2732
<option value="default" disabled>
2833
Choose an option
2934
</option>
30-
{rooms.map(([roomId, roomName, isActive]) => (
35+
{rooms.map(([roomId, roomName, isActive, archived]) => (
3136
<option key={roomId} value={roomId}>
32-
{(!isStaff || !isActive) && `${roomName}`}
33-
{isStaff && isActive && `${roomName} (active)`}
37+
{(!isStaff || (isActive && !archived)) && `${roomName}`}
38+
{isStaff && archived && `${roomName} (archived)`}
39+
{isStaff &&
40+
!archived &&
41+
!isActive &&
42+
`${roomName} (inactive)`}
3443
</option>
3544
))}
3645
</Select>

src/client/containers/CoursePageContainer.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ import {
3030
useUpdateQueueMutation,
3131
} from "../generated/graphql";
3232
import {
33-
Alert,
34-
AlertDescription,
35-
AlertIcon,
36-
AlertTitle,
3733
Button,
3834
Flex,
3935
FormControl,
@@ -42,7 +38,6 @@ import {
4238
Input,
4339
Text,
4440
useDisclosure,
45-
useMediaQuery,
4641
useToast,
4742
} from "@chakra-ui/react";
4843
import { QuestionProps } from "./QuestionContainer";
@@ -434,6 +429,7 @@ export const CoursePageContainer: React.FC<Props> = () => {
434429
room.id,
435430
room.name,
436431
room.isActive,
432+
room.archived,
437433
]) || [],
438434
([, name, isActive]) => [!isActive, name]
439435
)}

src/client/containers/RoomPageContainer.tsx

+69-13
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import { UserContext } from "../utils/user";
1010
import { Map } from "immutable";
1111
import {
1212
RoomInput,
13+
Room as GraphQLRoom,
1314
StaffRole,
14-
UpdateRoomMutation,
1515
useAddRoomMutation,
1616
useDeleteRoomMutation,
1717
useUpdateRoomMutation,
18+
WeeklyEvent,
19+
useArchiveRoomMutation,
1820
} from "../generated/graphql";
1921
import { Form, Formik } from "formik";
2022
import {
@@ -38,12 +40,20 @@ import { RoomDeleteAlert } from "../components/room/RoomDeleteAlert";
3840

3941
type Props = {};
4042

41-
const placeholderRoom: RoomInput = {
43+
const placeholderRoom: Room = {
44+
id: "",
4245
name: "",
4346
capacity: 0,
4447
enforceCapacity: false,
45-
manuallyDisabled: false,
4648
activeTimes: [],
49+
archived: false,
50+
};
51+
52+
type Room = Pick<
53+
GraphQLRoom,
54+
"id" | "name" | "capacity" | "enforceCapacity" | "archived"
55+
> & {
56+
activeTimes: Pick<WeeklyEvent, "startTime" | "endTime" | "day">[];
4757
};
4858

4959
export const RoomPageContainer: React.FC<Props> = () => {
@@ -58,8 +68,17 @@ export const RoomPageContainer: React.FC<Props> = () => {
5868
onOpen: openDeleteAlert,
5969
} = useDisclosure();
6070
const [courses, setCourses] = useState<
61-
Map<string, { [key: string]: RoomInput }>
71+
Map<string, { [key: string]: Room }>
6272
>(Map());
73+
const isCoordinator = useMemo(
74+
() =>
75+
user.getCourseStaff.some(
76+
(courseStaff) =>
77+
courseStaff.role === StaffRole.Coordinator &&
78+
courseStaff.course.id === chosenCourse
79+
),
80+
[user.getCourseStaff, chosenCourse]
81+
);
6382
const toast = useToast();
6483
const [
6584
updateRoomMutation,
@@ -73,6 +92,10 @@ export const RoomPageContainer: React.FC<Props> = () => {
7392
deleteRoomMutation,
7493
{ data: deleteRoomMutationData, loading: deleteRoomMutationLoading },
7594
] = useMutationWithError(useDeleteRoomMutation, { errorPolicy: "all" });
95+
const [
96+
archiveRoomMutation,
97+
{ data: archiveRoomMutationData, loading: archiveRoomMutationLoading },
98+
] = useMutationWithError(useArchiveRoomMutation, { errorPolicy: "all" });
7699
useEffect(() => {
77100
document.title = "Manage Rooms";
78101
}, []);
@@ -82,15 +105,16 @@ export const RoomPageContainer: React.FC<Props> = () => {
82105
setChosenRoom("");
83106
}, [chosenCourse]);
84107
const updateRoom = useCallback(
85-
(room: UpdateRoomMutation["updateRoom"]) => {
108+
(room: Room) => {
86109
setCourses((prev) =>
87110
prev.set(chosenCourse, {
88111
...prev.get(chosenCourse),
89112
[room.id]: {
113+
id: room.id,
90114
name: room.name,
91115
capacity: room.capacity,
92116
enforceCapacity: room.enforceCapacity,
93-
manuallyDisabled: room.manuallyDisabled,
117+
archived: room.archived,
94118
activeTimes: room.activeTimes,
95119
},
96120
})
@@ -127,6 +151,12 @@ export const RoomPageContainer: React.FC<Props> = () => {
127151
const updatedRoom = updateRoomMutationData.updateRoom;
128152
updateRoom(updatedRoom);
129153
}, [updateRoomMutationData, updateRoom]);
154+
useEffect(() => {
155+
if (!archiveRoomMutationData) {
156+
return;
157+
}
158+
updateRoom(archiveRoomMutationData.archiveRoom);
159+
}, [archiveRoomMutationData, updateRoom]);
130160
useEffect(() => {
131161
if (!addRoomMutationData) {
132162
return;
@@ -150,16 +180,17 @@ export const RoomPageContainer: React.FC<Props> = () => {
150180
prev.set(
151181
courseStaff.course.id,
152182
courseStaff.course.rooms.reduce<{
153-
[key: string]: RoomInput;
183+
[key: string]: Room;
154184
}>(
155185
(prevValue, currentRoom) => ({
156186
...prevValue,
157187
[currentRoom.id]: {
188+
id: currentRoom.id,
158189
name: currentRoom.name,
159190
capacity: currentRoom.capacity,
160191
enforceCapacity: currentRoom.enforceCapacity,
161-
manuallyDisabled: currentRoom.manuallyDisabled,
162192
activeTimes: currentRoom.activeTimes,
193+
archived: currentRoom.archived,
163194
},
164195
}),
165196
{}
@@ -168,7 +199,7 @@ export const RoomPageContainer: React.FC<Props> = () => {
168199
);
169200
});
170201
}, [user]);
171-
const room = useMemo<RoomInput>(() => {
202+
const room = useMemo<Room>(() => {
172203
if (isAdding) {
173204
return placeholderRoom;
174205
} else {
@@ -250,10 +281,6 @@ export const RoomPageContainer: React.FC<Props> = () => {
250281
label="Enforce Capacity:"
251282
name="enforceCapacity"
252283
/>
253-
<FormikCheckbox
254-
label="Disabled:"
255-
name="manuallyDisabled"
256-
/>
257284
<FormikActiveTimeInput
258285
name="activeTimes"
259286
label="Weekly Active Times"
@@ -270,6 +297,35 @@ export const RoomPageContainer: React.FC<Props> = () => {
270297
Save
271298
</Button>
272299
{!isAdding && (
300+
<Button
301+
isLoading={
302+
archiveRoomMutationLoading
303+
}
304+
colorScheme={
305+
room.archived
306+
? "green"
307+
: "orange"
308+
}
309+
variant={
310+
!room.archived
311+
? "solid"
312+
: "outline"
313+
}
314+
onClick={() =>
315+
archiveRoomMutation({
316+
variables: {
317+
roomId: chosenRoom,
318+
archive: !room.archived,
319+
},
320+
})
321+
}
322+
>
323+
{room.archived
324+
? "Restore"
325+
: "Archive"}
326+
</Button>
327+
)}
328+
{!isAdding && isCoordinator && (
273329
<Button
274330
colorScheme="red"
275331
isLoading={

0 commit comments

Comments
 (0)