mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { createEntityAdapter, createSlice } from '@reduxjs/toolkit';
|
|
|
|
import { Invitee } from 'app/types';
|
|
|
|
import { fetchInvitees, revokeInvite } from './actions';
|
|
|
|
export type Status = 'idle' | 'loading' | 'succeeded' | 'failed';
|
|
|
|
const invitesAdapter = createEntityAdapter({ selectId: (invite: Invitee) => invite.code });
|
|
export const selectors = invitesAdapter.getSelectors();
|
|
export const initialState = invitesAdapter.getInitialState<{ status: Status }>({ status: 'idle' });
|
|
|
|
const invitesSlice = createSlice({
|
|
name: 'invites',
|
|
initialState,
|
|
reducers: {},
|
|
extraReducers: (builder) => {
|
|
builder
|
|
.addCase(fetchInvitees.pending, (state) => {
|
|
state.status = 'loading';
|
|
})
|
|
.addCase(fetchInvitees.fulfilled, (state, { payload: invites }) => {
|
|
invitesAdapter.setAll(state, invites);
|
|
state.status = 'succeeded';
|
|
})
|
|
.addCase(fetchInvitees.rejected, (state) => {
|
|
state.status = 'failed';
|
|
})
|
|
.addCase(revokeInvite.fulfilled, (state, { payload: inviteCode }) => {
|
|
invitesAdapter.removeOne(state, inviteCode);
|
|
state.status = 'succeeded';
|
|
});
|
|
},
|
|
});
|
|
|
|
export const invitesReducer = invitesSlice.reducer;
|
|
|
|
export default {
|
|
invites: invitesReducer,
|
|
};
|