1- import React , { PureComponent } from 'react' ;
2- import { connect } from 'react-redux' ;
1+ import React , { Component } from 'react' ;
2+ import { connect , batch } from 'react-redux' ;
33import get from "lodash/get" ;
44import {
55 ACCESS_BEING_LOADED ,
@@ -11,7 +11,8 @@ import {
1111import PropTypes from "prop-types" ;
1212import { awaitHelper } from "../utils" ;
1313
14- class AccessTypeBase extends PureComponent {
14+
15+ class AccessTypeBase extends Component {
1516
1617 componentDidMount ( ) {
1718 this . initAccessType ( ) ;
@@ -70,9 +71,7 @@ class AccessTypeBase extends PureComponent {
7071 error : 'subscriptions fetch failed'
7172 } ;
7273 }
73- const { 'subscription_groups' : subscriptionGroups = [ ] } = subscriptions ;
74- this . props . subscriptionGroupLoaded ( subscriptionGroups ) ;
75- return subscriptionGroups ;
74+ return subscriptions [ "subscription_groups" ] || [ ] ;
7675 } ;
7776
7877 getPaymentOptions = async ( ) => {
@@ -85,15 +84,23 @@ class AccessTypeBase extends PureComponent {
8584 error : 'payment options fetch failed'
8685 } ;
8786 }
88- this . props . paymentOptionsLoaded ( paymentOptions ) ;
8987 return paymentOptions ;
9088 } ;
9189
9290 runSequentialCalls = async ( ) => {
9391 const user = await this . setUser ( this . props . email , this . props . phone ) ;
9492 if ( user ) {
95- this . getSubscription ( ) ;
96- this . getPaymentOptions ( ) ;
93+ try {
94+ Promise . all ( [ this . getSubscription ( ) , this . getPaymentOptions ( ) ] ) . then ( ( [ subscriptionGroups , paymentOptions ] ) => {
95+ batch ( ( ) => {
96+ this . props . subscriptionGroupLoaded ( subscriptionGroups ) ;
97+ this . props . paymentOptionsLoaded ( paymentOptions ) ;
98+ } )
99+ } )
100+ } catch ( e ) {
101+ console . log ( `Subscription / payments failed` , e ) ;
102+ }
103+
97104 }
98105 } ;
99106
@@ -146,8 +153,6 @@ class AccessTypeBase extends PureComponent {
146153
147154 const meteredBody = {
148155 method : "POST" ,
149- cache : "no-cache" ,
150- "Cache-Control" : "private,no-cache,no-store" ,
151156 headers : {
152157 "Content-Type" : "text/plain"
153158 } ,
@@ -165,13 +170,6 @@ class AccessTypeBase extends PureComponent {
165170
166171 this . props . accessIsLoading ( true ) ;
167172
168-
169- const accessObject = {
170- id : assetId ,
171- type : 'story' ,
172- attributes : { }
173- } ;
174-
175173 const meteringParam = this . props . disableMetering === true ? '?disable-meter=true' : '' ;
176174 const { error, data : accessData } = await awaitHelper ( ( await global . fetch ( `/api/access/v1/stories/${ assetId } /access${ meteringParam } ` ) ) . json ( ) ) ;
177175
@@ -193,16 +191,17 @@ class AccessTypeBase extends PureComponent {
193191 } ;
194192
195193 render ( ) {
196- const { children} = this . props ;
197- console . log ( `RENDERING AT` ) ;
198- return children ( {
199- initAccessType : this . initAccessType ,
200- initRazorPayPayment : this . initRazorPayPayment ,
201- checkAccess : this . checkAccess ,
202- getSubscriptionForUser : this . getSubscriptionForUser ,
203- accessUpdated : this . props . accessUpdated ,
204- accessIsLoading : this . props . accessIsLoading
205- } ) ;
194+ const { children} = this . props ;
195+
196+ return children ( {
197+ initAccessType : this . initAccessType ,
198+ initRazorPayPayment : this . initRazorPayPayment ,
199+ checkAccess : this . checkAccess ,
200+ getSubscriptionForUser : this . getSubscriptionForUser ,
201+ accessUpdated : this . props . accessUpdated ,
202+ accessIsLoading : this . props . accessIsLoading
203+ } ) ;
204+
206205 }
207206}
208207
0 commit comments