Skip to content

Commit

Permalink
feat: paperless documents modal
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirazad committed Jun 25, 2024
1 parent 7a5efdd commit f1ee4be
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/app/@modal/(.)/paperless-documents/modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client';

import { type ElementRef, useEffect, useRef } from 'react';
import { useRouter } from 'next/navigation';
import { createPortal } from 'react-dom';

export function Modal({ children }: { children: React.ReactNode }) {
const router = useRouter();
const dialogRef = useRef<ElementRef<'dialog'>>(null);

useEffect(() => {
if (!dialogRef.current?.open) {
dialogRef.current?.showModal();
}
}, []);

function onDismiss() {
router.back();
}

return createPortal(
<div className="modal-backdrop">
<dialog ref={dialogRef} className="modal" onClose={onDismiss}>
{children}
<button onClick={onDismiss} className="close-button" />
</dialog>
</div>,
document.getElementById('modal-root')!
);
}
9 changes: 9 additions & 0 deletions src/app/@modal/(.)/paperless-documents/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Modal } from './modal';

export default function PhotoModal({
params: { id: photoId },
}: {
params: { id: string };
}) {
return <Modal>{photoId}</Modal>;
}
3 changes: 3 additions & 0 deletions src/app/@modal/default.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Default() {
return null;
}

0 comments on commit f1ee4be

Please sign in to comment.