Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added confirmation dialog when skipping after entering text #3479

Merged
merged 5 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website/public/locales/de/tasks.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"available_task_count": "{{count}} Aufgaben verfügbar",
"skip_confirmation": "Sind Sie sicher das sie überspringen wollen?",
"classify_assistant_reply": {
"label": "Antwort des Assistenten klassifizieren",
"desc": "Labeln Sie die Antwort.",
Expand Down
1 change: 1 addition & 0 deletions website/public/locales/en/tasks.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"any_feedback_on_this_task": "Any feedback on this task?",
"available_task_count": "{{count}} tasks available",
"skip_confirmation": "Are you sure you want to skip?",
"default": {
"unchanged_title": "No changes",
"unchanged_message": "Are you sure you would like to continue?",
Expand Down
62 changes: 62 additions & 0 deletions website/src/components/Buttons/Skip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import {
Button,
ButtonProps,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
useDisclosure,
} from "@chakra-ui/react";
import { useTranslation } from "next-i18next";

interface SkipButtonProps extends ButtonProps {
onSkip: () => void;
confirmSkip: boolean;
}

export const SkipButton = ({ ...props }: SkipButtonProps) => {
const { t } = useTranslation();
const { isOpen, onOpen: showModal, onClose: closeModal } = useDisclosure();

const onClick = () => {
if (props.confirmSkip) {
showModal();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also can you only show the modal when the input is not empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm already doing that... that's what the confirmSkip flag is for. I'm setting that to true if taskstatus.replyValidity === "VALID" (see TaskControls.tsx), which corresponds to a non-empty reply field.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah thanks

} else {
props.onSkip();
}
};

const onConfirmedSkip = () => {
closeModal();
props.onSkip();
};

return (
<>
<Button size="lg" variant="solid" {...props} onClick={onClick}>
{t("skip")}
</Button>
<Modal isOpen={isOpen} onClose={closeModal}>
<ModalOverlay></ModalOverlay>
<ModalContent>
<ModalCloseButton></ModalCloseButton>
<ModalHeader>{t("skip")}</ModalHeader>
<ModalBody>
<div>{t("tasks:skip_confirmation")}</div>
</ModalBody>
<ModalFooter>
<Button mr={3} onClick={onConfirmedSkip}>
{t("yes")}
</Button>
<Button colorScheme="blue" onClick={closeModal}>
{t("no")}
</Button>
</ModalFooter>
</ModalContent>
</Modal>
</>
);
};
12 changes: 8 additions & 4 deletions website/src/components/Survey/TaskControls.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Button, Card, Flex, IconButton, Progress, Tooltip } from "@chakra-ui/react";
import { Card, Flex, IconButton, Progress, Tooltip } from "@chakra-ui/react";
import { Edit2 } from "lucide-react";
import { useTranslation } from "next-i18next";
import { SubmitButton } from "src/components/Buttons/Submit";
import { TaskInfo } from "src/components/TaskInfo/TaskInfo";
import { TaskStatus } from "src/components/Tasks/Task";
import { BaseTask } from "src/types/Task";

import { SkipButton } from "../Buttons/Skip";

export interface TaskControlsProps {
task: BaseTask;
taskStatus: TaskStatus;
Expand Down Expand Up @@ -39,9 +41,11 @@ export const TaskControls = ({
<Flex width={["full", "fit-content"]} justify="center" ml="auto" gap={2}>
{taskStatus.mode === "EDIT" ? (
<>
<Button size="lg" variant="outline" onClick={onSkip} isLoading={isRejecting}>
{t("skip")}
</Button>
<SkipButton
onSkip={onSkip}
confirmSkip={taskStatus.replyValidity === "VALID"}
isLoading={isRejecting}
></SkipButton>
<SubmitButton
colorScheme="blue"
data-cy="review"
Expand Down