1 import { 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 { scheduleCall } from '@proton/shared/lib/api/support';
6 import type { ScheduleCall } from '@proton/shared/lib/interfaces';
8 import { getInitialModelState } from '../initialModelState';
9 import type { ModelState } from '../interface';
11 const name = 'scheduleCall' as const;
13 export interface ScheduleCallState {
14 [name]: ModelState<ScheduleCall>;
17 type SliceState = ScheduleCallState[typeof name];
18 type Model = NonNullable<SliceState['value']>;
20 export const selectScheduleCall = (state: ScheduleCallState) => state[name];
22 const modelThunk = createAsyncModelThunk<Model, ScheduleCallState, ProtonThunkArguments>(`${name}/fetch`, {
23 miss: async ({ extraArgument }) => {
24 return extraArgument.api(scheduleCall());
26 previous: previousSelector(selectScheduleCall),
29 const initialState = getInitialModelState<Model>();
30 const slice = createSlice({
34 extraReducers: (builder) => {
35 handleAsyncModel(builder, modelThunk);
39 export const scheduleCallReducer = { [name]: slice.reducer };
40 export const scheduleCallThunk = modelThunk.thunk;