Share links list WIP
This commit is contained in:
43
app/stores/SharesStore.js
Normal file
43
app/stores/SharesStore.js
Normal file
@@ -0,0 +1,43 @@
|
||||
// @flow
|
||||
import { observable, action, runInAction } from 'mobx';
|
||||
import invariant from 'invariant';
|
||||
import { client } from 'utils/ApiClient';
|
||||
import type { Share, PaginationParams } from 'types';
|
||||
|
||||
class SharesStore {
|
||||
@observable data: Share[] = [];
|
||||
@observable isFetching: boolean = false;
|
||||
@observable isSaving: boolean = false;
|
||||
|
||||
@action
|
||||
fetchPage = async (options: ?PaginationParams): Promise<*> => {
|
||||
this.isFetching = true;
|
||||
|
||||
try {
|
||||
const res = await client.post('/shares.list', options);
|
||||
invariant(res && res.data, 'Data should be available');
|
||||
const { data } = res;
|
||||
|
||||
runInAction('fetchShares', () => {
|
||||
this.data = data;
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Something went wrong');
|
||||
}
|
||||
this.isFetching = false;
|
||||
};
|
||||
|
||||
@action
|
||||
deleteShare = async (id: string) => {
|
||||
try {
|
||||
await client.post('/shares.delete', { id });
|
||||
runInAction('deleteShare', () => {
|
||||
this.fetchPage();
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Something went wrong');
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default SharesStore;
|
||||
@@ -3,6 +3,7 @@ import AuthStore from './AuthStore';
|
||||
import UiStore from './UiStore';
|
||||
import ErrorsStore from './ErrorsStore';
|
||||
import DocumentsStore from './DocumentsStore';
|
||||
import SharesStore from './SharesStore';
|
||||
|
||||
const ui = new UiStore();
|
||||
const errors = new ErrorsStore();
|
||||
@@ -12,6 +13,7 @@ const stores = {
|
||||
ui,
|
||||
errors,
|
||||
documents: new DocumentsStore({ ui, errors }),
|
||||
shares: new SharesStore(),
|
||||
};
|
||||
|
||||
export default stores;
|
||||
|
||||
Reference in New Issue
Block a user