2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-03-08 05:52:17 +00:00
|
|
|
import Modal from '../base/modal';
|
|
|
|
import ModalBody from '../base/modal-body';
|
|
|
|
import ModalHeader from '../base/modal-header';
|
|
|
|
import ModalFooter from '../base/modal-footer';
|
2017-03-03 01:44:07 +00:00
|
|
|
import * as sync from '../../../sync';
|
|
|
|
import {SYNC_MODE_OFF, SYNC_MODE_ON, SYNC_MODE_NEVER, SYNC_MODE_UNSET} from '../../../sync/storage';
|
|
|
|
|
|
|
|
@autobind
|
|
|
|
class SetupSyncModal extends PureComponent {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2017-03-12 09:03:57 +00:00
|
|
|
syncMode: SYNC_MODE_UNSET,
|
|
|
|
selectedSyncMode: SYNC_MODE_ON
|
2017-03-03 01:44:07 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
_setModalRef (n) {
|
|
|
|
this.modal = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
async _handleDone () {
|
|
|
|
const {workspace} = this.props;
|
2017-03-12 09:03:57 +00:00
|
|
|
const {selectedSyncMode} = this.state;
|
2017-03-03 01:44:07 +00:00
|
|
|
|
|
|
|
const resource = await sync.getOrCreateResourceForDoc(workspace);
|
2017-03-12 09:03:57 +00:00
|
|
|
await sync.createOrUpdateConfig(resource.resourceGroupId, selectedSyncMode);
|
2017-03-03 01:44:07 +00:00
|
|
|
|
|
|
|
this.hide();
|
|
|
|
|
2017-03-12 09:03:57 +00:00
|
|
|
this._resolvePromise && this._resolvePromise(selectedSyncMode);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_handleSyncModeChange (e) {
|
2017-03-12 09:03:57 +00:00
|
|
|
this.setState({selectedSyncMode: e.target.value});
|
2017-03-03 20:09:08 +00:00
|
|
|
}
|
2017-03-03 01:44:07 +00:00
|
|
|
|
2017-08-12 21:56:24 +00:00
|
|
|
async show () {
|
|
|
|
const {workspace} = this.props;
|
|
|
|
|
|
|
|
const resource = await sync.getOrCreateResourceForDoc(workspace);
|
|
|
|
const config = await sync.getOrCreateConfig(resource.resourceGroupId);
|
|
|
|
const {syncMode} = config;
|
|
|
|
|
|
|
|
// Set selected sync mode. If it's unset, default it to ON
|
|
|
|
const selectedSyncMode = syncMode !== SYNC_MODE_UNSET ? syncMode : SYNC_MODE_ON;
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
syncMode,
|
|
|
|
selectedSyncMode
|
|
|
|
});
|
2017-03-03 01:44:07 +00:00
|
|
|
|
|
|
|
this.modal.show();
|
|
|
|
|
2017-03-03 20:09:08 +00:00
|
|
|
this._promise = new Promise(resolve => {
|
|
|
|
this._resolvePromise = resolve;
|
|
|
|
});
|
2017-03-12 09:03:57 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
return this._promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
hide () {
|
|
|
|
this.modal.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {workspace} = this.props;
|
2017-03-12 09:03:57 +00:00
|
|
|
const {syncMode, selectedSyncMode} = this.state;
|
2017-03-03 01:44:07 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal ref={this._setModalRef} noEscape>
|
|
|
|
<ModalHeader>Workspace Sync Setup</ModalHeader>
|
|
|
|
<ModalBody className="wide pad">
|
2017-03-03 20:09:08 +00:00
|
|
|
{syncMode === SYNC_MODE_UNSET
|
|
|
|
? <p className="notice info">
|
2017-03-03 01:44:07 +00:00
|
|
|
You have not yet configured sync for your <strong>{workspace.name}</strong> workspace.
|
|
|
|
</p> : null
|
|
|
|
}
|
|
|
|
<br/>
|
|
|
|
<div className="form-control form-control--outlined">
|
|
|
|
<label>Choose sync mode
|
2017-03-12 09:03:57 +00:00
|
|
|
<select onChange={this._handleSyncModeChange} value={selectedSyncMode}>
|
2017-03-03 01:44:07 +00:00
|
|
|
<option value={SYNC_MODE_ON}>
|
|
|
|
Automatically sync changes
|
|
|
|
</option>
|
|
|
|
<option value={SYNC_MODE_OFF}>
|
|
|
|
Manually sync changes
|
|
|
|
</option>
|
|
|
|
<option value={SYNC_MODE_NEVER}>
|
|
|
|
Disable sync for this workspace
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<br/>
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
|
|
|
<div className="margin-left faint italic txt-sm tall">
|
|
|
|
* This can be changed at any time
|
|
|
|
</div>
|
|
|
|
<button className="btn" onClick={this._handleDone}>
|
|
|
|
Continue
|
|
|
|
</button>
|
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
2017-03-03 20:09:08 +00:00
|
|
|
);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetupSyncModal.propTypes = {
|
2017-03-03 20:09:08 +00:00
|
|
|
workspace: PropTypes.object.isRequired
|
2017-03-03 01:44:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default SetupSyncModal;
|