actions.ts 906 B

1234567891011121314151617181920212223
  1. import { getBackendSrv } from '@grafana/runtime';
  2. import { contextSrv } from 'app/core/core';
  3. import { FormModel } from 'app/features/org/UserInviteForm';
  4. import { AccessControlAction, createAsyncThunk, Invitee } from 'app/types';
  5. export const fetchInvitees = createAsyncThunk('users/fetchInvitees', async () => {
  6. if (!contextSrv.hasPermission(AccessControlAction.UsersCreate)) {
  7. return [];
  8. }
  9. const invitees: Invitee[] = await getBackendSrv().get('/api/org/invites');
  10. return invitees;
  11. });
  12. export const addInvitee = createAsyncThunk('users/addInvitee', async (addInviteForm: FormModel, { dispatch }) => {
  13. await getBackendSrv().post(`/api/org/invites`, addInviteForm);
  14. await dispatch(fetchInvitees());
  15. });
  16. export const revokeInvite = createAsyncThunk('users/revokeInvite', async (code: string) => {
  17. await getBackendSrv().patch(`/api/org/invites/${code}/revoke`, {});
  18. return code;
  19. });