aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/ui')
-rw-r--r--src/components/ui/PremiumFeatureContainer/index.js76
-rw-r--r--src/components/ui/PremiumFeatureContainer/styles.js31
-rw-r--r--src/components/ui/Toggle.js6
3 files changed, 112 insertions, 1 deletions
diff --git a/src/components/ui/PremiumFeatureContainer/index.js b/src/components/ui/PremiumFeatureContainer/index.js
new file mode 100644
index 000000000..73984be94
--- /dev/null
+++ b/src/components/ui/PremiumFeatureContainer/index.js
@@ -0,0 +1,76 @@
1import React, { Component } from 'react';
2import { inject, observer } from 'mobx-react';
3import PropTypes from 'prop-types';
4import { defineMessages, intlShape } from 'react-intl';
5import injectSheet from 'react-jss';
6
7import { oneOrManyChildElements } from '../../../prop-types';
8
9import UserStore from '../../../stores/UserStore';
10
11import styles from './styles';
12
13const messages = defineMessages({
14 action: {
15 id: 'premiumFeature.button.upgradeAccount',
16 defaultMessage: '!!!Upgrade account',
17 },
18});
19
20export default @inject('stores', 'actions') @injectSheet(styles) @observer class PremiumFeatureContainer extends Component {
21 static propTypes = {
22 classes: PropTypes.object.isRequired,
23 condition: PropTypes.bool,
24 };
25
26 static defaultProps = {
27 condition: true,
28 };
29
30 static contextTypes = {
31 intl: intlShape,
32 };
33
34 render() {
35 const {
36 classes,
37 children,
38 actions,
39 condition,
40 stores,
41 } = this.props;
42
43 const { intl } = this.context;
44
45 return !stores.user.data.isPremium && !!condition ? (
46 <div className={classes.container}>
47 <div className={classes.titleContainer}>
48 <p className={classes.title}>Premium Feature</p>
49 <button
50 className={classes.actionButton}
51 type="button"
52 onClick={() => actions.ui.openSettings({ path: 'user' })}
53 >
54 {intl.formatMessage(messages.action)}
55 </button>
56 </div>
57 <div className={classes.content}>
58 {children}
59 </div>
60 </div>
61 ) : children;
62 }
63}
64
65PremiumFeatureContainer.wrappedComponent.propTypes = {
66 children: oneOrManyChildElements.isRequired,
67 stores: PropTypes.shape({
68 user: PropTypes.instanceOf(UserStore).isRequired,
69 }).isRequired,
70 actions: PropTypes.shape({
71 ui: PropTypes.shape({
72 openSettings: PropTypes.func.isRequired,
73 }).isRequired,
74 }).isRequired,
75};
76
diff --git a/src/components/ui/PremiumFeatureContainer/styles.js b/src/components/ui/PremiumFeatureContainer/styles.js
new file mode 100644
index 000000000..16c40d0ec
--- /dev/null
+++ b/src/components/ui/PremiumFeatureContainer/styles.js
@@ -0,0 +1,31 @@
1export default theme => ({
2 container: {
3 background: theme.colorSubscriptionContainerBackground,
4 border: theme.colorSubscriptionContainerBorder,
5 margin: [0, 0, 20, -20],
6 padding: 20,
7 'border-radius': theme.borderRadius,
8 },
9 titleContainer: {
10 display: 'flex',
11 },
12 title: {
13 'font-weight': 'bold',
14 color: theme.colorSubscriptionContainerTitle,
15 },
16 actionButton: {
17 background: theme.colorSubscriptionContainerActionButtonBackground,
18 color: theme.colorSubscriptionContainerActionButtonColor,
19 'margin-left': 'auto',
20 'border-radius': theme.borderRadiusSmall,
21 padding: [2, 4],
22 'font-size': 12,
23 },
24 content: {
25 opacity: 0.5,
26 'margin-top': 20,
27 '& :last-child': {
28 'margin-bottom': 0,
29 },
30 },
31});
diff --git a/src/components/ui/Toggle.js b/src/components/ui/Toggle.js
index f7c2ec955..78fb77cbe 100644
--- a/src/components/ui/Toggle.js
+++ b/src/components/ui/Toggle.js
@@ -9,11 +9,13 @@ export default @observer class Toggle extends Component {
9 field: PropTypes.instanceOf(Field).isRequired, 9 field: PropTypes.instanceOf(Field).isRequired,
10 className: PropTypes.string, 10 className: PropTypes.string,
11 showLabel: PropTypes.bool, 11 showLabel: PropTypes.bool,
12 disabled: PropTypes.bool,
12 }; 13 };
13 14
14 static defaultProps = { 15 static defaultProps = {
15 className: '', 16 className: '',
16 showLabel: true, 17 showLabel: true,
18 disabled: false,
17 }; 19 };
18 20
19 onChange(e) { 21 onChange(e) {
@@ -27,6 +29,7 @@ export default @observer class Toggle extends Component {
27 field, 29 field,
28 className, 30 className,
29 showLabel, 31 showLabel,
32 disabled,
30 } = this.props; 33 } = this.props;
31 34
32 if (field.value === '' && field.default !== '') { 35 if (field.value === '' && field.default !== '') {
@@ -38,6 +41,7 @@ export default @observer class Toggle extends Component {
38 className={classnames([ 41 className={classnames([
39 'franz-form__field', 42 'franz-form__field',
40 'franz-form__toggle-wrapper', 43 'franz-form__toggle-wrapper',
44 'franz-form__toggle-disabled',
41 className, 45 className,
42 ])} 46 ])}
43 > 47 >
@@ -55,7 +59,7 @@ export default @observer class Toggle extends Component {
55 name={field.name} 59 name={field.name}
56 value={field.name} 60 value={field.name}
57 checked={field.value} 61 checked={field.value}
58 onChange={e => this.onChange(e)} 62 onChange={e => (!disabled ? this.onChange(e) : null)}
59 /> 63 />
60 </label> 64 </label>
61 {field.error && <div className={field.error}>{field.error}</div>} 65 {field.error && <div className={field.error}>{field.error}</div>}