Skip to content

Commit

Permalink
Merge pull request #46 from JECT-Study/feature/modal
Browse files Browse the repository at this point in the history
[TASK-72] refactor: 모달 구현 로직 변경
  • Loading branch information
SangWoo9734 authored Jan 18, 2025
2 parents 7370733 + 49187b1 commit 084e927
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const RootLayout = ({ children, modal }: Readonly<LayoutProps>) => {
<MSWProvider>
<TanStackQueryProvider>
<AppShell>{children}</AppShell>
{modal}
</TanStackQueryProvider>
</MSWProvider>
<KakaoProvider />
Expand Down
28 changes: 14 additions & 14 deletions src/app/@Modal/page.tsx → src/app/providers/ModalProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client';

import { useEffect } from 'react';
import { createPortal } from 'react-dom';
import { useStore } from 'zustand';

import modalStore from '@/stores/modalStore';

const ModalPage = () => {
const ModalProvider = () => {
const { isOpen, modalSize, contents } = useStore(modalStore);

useEffect(() => {
Expand All @@ -23,19 +24,18 @@ const ModalPage = () => {
lg: 'tablet:w-[1011px] rounded-[20px]',
};

return (
<>
{isOpen && (
<div className='fixed top-0 left-0 w-full h-full bg-black bg-opacity-50 z-50'>
<div
className={`${modalClassNames[modalSize]} absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[366px] h-content bg-background-overlay text-black`}
>
{contents}
</div>
</div>
)}
</>
if (!isOpen) return null;

return createPortal(
<div className='fixed top-0 left-0 w-full h-full bg-black bg-opacity-50 z-50'>
<div
className={`${modalClassNames[modalSize]} absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 w-[366px] h-content bg-background-overlay text-black`}
>
{contents}
</div>
</div>,
document.body,
);
};

export default ModalPage;
export default ModalProvider;
2 changes: 2 additions & 0 deletions src/components/Layout/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NextUIProvider } from '@nextui-org/react';
import { ThemeProvider as NextThemesProvider } from 'next-themes';
import { ReactNode } from 'react';

import ModalProvider from '@/app/providers/ModalProvider';
import Footer from '@/components/Footer';
import Navbar from '@/components/Navbar';

Expand All @@ -25,6 +26,7 @@ const AppShell = ({ children }: { children: ReactNode }) => {
</main>
<Footer />
</div>
<ModalProvider />
</NextThemesProvider>
</NextUIProvider>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/stores/modalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const modalStore = create<ModalState & ModalAction>((set) => ({
set((state) => {
if (state.isOpen) return state;

return { isOpen: true, ...props };
return { ...state, isOpen: true, ...props };
}),
closeModal: () =>
set((state) => {
Expand Down

0 comments on commit 084e927

Please sign in to comment.