import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; import queryString from 'query-string' ; import { DriveFileData } from '../../../drive/types' ; import { FileInfoMenuItem } from '../../../drive/types' ; import navigationService from '../../../core/services/navigation.service' ; import { AccountViewTab } from '../../../core/views/AccountView/tabs' ; interface UISliceState { isSidenavCollapsed : boolean ; isReferralsWidgetCollapsed : boolean ; isFileLoggerOpen : boolean ; isFileInfoMenuOpen : boolean ; isCreateFolderDialogOpen : boolean ; isDeleteItemsDialogOpen : boolean ; isNewsletterDialogOpen : boolean ; isReachedPlanLimitDialogOpen : boolean ; isShareItemDialogOpen : boolean ; isInviteMemberDialogOpen : boolean ; isDriveItemInfoMenuOpen : boolean ; isGuestInviteDialogOpen : boolean ; isFileViewerOpen : boolean ; fileViewerItem : DriveFileData | null ; currentAccountTab : AccountViewTab ; currentFileInfoMenuItem : FileInfoMenuItem | null ; } const initialState = { isSidenavCollapsed : false , isReferralsWidgetCollapsed : false , isFileLoggerOpen : false , isFileInfoMenuOpen : false , isCreateFolderDialogOpen : false , isDeleteItemsDialogOpen : false , isNewsletterDialogOpen : false , isReachedPlanLimitDialogOpen : false , isShareItemDialogOpen : false , isInviteMemberDialogOpen : false , isDriveItemInfoMenuOpen : false , isGuestInviteDialogOpen : false , isFileViewerOpen : false , fileViewerItem : null , currentAccountTab : AccountViewTab . Info , currentFileInfoMenuItem : null , } ; export const uiSlice = createSlice ( { name : 'ui' , initialState , reducers : { setIsSidenavCollapsed : ( state , action ) => { state . isSidenavCollapsed = action . payload ; } , setIsReferralsWidgetCollapsed : ( state , action ) => { state . isReferralsWidgetCollapsed = action . payload ; } , setIsFileLoggerOpen : ( state , action ) => { state . isFileLoggerOpen = action . payload ; } , setIsFileInfoMenuOpen : ( state , action ) => { state . isFileInfoMenuOpen = action . payload ; } , setIsCreateFolderDialogOpen : ( state , action ) => { state . isCreateFolderDialogOpen = action . payload ; } , setIsDeleteItemsDialogOpen : ( state , action ) => { state . isDeleteItemsDialogOpen = action . payload ; } , setIsNewsletterDialogOpen : ( state , action ) => { state . isNewsletterDialogOpen = action . payload ; } , setIsReachedPlanLimitDialogOpen : ( state , action ) => { state . isReachedPlanLimitDialogOpen = action . payload ; } , setIsShareItemDialogOpen : ( state , action ) => { state . isShareItemDialogOpen = action . payload ; } , setIsInviteMemberDialogOpen : ( state , action ) => { state . isInviteMemberDialogOpen = action . payload ; } , setIsGuestInvitationDialogOpen : ( state , action ) => { state . isGuestInviteDialogOpen = action . payload ; } , setIsDriveItemInfoMenuOpen : ( state , action ) => { state . isDriveItemInfoMenuOpen = action . payload ; } , setIsFileViewerOpen : ( state , action ) => { state . isFileViewerOpen = action . payload ; } , setFileViewerItem : ( state , action ) => { state . fileViewerItem = action . payload ; } , setCurrentAccountTab : ( state , action ) => { const currentQueryParams = queryString . parse ( navigationService . history . location . search ) ; const newQueryParams = { ... currentQueryParams , tab : action . payload , } ; const newQueryString = queryString . stringify ( newQueryParams ) ; state . currentAccountTab = action . payload ; navigationService . history . push ( { pathname : navigationService . history . location . pathname , search : newQueryString && `?${ newQueryString }` , } ) ; } , setFileInfoItem : ( state , action ) => { state . currentFileInfoMenuItem = action . payload ; } , resetState : ( state ) => { Object . assign ( state , initialState ) ; } , } , } ) ; export const { setIsReferralsWidgetCollapsed , setIsCreateFolderDialogOpen , setIsDeleteItemsDialogOpen , setIsNewsletterDialogOpen , setIsFileLoggerOpen , setIsFileInfoMenuOpen , setIsReachedPlanLimitDialogOpen , setIsShareItemDialogOpen , setIsInviteMemberDialogOpen , setIsDriveItemInfoMenuOpen , setIsFileViewerOpen , setFileViewerItem , setCurrentAccountTab , setFileInfoItem , setIsGuestInvitationDialogOpen , } = uiSlice . actions ; export const uiActions = uiSlice . actions ; export default uiSlice . reducer ;