File size: 2,521 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
import { Button, Card, SegmentedControl } from '@automattic/components';
import { FunctionComponent, useState } from 'react';
import JetpackReviewPrompt from 'calypso/blocks/jetpack-review-prompt';
import CardHeading from 'calypso/components/card-heading';
import { useSelector, useDispatch } from 'calypso/state';
import { setValidFrom } from 'calypso/state/jetpack-review-prompt/actions';
import { PREFERENCE_NAME } from 'calypso/state/jetpack-review-prompt/constants';
import { getIsDismissed, getValidFromDate } from 'calypso/state/jetpack-review-prompt/selectors';
import { savePreference } from 'calypso/state/preferences/actions';

const JetpackReviewPromptExample: FunctionComponent = () => {
	const dispatch = useDispatch();

	const [ type, setType ] = useState< 'scan' | 'restore' >( 'scan' );
	const [ align, setAlign ] = useState< 'center' | 'left' >( 'center' );

	const validFrom = useSelector( ( state ) => getValidFromDate( state, type ) );
	const isDismissed = useSelector( ( state ) => getIsDismissed( state, type ) );

	const handleMakeValid = () => dispatch( setValidFrom( type ) );
	const handleClearDismiss = () => dispatch( savePreference( PREFERENCE_NAME, null ) );

	return (
		<div>
			<JetpackReviewPrompt align={ align } type={ type } />
			{ null === validFrom && (
				<Card>
					<p>No `validFrom` Date Set</p>
					<Button onClick={ handleMakeValid } primary>
						Set `validFrom` to now
					</Button>
				</Card>
			) }
			{ isDismissed && (
				<Card>
					<p>Review Prompt is dismissed</p>
					<Button onClick={ handleClearDismiss } primary>
						Clear Dismissal
					</Button>
				</Card>
			) }
			<Card>
				<CardHeading>Type</CardHeading>
				<SegmentedControl primary>
					<SegmentedControl.Item selected={ 'scan' === type } onClick={ () => setType( 'scan' ) }>
						Scan Prompt
					</SegmentedControl.Item>
					<SegmentedControl.Item
						selected={ 'restore' === type }
						onClick={ () => setType( 'restore' ) }
					>
						Restore Prompt
					</SegmentedControl.Item>
				</SegmentedControl>
				<CardHeading>Align</CardHeading>
				<SegmentedControl primary>
					<SegmentedControl.Item
						selected={ 'center' === align }
						onClick={ () => setAlign( 'center' ) }
					>
						Center Align
					</SegmentedControl.Item>
					<SegmentedControl.Item selected={ 'left' === align } onClick={ () => setAlign( 'left' ) }>
						Left Align
					</SegmentedControl.Item>
				</SegmentedControl>
			</Card>
		</div>
	);
};

export default JetpackReviewPromptExample;