i18n: Upgrade translations from crowdin (a80a6511). (vpn-settings)
[ProtonMail-WebClient.git] / packages / account / scheduleCall / index.ts
blobb406a06e3fb61f571618eccacacb0f90b16abce6
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());
25     },
26     previous: previousSelector(selectScheduleCall),
27 });
29 const initialState = getInitialModelState<Model>();
30 const slice = createSlice({
31     name,
32     initialState,
33     reducers: {},
34     extraReducers: (builder) => {
35         handleAsyncModel(builder, modelThunk);
36     },
37 });
39 export const scheduleCallReducer = { [name]: slice.reducer };
40 export const scheduleCallThunk = modelThunk.thunk;