get project
This commit is contained in:
@@ -18,6 +18,14 @@ export const useGetProjectDetail = (id: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetProject = (id: string) => {
|
||||
return useQuery({
|
||||
queryKey: ["project", id],
|
||||
queryFn: () => api.getProject(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateProject = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
@@ -35,13 +43,7 @@ export const useUpdateProject = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
params,
|
||||
}: {
|
||||
id: string;
|
||||
params: UpdateProjectType;
|
||||
}) => api.updateProject(id, params),
|
||||
mutationFn: ({ id, params }: { id: string; params: UpdateProjectType }) => api.updateProject(id, params),
|
||||
onSuccess: (_data, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey: ["projects"] });
|
||||
queryClient.invalidateQueries({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import axios from "../../../../config/axios";
|
||||
import { CreateProjectType, UpdateProjectType } from "../types/ProjectTypes";
|
||||
import { CreateProjectType, GetProjectResponse, UpdateProjectType } from "../types/ProjectTypes";
|
||||
|
||||
export const getProjectsByWorkspace = async (workspaceId: string) => {
|
||||
const { data } = await axios.get(`/task-manager/projects/user/workspace/${workspaceId}`);
|
||||
@@ -11,6 +11,11 @@ export const getProjectDetail = async (id: string) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getProject = async (id: string): Promise<GetProjectResponse> => {
|
||||
const { data } = await axios.get(`/task-manager/projects/detail/${id}`);
|
||||
return data;
|
||||
};
|
||||
|
||||
export const createProject = async (params: CreateProjectType) => {
|
||||
const { data } = await axios.post(`/task-manager/projects`, params);
|
||||
return data;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { IResponse } from "../../../../types/response.types";
|
||||
|
||||
export type ProjectItem = {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -29,3 +31,21 @@ export type ProjectDetailType = CreateProjectType & {
|
||||
};
|
||||
|
||||
export type UpdateProjectType = CreateProjectType;
|
||||
|
||||
export type ProjectTaskType = unknown;
|
||||
|
||||
export type ProjectTaskPhaseType = {
|
||||
id: string;
|
||||
name: string;
|
||||
tasks: ProjectTaskType[];
|
||||
};
|
||||
|
||||
export type ProjectWithPhasesType = {
|
||||
id: string;
|
||||
name: string;
|
||||
taskPhases: ProjectTaskPhaseType[];
|
||||
};
|
||||
|
||||
export interface GetProjectResponse extends IResponse<ProjectWithPhasesType> {
|
||||
statusCode: number;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import Column from "./components/Column";
|
||||
import HeaderWorkspace from "./components/HeaderWorkspace";
|
||||
import TaskDetailModal from "./components/task-detail/TaskDetailModal";
|
||||
import tasksData from "./data/tasks.json";
|
||||
import { useGetProject } from "./project/hooks/useProjectData";
|
||||
import type { TaskPhaseItemType } from "./task-phase/types/TaskPhaseTypes";
|
||||
import type { Task, WorkspaceData } from "./types";
|
||||
import { reorderColumns } from "./utils/reorderColumns";
|
||||
@@ -12,9 +13,8 @@ import { reorderTasks } from "./utils/reorderTasks";
|
||||
|
||||
const Workspace: FC = () => {
|
||||
const { slug: projectId = "" } = useParams<{ slug: string }>();
|
||||
const [columns, setColumns] = useState(
|
||||
(tasksData as WorkspaceData).columns,
|
||||
);
|
||||
const { data: project } = useGetProject(projectId);
|
||||
const [columns, setColumns] = useState((tasksData as WorkspaceData).columns);
|
||||
const [tasks, setTasks] = useState<Task[]>(tasksData.tasks as Task[]);
|
||||
const [draggedTaskId, setDraggedTaskId] = useState<string | null>(null);
|
||||
const [draggedColumnId, setDraggedColumnId] = useState<string | null>(null);
|
||||
@@ -22,9 +22,7 @@ const Workspace: FC = () => {
|
||||
|
||||
const tasksByColumn = useMemo(() => {
|
||||
return columns.reduce<Record<string, Task[]>>((acc, column) => {
|
||||
acc[column.id] = tasks
|
||||
.filter((task) => task.columnId === column.id)
|
||||
.sort((a, b) => a.order - b.order);
|
||||
acc[column.id] = tasks.filter((task) => task.columnId === column.id).sort((a, b) => a.order - b.order);
|
||||
return acc;
|
||||
}, {});
|
||||
}, [columns, tasks]);
|
||||
@@ -77,9 +75,7 @@ const Workspace: FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const selectedTaskColumn = selectedTask
|
||||
? columns.find((column) => column.id === selectedTask.columnId)
|
||||
: null;
|
||||
const selectedTaskColumn = selectedTask ? columns.find((column) => column.id === selectedTask.columnId) : null;
|
||||
|
||||
return (
|
||||
<div className="bg-[#01347A] h-full rounded-none xl:rounded-[32px] overflow-hidden flex flex-col">
|
||||
|
||||
Reference in New Issue
Block a user