1 import { createAction, createSlice } from '@reduxjs/toolkit';
3 import type { ProtonThunkArguments } from '@proton/redux-shared-store-types';
4 import { createAsyncModelThunk, handleAsyncModel, previousSelector } from '@proton/redux-utilities';
5 import { getAllowAddressDeletion } from '@proton/shared/lib/api/addresses';
7 import { getInitialModelState } from '../initialModelState';
8 import type { ModelState } from '../interface';
10 const name = 'allowAddressDeletion' as const;
12 export interface AllowAddressDeletionState {
13 [name]: ModelState<boolean>;
16 const initialState = getInitialModelState<boolean>();
18 export const selectAllowAddressDeletion = (state: AllowAddressDeletionState) => state[name];
20 const modelThunk = createAsyncModelThunk<boolean, AllowAddressDeletionState, ProtonThunkArguments>(`${name}/fetch`, {
21 miss: async ({ extraArgument }) => {
23 .api(getAllowAddressDeletion())
24 .then((response) => response.AddressDeletion.Allow)
27 previous: previousSelector(selectAllowAddressDeletion),
30 export const disableAllowAddressDeletion = createAction('allowAddressDeletion/update', () => ({ payload: {} }));
32 const slice = createSlice({
36 extraReducers: (builder) => {
37 handleAsyncModel(builder, modelThunk);
39 builder.addCase(disableAllowAddressDeletion, (state) => {
45 export const allowAddressDeletionReducer = { [name]: slice.reducer };
46 export const allowAddressDeletionThunk = modelThunk.thunk;