File size: 2,467 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import {
	PLAN_ECOMMERCE,
	PLAN_BUSINESS,
	PLAN_PREMIUM,
	PLAN_PERSONAL,
	PLAN_FREE,
} from '@automattic/calypso-products';
import { get } from 'lodash';
import { connect } from 'react-redux';
import { getCurrentUser } from 'calypso/state/current-user/selectors';
import { getSiteSlug } from 'calypso/state/sites/selectors';
import PlanStorageBar from '../bar';
import PlanStorage from '../index';

const PlanStorageExample = ( { siteId, siteSlug } ) => {
	const mediaStorage = {
		red: {
			storageUsedBytes: 11362335981,
			maxStorageBytes: 13958643712,
		},
		yellow: {
			storageUsedBytes: 1971389988,
			maxStorageBytes: 3221225472,
		},
		green: {
			storageUsedBytes: 167503724,
			maxStorageBytes: 3221225472,
		},
	};

	if ( ! siteSlug ) {
		return null;
	}

	return (
		<div>
			<div style={ { marginBottom: 16 } }>
				<PlanStorage siteId={ siteId } />
			</div>

			<div style={ { marginBottom: 16 } }>
				<PlanStorageBar
					siteSlug={ siteSlug }
					sitePlanSlug={ PLAN_FREE }
					mediaStorage={ mediaStorage.green }
				/>
			</div>
			<div style={ { marginBottom: 16, maxWidth: '400px' } }>
				<PlanStorageBar
					siteSlug={ siteSlug }
					sitePlanSlug={ PLAN_PERSONAL }
					mediaStorage={ mediaStorage.yellow }
				/>
			</div>

			<div style={ { marginBottom: 16, maxWidth: '300px' } }>
				<PlanStorageBar
					siteSlug={ siteSlug }
					sitePlanSlug={ PLAN_PREMIUM }
					mediaStorage={ mediaStorage.red }
				/>
			</div>

			<div style={ { marginBottom: 16 } }>
				<span style={ { fontSize: 12, color: 'grey' } }>
					Business plans have unlimited storage, so PlanStorage will not be rendered.
				</span>
				<PlanStorageBar
					siteSlug={ siteSlug }
					sitePlanSlug={ PLAN_BUSINESS }
					mediaStorage={ mediaStorage.red }
				/>
			</div>

			<div style={ { marginBottom: 16 } }>
				<span style={ { fontSize: 12, color: 'grey' } }>
					Ecommerce plans have unlimited storage, so PlanStorage will not be rendered.
				</span>
				<PlanStorageBar
					siteSlug={ siteSlug }
					sitePlanSlug={ PLAN_ECOMMERCE }
					mediaStorage={ mediaStorage.red }
				/>
			</div>
		</div>
	);
};

const ConnectedPlanStorageExample = connect( ( state ) => {
	const siteId = get( getCurrentUser( state ), 'primary_blog', null );
	const siteSlug = getSiteSlug( state, siteId );

	return {
		siteId,
		siteSlug,
	};
} )( PlanStorageExample );

ConnectedPlanStorageExample.displayName = 'PlanStorage';

export default ConnectedPlanStorageExample;