blob: 7ddb1338b268f938d2f21e0e0795c1f605ededb7 [file] [log] [blame]
simond47ef9e2022-09-28 22:24:28 -04001import { createSlice, PayloadAction } from '@reduxjs/toolkit';
2import Account from '../../model/Account';
idillond858c182022-09-16 13:18:26 -04003
4// Define a type for the slice state
5interface appState {
idillon531b6f22022-09-16 14:02:00 -04006 accountId: string;
simonc7d52452022-09-23 02:09:42 -04007 accountObject: Account | null;
ervinanoh34eb9472022-09-13 04:20:28 -04008 refresh: boolean;
idillond858c182022-09-16 13:18:26 -04009}
10
11// Define the initial state using that type
12const initialState: appState = {
simond47ef9e2022-09-28 22:24:28 -040013 accountId: '',
ervinanoh99655642022-09-01 15:11:31 -040014 accountObject: null,
ervinanoh34eb9472022-09-13 04:20:28 -040015 refresh: true,
idillond858c182022-09-16 13:18:26 -040016};
17
18export const appSlice = createSlice({
simond47ef9e2022-09-28 22:24:28 -040019 name: 'app',
idillond858c182022-09-16 13:18:26 -040020 // `createSlice` will infer the state type from the `initialState` argument
21 initialState,
22 reducers: {
idillon531b6f22022-09-16 14:02:00 -040023 setAccountId: (state, action: PayloadAction<string>) => {
24 state.accountId = action.payload;
idillond858c182022-09-16 13:18:26 -040025 },
ervinanoh99655642022-09-01 15:11:31 -040026 setAccountObject: (state, action: PayloadAction<Account>) => {
ervinanoh34eb9472022-09-13 04:20:28 -040027 state.accountObject = action.payload;
28 },
29 setRefreshFromSlice: (state) => {
30 state.refresh = !state.refresh;
ervinanoh99655642022-09-01 15:11:31 -040031 },
idillond858c182022-09-16 13:18:26 -040032 },
33});
34
ervinanoh34eb9472022-09-13 04:20:28 -040035export const { setAccountId, setAccountObject, setRefreshFromSlice } = appSlice.actions;
idillond858c182022-09-16 13:18:26 -040036
37// Other code such as selectors can use the imported `RootState` type
idillon531b6f22022-09-16 14:02:00 -040038// export const selectCount = (state: RootState) => state.app.value;
idillond858c182022-09-16 13:18:26 -040039
40export default appSlice.reducer;