File size: 3,158 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 { Button, Gridicon, Popover } from '@automattic/components';
import { useTranslate } from 'i18n-calypso';
import { useRef, useState } from 'react';

type OwnProps = {
	className?: string;
	storageUpgradeUrl: string;
	forecastInDays: number | undefined;
	onClickedPurchase: () => void;
};
const StorageHelpPopover: React.FC< OwnProps > = ( {
	className,
	storageUpgradeUrl,
	forecastInDays,
	onClickedPurchase,
} ) => {
	const translate = useTranslate();
	const STORAGE_USAGE_HELP_POPOVER_STATE_KEY = 'storage_usage_help_popover_state';
	const popoverState = null === localStorage.getItem( STORAGE_USAGE_HELP_POPOVER_STATE_KEY );
	const [ isPopoverVisible, setPopoverVisible ] = useState< boolean >( popoverState );
	const popover = useRef< SVGSVGElement >( null );

	if ( ! forecastInDays ) {
		return null;
	}

	const toggleHelpPopover = ( event: React.MouseEvent< HTMLButtonElement, MouseEvent > ): void => {
		setPopoverVisible( ! isPopoverVisible );
		localStorage.setItem( STORAGE_USAGE_HELP_POPOVER_STATE_KEY, 'shown' );
		// when the info popover inside a button, we don't want clicking it to propagate up
		event.stopPropagation();
	};

	return (
		<span className={ className }>
			<Button
				borderless
				compact
				className="storage-usage-help-popover__toggle-popover"
				onClick={ toggleHelpPopover }
			>
				<Gridicon ref={ popover } icon="info-outline" size={ 18 } />
			</Button>
			<Popover
				className="storage-usage-help-popover__popover"
				isVisible={ isPopoverVisible }
				position="bottom right"
				context={ popover.current }
				showOnMobile
			>
				<h3> { translate( 'Backup archive size' ) }</h3>
				<p>
					{ translate(
						'Based on the current size of your site, Jetpack will save up to {{strong}}%(forecastInDays)d full backup{{/strong}}.',
						'Based on the current size of your site, Jetpack will save up to {{strong}}%(forecastInDays)d days of full backups{{/strong}}.',
						{
							components: { strong: <strong /> },
							count: forecastInDays,
							args: {
								forecastInDays,
							},
							comment:
								'Forecasts how many days of backups site can store based on current site size. %(forecastInDays)d is day count number',
						}
					) }
					<Button
						borderless
						compact
						className="storage-usage-help-popover__close-popover"
						onClick={ toggleHelpPopover }
					>
						<Gridicon icon="cross" size={ 18 } />
					</Button>
				</p>
				<p>
					{ translate(
						'If you need more backup days, try {{link}}reducing the backup size{{/link}} or adding more storage.',
						{
							components: {
								link: (
									<a
										href="https://jetpack.com/support/backup/jetpack-vaultpress-backup-storage-and-retention/#reduce-storage-size"
										target="_blank"
										rel="external noreferrer noopener"
									/>
								),
							},
						}
					) }
				</p>
				<div className="storage-usage-help-popover__button-section">
					<Button primary href={ storageUpgradeUrl } onClick={ onClickedPurchase }>
						{ translate( 'Add more storage' ) }
					</Button>
				</div>
			</Popover>
		</span>
	);
};

export default StorageHelpPopover;