blob: 8ad47cd11bc70d7d23ee76ab0d806addfb5f2a03 [file] [log] [blame]
idillond858c182022-09-16 13:18:26 -04001import { createSlice, PayloadAction } from "@reduxjs/toolkit";
ervinanoh99655642022-09-01 15:11:31 -04002import Account from "../../model/Account";
idillond858c182022-09-16 13:18:26 -04003import type { RootState } from "./store";
4
5// Define a type for the slice state
6interface appState {
idillon531b6f22022-09-16 14:02:00 -04007 accountId: string;
ervinanoh99655642022-09-01 15:11:31 -04008 accountObject: Account;
idillond858c182022-09-16 13:18:26 -04009}
10
11// Define the initial state using that type
12const initialState: appState = {
idillon531b6f22022-09-16 14:02:00 -040013 accountId: "",
ervinanoh99655642022-09-01 15:11:31 -040014 accountObject: null,
idillond858c182022-09-16 13:18:26 -040015};
16
17export const appSlice = createSlice({
18 name: "app",
19 // `createSlice` will infer the state type from the `initialState` argument
20 initialState,
21 reducers: {
idillon531b6f22022-09-16 14:02:00 -040022 setAccountId: (state, action: PayloadAction<string>) => {
23 state.accountId = action.payload;
idillond858c182022-09-16 13:18:26 -040024 },
ervinanoh99655642022-09-01 15:11:31 -040025 setAccountObject: (state, action: PayloadAction<Account>) => {
26 state.accountObject = action.payload ;
27 },
idillond858c182022-09-16 13:18:26 -040028 },
29});
30
ervinanoh99655642022-09-01 15:11:31 -040031export const { setAccountId, setAccountObject } = appSlice.actions;
idillond858c182022-09-16 13:18:26 -040032
33// Other code such as selectors can use the imported `RootState` type
idillon531b6f22022-09-16 14:02:00 -040034// export const selectCount = (state: RootState) => state.app.value;
idillond858c182022-09-16 13:18:26 -040035
36export default appSlice.reducer;