| 1 |
import { createSlice, PayloadAction } from "@reduxjs/toolkit"; |
| 2 |
|
| 3 |
interface GlobalState { |
| 4 |
// TODO: Specify data types |
| 5 |
ipaServerConfiguration: Record<string, unknown>; |
| 6 |
loggedUserInfo: LoggedUserInfo; |
| 7 |
environment: Record<string, unknown>; |
| 8 |
dnsIsEnabled: boolean; |
| 9 |
trustConfiguration: Record<string, unknown>; |
| 10 |
domainLevel: Record<string, unknown>; |
| 11 |
caIsEnabled: Record<string, unknown>; |
| 12 |
vaultConfiguration: Record<string, unknown>; |
| 13 |
} |
| 14 |
|
| 15 |
interface LoggedUserInfo { |
| 16 |
arguments: string | Record<string, unknown>; |
| 17 |
command: string; |
| 18 |
error: Record<string, unknown>; |
| 19 |
object: string; |
| 20 |
} |
| 21 |
|
| 22 |
const initialState: GlobalState = { |
| 23 |
ipaServerConfiguration: {}, |
| 24 |
loggedUserInfo: { |
| 25 |
arguments: "", |
| 26 |
command: "", |
| 27 |
error: {}, |
| 28 |
object: "", |
| 29 |
}, |
| 30 |
environment: {}, |
| 31 |
dnsIsEnabled: false, |
| 32 |
trustConfiguration: {}, |
| 33 |
domainLevel: {}, |
| 34 |
caIsEnabled: {}, |
| 35 |
vaultConfiguration: {}, |
| 36 |
}; |
| 37 |
|
| 38 |
const globalSlice = createSlice({ |
| 39 |
name: "global", |
| 40 |
initialState, |
| 41 |
reducers: { |
| 42 |
updateIpaServerConfiguration: ( |
| 43 |
state, |
| 44 |
action: PayloadAction<Record<string, unknown>> |
| 45 |
) => { |
| 46 |
const newIpaServerConfig = action.payload; |
| 47 |
state.ipaServerConfiguration = newIpaServerConfig; |
| 48 |
}, |
| 49 |
updateLoggedUserInfo: ( |
| 50 |
state, |
| 51 |
action: PayloadAction<Record<string, unknown>> |
| 52 |
) => { |
| 53 |
const newLoggedUserInfo = action.payload; |
| 54 |
state.loggedUserInfo = { |
| 55 |
...state.loggedUserInfo, |
| 56 |
arguments: newLoggedUserInfo, |
| 57 |
}; |
| 58 |
}, |
| 59 |
updateEnvironment: ( |
| 60 |
state, |
| 61 |
action: PayloadAction<Record<string, unknown>> |
| 62 |
) => { |
| 63 |
const newEnv = action.payload; |
| 64 |
state.environment = newEnv; |
| 65 |
}, |
| 66 |
updateDnsIsEnabled: (state, action: PayloadAction<boolean>) => { |
| 67 |
const newDnsIsEnabled = action.payload; |
| 68 |
state.dnsIsEnabled = newDnsIsEnabled; |
| 69 |
}, |
| 70 |
updateTrustConfiguration: ( |
| 71 |
state, |
| 72 |
action: PayloadAction<Record<string, unknown>> |
| 73 |
) => { |
| 74 |
const newTrustConfig = action.payload; |
| 75 |
state.trustConfiguration = newTrustConfig; |
| 76 |
}, |
| 77 |
updateDomainLevel: ( |
| 78 |
state, |
| 79 |
action: PayloadAction<Record<string, unknown>> |
| 80 |
) => { |
| 81 |
const newDomainLevel = action.payload; |
| 82 |
state.domainLevel = newDomainLevel; |
| 83 |
}, |
| 84 |
updateCaIsEnabled: ( |
| 85 |
state, |
| 86 |
action: PayloadAction<Record<string, unknown>> |
| 87 |
) => { |
| 88 |
const newCaIsEnabled = action.payload; |
| 89 |
state.caIsEnabled = newCaIsEnabled; |
| 90 |
}, |
| 91 |
updateVaultConfiguration: ( |
| 92 |
state, |
| 93 |
action: PayloadAction<Record<string, unknown>> |
| 94 |
) => { |
| 95 |
const newVaultConfig = action.payload; |
| 96 |
state.vaultConfiguration = newVaultConfig; |
| 97 |
}, |
| 98 |
}, |
| 99 |
}); |
| 100 |
|
| 101 |
export const { |
| 102 |
updateIpaServerConfiguration, |
| 103 |
updateLoggedUserInfo, |
| 104 |
updateEnvironment, |
| 105 |
updateDnsIsEnabled, |
| 106 |
updateTrustConfiguration, |
| 107 |
updateDomainLevel, |
| 108 |
updateCaIsEnabled, |
| 109 |
updateVaultConfiguration, |
| 110 |
} = globalSlice.actions; |
| 111 |
export default globalSlice.reducer; |