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

[ITG-30] Stworzyć button delete #11

Merged
merged 2 commits into from
Apr 8, 2022
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
2 changes: 2 additions & 0 deletions cabra/src/api/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const getTasks = {
run: () => axios.get<ITask[]>("/tasks"),
};

export const deleteTask = (id: string) => axios.delete<ITask>(`/tasks/${id}`);

export const updateTask = (id: string, data: TaskApiInput) =>
axios.put<ITask>(`/tasks/${id}`, data);

Expand Down
20 changes: 17 additions & 3 deletions cabra/src/pages/TaskDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import "twin.macro";

import { ArrowLeftIcon, PencilAltIcon } from "@heroicons/react/solid";
import {
ArrowLeftIcon,
PencilAltIcon,
TrashIcon,
} from "@heroicons/react/solid";
import { Link, useNavigate, useParams } from "react-router-dom";
import { deleteTask, getTask } from "../api/tasks";
import { useMutation, useQuery } from "react-query";

import Layout from "./components/Layout";
import NavigationButton from "./components/NavigationButton";
import Task from "./components/Task";
import { getTask } from "../api/tasks";
import { routeHelpers } from "../routes";
import { useQuery } from "react-query";

export default function TaskDetailsPage() {
const navigate = useNavigate();
Expand All @@ -22,6 +26,10 @@ export default function TaskDetailsPage() {
}
);

const removeTask = useMutation(() => deleteTask(id), {
onSuccess: () => navigate(-1),
});

if (isLoading || !data) return <Layout>Loading</Layout>;

return (
Expand All @@ -41,6 +49,12 @@ export default function TaskDetailsPage() {
<PencilAltIcon height={20} width={20} /> Edit
</NavigationButton>
</Link>
<NavigationButton
tw="text-stone-50 bg-red-500"
onClick={() => removeTask.mutateAsync()}
>
<TrashIcon height={20} width={20} /> Delete
</NavigationButton>
</div>
</div>
</Layout>
Expand Down