-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsagas.ts
More file actions
26 lines (22 loc) · 972 Bytes
/
sagas.ts
File metadata and controls
26 lines (22 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { call, put, takeEvery } from 'redux-saga/effects';
import { ActionsOfType } from '@martin_hotell/rex-tils';
import { SignUpApi } from '../../api/signup';
import { TSignUpActionObjectTypes } from './actions';
import { SignUpActionTypes } from './types';
import { ToasterActions } from '../toaster/actions';
import { wording } from '../../utils/wording';
function* subscribeNewsletterSaga(
action: ActionsOfType<TSignUpActionObjectTypes, SignUpActionTypes.SUBSCRIBE_NEWSLETTER>
) {
try {
const { email } = action.payload;
// eslint-disable-next-line @typescript-eslint/unbound-method
yield call(SignUpApi.subscribeNewsletter, { email });
yield put(ToasterActions.showSuccessMessage(wording.subscriptionSuccessful));
} catch (err) {
yield put(ToasterActions.showErrorMessage(wording.basicError));
}
}
export function* subscribeNewsletterWatcher() {
yield takeEvery(SignUpActionTypes.SUBSCRIBE_NEWSLETTER, subscribeNewsletterSaga);
}