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