jam-cloud/web/app/assets/javascripts/react-components/AccountSubscriptionScreen.j...

113 lines
3.0 KiB
CoffeeScript
Raw Permalink Normal View History

2020-09-15 00:51:01 +00:00
context = window
rest = context.JK.Rest()
logger = context.JK.logger
AppStore = context.AppStore
UserStore = context.UserStore
2020-11-21 22:14:37 +00:00
SubscriptionStore = context.SubscriptionStore
SubscriptionActions = context.SubscriptionActions
2020-09-15 00:51:01 +00:00
profileUtils = context.JK.ProfileUtils
@AccountSubscriptionScreen = React.createClass({
mixins: [
ICheckMixin,
Reflux.listenTo(AppStore, "onAppInit"),
2020-11-21 22:14:37 +00:00
Reflux.listenTo(UserStore, "onUserChanged"),
Reflux.listenTo(SubscriptionStore, "onSubscriptionChanged")
2020-09-15 00:51:01 +00:00
]
2020-12-08 15:59:29 +00:00
subRef: null
2020-09-15 00:51:01 +00:00
onAppInit: (@app) ->
2020-12-08 15:59:29 +00:00
@app.bindScreen('account/subscription', {beforeShow: @beforeShow, afterShow: @afterShow, beforeHide: @beforeHide, beforeLeave: @beforeLeave})
2020-09-15 00:51:01 +00:00
onUserChanged: (userState) ->
@setState({user: userState?.user})
2020-11-21 22:14:37 +00:00
onSubscriptionChanged: (subscription) ->
@setState({subscription: subscription})
2020-09-15 00:51:01 +00:00
beforeHide: (e) ->
@screenVisible = false
return true
beforeShow: (e) ->
2020-12-08 15:59:29 +00:00
@allowLeave = false
2020-11-21 22:14:37 +00:00
SubscriptionActions.updateSubscription()
2020-09-15 00:51:01 +00:00
2020-12-08 15:59:29 +00:00
forceUpdate: () ->
this.refs.sub.onSubmit()
userMustLeave: (location) ->
@allowLeave = true
window.location.href = '/client' + location
beforeLeave: (data) ->
console.debug("subscription beforeLeave", @allowLeave)
if !this.refs.sub? || @allowLeave
return true
else
if this.refs.sub?
if !this.refs.sub.state.selectedPlan?
console.log("no selected plan; can leave")
return true
buttons = []
buttons.push({name: 'LEAVE ANYWAY', buttonStyle: 'button-grey', click: (() => (@userMustLeave(data.hash)))})
buttons.push({
name: 'UPDATE PLAN',
buttonStyle: 'button-orange',
click: (() => (@forceUpdate()))
})
context.JK.Banner.show({
title: "Subscription Not Updated",
html: '<div>If you leave this page without saving your new subscription plan preference, your selection will not take effect.<br/><br/>To save your new plan, please click the Update Plan button</div>',
buttons: buttons})
return false
2020-09-15 00:51:01 +00:00
afterShow: (e) ->
@screenVisible = true
logger.debug("AccountSubscriptionScreen: afterShow")
getInitialState: () ->
2020-11-21 22:14:37 +00:00
{ user: null, updating: false, subscription: null}
2020-09-15 00:51:01 +00:00
onCancel: (e) ->
e.preventDefault()
context.location.href = '/client#/account'
render: () ->
2020-11-21 22:14:37 +00:00
if @state.subscription
2020-12-08 15:59:29 +00:00
currentSubscription = `<CurrentSubscription ref="sub" subscription={this.state.subscription} app={this.app}/>`
2020-11-21 22:14:37 +00:00
content = `<div>
<div className="current-subscription-block">
{currentSubscription}
</div>
</div>`
else
content = `<div className="loading">Loading...</div>`
2020-09-15 00:51:01 +00:00
`<div className="content-body-scroller">
<div className="profile-header profile-head">
2020-11-21 22:14:37 +00:00
</div>
2020-09-15 00:51:01 +00:00
<div className="profile-body">
<div className="profile-wrapper">
<div className="main-content">
2020-11-21 22:14:37 +00:00
{content}
2020-09-15 00:51:01 +00:00
<br />
</div>
</div>
</div>
</div>`
})