Skip to content

Commit

Permalink
Merge pull request #73 from SolidStateGroup/develop
Browse files Browse the repository at this point in the history
features/Web Payments
  • Loading branch information
p-maks authored Feb 2, 2022
2 parents f24ad87 + a285b32 commit cde28fc
Show file tree
Hide file tree
Showing 22 changed files with 239 additions and 85 deletions.
6 changes: 4 additions & 2 deletions common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ var Constants = {
occupations: [{value: 'Healthcare Student'}, {value: 'Healthcare Practitioner'}, {value: 'Patient'}, {value: 'Other'}],
pages: {},
strings: {},

mobileSubscriptionMessage: "You have an active subscription via the mobile app. To manage your subscription please log into the mobile app.",
webSubscriptionMessage: "Your web subscription is active. Login to diagnosisview.org to manage.",
simulate: false ? {
SUBSCRIBED: false,
MANAGE_SUBSCRIPTION: true,
MOBILE_SUBSCRIBED: false,
MANAGE_SUBSCRIPTION: false,
LOGGED_IN: false,
PRE_FILLED_REGISTER: false,
ALL_FAVES_REMOVED_EXTERNALLY: false,
Expand Down
1 change: 1 addition & 0 deletions common/dispatcher/action-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = Object.assign({}, require('./base/_action-constants'), {
"DELETE_USER": "DELETE_USER",
"SET_TOKEN": "SET_TOKEN",
"UPDATE_USER": "UPDATE_USER",
"UPDATE_SUBSCRIPTION": "UPDATE_SUBSCRIPTION",
"ADMIN_LOGIN": "ADMIN_LOGIN",
"UPDATE_CODE": "UPDATE_CODE",
"UPDATE_LINK": "UPDATE_LINK",
Expand Down
6 changes: 6 additions & 0 deletions common/dispatcher/app-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ module.exports = Object.assign({}, require('./base/_app-actions'), {
details
});
},
updateSubscription: function(pageId) {
Dispatcher.handleViewAction({
actionType: Actions.UPDATE_SUBSCRIPTION,
data:{pageId}
});
},
adminLogin: function (details) {
Dispatcher.handleViewAction({
actionType: Actions.ADMIN_LOGIN,
Expand Down
9 changes: 7 additions & 2 deletions common/project.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module.exports = {
debug: false,
api: 'https://api.diagnosisview.org/api/',
baseUrl: "https://diagnosisview.org/",
baseUrl: "https://www.diagnosisview.org/",
public: 'https://api.diagnosisview.org/public/',
codepushIOS: "n_v9269jFN38lTv8i3Mbe0p8t6Xw0e4BjVrJp",
codepushAndroid: "JHGFbOmwdHWqtkE-Ck4osQ_aJxBD9Sj_nU5Mr",
captchaSiteKey: "6LdekQAdAAAAANSJB5HNaHO0fOV8yJUsORpEaM2A",
captchaBaseUrl: "https://www.diagnosisview.org",
ga: ''
ga: '',
chargebee: {
site: 'diagnosisview',
product:"professional-GBP-Yearly",
productInternal:"professional",
},
};
27 changes: 27 additions & 0 deletions common/stores/account-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ var controller = {
subscribe: function (purchase, silent) {
if (!store.model) return;

if (typeof Platform === "undefined") {
return
}
store.saving();

// Get device favourites and history to sync with server
Expand Down Expand Up @@ -227,6 +230,18 @@ var controller = {
})
.catch(e => AjaxHandler.error(AccountStore, e));
},
updateSubscription: function (details) {
if (!store.model) return;
store.saving();
data.post(Project.api + 'user/subscriptions/chargebee', details)
.then(res => {
controller.getAccount()
})
.then(res => {
store.saved();
})
.catch(e => AjaxHandler.error(AccountStore, e));
},
},
store = Object.assign({}, BaseStore, {
id: 'account',
Expand All @@ -246,6 +261,9 @@ var controller = {
return !store.model || !store.model.expiryDate
},
hasActiveSubscription: function () {
if (Constants.simulate.SUBSCRIBED) {
return true
}
if (store.isAdmin())
return true

Expand All @@ -254,6 +272,12 @@ var controller = {
}
return !store.hasExpiredSubscription() && store.model && store.model.activeSubscription;
},
isMobileSubscription: function (){
if (Constants.simulate.MOBILE_SUBSCRIBED) {
return true
}
return store.hasActiveSubscription() && store.model.currentSubscription !== "CHARGEBEE"
},
hasExpiredSubscription: function () {
if (store.isAdmin())
return false
Expand Down Expand Up @@ -296,6 +320,9 @@ store.dispatcherIndex = Dispatcher.register(store, function (payload) {
case Actions.SET_TOKEN:
controller.setToken(action.token);
break;
case Actions.UPDATE_SUBSCRIPTION:
controller.updateSubscription(action.data);
break;
case Actions.ADMIN_LOGIN:
controller.adminLogin(action.details);
break;
Expand Down
8 changes: 4 additions & 4 deletions common/stores/subscription-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ var controller = {
try {
} catch (e) {}

// if (__DEV__) {
// store.goneABitWest()
// return
// }
if (__DEV__) {
store.goneABitWest()
return
}
const subscriptions = await RNIap.getSubscriptions(iapItemSkus).catch((e)=>{
store.goneABitWest()
});
Expand Down
7 changes: 6 additions & 1 deletion env/project_dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ module.exports = {
captchaSiteKey: "6LdekQAdAAAAANSJB5HNaHO0fOV8yJUsORpEaM2A",
captchaBaseUrl: "https://www.diagnosisview.org",
public: 'https://api-staging.diagnosisview.org/public/',
ga: ''
ga: '',
chargebee: {
site: 'diagnosisview',
product:"professional-GBP-Yearly",
productInternal:"professional",
},
};
9 changes: 7 additions & 2 deletions env/project_prod.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
module.exports = {
debug: false,
api: 'https://api.diagnosisview.org/api/',
baseUrl: "https://diagnosisview.org/",
baseUrl: "https://www.diagnosisview.org/",
public: 'https://api.diagnosisview.org/public/',
codepushIOS: "n_v9269jFN38lTv8i3Mbe0p8t6Xw0e4BjVrJp",
codepushAndroid: "JHGFbOmwdHWqtkE-Ck4osQ_aJxBD9Sj_nU5Mr",
captchaSiteKey: "6LdekQAdAAAAANSJB5HNaHO0fOV8yJUsORpEaM2A",
captchaBaseUrl: "https://www.diagnosisview.org",
ga: ''
ga: '',
chargebee: {
site: 'diagnosisview',
product:"professional-GBP-Yearly",
productInternal:"professional",
},
};
4 changes: 4 additions & 0 deletions mobile/app/route-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ module.exports = {
},

openWebModal: (uri, title) => {
if (ReactNative.Platform.OS === "ios"){
ReactNative.Linking.openURL(uri)
return
}
Navigation.showModal({
screen: "/webmodal",
title: title || '',
Expand Down
6 changes: 4 additions & 2 deletions mobile/app/screens/AccountPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,10 @@ const AccountPage = class extends Component {
{user ? <Text style={[Styles.textCenter, Styles.semiBold]}>{user.emailAddress}</Text> : null}
{AccountStore.hasActiveSubscription() && !noAutoRenewal ? (
<React.Fragment>
<Text style={[Styles.textCenter]}>Your subscription is active.</Text>
{SubscriptionStore.isMobileSubscription() &&(
<Text style={[Styles.textCenter]}>{
!AccountStore.isMobileSubscription()? Constants.webSubscriptionMessage: "Your subscription is active."
}</Text>
{AccountStore.isMobileSubscription() &&(
<Text style={[Styles.textCenter, { color: '#2980b9', textDecorationLine: 'underline' }]} onPress={() => Linking.openURL(manageSubscriptionLink)}>Manage your subscription</Text>
)}
</React.Fragment>
Expand Down
11 changes: 3 additions & 8 deletions mobile/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions web/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ export default class App extends Component {
{pageHasAside && <DashboardNavbar/>}
<div className={"dashboard-container"}>
{AccountStore.hasExpiredSubscription() && (
<div className="col-md-6 mb-4">
<div className="col-md-6 ml-4 mb-4">
<ErrorAlert>
Your annual Professional subscription expired on {moment(AccountStore.hasExpiredSubscription()).format("Do MMM HH:mm")}.
<br/>
<Link to="/account?manage=1">Click here to renew</Link>
<Link to="/dashboard/account?manage=1">Click here to renew</Link>
</ErrorAlert>
</div>
)}
Expand Down
13 changes: 12 additions & 1 deletion web/components/Captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@ export default class Captcha extends Component {
componentDidMount() {
this.handleOpenPress()
}
componentDidUpdate(prevProps, prevState, snapshot) {
if(prevProps.ts !== this.props.ts) {
this.setState({revalidate:true})
setTimeout(()=>{
this.setState({revalidate:false})
},500)
}
}

render() {
const { onSuccess} =this.props
if(this.state.revalidate) {
return null
}
return (
<div className="mb-2">
<Recaptcha
Expand All @@ -19,7 +31,6 @@ export default class Captcha extends Component {
baseUrl={Project.captchaBaseUrl}
size="normal"
theme="light"
onExpire={() => alert('onExpire event')}
onVerify={(res)=>{
onSuccess(res);
}}
Expand Down
2 changes: 1 addition & 1 deletion web/components/DashboardNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TheComponent extends Component {
</strong>
</Link>
{!AccountStore.hasActiveSubscription() && Constants.webPayments && (
<Link to="/dashboard/account">
<Link to="/dashboard/account?manage=1">
<Button onClick={()=>this.setState({modalOpen:true})} className={'btn btn--primary nav__button'}>
<span className="nav__button__text">{'Subscribe now'}</span>
</Button>
Expand Down
12 changes: 8 additions & 4 deletions web/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class TheComponent extends Component {
}

componentDidMount() {
ES6Component(this)
this.listenTo(AccountStore, 'problem',()=>{
this.setState({ts:Date.now().valueOf()})
})
const isSignup = this.props.location.pathname === "/signup"
if(isSignup) {
setTimeout(()=>{
Expand Down Expand Up @@ -122,9 +126,9 @@ class TheComponent extends Component {
})
.catch(e => {
e.json().then(error => {
this.setState({ isLoading: false, step: 2, error: error });
this.setState({ isLoading: false, ts:Date.now().valueOf(), step: 2, error: error });
}).catch(() => {
this.setState({ isLoading: false, step: 2, error: {message:'Sorry there was a problem resetting your password, try again later' }});
this.setState({ isLoading: false, ts:Date.now().valueOf(), step: 2, error: {message:'Sorry there was a problem resetting your password, try again later' }});
})
});
}
Expand Down Expand Up @@ -306,7 +310,7 @@ class TheComponent extends Component {

</div>

<Captcha onSuccess={(captchaResponse)=>this.setState({captchaResponse})}/>
<Captcha ts={this.state.ts} onSuccess={(captchaResponse)=>this.setState({captchaResponse})}/>
<Button disabled={isLoading
|| isSaving || this.invalid()} onClick={this.register} className={'btn btn-lg btn--primary nav__button'}>
<span className="nav__button__text">{isLoading ? 'Signing up..' : 'Sign up'}</span>
Expand Down Expand Up @@ -398,7 +402,7 @@ class TheComponent extends Component {

onChange={(e) => this.setState({ resetUsername: Utils.safeParseEventValue(e) })}
inputClassName="input--default" />
<Captcha onSuccess={(captchaResponseForgot)=>this.setState({captchaResponseForgot})}/>
<Captcha ts={this.state.ts} onSuccess={(captchaResponseForgot)=>this.setState({captchaResponseForgot})}/>

<Button disabled={ this.state.isLoading || !this.state.resetUsername || !this.state.captchaResponseForgot
} onClick={this.forgotPassword} className={'btn btn-lg btn--primary nav__button'}>
Expand Down
9 changes: 6 additions & 3 deletions web/components/PremiumLinkMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ const PremiumLinkMessage = ({className}) => {

</Row>
<div className="mt-4 text-center">
<Link to={Constants.webPayments?"/#pricing":"/signup"}>
<Button className={'btn btn--primary nav__button'}>
<Button onClick={()=>{
if (!AccountStore.model){
document.location = "/#pricing"
}
document.getElementsByClassName("js-manage")[0].click()
}} className={'btn btn--primary nav__button'}>
<span className="nav__button__text">{ 'Sign up Now'}</span>
</Button>
</Link>
</div>
</div>

Expand Down
Loading

0 comments on commit cde28fc

Please sign in to comment.