Skip to content

Commit

Permalink
Feat: #51 PageLayout의 Outlet Context 설정 & 커스텀훅 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Seok93 committed Jul 22, 2024
1 parent 3bd4058 commit 361c6bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/hooks/useProjectContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useOutletContext } from 'react-router-dom';
import { Project } from '@/types/ProjectType';

export type ProjectContext = { project: Project };

export default function useProjectContext() {
return useOutletContext<ProjectContext>();
}
13 changes: 8 additions & 5 deletions src/layouts/page/ProjectLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { useMemo } from 'react';
import { NavLink, Outlet, useParams } from 'react-router-dom';
import { Navigate, NavLink, Outlet, useParams } from 'react-router-dom';
import useModal from '@hooks/useModal';
import ListSidebar from '@components/sidebar/ListSidebar';
import ListProject from '@components/sidebar/ListProject';
import CreateModalTask from '@components/modal/task/CreateModalTask';
import CreateModalProjectStatus from '@components/modal/project-status/CreateModalProjectStatus';
import { ProjectContext } from '@hooks/useProjectContext';
import { PROJECT_DUMMY } from '@mocks/mockData';
import { RiSettings5Fill } from 'react-icons/ri';
import CreateModalTask from '@/components/modal/task/CreateModalTask';

export default function ProjectLayout() {
const { projectId } = useParams();
const { showModal: showTaskModal, openModal: openTaskModal, closeModal: closeTaskModal } = useModal();
const { showModal: showStatusModal, openModal: openStatusModal, closeModal: closeStatusModal } = useModal();
const target = useMemo(
const project = useMemo(
() => PROJECT_DUMMY.find((project) => project.projectId.toString() === projectId),
[projectId],
);

if (!project) return <Navigate to="/error" replace />;

return (
<>
<section className="flex h-full p-15">
Expand All @@ -27,7 +30,7 @@ export default function ProjectLayout() {
<header className="flex h-30 items-center justify-between border-b p-10">
<div>
<small className="mr-5 font-bold text-category">project</small>
<span className="text-emphasis">{target?.name}</span>
<span className="text-emphasis">{project?.name}</span>
</div>
<div className="flex cursor-pointer items-center text-sm text-main">
<RiSettings5Fill /> Project Setting
Expand Down Expand Up @@ -56,7 +59,7 @@ export default function ProjectLayout() {
</button>
</div>
</div>
<Outlet />
<Outlet context={{ project } satisfies ProjectContext} />
</div>
</section>
</section>
Expand Down

0 comments on commit 361c6bc

Please sign in to comment.