summaryrefslogtreecommitdiff
path: root/client/src/slices/auth/adminSlice.ts
blob: 8753b558fbcf32e5cb8c500307ff70d18cbda10f (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
28
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;