diff options
Diffstat (limited to 'client/src/slices/auth')
-rw-r--r-- | client/src/slices/auth/adminSlice.ts | 29 | ||||
-rw-r--r-- | client/src/slices/auth/guestSlice.ts | 29 |
2 files changed, 58 insertions, 0 deletions
diff --git a/client/src/slices/auth/adminSlice.ts b/client/src/slices/auth/adminSlice.ts new file mode 100644 index 0000000..8753b55 --- /dev/null +++ b/client/src/slices/auth/adminSlice.ts @@ -0,0 +1,29 @@ +import { createSlice } from '@reduxjs/toolkit'; +import type { PayloadAction } from '@reduxjs/toolkit'; +import type { RootState } from '../../store'; +import type { Guest } from '../api/guestSlice'; + +type AdminAuth = { + guests?: Guest[]; + token?: string; +}; + +const adminSlice = createSlice({ + name: 'admin', + initialState: { guest: undefined, token: undefined } as AdminAuth, + reducers: { + setAdmin: ( + state, + { payload: { guests, token } }: PayloadAction<AdminAuth> + ) => { + state.guests = guests; + state.token = token; + }, + }, +}); + +export const { setAdmin } = adminSlice.actions; + +export default adminSlice.reducer; + +export const selectGuests = (state: RootState) => state.admin.guests; diff --git a/client/src/slices/auth/guestSlice.ts b/client/src/slices/auth/guestSlice.ts new file mode 100644 index 0000000..701148e --- /dev/null +++ b/client/src/slices/auth/guestSlice.ts @@ -0,0 +1,29 @@ +import { createSlice } from '@reduxjs/toolkit'; +import type { PayloadAction } from '@reduxjs/toolkit'; +import type { RootState } from '../../store'; +import type { Guest } from '../api/guestSlice'; + +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 default guestSlice.reducer; + +export const selectGuest = (state: RootState) => state.guest.guest; |