Refactor alerts to TypeScript, remove react-notification
dependency (#34239)
This commit is contained in:
parent
e1dbbf6c9d
commit
94d71c992e
14 changed files with 171 additions and 121 deletions
|
@ -12,19 +12,21 @@ import type { AsyncThunkRejectValue } from '../typed_functions';
|
|||
const defaultFailSuffix = 'FAIL';
|
||||
const isFailedAction = new RegExp(`${defaultFailSuffix}$`, 'g');
|
||||
|
||||
interface ActionWithMaybeAlertParams extends Action, AsyncThunkRejectValue {}
|
||||
|
||||
interface RejectedAction extends Action {
|
||||
payload: AsyncThunkRejectValue;
|
||||
}
|
||||
|
||||
interface ActionWithMaybeAlertParams extends Action, AsyncThunkRejectValue {
|
||||
payload?: AsyncThunkRejectValue;
|
||||
}
|
||||
|
||||
function isRejectedActionWithPayload(
|
||||
action: unknown,
|
||||
): action is RejectedAction {
|
||||
return isAsyncThunkAction(action) && isRejectedWithValue(action);
|
||||
}
|
||||
|
||||
function isActionWithmaybeAlertParams(
|
||||
function isActionWithMaybeAlertParams(
|
||||
action: unknown,
|
||||
): action is ActionWithMaybeAlertParams {
|
||||
return isAction(action);
|
||||
|
@ -40,11 +42,12 @@ export const errorsMiddleware: Middleware<{}, RootState> =
|
|||
showAlertForError(action.payload.error, action.payload.skipNotFound),
|
||||
);
|
||||
} else if (
|
||||
isActionWithmaybeAlertParams(action) &&
|
||||
!action.skipAlert &&
|
||||
isActionWithMaybeAlertParams(action) &&
|
||||
!(action.payload?.skipAlert || action.skipAlert) &&
|
||||
action.type.match(isFailedAction)
|
||||
) {
|
||||
dispatch(showAlertForError(action.error, action.skipNotFound));
|
||||
const { error, skipNotFound } = action.payload ?? action;
|
||||
dispatch(showAlertForError(error, skipNotFound));
|
||||
}
|
||||
|
||||
return next(action);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue