context = window rest = context.JK.Rest() logger = context.JK.logger LocationActions = context.LocationActions SubscriptionActions = context.SubscriptionActions UserStore = context.UserStore AppStore = context.AppStore @CurrentSubscription = React.createClass({ mixins: [Reflux.listenTo(AppStore, "onAppInit")] getInitialState: () -> { selectedPlan: null updating: false } getDisplayNameTier: (plan_code) -> if plan_code == '' plan_code = null for subscriptionCode in gon.global.subscription_codes if plan_code == subscriptionCode.id return subscriptionCode.name return "Unknown plan code=#{plan_code}" getDisplayNamePrice: (plan_code) -> if plan_code == '' plan_code = null for subscriptionCode in gon.global.subscription_codes if plan_code == subscriptionCode.id return subscriptionCode.price return "Unknown plan code=#{plan_code}" onPlanChanged: (e) -> val = e.target.value @setState({selectedPlan: val}) currentPlan: () -> if this.state.selectedPlan? this.state.selectedPlan else this.props.subscription.desired_plan_code || '' checkIfPending:() -> return this.state.selectedPlan? onSubmit: (event) -> if event event.preventDefault() @performSubmit() onChangeSubmit: (form) -> if @state.updating return @performSubmit() # user selects button on main page onUpdatePaymentMethod: () -> if gon.isNativeClient context.JK.popExternalLink("/client#/account/paymentHistory", true) else window.location.href = "/client#/account/paymentHistory" openBrowserToPayment: () -> if gon.isNativeClient context.JK.popExternalLink("/client#/account/paymentHistory", true) else window.location.href = "/client#/account/paymentHistory" performSubmit: () -> if !@state.selectedPlan? return @setState({updating: true}) #SubscriptionActions.changeSubscription(this.state.selectedPlan) rest.changeSubscription(this.state.selectedPlan).done((subscription) => SubscriptionActions.forceUpdate(subscription) has_billing_info = subscription.has_billing_info console.log("subscription change update", subscription) @setState({updating: false, selectedPlan: null}) if has_billing_info @props.app.layout.notify({ title: "Subscription updated!", text: "Thank you for supporting JamKazam!" }) else if subscription.desired_plan_code if gon.isNativeClient html = context._.template($('#template-payment-still-needed-native').html(), {}, { variable: 'data' }) else html = context._.template($('#template-payment-still-needed').html(), {}, { variable: 'data' }) buttons = [] buttons.push({name: 'CLOSE', buttonStyle: 'button-grey'}) buttons.push({ name: 'UPDATE PAYMENT METHOD', buttonStyle: 'button-orange', click: (() => (@openBrowserToPayment())) }) context.JK.Banner.show({ title: "Payment Method Needed", html: html, buttons: buttons}) else @props.app.layout.notify({ title: "Subscription updated!", text: "Thank you for supporting JamKazam!" }) #@props.app.layout.notify({ # title: "Payment method still needed", # text: "Please click UPDATE PAYMENT METHOD in the bottom-right of the screen." #}) ) .fail((jqXHR) => @setState({updating: false}) if jqXHR.status == 422 @props.app.layout.notify({ title: "you already have this subscription", text: "No changes were made to your account." }) else @props.app.layout.notify({ title: "unable to update subscription status", text: "Please contact support@jamkazam.com. Error:\n #{jqXHR.responseText}" }) ) onCancelPlan: (event) -> if confirm("Are you sure you want to cancel your plan?") SubscriptionActions.cancelSubscription() componentDidMount: () -> @root = $(@getDOMNode()) document.querySelector('#change-subscription-form').addEventListener('submit', @onChangeSubmit.bind(this)) comparePlans: (e) -> if context.JK.clientType() == 'client' context.JK.popExternalLink("https://jamkazam.freshdesk.com/support/solutions/articles/66000122535-what-are-jamkazam-s-free-vs-premium-features-") e.preventDefault() render: () -> plan_codes = [] monthlies = [] yearlies = [] for plan in gon.global.subscription_codes if plan.cycle == 'month' monthlies.push(plan) else yearlies.push(plan) plan_codes.push(``) for plan in monthlies plan_codes.push(``) plan_codes.push(``) for plan in yearlies plan_codes.push(``) plansJsx = `` changeClass = 'button-orange update-plan' if !@state.selectedPlan? || @state.updating changeClass = changeClass + ' disabled' if @state.updating update_plan_text = 'UPDATING PLAN ... PLEASE WAIT' else update_plan_text = 'UPDATE PLAN' recurly_subscription = @props.subscription.subscription effective_plan_name = `{this.getDisplayNameTier(this.props.subscription.plan_code)}` desired_plan_name = `{this.getDisplayNameTier(this.props.subscription.desired_plan_code)}` admin_override_plan_name = `{this.getDisplayNameTier(this.props.subscription.admin_override_plan_code)}` in_trial = @props.subscription.in_trial admin_override = @props.subscription.admin_override_plan_code? effective_is_free = !!this.props.subscription.plan_code has_pending_subscription = @props.subscription.subscription?.pending_subscription? cancelled_subscription = @props.subscription.subscription?.remaining_billing_cycles == 0 show_payment_info = null has_billing_info = @props.subscription.has_billing_info if admin_override explanation = `You have a {effective_plan_name} account until your gifted plan ends {context.JK.formatDateShort(this.props.subscription.admin_override_ends_at)}.` else if in_trial if @props.subscription.desired_plan_code if has_billing_info note = `Billing starts for the {desired_plan_name} plan after the trial ends.` else warning = `
You will drop to the Free free plan after the trial ends because you have not yet entered payment info.
` show_payment_info = true else if has_billing_info warning = `You will drop to the Free free plan after the trial ends because you have not selected a plan.
` else warning = `You will drop to the Free free plan after the trial ends because you have not yet entered payment info or selected a plan.
` show_payment_info = true explanation = `You have a {effective_plan_name} account until your trial ends {context.JK.formatDateShort(this.props.subscription.trial_ends_at)}. {note}` else if @props.subscription.desired_plan_code && !@props.subscription.plan_code && !has_billing_info explanation = `You have successfully upgraded your plan to the {desired_plan_name} level, thank you!` warning = `For this plan to take effect, you must provide a payment method (e.g. a credit card), for the monthly subscription charge. Please click the Update Payment Method button to do this now.
` show_payment_info = true else if @props.subscription.desired_plan_code if !has_billing_info show_payment_info = true explanation = `You have successfully upgraded your plan to the {desired_plan_name} level, thank you` warning = `However, you must provide a payment method (e.g. a credit card), for the monthly subscription charge. Please click the Update Payment Method button to do this now.
` else explanation = `You have successfully upgraded your plan to the {desired_plan_name} level, thank you!` else # free plan situation - not much to go on about explanation = `You are currently on the {desired_plan_name} plan.` if show_payment_info update_payment_btn = `UPDATE PAYMENT METHOD` if has_pending_subscription billingAddendum = null #`Your JamKazam subscription is currently set to the plan displayed below. To compare the features available for different subscription plans, click the Compare Plans button below. To change your plan, click the "subscription plan" list box below, select a new plan, and then click the Update Plan button below.
{explanation} {billingAddendum}
{warning}