import { createSlice , PayloadAction } from '@reduxjs/toolkit' ; import { LocalStorageItem , Workspace } from '../../../core/types' ; import localStorageService from '../../../core/services/local-storage.service' ; import { SessionState } from './session.model' ; import { sessionExtraReducers } from './session.thunks' ; const initialState = { hasConnection : true , workspace : Workspace . Individuals , } ; export const sessionSlice = createSlice ( { name : 'session' , initialState , reducers : { initialize : ( state ) => { state . workspace = ( localStorageService . getWorkspace ( ) as Workspace ) || Workspace . Individuals ; localStorageService . set ( LocalStorageItem . Workspace , state . workspace ) ; } , setHasConnection : ( state , action ) => { state . hasConnection = action . payload ; } , setWorkspace : ( state , action ) => { state . workspace = action . payload ; } , resetState : ( state ) => { Object . assign ( state , initialState ) ; } , } , extraReducers : sessionExtraReducers , } ) ; export const sessionActions = sessionSlice . actions ; export default sessionSlice . reducer ;