forked from cryppadotta/dotta-license
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReduxAppDemo.js
148 lines (134 loc) · 3.63 KB
/
ReduxAppDemo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// npm dependencies
import React, { Component } from 'react';
import { createStore, combineReducers, applyMiddleware, compose } from 'redux';
import { Provider } from 'react-redux';
import { render } from 'react-dom';
import createSagaMiddleware from 'redux-saga';
import Helmet from 'react-helmet';
import styled from 'styled-components';
// local demo-specific dependencies
import '../../css/style.css';
import config from '../config';
import logo from '../../img/dottabot-cart-circle.png';
import logo2x from '../../img/[email protected]';
// DotLicense imports
import {
dotCheckoutReducer as dotCheckout,
dotCheckoutSagas,
DotCheckoutProvider,
DotCheckoutButton
} from '../../../src';
function createReduxStore() {
// e.g. your reducers
const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
default:
return state;
}
};
// This adds sagas with redux devtools
const composeEnhancers =
typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
combineReducers({
counter,
dotCheckout
}),
composeEnhancers(applyMiddleware(sagaMiddleware))
);
// run our sagas
sagaMiddleware.run(dotCheckoutSagas());
return store;
}
const store = createReduxStore();
// Now configure the store properties
const ONE_DAY = 60 * 60 * 24;
const ONE_MONTH = ONE_DAY * 30;
const ONE_YEAR = ONE_MONTH * 12;
let offers = [
{
id: '1', // client-side id for e.g. forms
productId: '3',
duration: ONE_MONTH,
name: '1 month'
},
{
id: '3', // client-side id for e.g. forms
productId: '3',
duration: ONE_MONTH * 3,
name: '3 months'
},
{
id: '12',
productId: '3',
duration: ONE_YEAR,
name: '12 months'
},
{
id: '24',
productId: '4',
duration: ONE_YEAR * 2,
name: '24 months'
}
];
let productName = 'Dottabot';
let productSubheading = 'Unlimited License';
let offerLabel = 'Subscription length';
class Demo extends Component {
render() {
return (
<div className={this.props.className}>
<Helmet>
<link
href="https://fonts.googleapis.com/css?family=Roboto:400,700|Roboto+Mono:400,700"
rel="stylesheet"
/>
</Helmet>
<h1>DotLicenseCheckout with Redux Demo</h1>
<Provider store={store}>
<DotCheckoutProvider
productName={productName}
offerLabel={offerLabel}
offers={offers}
logo={logo}
logo2x={logo2x}
vanityAddressPrefix={'db'}
httpProviderURL={config.httpProviderURL}
licenseCoreAddress={config.licenseCoreAddress}
tosURL="/tos"
helpURL="/what-is-a-dottabot-address"
>
<DotCheckoutButton
productSubheading={productSubheading}
defaultOffer="1"
>
Buy 1 month
</DotCheckoutButton>
<br />
<DotCheckoutButton
productSubheading="Ultimate Dottabot Package"
defaultOffer="12"
>
Buy 12 months
</DotCheckoutButton>
</DotCheckoutProvider>
</Provider>
</div>
);
}
}
Demo = styled(Demo)`
padding: 1em;
font-family: 'Roboto', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif,
'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
> h1 {
color: rgba(0, 0, 0, 0.5);
text-align: center;
}
`;
export default Demo;