Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / activation / src / logic / importers / importers.actions.ts
blob9befd0e4254b0e4b0e06b90abeafb604d6f4fbb9
1 import { createAsyncThunk } from '@reduxjs/toolkit';
2 import { c } from 'ttag';
4 import { cancelImport, getImportsList } from '@proton/activation/src/api';
5 import type { ApiImportListResponse } from '@proton/activation/src/api/api.interface';
7 import type { EasySwitchThunkExtra } from '../store';
8 import type { ActiveImportID } from './importers.interface';
10 export const loadImporters = createAsyncThunk<ApiImportListResponse, undefined, EasySwitchThunkExtra>(
11     'importers/load',
12     async (_, thunkApi) => {
13         const importers = await thunkApi.extra.api<ApiImportListResponse>(getImportsList());
14         return importers;
15     }
18 export const cancelImporter = createAsyncThunk<void, { activeImporterID: ActiveImportID }, EasySwitchThunkExtra>(
19     'importers/cancel',
20     async ({ activeImporterID }, thunkApi) => {
21         const state = thunkApi.getState();
22         const activeImporter = state.importers.activeImporters[activeImporterID];
24         await thunkApi.extra.api(
25             cancelImport({
26                 ImporterID: activeImporter.importerID,
27                 Products: [activeImporter.product],
28             })
29         );
30         await thunkApi.extra.eventManager.call();
32         thunkApi.extra.notificationManager.createNotification({ text: c('Success').t`Canceling import` });
33     }