Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / pass / store / sagas / invites / invite-recommendations.saga.ts
blob1185d67dc97e6af2412b9b23be1a73a9b52ed69b
1 import { cancelled, put, takeLatest } from 'redux-saga/effects';
3 import { getInviteRecommendations } from '@proton/pass/lib/invites/invite.requests';
4 import {
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({
13     payload,
14     meta: { request },
15 }: ReturnType<typeof inviteRecommendationsIntent>): Generator {
16     const ctrl = new AbortController();
18     try {
19         yield wait(100);
21         const result = (yield getInviteRecommendations(payload, ctrl.signal)) as InviteRecommendationsResponse;
22         const { RecommendedEmails, GroupDisplayName, PlanRecommendedEmails, PlanRecommendedEmailsNextToken } = result;
24         yield put(
25             inviteRecommendationsSuccess(request.id, {
26                 emails: RecommendedEmails,
27                 more: PlanRecommendedEmailsNextToken !== null,
28                 next: PlanRecommendedEmailsNextToken ?? null,
29                 organization: GroupDisplayName ? { emails: PlanRecommendedEmails, name: GroupDisplayName } : null,
30                 since: payload.since,
31             })
32         );
33     } catch (error) {
34         yield put(inviteRecommendationsFailure(request.id, error));
35     } finally {
36         if (yield cancelled()) ctrl.abort();
37     }
40 export default function* watcher() {
41     yield takeLatest(inviteRecommendationsIntent.match, loadRecommendationsWorker);