import { createSlice, PayloadAction } from "@reduxjs/toolkit"; interface GlobalState { // TODO: Specify data types ipaServerConfiguration: Record; loggedUserInfo: LoggedUserInfo; environment: Record; dnsIsEnabled: boolean; trustConfiguration: Record; domainLevel: Record; caIsEnabled: Record; vaultConfiguration: Record; } interface LoggedUserInfo { arguments: string | Record; command: string; error: Record; object: string; } const initialState: GlobalState = { ipaServerConfiguration: {}, loggedUserInfo: { arguments: "", command: "", error: {}, object: "", }, environment: {}, dnsIsEnabled: false, trustConfiguration: {}, domainLevel: {}, caIsEnabled: {}, vaultConfiguration: {}, }; const globalSlice = createSlice({ name: "global", initialState, reducers: { updateIpaServerConfiguration: ( state, action: PayloadAction> ) => { const newIpaServerConfig = action.payload; state.ipaServerConfiguration = newIpaServerConfig; }, updateLoggedUserInfo: ( state, action: PayloadAction> ) => { const newLoggedUserInfo = action.payload; state.loggedUserInfo = { ...state.loggedUserInfo, arguments: newLoggedUserInfo, }; }, updateEnvironment: ( state, action: PayloadAction> ) => { const newEnv = action.payload; state.environment = newEnv; }, updateDnsIsEnabled: (state, action: PayloadAction) => { const newDnsIsEnabled = action.payload; state.dnsIsEnabled = newDnsIsEnabled; }, updateTrustConfiguration: ( state, action: PayloadAction> ) => { const newTrustConfig = action.payload; state.trustConfiguration = newTrustConfig; }, updateDomainLevel: ( state, action: PayloadAction> ) => { const newDomainLevel = action.payload; state.domainLevel = newDomainLevel; }, updateCaIsEnabled: ( state, action: PayloadAction> ) => { const newCaIsEnabled = action.payload; state.caIsEnabled = newCaIsEnabled; }, updateVaultConfiguration: ( state, action: PayloadAction> ) => { const newVaultConfig = action.payload; state.vaultConfiguration = newVaultConfig; }, }, }); export const { updateIpaServerConfiguration, updateLoggedUserInfo, updateEnvironment, updateDnsIsEnabled, updateTrustConfiguration, updateDomainLevel, updateCaIsEnabled, updateVaultConfiguration, } = globalSlice.actions; export default globalSlice.reducer;