@@ -1,21 +1,28 @@
|
||||
import queryString from "query-string";
|
||||
import {useLocation} from "react-router-dom";
|
||||
import {useQuery} from "@apollo/client";
|
||||
import {QUERY_ALL_TASKS_PAGINATED} from "../../graphql/tasks.queries.js";
|
||||
import {useMutation, useQuery} from "@apollo/client";
|
||||
import {
|
||||
MUTATION_TOGGLE_TASK_COMPLETED, MUTATION_TOGGLE_TASK_DELETED,
|
||||
QUERY_MY_TASKS_PAGINATED
|
||||
} from "../../graphql/tasks.queries.js";
|
||||
import {pageLimit} from "../../utils/config.js";
|
||||
import AlertComponent from "../alert/alert.component.jsx";
|
||||
import React from "react";
|
||||
import TaskListComponent from "./task-list.component.jsx";
|
||||
|
||||
export default function TaskListContainer() {
|
||||
export default function TaskListContainer({bodyshop, currentUser}) {
|
||||
const searchParams = queryString.parse(useLocation().search);
|
||||
const {page, sortcolumn, sortorder, search} = searchParams;
|
||||
const {page, sortcolumn, sortorder, deleted, completed} = searchParams;
|
||||
const {loading, error, data, refetch} = useQuery(
|
||||
QUERY_ALL_TASKS_PAGINATED,
|
||||
QUERY_MY_TASKS_PAGINATED,
|
||||
{
|
||||
fetchPolicy: "network-only",
|
||||
nextFetchPolicy: "network-only",
|
||||
variables: {
|
||||
bodyshop: bodyshop.id,
|
||||
user: currentUser.email,
|
||||
deleted: deleted === 'true',
|
||||
completed: completed === "true",
|
||||
offset: page ? (page - 1) * pageLimit : 0,
|
||||
limit: pageLimit,
|
||||
order: [
|
||||
@@ -30,6 +37,34 @@ export default function TaskListContainer() {
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const [toggleTaskCompleted] = useMutation(MUTATION_TOGGLE_TASK_COMPLETED);
|
||||
|
||||
const toggleCompletedStatus = async (id, currentStatus) => {
|
||||
const completed_at = !currentStatus ? new Date().toISOString() : null;
|
||||
await toggleTaskCompleted({
|
||||
variables: {
|
||||
id: id,
|
||||
completed: !currentStatus,
|
||||
completed_at: completed_at
|
||||
}
|
||||
});
|
||||
refetch();
|
||||
};
|
||||
|
||||
const [toggleTaskDeleted] = useMutation(MUTATION_TOGGLE_TASK_DELETED);
|
||||
|
||||
const toggleDeletedStatus = async (id, currentStatus) => {
|
||||
const deleted_at = !currentStatus ? new Date().toISOString() : null;
|
||||
await toggleTaskDeleted({
|
||||
variables: {
|
||||
id: id,
|
||||
deleted: !currentStatus,
|
||||
deleted_at: deleted_at
|
||||
}
|
||||
});
|
||||
refetch();
|
||||
};
|
||||
|
||||
if (error) return <AlertComponent message={error.message} type="error"/>;
|
||||
|
||||
@@ -39,6 +74,8 @@ export default function TaskListContainer() {
|
||||
tasks={data ? data.tasks : null}
|
||||
total={data ? data.tasks_aggregate.aggregate.count : 0}
|
||||
refetch={refetch}
|
||||
toggleCompletedStatus={toggleCompletedStatus}
|
||||
toggleDeletedStatus={toggleDeletedStatus}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user