import { ModalName } from '@/types/modal'; import { PayloadAction } from '@reduxjs/toolkit'; import { ModalState, OpenEditOverlayModalAction } from './modal.types'; export const openModalReducer = (state: ModalState, action: PayloadAction<ModalName>): void => { state.isOpen = true; state.modalName = action.payload; }; export const closeModalReducer = (state: ModalState): void => { state.isOpen = false; state.modalName = 'none'; }; export const openOverviewImagesModalByIdReducer = ( state: ModalState, action: PayloadAction<number>, ): void => { state.isOpen = true; state.modalName = 'overview-images'; state.modalTitle = 'Overview images'; state.overviewImagesState = { imageId: action.payload, }; }; export const openMolArtModalByIdReducer = ( state: ModalState, action: PayloadAction<string | undefined>, ): void => { state.isOpen = true; state.modalName = 'mol-art'; state.modalTitle = 'MolArt'; state.molArtState = { uniprotId: action.payload, }; }; export const openLoginModalReducer = (state: ModalState): void => { state.isOpen = true; state.modalName = 'login'; state.modalTitle = 'You need to login'; }; export const setOverviewImageIdReducer = ( state: ModalState, action: PayloadAction<number>, ): void => { state.overviewImagesState = { imageId: action.payload, }; }; export const openPublicationsModalReducer = (state: ModalState): void => { state.isOpen = true; state.modalName = 'publications'; state.modalTitle = 'Publications'; }; export const openEditOverlayModalReducer = ( state: ModalState, action: OpenEditOverlayModalAction, ): void => { state.isOpen = true; state.modalName = 'edit-overlay'; state.modalTitle = action.payload.name; state.editOverlayState = action.payload; };