feat: state redux toolkit & feedback slice
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { type Alert } from '@/types/feedback'
|
||||
import { createSlice, type PayloadAction } from '@reduxjs/toolkit'
|
||||
|
||||
interface FeedbackState {
|
||||
alerts: Alert[]
|
||||
}
|
||||
|
||||
const initialState: FeedbackState = {
|
||||
alerts: []
|
||||
}
|
||||
|
||||
const feedbackSlice = createSlice({
|
||||
name: 'feedback',
|
||||
initialState,
|
||||
reducers: {
|
||||
addAlert (state, action: PayloadAction<Alert>) {
|
||||
return {
|
||||
...state,
|
||||
alerts: [...state.alerts, action.payload]
|
||||
}
|
||||
},
|
||||
removeAlert (state, action: PayloadAction<string>) {
|
||||
return {
|
||||
...state,
|
||||
alerts: state.alerts.filter(alert => alert.id !== action.payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const { addAlert, removeAlert } = feedbackSlice.actions
|
||||
|
||||
export default feedbackSlice
|
||||
@@ -0,0 +1,13 @@
|
||||
import feedbackSlice from '@/state/feedbackSlice'
|
||||
import { configureStore } from '@reduxjs/toolkit'
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
feedback: feedbackSlice.reducer
|
||||
}
|
||||
})
|
||||
|
||||
export default store
|
||||
|
||||
export type RootState = ReturnType<typeof store.getState>
|
||||
export type AppDispatch = typeof store.dispatch
|
||||
Reference in New Issue
Block a user