8cbcb77486
* Big upgrades * WIP: Stash * Stash, 30 flow errors left * Downgrade mobx * WIP * When I understand the difference between class and instance methods * 💚 * Fixes: File import Model saving edge cases pinning and starring docs Collection editing Upgrade mobx devtools * Notification settings saving works * Disabled settings * Document mailer * Working notifications * Colletion created notification Ensure not notified for own actions * Tidy up * Document updated event only for document creation Add indexes Notification setting on user creation * Commentary * Fixed: Notification setting on signup * Fix document move / duplicate stale data Add BaseModel.refresh method * Fixes: Title in sidebar not updated after editing document * 💚 * Improve / restore error handling Better handle offline errors * 👕
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
// @flow
|
|
import { filter } from 'lodash';
|
|
import { computed, action, runInAction } from 'mobx';
|
|
import invariant from 'invariant';
|
|
import { client } from 'utils/ApiClient';
|
|
import BaseStore from './BaseStore';
|
|
import RootStore from './RootStore';
|
|
import User from 'models/User';
|
|
|
|
export default class UsersStore extends BaseStore<User> {
|
|
constructor(rootStore: RootStore) {
|
|
super(rootStore, User);
|
|
}
|
|
|
|
@computed
|
|
get active(): User[] {
|
|
return filter(this.orderedData, user => !user.isSuspended);
|
|
}
|
|
|
|
@computed
|
|
get admins(): User[] {
|
|
return filter(this.orderedData, user => user.isAdmin);
|
|
}
|
|
|
|
@action
|
|
promote = (user: User) => {
|
|
return this.actionOnUser('promote', user);
|
|
};
|
|
|
|
@action
|
|
demote = (user: User) => {
|
|
return this.actionOnUser('demote', user);
|
|
};
|
|
|
|
@action
|
|
suspend = (user: User) => {
|
|
return this.actionOnUser('suspend', user);
|
|
};
|
|
|
|
@action
|
|
activate = (user: User) => {
|
|
return this.actionOnUser('activate', user);
|
|
};
|
|
|
|
actionOnUser = async (action: string, user: User) => {
|
|
const res = await client.post(`/users.${action}`, {
|
|
id: user.id,
|
|
});
|
|
invariant(res && res.data, 'Data should be available');
|
|
const { data } = res;
|
|
|
|
runInAction(`UsersStore#${action}`, () => {
|
|
this.add(data);
|
|
});
|
|
};
|
|
}
|