Skip to content

Commit

Permalink
Remove reason modal when skipping task (#1766)
Browse files Browse the repository at this point in the history
issue #1756
  • Loading branch information
Mekacher-Anis committed Feb 20, 2023
1 parent d396575 commit afc0670
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 81 deletions.
3 changes: 0 additions & 3 deletions website/src/components/Buttons/Buttons.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ComponentMeta } from "@storybook/react";

import { LikertButtons } from "./LikertButtons";
import { SkipButton } from "./Skip";
import { SubmitButton } from "./Submit";

export default {
Expand All @@ -20,5 +19,3 @@ export const Likert = () => {
></LikertButtons>
);
};

export const Skip = () => <SkipButton onSkip={() => console.log("onClick")}>Skip</SkipButton>;
60 changes: 0 additions & 60 deletions website/src/components/Buttons/Skip.tsx

This file was deleted.

9 changes: 5 additions & 4 deletions website/src/components/Survey/TaskControls.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Box, Flex, IconButton, Progress, Tooltip, useColorModeValue } from "@chakra-ui/react";
import { Box, Button, Flex, IconButton, Progress, Tooltip, useColorModeValue } from "@chakra-ui/react";
import { Edit2 } from "lucide-react";
import { useTranslation } from "next-i18next";
import { SkipButton } from "src/components/Buttons/Skip";
import { SubmitButton } from "src/components/Buttons/Submit";
import { TaskInfo } from "src/components/TaskInfo/TaskInfo";
import { TaskStatus } from "src/components/Tasks/Task";
Expand All @@ -14,7 +13,7 @@ export interface TaskControlsProps {
onEdit: () => void;
onReview: () => void;
onSubmit: () => void;
onSkip: (reason: string) => void;
onSkip: () => void;
}

export const TaskControls = ({
Expand All @@ -37,7 +36,9 @@ export const TaskControls = ({
<Flex width={["full", "fit-content"]} justify="center" ml="auto" gap={2}>
{taskStatus.mode === "EDIT" ? (
<>
<SkipButton onSkip={onSkip} />
<Button size="lg" variant="outline" onClick={onSkip}>
{t("skip")}
</Button>
<SubmitButton
colorScheme="blue"
data-cy="review"
Expand Down
15 changes: 6 additions & 9 deletions website/src/hooks/tasks/useGenericTaskAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ export const useGenericTaskAPI = <TaskType extends BaseTask, ResponseContent = A
}, [requestNewTask]);

const { trigger: sendRejection } = useSWRMutation("/api/reject_task", post, { onSuccess: skipTask });
const rejectTask = useCallback(
async (reason: string) => {
if (response.taskAvailability !== "AVAILABLE") {
throw new Error("Cannot reject task that is not yet ready");
}
await sendRejection({ id: response.id, reason });
},
[response, sendRejection]
);
const rejectTask = useCallback(async () => {
if (response.taskAvailability !== "AVAILABLE") {
throw new Error("Cannot reject task that is not yet ready");
}
await sendRejection({ id: response.id });
}, [response, sendRejection]);

const completeTask = useCallback(
async (content: ResponseContent) => {
Expand Down
4 changes: 2 additions & 2 deletions website/src/lib/oasst_api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ export class OasstApiClient {
return this.post(`/api/v1/tasks/${taskId}/ack`, { message_id: messageId });
}

async nackTask(taskId: string, reason: string): Promise<null> {
return this.post(`/api/v1/tasks/${taskId}/nack`, { reason });
async nackTask(taskId: string): Promise<null> {
return this.post(`/api/v1/tasks/${taskId}/nack`, {});
}

// TODO return a strongly typed Task?
Expand Down
4 changes: 2 additions & 2 deletions website/src/pages/api/reject_task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import prisma from "src/lib/prismadb";

const handler = withoutRole("banned", async (req, res, token) => {
// Parse out the local task ID and the interaction contents.
const { id: frontendId, reason } = req.body;
const { id: frontendId } = req.body;

const [oasstApiClient, registeredTask] = await Promise.all([
createApiClient(token),
Expand All @@ -15,7 +15,7 @@ const handler = withoutRole("banned", async (req, res, token) => {
const taskId = (registeredTask.task as Prisma.JsonObject).id as string;

// Update the backend with the rejection
await oasstApiClient.nackTask(taskId, reason);
await oasstApiClient.nackTask(taskId);

// Send the results to the client.
res.status(200).json({});
Expand Down
2 changes: 1 addition & 1 deletion website/src/types/Hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type TaskApiHook<Task extends BaseTask, ResponseContent> = {
response: TaskResponse<Task>;
isLoading: boolean;
completeTask: (interaction: ResponseContent) => Promise<void>;
rejectTask: (reason: string) => Promise<void>;
rejectTask: () => Promise<void>;
};

export type TaskApiHooks = Record<TaskType, (args: TaskType) => TaskApiHook<BaseTask, AllTaskReplies>>;

0 comments on commit afc0670

Please sign in to comment.