diff --git a/client/src/Features/Settings/settingsSlice.js b/client/src/Features/Settings/settingsSlice.js deleted file mode 100644 index d0725627a..000000000 --- a/client/src/Features/Settings/settingsSlice.js +++ /dev/null @@ -1,100 +0,0 @@ -import { networkService } from "../../main"; -import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; - -const initialState = { - isLoading: false, - apiBaseUrl: "", - logLevel: "debug", - pagespeedApiKey: "", -}; - -export const getAppSettings = createAsyncThunk( - "settings/getSettings", - async (data, thunkApi) => { - try { - const res = await networkService.getAppSettings(); - return res.data; - } catch (error) { - if (error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -export const updateAppSettings = createAsyncThunk( - "settings/updateSettings", - async ({ settings }, thunkApi) => { - try { - const parsedSettings = { - language: settings.language, - pagespeedApiKey: settings.pagespeedApiKey, - }; - const res = await networkService.updateAppSettings({ settings: parsedSettings }); - return res.data; - } catch (error) { - if (error.response && error.response.data) { - return thunkApi.rejectWithValue(error.response.data); - } - const payload = { - status: false, - msg: error.message ? error.message : "Unknown error", - }; - return thunkApi.rejectWithValue(payload); - } - } -); - -const handleGetSettingsFulfilled = (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - state.apiBaseUrl = action.payload.data.apiBaseUrl; - state.logLevel = action.payload.data.logLevel; - state.language = action.payload.data.language; - state.pagespeedApiKey = action.payload.data.pagespeedApiKey; -}; -const handleGetSettingsRejected = (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload ? action.payload.msg : "Failed to get settings."; -}; -const handleUpdateSettingsFulfilled = (state, action) => { - state.isLoading = false; - state.success = action.payload.success; - state.msg = action.payload.msg; - state.apiBaseUrl = action.payload.data.apiBaseUrl; - state.logLevel = action.payload.data.logLevel; -}; -const handleUpdateSettingsRejected = (state, action) => { - state.isLoading = false; - state.success = false; - state.msg = action.payload ? action.payload.msg : "Failed to update settings."; -}; - -const settingsSlice = createSlice({ - name: "settings", - initialState, - extraReducers: (builder) => { - builder - .addCase(getAppSettings.pending, (state) => { - state.isLoading = true; - }) - .addCase(getAppSettings.fulfilled, handleGetSettingsFulfilled) - .addCase(getAppSettings.rejected, handleGetSettingsRejected); - - builder - .addCase(updateAppSettings.pending, (state) => { - state.isLoading = true; - }) - .addCase(updateAppSettings.fulfilled, handleUpdateSettingsFulfilled) - .addCase(updateAppSettings.rejected, handleUpdateSettingsRejected); - }, -}); - -export default settingsSlice.reducer; diff --git a/client/src/store.js b/client/src/store.js index 309ba52e2..69aa3d50b 100644 --- a/client/src/store.js +++ b/client/src/store.js @@ -2,7 +2,6 @@ import { configureStore, combineReducers } from "@reduxjs/toolkit"; import authReducer from "./Features/Auth/authSlice"; import uiReducer from "./Features/UI/uiSlice"; -import settingsReducer from "./Features/Settings/settingsSlice"; import storage from "redux-persist/lib/storage"; import { persistReducer, persistStore, createTransform } from "redux-persist"; @@ -20,14 +19,13 @@ const authTransform = createTransform( const persistConfig = { key: "root", storage, - whitelist: ["auth", "ui", "settings"], + whitelist: ["auth", "ui"], transforms: [authTransform], }; const rootReducer = combineReducers({ auth: authReducer, ui: uiReducer, - settings: settingsReducer, }); const persistedReducer = persistReducer(persistConfig, rootReducer);