chore: refactor app reducer to use rtk

This commit is contained in:
2024-08-17 18:33:20 +02:00
parent 7cd60b5c61
commit 5067f64ec3
4 changed files with 46 additions and 78 deletions

View File

@@ -1,15 +1,10 @@
import {
setAppErrorAC,
SetAppErrorActionType,
setAppStatusAC,
SetAppStatusActionType,
} from 'app/app-reducer'
import { setAppErrorAC, setAppStatusAC } from 'app/app-reducer'
import { ResponseType } from 'api/todolists-api'
import { Dispatch } from 'redux'
export const handleServerAppError = <D>(
data: ResponseType<D>,
dispatch: Dispatch<SetAppErrorActionType | SetAppStatusActionType>
dispatch: Dispatch
) => {
if (data.messages.length) {
dispatch(setAppErrorAC(data.messages[0]))
@@ -21,7 +16,7 @@ export const handleServerAppError = <D>(
export const handleServerNetworkError = (
error: { message: string },
dispatch: Dispatch<SetAppErrorActionType | SetAppStatusActionType>
dispatch: Dispatch
) => {
dispatch(setAppErrorAC(error.message ? error.message : 'Some error occurred'))
dispatch(setAppStatusAC('failed'))