github.com/minio/console@v1.4.1/web-app/src/screens/LoginPage/loginSlice.ts (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2022 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import { createSlice, PayloadAction } from "@reduxjs/toolkit"; 18 import { LoginDetails } from "api/consoleApi"; 19 import { doLoginAsync, getFetchConfigurationAsync } from "./loginThunks"; 20 21 export interface LoginState { 22 accessKey: string; 23 secretKey: string; 24 sts: string; 25 useSTS: boolean; 26 backgroundAnimation: boolean; 27 loginStrategy: LoginDetails; 28 loginSending: boolean; 29 loadingFetchConfiguration: boolean; 30 isK8S: boolean; 31 navigateTo: string; 32 ssoEmbeddedIDPDisplay: boolean; 33 } 34 35 const initialState: LoginState = { 36 accessKey: "", 37 secretKey: "", 38 sts: "", 39 useSTS: false, 40 loginStrategy: { 41 loginStrategy: undefined, 42 redirectRules: [], 43 }, 44 loginSending: false, 45 loadingFetchConfiguration: true, 46 isK8S: false, 47 backgroundAnimation: false, 48 navigateTo: "", 49 ssoEmbeddedIDPDisplay: false, 50 }; 51 52 export const loginSlice = createSlice({ 53 name: "login", 54 initialState, 55 reducers: { 56 setAccessKey: (state, action: PayloadAction<string>) => { 57 state.accessKey = action.payload; 58 }, 59 setSecretKey: (state, action: PayloadAction<string>) => { 60 state.secretKey = action.payload; 61 }, 62 setUseSTS: (state, action: PayloadAction<boolean>) => { 63 state.useSTS = action.payload; 64 }, 65 setSTS: (state, action: PayloadAction<string>) => { 66 state.sts = action.payload; 67 }, 68 setNavigateTo: (state, action: PayloadAction<string>) => { 69 state.navigateTo = action.payload; 70 }, 71 setDisplayEmbeddedIDPForms: (state, action: PayloadAction<boolean>) => { 72 state.ssoEmbeddedIDPDisplay = action.payload; 73 }, 74 resetForm: (state) => initialState, 75 }, 76 extraReducers: (builder) => { 77 builder 78 .addCase(getFetchConfigurationAsync.pending, (state, action) => { 79 state.loadingFetchConfiguration = true; 80 }) 81 .addCase(getFetchConfigurationAsync.rejected, (state, action) => { 82 state.loadingFetchConfiguration = false; 83 }) 84 .addCase(getFetchConfigurationAsync.fulfilled, (state, action) => { 85 state.loadingFetchConfiguration = false; 86 if (action.payload) { 87 state.loginStrategy = action.payload; 88 state.isK8S = !!action.payload.isK8S; 89 state.backgroundAnimation = !!action.payload.animatedLogin; 90 } 91 }) 92 .addCase(doLoginAsync.pending, (state, action) => { 93 state.loginSending = true; 94 }) 95 .addCase(doLoginAsync.rejected, (state, action) => { 96 state.loginSending = false; 97 }) 98 .addCase(doLoginAsync.fulfilled, (state, action) => { 99 state.loginSending = false; 100 }); 101 }, 102 }); 103 104 // Action creators are generated for each case reducer function 105 export const { 106 setAccessKey, 107 setSecretKey, 108 setUseSTS, 109 setSTS, 110 setNavigateTo, 111 setDisplayEmbeddedIDPForms, 112 resetForm, 113 } = loginSlice.actions; 114 115 export default loginSlice.reducer;