-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from it-goats/feature/ITG-46
[ITG-46] Dodanie listy zadań w relacji w widoku szczegółów zadania
- Loading branch information
Showing
6 changed files
with
166 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { getTask, getTasks, updateTask } from "../../api/tasks"; | ||
import tw, { styled } from "twin.macro"; | ||
import { useMutation, useQueryClient } from "react-query"; | ||
|
||
import Checkbox from "./CheckBox"; | ||
import { DirectedRelationType } from "../../types/taskRelation"; | ||
import { ITask } from "../../types/task"; | ||
import { getRelatedTasks } from "../../api/taskRelations"; | ||
import { useState } from "react"; | ||
|
||
interface Props { | ||
task: ITask; | ||
relationType: DirectedRelationType; | ||
parentTaskId: string; | ||
} | ||
|
||
const Container = styled.div( | ||
tw`rounded-xl bg-tertiary text-secondary m-1.5 p-1.5 grid` | ||
); | ||
|
||
export default function RelatedTask({ | ||
task, | ||
relationType, | ||
parentTaskId, | ||
}: Props) { | ||
const [errorMessage, setErrorMessage] = useState(""); | ||
const client = useQueryClient(); | ||
const editTask = useMutation((task: ITask) => updateTask(task.id, task), { | ||
onSuccess: () => { | ||
client.invalidateQueries(getTasks.cacheKey); | ||
client.invalidateQueries(getTask.cacheKey(parentTaskId)); | ||
client.invalidateQueries( | ||
getRelatedTasks.cacheKey(parentTaskId, relationType) | ||
); | ||
}, | ||
}); | ||
const handleIsDoneChange = async () => { | ||
try { | ||
const updatedTask = { | ||
...task, | ||
isDone: !task.isDone, | ||
}; | ||
await editTask.mutateAsync(updatedTask); | ||
} catch (error) { | ||
setErrorMessage( | ||
"Something went wrong :C, It's not possible to uncheck the task." | ||
); | ||
} | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<p tw="font-bold text-base">{task.title}</p> | ||
<p tw="place-self-end"> | ||
<Checkbox | ||
id={task.id} | ||
checked={task.isDone} | ||
onChange={handleIsDoneChange} | ||
/> | ||
</p> | ||
{errorMessage && ( | ||
<p tw="flex items-center text-orange-500 pt-1"> {errorMessage}</p> | ||
)} | ||
</Container> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import tw, { styled } from "twin.macro"; | ||
|
||
import { DirectedRelationType } from "../../types/taskRelation"; | ||
import RelatedTask from "./RelatedTask"; | ||
import { getRelatedTasks } from "../../api/taskRelations"; | ||
import { useQuery } from "react-query"; | ||
|
||
interface RelatedTasksListProps { | ||
relationType: DirectedRelationType; | ||
parentTaskId: string; | ||
} | ||
|
||
const Container = styled.div(tw``); | ||
|
||
export default function RelatedTasksList({ | ||
relationType, | ||
parentTaskId, | ||
}: RelatedTasksListProps) { | ||
const { data, isLoading, error } = useQuery( | ||
getRelatedTasks.cacheKey(parentTaskId, relationType), | ||
() => getRelatedTasks.run(parentTaskId, relationType) | ||
); | ||
|
||
if (isLoading) return <Container>Loading</Container>; | ||
if (error) return <Container>Oops</Container>; | ||
if (!data?.data) return <Container />; | ||
|
||
const subtasks = data.data.slice().reverse(); | ||
|
||
if (subtasks.length == 0) { | ||
return <Container>{"<No tasks>"}</Container>; | ||
} | ||
|
||
return ( | ||
<Container> | ||
{subtasks.map((relatedTask) => ( | ||
<RelatedTask | ||
key={relatedTask.relationId} | ||
task={relatedTask.task} | ||
relationType={relationType} | ||
parentTaskId={parentTaskId} | ||
/> | ||
))} | ||
</Container> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters