import { ofType } from 'redux-observable';
import { of } from 'rxjs';
import { switchMap } from 'rxjs/operators';

import { TYPE_ERROR } from '@/modules/@common/notify/constants';

import { notifyAction } from '@/modules/@common/notify/redux/slices';
import { errorEventAction } from '@/modules/@common/request/redux/slices';

export default (action$) =>
  action$.pipe(
    ofType(errorEventAction.type),
    switchMap((action) =>
      of(
        notifyAction({
          variant: TYPE_ERROR,
          message: action.payload || 'Please try again!',
        }),
      ),
    ),
  );
