Skip to content
Snippets Groups Projects
PublicationsModalLayout.component.tsx 1.68 KiB
Newer Older
import { twMerge } from 'tailwind-merge';
import { useAppDispatch } from '@/redux/hooks/useAppDispatch';
import { useAppSelector } from '@/redux/hooks/useAppSelector';
import { closeModal } from '@/redux/modal/modal.slice';
import { Icon } from '@/shared/Icon';
import { filteredSizeSelector } from '@/redux/publications/publications.selectors';
import { MODAL_ROLE } from './PublicationsModalLayout.constants';
import { PublicationsSearch } from '../PublicationsSearch';

type ModalLayoutProps = {
  children: React.ReactNode;
};

export const PublicationsModalLayout = ({ children }: ModalLayoutProps): JSX.Element => {
  const dispatch = useAppDispatch();
  const numberOfPublications = useAppSelector(filteredSizeSelector);

  const handleCloseModal = (): void => {
    dispatch(closeModal());
  };

  return (
    <div
      className={twMerge('absolute left-0 top-0 z-10 h-full w-full bg-cetacean-blue/[.48]')}
      role={MODAL_ROLE}
    >
      <div className="flex h-full w-full items-center justify-center">
        <div className={twMerge('flex h-5/6 w-10/12	flex-col	overflow-hidden rounded-lg')}>
          <div className="flex items-center  justify-between bg-white p-[24px] text-xl">
            <div className="font-semibold">
              <div>Publications ({numberOfPublications} results)</div>
            </div>
            <div className="flex flex-row flex-nowrap items-center">
              <PublicationsSearch />
              <button type="button" onClick={handleCloseModal} aria-label="close button">
                <Icon name="close" className="fill-font-500" />
              </button>
            </div>
          </div>
          {children}
        </div>
      </div>
    </div>
  );
};