DRVDOC-1129: Clicking on editor margins should focus editor
[ProtonMail-WebClient.git] / packages / account / inactiveKeys / index.ts
blob372a90a6decc7f9b451745bf77f109502ac1117e
1 import { type PayloadAction, createSlice } from '@reduxjs/toolkit';
3 import type { InactiveKey } from '@proton/shared/lib/interfaces';
5 interface State {
6     user: InactiveKey[];
7     addresses: { [key: string]: InactiveKey[] };
10 const name = 'inactiveKeys' as const;
12 export interface InactiveKeysState {
13     [name]: State;
16 const initialState: { user: InactiveKey[]; addresses: { [key: string]: InactiveKey[] } } = {
17     user: [],
18     addresses: {},
20 const slice = createSlice({
21     name,
22     initialState,
23     reducers: {
24         set: (state, action: PayloadAction<{ id: 'user' | string; value: InactiveKey[] }>) => {
25             if (action.payload.id === 'user') {
26                 state.user = action.payload.value || [];
27             } else {
28                 if (!action.payload.value?.length) {
29                     if (state.addresses[action.payload.id]) {
30                         delete state.addresses[action.payload.id];
31                     }
32                 } else {
33                     state.addresses[action.payload.id] = action.payload.value;
34                 }
35             }
36         },
37     },
38 });
40 export const selectInactiveKeys = (state: InactiveKeysState) => state.inactiveKeys;
42 export const inactiveKeysReducer = slice.reducer;
43 export const inactiveKeysActions = slice.actions;