-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui-slice.js
45 lines (43 loc) · 1.37 KB
/
ui-slice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { createSlice } from "@reduxjs/toolkit";
import { fetchCartData, sendCartData } from "./cart-action";
const uiSlice = createSlice({
name: "ui",
initialState: { cartIsVisible: false, notification: null },
reducers: {
toggle(state) {
state.cartIsVisible = !state.cartIsVisible;
},
},
extraReducers: {
[fetchCartData.rejected]: (state, action) => {
state.notification = {
status: "error",
title: "Error!",
message: action.error.message || "Fetching cart data failed.",
};
},
[sendCartData.pending]: (state, action) => {
state.notification = {
status: "pending",
title: "Sending...",
message: "Sending Cart Data...",
};
},
[sendCartData.fulfilled]: (state, action) => {
state.notification = {
status: "success",
title: "Success!",
message: "Sent cart data Successfully!",
};
},
[sendCartData.rejected]: (state, action) => {
state.notification = {
status: "error",
title: "Error!",
message: action.error.message,
};
},
},
});
export const uiActions = uiSlice.actions;
export default uiSlice;