blob: 238781f7912fba7c83b1e410f5e75bf22305e83f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from '../../store';
import type { Guest } from '../../models';
type GuestAuth = {
guest?: Guest;
token?: string;
};
const guestSlice = createSlice({
name: 'guest',
initialState: { guest: undefined, token: undefined } as GuestAuth,
reducers: {
setGuest: (
state,
{ payload: { guest, token } }: PayloadAction<GuestAuth>
) => {
state.guest = guest;
state.token = token;
},
},
});
export const { setGuest } = guestSlice.actions;
export const selectGuest = (state: RootState) => state.guest.guest;
export default guestSlice.reducer;
|