app/config/appSettingsSlice.js

/**
 * @file
 * File : appSettingsSlice.js\
 * It is used by redux as a state management provider\
 * Defines the authorization profile slices
 *
 * @author  Pierre-Yves Léglise <contact@axialdata.net>
 * @name appSettingsSlice
 */
import { createSlice } from '@reduxjs/toolkit'

/**
 * AppSettingsSlice initial state.
 *
 * @typedef {Object} InitialState
 * @author  Pierre-Yves Léglise <contact@axialdata.net>
 * @property {Object} server - Server configuration.
 * @property {Object} features - Features configuration.
 * @property {Object} mailer - Mailer configuration.
 * @property {Object} otp - OTP configuration.
 * @property {Object} security - Security configuration.
 * @property {Object} frontend - Frontend configuration.
 * @property {Object} backend - Backend configuration.
 * @example
 *  const initialState = reducer(state, action)
 * @returns {Object} Initial state.
 */
const initialState = {
  server: {},
  // accessToken: {},
  features: {},
  mailer: {},
  // otp: {},
  security: {},
  frontend: {},
  backend: {},
}

/**
 * AppSettingsSlice reducer.
 *
 * @function
 * @author  Pierre-Yves Léglise <contact@axialdata.net>
 * @param {Object} state - Current state.
 * @param {Object} action - Action to handle.
 * @example
 *  const newState = reducer(state, action)
 * @returns {Object} New state.
 */
const appSettingsSlice = createSlice({
  name: 'appSettings',
  initialState,
  reducers: {
    setConfig: (state, action) => {
      state.server = action.payload.server
      // state.accessToken = action.payload.accessToken
      state.features = action.payload.features
      state.featuresDetails = action.payload.featuresDetails
      state.mailer = action.payload.mailer
      // state.otp = action.payload.otp
      state.security = action.payload.security
      state.frontend = action.payload.frontend
      state.backend = action.payload.backend
    },
  },
})

/**
 * AppSettingsSlice actions.
 *
 * @typedef {Object} Actions
 * @author  Pierre-Yves Léglise <contact@axialdata.net>
 * @property {Function} setConfig - Action to set the app settings configuration.
 * @example
 *  const { data, isLoading, isFetching } = useGetFeaturesQuery()
 * @returns {Object} Object containing user feature and role endpoint hooks.
 */
const { actions, reducer } = appSettingsSlice

export const { setConfig } = actions
export default reducer