12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { createSlice, PayloadAction } from '@reduxjs/toolkit';
- import config from 'app/core/config';
- import { OrgUser, UsersState } from 'app/types';
- export const initialState: UsersState = {
- users: [] as OrgUser[],
- searchQuery: '',
- searchPage: 1,
- canInvite: !config.externalUserMngLinkName,
- externalUserMngInfo: config.externalUserMngInfo,
- externalUserMngLinkName: config.externalUserMngLinkName,
- externalUserMngLinkUrl: config.externalUserMngLinkUrl,
- hasFetched: false,
- };
- const usersSlice = createSlice({
- name: 'users',
- initialState,
- reducers: {
- usersLoaded: (state, action: PayloadAction<OrgUser[]>): UsersState => {
- return { ...state, hasFetched: true, users: action.payload };
- },
- setUsersSearchQuery: (state, action: PayloadAction<string>): UsersState => {
- // reset searchPage otherwise search results won't appear
- return { ...state, searchQuery: action.payload, searchPage: initialState.searchPage };
- },
- setUsersSearchPage: (state, action: PayloadAction<number>): UsersState => {
- return { ...state, searchPage: action.payload };
- },
- },
- });
- export const { setUsersSearchQuery, setUsersSearchPage, usersLoaded } = usersSlice.actions;
- export const usersReducer = usersSlice.reducer;
- export default {
- users: usersReducer,
- };
|