This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/models/Integration.js
2018-06-01 15:13:05 -04:00

58 lines
1.2 KiB
JavaScript

// @flow
import { extendObservable, action } from 'mobx';
import BaseModel from 'models/BaseModel';
import { client } from 'utils/ApiClient';
import stores from 'stores';
import UiStore from 'stores/UiStore';
type Settings = {
url: string,
channel: string,
channelId: string,
};
type Events = 'documents.create' | 'collections.create';
class Integration extends BaseModel {
ui: UiStore;
id: string;
service: string;
collectionId: string;
events: Events;
settings: Settings;
@action
update = async (data: Object) => {
try {
await client.post('/integrations.update', { id: this.id, ...data });
extendObservable(this, data);
} catch (e) {
this.ui.showToast('Integration failed to update');
}
return false;
};
@action
delete = async () => {
try {
await client.post('/integrations.delete', { id: this.id });
this.emit('integrations.delete', { id: this.id });
return true;
} catch (e) {
this.ui.showToast('Integration failed to delete');
}
return false;
};
constructor(data?: Object = {}) {
super();
extendObservable(this, data);
this.ui = stores.ui;
}
}
export default Integration;