feat: state redux toolkit & feedback slice

This commit is contained in:
2024-01-05 15:08:11 -06:00
parent ab82d0797d
commit b7e273ae06
10 changed files with 171 additions and 10 deletions
+33
View File
@@ -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
+13
View File
@@ -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