UI work
This commit is contained in:
@@ -4,7 +4,7 @@ import invariant from 'invariant';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import type { ApiKey } from 'types';
|
||||
|
||||
class SettingsApiKeysStore {
|
||||
class SettingsApiKeySettingsStore {
|
||||
@observable apiKeys: ApiKey[] = [];
|
||||
@observable isFetching: boolean = false;
|
||||
@observable isSaving: boolean = false;
|
||||
@@ -57,4 +57,4 @@ class SettingsApiKeysStore {
|
||||
};
|
||||
}
|
||||
|
||||
export default SettingsApiKeysStore;
|
||||
export default SettingsApiKeySettingsStore;
|
||||
67
app/stores/MemberSettingsStore.js
Normal file
67
app/stores/MemberSettingsStore.js
Normal file
@@ -0,0 +1,67 @@
|
||||
// @flow
|
||||
import { observable, action, runInAction } from 'mobx';
|
||||
import invariant from 'invariant';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import type { User } from 'types';
|
||||
|
||||
class MemberSettingsStore {
|
||||
@observable users: User[] = [];
|
||||
@observable isLoaded: boolean = false;
|
||||
@observable isSaving: boolean = false;
|
||||
|
||||
@action
|
||||
fetchUsers = async () => {
|
||||
try {
|
||||
const res = await client.post('/team.users');
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
const { data } = res;
|
||||
|
||||
runInAction('fetchUsers', () => {
|
||||
this.users = data.reverse();
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Something went wrong');
|
||||
}
|
||||
this.isLoaded = false;
|
||||
};
|
||||
|
||||
@action
|
||||
promote = async (user: User) => {
|
||||
return this.actionOnUser('promote', user);
|
||||
};
|
||||
|
||||
@action
|
||||
demote = async (user: User) => {
|
||||
return this.actionOnUser('demote', user);
|
||||
};
|
||||
|
||||
@action
|
||||
suspend = async (user: User) => {
|
||||
return this.actionOnUser('suspend', user);
|
||||
};
|
||||
|
||||
@action
|
||||
activate = async (user: User) => {
|
||||
return this.actionOnUser('activate', user);
|
||||
};
|
||||
|
||||
actionOnUser = async (action: string, user: User) => {
|
||||
try {
|
||||
const res = await client.post(`/user.${action}`, {
|
||||
id: user.id,
|
||||
});
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
const { data } = res;
|
||||
|
||||
runInAction(`MemberSettingsStore#${action}`, () => {
|
||||
this.users = this.users.map(
|
||||
user => (user.id === data.id ? data : user)
|
||||
);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Something went wrong');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default MemberSettingsStore;
|
||||
@@ -1,31 +0,0 @@
|
||||
// @flow
|
||||
import { observable, action, runInAction } from 'mobx';
|
||||
import invariant from 'invariant';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import type { User } from 'types';
|
||||
|
||||
class SettingsUsersStore {
|
||||
@observable members: User[] = [];
|
||||
@observable isFetching: boolean = false;
|
||||
@observable isSaving: boolean = false;
|
||||
|
||||
@action
|
||||
fetchMembers = async () => {
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post('/team.users');
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
const { data } = res;
|
||||
|
||||
runInAction('fetchMembers', () => {
|
||||
this.members = data.reverse();
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Something went wrong');
|
||||
}
|
||||
this.isFetching = false;
|
||||
};
|
||||
}
|
||||
|
||||
export default SettingsUsersStore;
|
||||
Reference in New Issue
Block a user