grafana/public/app/features/auth-config/state/reducers.ts
Alex Khomenko 1141dd62ab
SSO: Display provider list (#78472)
* Load providers

* Display providers

* Rename

* Remove redundant styles

* Update Grid import

* Return data in camelCase from the OAuth fb strategy

* Update cards and remove empty state

* Add comment

* Add feature toggle

* Update betterer

* Add empty state

* Fix configPath

* Update betterer

* Revert backend changes

* Remove newline

* Enable auth routes

---------

Co-authored-by: Mihaly Gyongyosi <mgyongyosi@users.noreply.github.com>
2023-11-29 19:09:36 +02:00

65 lines
1.9 KiB
TypeScript

import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { Settings } from 'app/types';
import { SettingsError, AuthProviderStatus, AuthConfigState, SSOProvider } from '../types';
export const initialState: AuthConfigState = {
settings: {},
providerStatuses: {},
isLoading: false,
providers: [],
};
const authConfigSlice = createSlice({
name: 'authConfig',
initialState,
reducers: {
settingsUpdated: (state, action: PayloadAction<Settings>): AuthConfigState => {
return { ...state, settings: action.payload };
},
providerStatusesLoaded: (state, action: PayloadAction<{ [key: string]: AuthProviderStatus }>): AuthConfigState => {
return { ...state, providerStatuses: action.payload };
},
loadingBegin: (state: AuthConfigState) => {
return { ...state, isLoading: true };
},
loadingEnd: (state: AuthConfigState) => {
return { ...state, isLoading: false };
},
setError: (state, action: PayloadAction<SettingsError>): AuthConfigState => {
return { ...state, updateError: action.payload };
},
resetError: (state): AuthConfigState => {
return { ...state, updateError: undefined };
},
setWarning: (state, action: PayloadAction<SettingsError>): AuthConfigState => {
return { ...state, warning: action.payload };
},
resetWarning: (state): AuthConfigState => {
return { ...state, warning: undefined };
},
providersLoaded: (state, action: PayloadAction<SSOProvider[]>): AuthConfigState => {
return { ...state, providers: action.payload };
},
},
});
export const {
settingsUpdated,
providerStatusesLoaded,
loadingBegin,
loadingEnd,
setError,
resetError,
setWarning,
resetWarning,
providersLoaded,
} = authConfigSlice.actions;
export const authConfigReducer = authConfigSlice.reducer;
export default {
authConfig: authConfigReducer,
};