Skip to content

Commit

Permalink
fix: revert task services changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
wyattchris committed Apr 18, 2024
1 parent 6cf2272 commit df0131f
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions client/services/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export type TaskQueryParams = {
endDate?: string;
quickTask?: boolean;
};

const getTask = async (taskID: string): Promise<Task> => {
if (!parseInt(taskID)) return {} as Task;
const { data } = await axios.get(`${api_url}/tasks/${taskID}`);
Expand All @@ -30,6 +29,13 @@ const getTaskByAssigned = async (userId: string): Promise<Task[]> => {
return data;
};

const getAssignedByTask = async (taskID: string): Promise<string> => {
if (!parseInt(taskID)) return '';
const { data } = await axios.get(`${api_url}/tasks/${taskID}/assigned`);

return data.at(0);
};

const getFilteredTasks = async (
queryParams: TaskQueryParams
): Promise<Task[]> => {
Expand Down Expand Up @@ -58,6 +64,9 @@ const editTask = async (taskID: string, updatedTask: Task): Promise<Task> => {
return response.data;
};

const updateTaskStatus = async (taskID: string, status: string) =>
await axios.put(`${api_url}/tasks/${taskID}/status/${status}`);

export const useFilteredTasks = (queryParams: TaskQueryParams) => {
const {
data: tasks,
Expand Down Expand Up @@ -87,6 +96,7 @@ export const useTaskByAssigned = (userId: string) => {
};

export const useTaskById = (taskId: string) => {
const queryClient = useQueryClient();
const { data: task, isLoading: taskIsLoading } = useQuery<Task>({
queryKey: ['task', taskId],
queryFn: () => getTask(taskId)
Expand All @@ -99,11 +109,30 @@ export const useTaskById = (taskId: string) => {
queryFn: () => getTaskLabels(taskId)
});

const { data: assigned, isLoading: assignedIsLoading } = useQuery<string>({
queryKey: ['assigned', taskId],
queryFn: () => getAssignedByTask(taskId),
retry: 2
});

const { mutate: updateTaskStatusMutation } = useMutation({
mutationFn: (taskStatus: string) => updateTaskStatus(taskId, taskStatus),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['task', taskId] });
},
onError: (err) => {
console.error('ERROR: Failed to Update Task Status. Code:', err);
}
});

return {
task,
taskIsLoading,
taskLabels,
taskLabelsIsLoading
taskLabelsIsLoading,
assigned,
assignedIsLoading,
updateTaskStatusMutation
};
};

Expand Down Expand Up @@ -136,6 +165,7 @@ export const editTaskMutation = () => {
}) => editTask(taskId, updatedTask),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['filteredTaskList'] });
queryClient.invalidateQueries({ queryKey: ['taskStatus'] });
},
onError: (err) => {
console.error('ERROR: Failed to Edit Task. Code:', err);
Expand Down

0 comments on commit df0131f

Please sign in to comment.