From 853bd07b78cf9e65c8cbd8343c8685856bae96b7 Mon Sep 17 00:00:00 2001 From: Ryan Tanenholz <44756861+RockCrafts@users.noreply.github.com> Date: Sun, 13 Oct 2024 03:20:19 -0400 Subject: [PATCH] Refactored Queue Forms to make consistent with other forms and between each other --- .../CreateQueue/CreateQueue.tsx | 334 ------------ .../InstructorQueuePage.tsx | 4 +- .../InstructorQueuePage/QuestionCard.tsx | 24 +- .../InstructorQueuePage/QuestionTimer.tsx | 16 +- .../QueueCreate/QueueCreate.tsx | 99 ++++ .../InstructorQueuePage/QueueFormFields.tsx | 412 ++++++++++++++ .../QueueSettings/QueueForm.tsx | 501 ------------------ .../QueueSettings/QueueSettings.tsx | 4 +- .../QueueSettings/QueueSettingsForm.tsx | 142 +++++ .../InstructorQueuePage/timeupsound.mp3 | Bin 0 -> 21150 bytes 10 files changed, 683 insertions(+), 853 deletions(-) delete mode 100644 frontend/components/Course/InstructorQueuePage/CreateQueue/CreateQueue.tsx create mode 100644 frontend/components/Course/InstructorQueuePage/QueueCreate/QueueCreate.tsx create mode 100644 frontend/components/Course/InstructorQueuePage/QueueFormFields.tsx delete mode 100644 frontend/components/Course/InstructorQueuePage/QueueSettings/QueueForm.tsx create mode 100644 frontend/components/Course/InstructorQueuePage/QueueSettings/QueueSettingsForm.tsx create mode 100644 frontend/components/Course/InstructorQueuePage/timeupsound.mp3 diff --git a/frontend/components/Course/InstructorQueuePage/CreateQueue/CreateQueue.tsx b/frontend/components/Course/InstructorQueuePage/CreateQueue/CreateQueue.tsx deleted file mode 100644 index 436d19219..000000000 --- a/frontend/components/Course/InstructorQueuePage/CreateQueue/CreateQueue.tsx +++ /dev/null @@ -1,334 +0,0 @@ -import { useState, useMemo } from "react"; -import { Grid, Segment, Header, Form, Button } from "semantic-ui-react"; -import { mutateResourceListFunction } from "@pennlabs/rest-hooks/dist/types"; -import Snackbar from "@material-ui/core/Snackbar"; -import Alert from "@material-ui/lab/Alert"; -import { createQueue } from "../../../../hooks/data-fetching/course"; -import { Queue, VideoChatSetting } from "../../../../types"; - -interface CreateQueueProps { - courseId: number; - backFunc: () => void; - successFunc: () => void; - mutate: mutateResourceListFunction; -} - -interface QueueFormInput { - name: string; - description: string; - questionTemplate: string; - videoChatSetting: VideoChatSetting; - pinEnabled: boolean; - rateLimitEnabled: boolean; - rateLimitLength?: number; - rateLimitQuestions?: number; - rateLimitMinutes?: number; -} - -enum RateLimitFields { - RATE_LIMIT_QUESTIONS = "rateLimitQuestions", - RATE_LIMIT_MINUTES = "rateLimitMinutes", - RATE_LIMIT_LENGTH = "rateLimitLength", -} - -const castInt = (n: string): number | undefined => { - let casted: number | undefined = parseInt(n, 10); - if (isNaN(casted)) { - casted = undefined; - } - - return casted; -}; - -const CreateQueue = (props: CreateQueueProps) => { - const { courseId, backFunc, successFunc, mutate } = props; - /* STATE */ - const [error, setError] = useState(false); - const [input, setInput] = useState({ - name: "", - description: "", - questionTemplate: "", - videoChatSetting: VideoChatSetting.DISABLED, - pinEnabled: false, - rateLimitEnabled: false, - rateLimitLength: undefined, - rateLimitQuestions: undefined, - rateLimitMinutes: undefined, - }); - - const handleVideoChatInputChange = (e, { name }) => { - switch (name) { - case "videoChatRequired": - input.videoChatSetting = VideoChatSetting.REQUIRED; - break; - case "videoChatOptional": - input.videoChatSetting = VideoChatSetting.OPTIONAL; - break; - case "videoChatDisabled": - input.videoChatSetting = VideoChatSetting.DISABLED; - break; - } - setInput({ ...input }); - }; - - const handlePinInputChange = (e, { name }) => { - switch (name) { - case "pinEnabled": - input.pinEnabled = true; - break; - case "pinDisabled": - input.pinEnabled = false; - break; - } - setInput({ ...input }); - }; - - const isDisabled = useMemo(() => { - let invalidInps = !input.name || !input.description; - if (input.rateLimitEnabled) { - invalidInps = - invalidInps || - input.rateLimitLength === undefined || - (input.rateLimitLength !== undefined && - input.rateLimitLength < 0); - invalidInps = - invalidInps || - input.rateLimitQuestions === undefined || - (input.rateLimitQuestions !== undefined && - input.rateLimitQuestions <= 0); - invalidInps = - invalidInps || - input.rateLimitMinutes === undefined || - (input.rateLimitMinutes !== undefined && - input.rateLimitMinutes <= 0); - } - return invalidInps; - }, [input]); - - const [validQuestionRate, setValidQuestionRate] = useState(true); - const [validMinsRate, setValidMinsRate] = useState(true); - const [validLenRate, setValidLenRate] = useState(true); - const [mutateLoading, setRefetchLoading] = useState(false); - - /* HANDLER FUNCTIONS */ - const handleInputChange = (e, { name, value }) => { - input[name] = value; - if (name === RateLimitFields.RATE_LIMIT_QUESTIONS) { - input[name] = castInt(input[name]); - setValidQuestionRate(input[name] > 0); - } - - if (name === RateLimitFields.RATE_LIMIT_MINUTES) { - input[name] = castInt(input[name]); - setValidMinsRate(input[name] > 0); - } - - if (name === RateLimitFields.RATE_LIMIT_LENGTH) { - input[name] = castInt(input[name]); - setValidLenRate(input[name] >= 0); - } - setInput({ ...input }); - }; - - const onSubmit = async () => { - try { - await createQueue(courseId, input); - setRefetchLoading(true); - await mutate(-1, null); - setRefetchLoading(false); - backFunc(); - successFunc(); - } catch (e) { - setError(true); - } - }; - - return ( - - - -
Create New Queue
-
-
- - -
- - - - - - - - - - - - - - - setInput({ - ...input, - rateLimitEnabled: - !input.rateLimitEnabled, - }) - } - /> - - {input.rateLimitEnabled && ( - - - - - - - - - )} - - - - - - - - - - - - - - - -
- setOpen(true)}> - Archive - - } - > - Archive Queue - - You are about to archive this queue:{" "} - {queue.name}. - - - + setOpen(true)}> + Archive + + } + > + Archive Queue + + You are about to archive this queue:{" "} + {queue.name}. + + +