-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Button, Modal } from "semantic-ui-react"; | ||
|
||
interface FinishConfirmModalProps { | ||
finishFunc: () => void; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
closeFunc: () => void; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
open: boolean; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
const FinishConfirmModal = (props: FinishConfirmModalProps) => { | ||
const { finishFunc, closeFunc, open } = props; | ||
|
||
return ( | ||
<Modal open={open}> | ||
<Modal.Header>Finish Confirmation</Modal.Header> | ||
<Modal.Content> | ||
<Modal.Description> | ||
You are about to finish a question that you did not start. | ||
Is this intended? | ||
</Modal.Description> | ||
</Modal.Content> | ||
<Modal.Actions> | ||
<Button content="Cancel" onClick={closeFunc} /> | ||
<Button | ||
content="Finish" | ||
loading={false} | ||
color="green" | ||
onClick={finishFunc} | ||
/> | ||
</Modal.Actions> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default FinishConfirmModal; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import RejectQuestionModal from "./RejectQuestionModal"; | |
import { AuthUserContext } from "../../../context/auth"; | ||
import { Question, QuestionStatus, User } from "../../../types"; | ||
import MessageQuestionModal from "./MessageQuestionModal"; | ||
import FinishConfirmModal from "./FinishConfirmModal"; | ||
import LinkedText from "../../common/ui/LinkedText"; | ||
|
||
export const fullName = (user: User) => `${user.firstName} ${user.lastName}`; | ||
|
@@ -24,6 +25,7 @@ interface QuestionCardProps { | |
notifs: boolean; | ||
setNotifs: (boolean) => void; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
} | ||
|
||
const QuestionCard = (props: QuestionCardProps) => { | ||
const { question, mutate: mutateQuestion, notifs, setNotifs } = props; | ||
const { id: questionId, askedBy } = question; | ||
|
@@ -36,6 +38,7 @@ const QuestionCard = (props: QuestionCardProps) => { | |
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
const [open, setOpen] = useState(false); | ||
const [messageModalOpen, setMessageModalOpen] = useState(false); | ||
const [finishConfirmModalOpen, setFinishConfirmModalOpen] = useState(false); | ||
|
||
// save notification preference for when an instructor answers a question | ||
const [lastNotif, setLastNotif] = useState(notifs); | ||
|
@@ -58,8 +61,17 @@ const QuestionCard = (props: QuestionCardProps) => { | |
}; | ||
|
||
const onFinish = async () => { | ||
setNotifs(lastNotif); // resets notification preference when finished answering question | ||
await mutateQuestion(questionId, { status: QuestionStatus.ANSWERED }); | ||
if ( | ||
question.respondedToBy!.username === user.username || | ||
This comment has been minimized.
Sorry, something went wrong. |
||
finishConfirmModalOpen | ||
) { | ||
setNotifs(lastNotif); // resets notification preference when finished answering question | ||
await mutateQuestion(questionId, { | ||
status: QuestionStatus.ANSWERED, | ||
}); | ||
} else { | ||
setFinishConfirmModalOpen(true); | ||
} | ||
}; | ||
|
||
const onUndo = async () => { | ||
|
@@ -94,6 +106,11 @@ const QuestionCard = (props: QuestionCardProps) => { | |
closeFunc={() => setMessageModalOpen(false)} | ||
mutate={mutateQuestion} | ||
/> | ||
<FinishConfirmModal | ||
open={finishConfirmModalOpen} | ||
finishFunc={onFinish} | ||
This comment has been minimized.
Sorry, something went wrong.
esinx
Member
|
||
closeFunc={() => setMessageModalOpen(false)} | ||
/> | ||
<Segment attached="top" color="blue" clearing> | ||
<div | ||
style={{ | ||
|
@@ -239,19 +256,17 @@ const QuestionCard = (props: QuestionCardProps) => { | |
/> | ||
)} | ||
{/* if response started, then some user responded */} | ||
{question.timeResponseStarted && | ||
question.respondedToBy!.username === | ||
user.username && ( | ||
<Button | ||
compact | ||
size="mini" | ||
color="green" | ||
content="Finish" | ||
disabled={isLoading()} | ||
onClick={onFinish} | ||
loading={false} | ||
/> | ||
)} | ||
{question.timeResponseStarted && ( | ||
<Button | ||
compact | ||
size="mini" | ||
color="green" | ||
content="Finish" | ||
disabled={isLoading()} | ||
onClick={onFinish} | ||
loading={false} | ||
/> | ||
)} | ||
{question.timeResponseStarted && | ||
question.videoChatUrl && ( | ||
<a | ||
|
1 comment
on commit 79b4530
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks... fine to me but can improve
onFinish