dg-npm-templates
Version:
Npx generator for react app dependency creation by digite
55 lines (48 loc) • 1.5 kB
JavaScript
import { createSlice } from '@reduxjs/toolkit';
export const MessageSlice = createSlice({
name: 'messageData',
initialState: {
show: false
},
reducers: {
initMessageComp: (state, action) => {
state.messageData = {
show: false,
type: undefined, //eg.confirmation/error/warning/success/failure
message: undefined
}
},
showMessage: (state, action) => {
state.messageData = Object.assign({}, state.messageData, {
show: true,
type: action.payload.type,
message: action.payload.message,
onConfirmFn: action.payload.onConfirmFn,
onCancelFn: action.payload.onCancelFn,
headerText: action.payload.headerText,
actionLabels: action.payload.actionLabels,
dontShowMeAgain: action.payload.dontShowMeAgain,
showMainBox: action.payload.showMainBox,
htmlMessage: action.payload.htmlMessage,
noHeaderIcon: action.payload.noHeaderIcon
});
},
hideMessage: (state, action) => {
state.messageData = Object.assign({}, state.messageData, {
show: false,
type: undefined,
message: undefined,
headerText: undefined,
actionLabels: undefined,
onConfirmFn: undefined,
dontShowMeAgain: false,
showMainBox: false,
onCancelFn: undefined,
htmlMessage: undefined,
noHeaderIcon: undefined
});
},
},
});
export const { initMessageComp, showMessage, hideMessage } = MessageSlice.actions;
export default MessageSlice.reducer;