This commit is contained in:
Jori Lallo
2018-03-04 16:53:57 -08:00
parent 06a6573feb
commit a0f58583b5
12 changed files with 136 additions and 123 deletions

View File

@@ -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;

View 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;

View File

@@ -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;