Disable btn on action in Subscriptions

This commit is contained in:
vjrj 2018-03-02 09:22:55 +01:00
parent ceebb5d5ad
commit 3ce7d65bb8
3 changed files with 22 additions and 9 deletions

View file

@ -249,6 +249,7 @@ class SelectionMap extends Component {
} }
<Button <Button
bsStyle="success" bsStyle="success"
disabled={this.props.disableFstBtn}
onClick={event => this.onFstBtn(event)} onClick={event => this.onFstBtn(event)}
> >
{this.props.fstBtn} {this.props.fstBtn}
@ -282,6 +283,7 @@ SelectionMap.propTypes = {
onRemove: PropTypes.func, onRemove: PropTypes.func,
action: PropTypes.number.isRequired, action: PropTypes.number.isRequired,
loadingSubs: PropTypes.bool.isRequired, loadingSubs: PropTypes.bool.isRequired,
disableFstBtn: PropTypes.bool.isRequired,
currentSubs: PropTypes.arrayOf(PropTypes.shape({ currentSubs: PropTypes.arrayOf(PropTypes.shape({
location: PropTypes.shape({ latitude: PropTypes.number, longitude: PropTypes.number }).isRequired, location: PropTypes.shape({ latitude: PropTypes.number, longitude: PropTypes.number }).isRequired,
distance: PropTypes.number.isRequired distance: PropTypes.number.isRequired

View file

@ -16,7 +16,8 @@ class SubscriptionEditor extends React.Component {
super(props); super(props);
this.state = { this.state = {
center: props.center || [null, null], center: props.center || [null, null],
zoom: props.zoom || null zoom: props.zoom || null,
disableFstBtn: false
}; };
} }
@ -32,14 +33,18 @@ class SubscriptionEditor extends React.Component {
if (existingSubscription) doc._id = existingSubscription; if (existingSubscription) doc._id = existingSubscription;
const authenticated = !!Meteor.userId(); const authenticated = !!Meteor.userId();
const self = this;
self.setState({ disableFstBtn: true });
if (authenticated) { if (authenticated) {
Meteor.call(methodToCall, doc, (error, subscriptionId) => { Meteor.call(methodToCall, doc, (error, subscriptionId) => {
if (error) { if (error) {
self.setState({ disableFstBtn: false });
if (error.reason && error.reason.reason) { if (error.reason && error.reason.reason) {
Bert.alert(t(error.reason.reason), 'danger'); Bert.alert(t(error.reason.reason), 'danger');
} }
} else { } else {
self.setState({ disableFstBtn: false });
const confirmation = existingSubscription ? t('Zona actualizada') : t('Zona añadida'); const confirmation = existingSubscription ? t('Zona actualizada') : t('Zona añadida');
Bert.alert(confirmation, 'success'); Bert.alert(confirmation, 'success');
// history.push(`/subscriptions/${subscriptionId}`); // history.push(`/subscriptions/${subscriptionId}`);
@ -61,6 +66,7 @@ class SubscriptionEditor extends React.Component {
zoom={this.state.zoom} zoom={this.state.zoom}
distance={doc.distance} distance={doc.distance}
focusInput={focus} focusInput={focus}
disableFstBtn={this.state.disableFstBtn}
subsBtn={isEdit ? t('Actualizar') : t(isAnyMobile ? 'Suscribirme a este radio' : 'Suscribirme a fuegos en este radio')} subsBtn={isEdit ? t('Actualizar') : t(isAnyMobile ? 'Suscribirme a este radio' : 'Suscribirme a fuegos en este radio')}
onSubs={state => this.onSubs(state)} onSubs={state => this.onSubs(state)}
/> />

View file

@ -35,6 +35,9 @@ class FireSubscription extends React.Component {
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
if (nextProps.disableFstBtn !== this.props.disableFstBtn) {
return true;
}
if (this.state.init && if (this.state.init &&
nextState.center === this.state.center && nextState.center === this.state.center &&
nextState.distance === this.state.distance) { nextState.distance === this.state.distance) {
@ -95,13 +98,14 @@ class FireSubscription extends React.Component {
</Col> </Col>
</Row> </Row>
<SelectionMap <SelectionMap
center={this.state.center} center={this.state.center}
zoom={this.state.zoom} zoom={this.state.zoom}
distance={this.state.distance} distance={this.state.distance}
fstBtn={this.props.subsBtn} fstBtn={this.props.subsBtn}
onFstBtn={state => this.onSubs(state)} onFstBtn={state => this.onSubs(state)}
onSelection={state => this.onSelection(state)} onSelection={state => this.onSelection(state)}
action={action.add} action={action.add}
disableFstBtn={this.props.disableFstBtn}
/> />
</div> </div>
); );
@ -114,7 +118,8 @@ FireSubscription.propTypes = {
distance: PropTypes.number, distance: PropTypes.number,
focusInput: PropTypes.bool.isRequired, focusInput: PropTypes.bool.isRequired,
subsBtn: PropTypes.string.isRequired, subsBtn: PropTypes.string.isRequired,
onSubs: PropTypes.func.isRequired onSubs: PropTypes.func.isRequired,
disableFstBtn: PropTypes.bool.isRequired
}; };
export default translate([], { wait: true })(FireSubscription); export default translate([], { wait: true })(FireSubscription);