1 import { cancelled, put, takeLatest } from 'redux-saga/effects';
3 import { getInviteRecommendations } from '@proton/pass/lib/invites/invite.requests';
5 inviteRecommendationsFailure,
6 inviteRecommendationsIntent,
7 inviteRecommendationsSuccess,
8 } from '@proton/pass/store/actions';
9 import type { InviteRecommendationsResponse } from '@proton/pass/types';
10 import { wait } from '@proton/shared/lib/helpers/promise';
12 function* loadRecommendationsWorker({
15 }: ReturnType<typeof inviteRecommendationsIntent>): Generator {
16 const ctrl = new AbortController();
21 const result = (yield getInviteRecommendations(payload, ctrl.signal)) as InviteRecommendationsResponse;
22 const { RecommendedEmails, GroupDisplayName, PlanRecommendedEmails, PlanRecommendedEmailsNextToken } = result;
25 inviteRecommendationsSuccess(request.id, {
26 emails: RecommendedEmails,
27 more: PlanRecommendedEmailsNextToken !== null,
28 next: PlanRecommendedEmailsNextToken ?? null,
29 organization: GroupDisplayName ? { emails: PlanRecommendedEmails, name: GroupDisplayName } : null,
34 yield put(inviteRecommendationsFailure(request.id, error));
36 if (yield cancelled()) ctrl.abort();
40 export default function* watcher() {
41 yield takeLatest(inviteRecommendationsIntent.match, loadRecommendationsWorker);