Refactor alerts to TypeScript, remove react-notification dependency (#34239)

This commit is contained in:
Eugen Rochko 2025-03-25 19:25:07 +01:00 committed by GitHub
parent e1dbbf6c9d
commit 94d71c992e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 171 additions and 121 deletions

View file

@ -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);