File size: 1,648 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
import { Button } from '@wordpress/components';
import clsx from 'clsx';
import { TranslateResult, useTranslate } from 'i18n-calypso';
import { SelectorProduct } from 'calypso/my-sites/plans/jetpack-plans/types';
import { StorageUsageLevelName } from 'calypso/state/rewind/storage/types';
import useStorageStatusText from './use-storage-status-text';

type OwnProps = {
	className?: string;
	usageLevel: StorageUsageLevelName;
	href?: string;
	upsellSlug: SelectorProduct | null;
	storage: TranslateResult;
	onClick?: React.MouseEventHandler;
	price: JSX.Element;
	daysOfBackupsSaved: number;
	minDaysOfBackupsAllowed: number;
};

const ActionButton: React.FC< OwnProps > = ( {
	className,
	usageLevel,
	href,
	storage,
	onClick,
	price,
	daysOfBackupsSaved,
	minDaysOfBackupsAllowed,
} ) => {
	const storageStatusText = useStorageStatusText(
		usageLevel,
		daysOfBackupsSaved,
		minDaysOfBackupsAllowed
	);

	const hasClickableAction = Boolean( href || onClick );
	const translate = useTranslate();

	return (
		<Button
			className={ clsx( className, 'usage-warning__action-button', {
				'has-clickable-action': hasClickableAction,
			} ) }
			href={ href }
			onClick={ onClick }
		>
			<div className="action-button__copy">
				<div className="action-button__status">{ storageStatusText }</div>
				<div className="action-button__action-text">
					{ translate( 'Add %(storage)s additional storage for {{price/}}', {
						components: { price: price },
						args: { storage },
					} ) }
				</div>
			</div>
			{ hasClickableAction && <span className="action-button__arrow">&#8594;</span> }
		</Button>
	);
};

export default ActionButton;