Archived
Fetch default membership price from dusken
This uses apollo-client to connect and fetch from the graphql API
This commit is contained in:
1 parent
a0e976ee1f
commit
6511a4422f
5 files changed
+158
-13
No files matched your search
+19
-5
@@ -1,24 +1,38 @@
|
||||
import Dusken from "./Dusken";
|
||||
import React, {Component} from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
import { createStore, applyMiddleware } from 'redux';
|
||||
import {Provider} from 'react-redux';
|
||||
import {applyMiddleware, createStore} from 'redux';
|
||||
import logger from 'redux-logger';
|
||||
import thunk from 'redux-thunk';
|
||||
import {persistStore, autoRehydrate} from 'redux-persist'
|
||||
import {autoRehydrate, persistStore} from 'redux-persist'
|
||||
import {AsyncStorage} from 'react-native'
|
||||
import Config from 'react-native-config';
|
||||
import {ApolloClient} from 'apollo-client';
|
||||
import {HttpLink} from 'apollo-link-http';
|
||||
import {InMemoryCache} from 'apollo-cache-inmemory';
|
||||
import {ApolloProvider} from "react-apollo";
|
||||
|
||||
import Dusken from "./Dusken";
|
||||
import duskenApp from "./reducers";
|
||||
|
||||
|
||||
let store = createStore(
|
||||
duskenApp,
|
||||
applyMiddleware(...[logger, thunk]),
|
||||
autoRehydrate()
|
||||
);
|
||||
|
||||
const apolloClient = new ApolloClient({
|
||||
link: new HttpLink({uri: `${Config.DUSKEN_API_URL}/api/graphql/`}),
|
||||
cache: new InMemoryCache()
|
||||
});
|
||||
|
||||
export default class App extends Component {
|
||||
render() {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<Dusken />
|
||||
<ApolloProvider client={apolloClient}>
|
||||
<Dusken />
|
||||
</ApolloProvider>
|
||||
</Provider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, {Component} from 'react';
|
||||
import {Image, Platform, ScrollView, StyleSheet, Text, TouchableOpacity, View} from "react-native";
|
||||
import {Image, ScrollView, StyleSheet, Text, TouchableOpacity, View} from "react-native";
|
||||
import {Button, Text as NBText, Spinner} from 'native-base';
|
||||
import Confetti from 'react-native-confetti';
|
||||
import theme from "../../theme";
|
||||
|
||||
@@ -2,6 +2,8 @@ import React, {Component} from 'react';
|
||||
import {connect} from "react-redux";
|
||||
import stripe from 'tipsi-stripe'
|
||||
import Config from 'react-native-config';
|
||||
import { graphql } from 'react-apollo';
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
import Proof from "./Proof";
|
||||
import {requestMembershipCharge} from "../../api";
|
||||
@@ -11,17 +13,23 @@ stripe.init({
|
||||
publishableKey: Config.STRIPE_PUBLISHABLE_KEY || '',
|
||||
});
|
||||
|
||||
class ProofContainer extends Component {
|
||||
price = 200; // TODO: fetch from backend
|
||||
|
||||
class ProofContainer extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
refreshing: false,
|
||||
}
|
||||
}
|
||||
|
||||
getPrice(membershipTypes) {
|
||||
if (!membershipTypes || membershipTypes.length !== 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return membershipTypes[0].price / 100;
|
||||
}
|
||||
|
||||
render() {
|
||||
return <Proof
|
||||
{...this.state}
|
||||
@@ -30,7 +38,7 @@ class ProofContainer extends Component {
|
||||
chargeError={this.props.chargeError}
|
||||
onChargePress={this.openStripe}
|
||||
onLogoutPress={this.props.onLogoutPress}
|
||||
membershipPrice={this.price}
|
||||
membershipPrice={this.getPrice(this.props.data.membershipTypes)}
|
||||
/>
|
||||
}
|
||||
|
||||
@@ -75,7 +83,20 @@ class ProofContainer extends Component {
|
||||
// }
|
||||
}
|
||||
|
||||
export default connect(
|
||||
const PROOF_QUERY = gql`{
|
||||
membershipTypes(isDefault: true) {
|
||||
id
|
||||
slug
|
||||
price
|
||||
expiryType
|
||||
duration
|
||||
isActive
|
||||
name
|
||||
isDefault
|
||||
}
|
||||
}`;
|
||||
|
||||
const proofContainerWithState = connect(
|
||||
(store) => ({
|
||||
userToken: store.userToken,
|
||||
isChargingMembership: store.isChargingMembership,
|
||||
@@ -83,3 +104,5 @@ export default connect(
|
||||
}),
|
||||
{requestMembershipCharge}
|
||||
)(ProofContainer);
|
||||
|
||||
export default graphql(PROOF_QUERY)(proofContainerWithState);
|
||||
Reference in new issue
Block a user