Skip to content

Commit

Permalink
Implement archive room functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-fam committed Apr 23, 2023
1 parent d9f1893 commit 3793684
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 100 deletions.
100 changes: 50 additions & 50 deletions bootstrap/modheaders.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/client/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { __prod__ } from "../constants";
const hostname = __prod__
? window.location.hostname +
(window.location.port ? ":" + window.location.port : "")
: "localhost:5000";
: `${window.location.hostname}:5000`;

const httpLink = new HttpLink({
uri: `http${__prod__ ? "s" : ""}://${hostname}/graphql`,
Expand Down
1 change: 0 additions & 1 deletion src/client/components/queue/Queue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Tooltip,
UnorderedList,
useColorModeValue,
useMediaQuery,
} from "@chakra-ui/react";
import React from "react";
import {
Expand Down
17 changes: 13 additions & 4 deletions src/client/components/queue/RoomSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ type Props = {
isStaff: boolean;
selected: string;
onSelect: (roomId: string) => void;
rooms: [roomId: string, roomName: string, isActive: boolean][];
rooms: [
roomId: string,
roomName: string,
isActive: boolean,
archived: boolean
][];
};

export const RoomSelector: React.FC<Props> = ({
Expand All @@ -27,10 +32,14 @@ export const RoomSelector: React.FC<Props> = ({
<option value="default" disabled>
Choose an option
</option>
{rooms.map(([roomId, roomName, isActive]) => (
{rooms.map(([roomId, roomName, isActive, archived]) => (
<option key={roomId} value={roomId}>
{(!isStaff || !isActive) && `${roomName}`}
{isStaff && isActive && `${roomName} (active)`}
{(!isStaff || (isActive && !archived)) && `${roomName}`}
{isStaff && archived && `${roomName} (archived)`}
{isStaff &&
!archived &&
!isActive &&
`${roomName} (inactive)`}
</option>
))}
</Select>
Expand Down
6 changes: 1 addition & 5 deletions src/client/containers/CoursePageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import {
useUpdateQueueMutation,
} from "../generated/graphql";
import {
Alert,
AlertDescription,
AlertIcon,
AlertTitle,
Button,
Flex,
FormControl,
Expand All @@ -42,7 +38,6 @@ import {
Input,
Text,
useDisclosure,
useMediaQuery,
useToast,
} from "@chakra-ui/react";
import { QuestionProps } from "./QuestionContainer";
Expand Down Expand Up @@ -434,6 +429,7 @@ export const CoursePageContainer: React.FC<Props> = () => {
room.id,
room.name,
room.isActive,
room.archived,
]) || [],
([, name, isActive]) => [!isActive, name]
)}
Expand Down
82 changes: 69 additions & 13 deletions src/client/containers/RoomPageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { UserContext } from "../utils/user";
import { Map } from "immutable";
import {
RoomInput,
Room as GraphQLRoom,
StaffRole,
UpdateRoomMutation,
useAddRoomMutation,
useDeleteRoomMutation,
useUpdateRoomMutation,
WeeklyEvent,
useArchiveRoomMutation,
} from "../generated/graphql";
import { Form, Formik } from "formik";
import {
Expand All @@ -38,12 +40,20 @@ import { RoomDeleteAlert } from "../components/room/RoomDeleteAlert";

type Props = {};

const placeholderRoom: RoomInput = {
const placeholderRoom: Room = {
id: "",
name: "",
capacity: 0,
enforceCapacity: false,
manuallyDisabled: false,
activeTimes: [],
archived: false,
};

type Room = Pick<
GraphQLRoom,
"id" | "name" | "capacity" | "enforceCapacity" | "archived"
> & {
activeTimes: Pick<WeeklyEvent, "startTime" | "endTime" | "day">[];
};

export const RoomPageContainer: React.FC<Props> = () => {
Expand All @@ -58,8 +68,17 @@ export const RoomPageContainer: React.FC<Props> = () => {
onOpen: openDeleteAlert,
} = useDisclosure();
const [courses, setCourses] = useState<
Map<string, { [key: string]: RoomInput }>
Map<string, { [key: string]: Room }>
>(Map());
const isCoordinator = useMemo(
() =>
user.getCourseStaff.some(
(courseStaff) =>
courseStaff.role === StaffRole.Coordinator &&
courseStaff.course.id === chosenCourse
),
[user.getCourseStaff, chosenCourse]
);
const toast = useToast();
const [
updateRoomMutation,
Expand All @@ -73,6 +92,10 @@ export const RoomPageContainer: React.FC<Props> = () => {
deleteRoomMutation,
{ data: deleteRoomMutationData, loading: deleteRoomMutationLoading },
] = useMutationWithError(useDeleteRoomMutation, { errorPolicy: "all" });
const [
archiveRoomMutation,
{ data: archiveRoomMutationData, loading: archiveRoomMutationLoading },
] = useMutationWithError(useArchiveRoomMutation, { errorPolicy: "all" });
useEffect(() => {
document.title = "Manage Rooms";
}, []);
Expand All @@ -82,15 +105,16 @@ export const RoomPageContainer: React.FC<Props> = () => {
setChosenRoom("");
}, [chosenCourse]);
const updateRoom = useCallback(
(room: UpdateRoomMutation["updateRoom"]) => {
(room: Room) => {
setCourses((prev) =>
prev.set(chosenCourse, {
...prev.get(chosenCourse),
[room.id]: {
id: room.id,
name: room.name,
capacity: room.capacity,
enforceCapacity: room.enforceCapacity,
manuallyDisabled: room.manuallyDisabled,
archived: room.archived,
activeTimes: room.activeTimes,
},
})
Expand Down Expand Up @@ -127,6 +151,12 @@ export const RoomPageContainer: React.FC<Props> = () => {
const updatedRoom = updateRoomMutationData.updateRoom;
updateRoom(updatedRoom);
}, [updateRoomMutationData, updateRoom]);
useEffect(() => {
if (!archiveRoomMutationData) {
return;
}
updateRoom(archiveRoomMutationData.archiveRoom);
}, [archiveRoomMutationData, updateRoom]);
useEffect(() => {
if (!addRoomMutationData) {
return;
Expand All @@ -150,16 +180,17 @@ export const RoomPageContainer: React.FC<Props> = () => {
prev.set(
courseStaff.course.id,
courseStaff.course.rooms.reduce<{
[key: string]: RoomInput;
[key: string]: Room;
}>(
(prevValue, currentRoom) => ({
...prevValue,
[currentRoom.id]: {
id: currentRoom.id,
name: currentRoom.name,
capacity: currentRoom.capacity,
enforceCapacity: currentRoom.enforceCapacity,
manuallyDisabled: currentRoom.manuallyDisabled,
activeTimes: currentRoom.activeTimes,
archived: currentRoom.archived,
},
}),
{}
Expand All @@ -168,7 +199,7 @@ export const RoomPageContainer: React.FC<Props> = () => {
);
});
}, [user]);
const room = useMemo<RoomInput>(() => {
const room = useMemo<Room>(() => {
if (isAdding) {
return placeholderRoom;
} else {
Expand Down Expand Up @@ -250,10 +281,6 @@ export const RoomPageContainer: React.FC<Props> = () => {
label="Enforce Capacity:"
name="enforceCapacity"
/>
<FormikCheckbox
label="Disabled:"
name="manuallyDisabled"
/>
<FormikActiveTimeInput
name="activeTimes"
label="Weekly Active Times"
Expand All @@ -270,6 +297,35 @@ export const RoomPageContainer: React.FC<Props> = () => {
Save
</Button>
{!isAdding && (
<Button
isLoading={
archiveRoomMutationLoading
}
colorScheme={
room.archived
? "green"
: "orange"
}
variant={
!room.archived
? "solid"
: "outline"
}
onClick={() =>
archiveRoomMutation({
variables: {
roomId: chosenRoom,
archive: !room.archived,
},
})
}
>
{room.archived
? "Restore"
: "Archive"}
</Button>
)}
{!isAdding && isCoordinator && (
<Button
colorScheme="red"
isLoading={
Expand Down
Loading

0 comments on commit 3793684

Please sign in to comment.