Update selected item color in Pass menu
[ProtonMail-WebClient.git] / packages / pass / store / sagas / items / item-delete.saga.ts
blobd709ac761c00539042e3fa993af15211bbb09e38
1 import { put, takeEvery } from 'redux-saga/effects';
3 import { api } from '@proton/pass/lib/api/api';
4 import { createTelemetryEvent } from '@proton/pass/lib/telemetry/event';
5 import { itemDeleteFailure, itemDeleteIntent, itemDeleteSuccess } from '@proton/pass/store/actions';
6 import type { RootSagaOptions } from '@proton/pass/store/types';
7 import { TelemetryEventName, TelemetryItemType } from '@proton/pass/types/data/telemetry';
9 function* deleteItem(
10     { onItemsUpdated, getTelemetry }: RootSagaOptions,
11     { payload }: ReturnType<typeof itemDeleteIntent>
12 ) {
13     const telemetry = getTelemetry();
14     const { item, shareId } = payload;
16     try {
17         yield api({
18             url: `pass/v1/share/${payload.shareId}/item`,
19             method: 'delete',
20             data: {
21                 Items: [
22                     {
23                         ItemID: item.itemId,
24                         Revision: item.revision,
25                     },
26                 ],
27             },
28         });
30         void telemetry?.push(createTelemetryEvent(TelemetryEventName.ItemDeletion, {}, { type: TelemetryItemType[item.data.type] }));
31         yield put(itemDeleteSuccess({ itemId: item.itemId, shareId }));
32         onItemsUpdated?.();
33     } catch (e) {
34         yield put(itemDeleteFailure({ itemId: item.itemId, shareId }, e));
35     }
38 export default function* watcher(options: RootSagaOptions) {
39     yield takeEvery(itemDeleteIntent.match, deleteItem, options);