File size: 1,318 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
import { Button, Card, Dialog } from '@automattic/components';
import { useTranslate } from 'i18n-calypso';
import { useState } from 'react';
import { useDispatch } from 'react-redux';
import { deleteReaderList } from 'calypso/state/reader/lists/actions';

function ListDelete( { list } ) {
	const translate = useTranslate();
	const dispatch = useDispatch();
	const [ showDeleteConfirmation, setShowDeleteConfirmation ] = useState( false );

	return (
		<>
			<Card>
				<p>{ translate( 'Delete the list forever. Be careful - this is not reversible.' ) }</p>
				<Button primary onClick={ () => setShowDeleteConfirmation( true ) }>
					{ translate( 'Delete list' ) }
				</Button>
			</Card>

			{ showDeleteConfirmation && (
				<Dialog
					isVisible
					buttons={ [
						{ action: 'cancel', label: translate( 'Cancel' ) },
						{ action: 'delete', label: translate( 'Delete list' ), isPrimary: true },
					] }
					onClose={ ( action ) => {
						setShowDeleteConfirmation( false );
						if ( action === 'delete' ) {
							dispatch( deleteReaderList( list.ID, list.owner, list.slug ) );
						}
					} }
				>
					<h1>{ translate( 'Are you sure you want to delete this list?' ) }</h1>
					<p>{ translate( 'This action cannot be undone.' ) }</p>
				</Dialog>
			) }
		</>
	);
}

export default ListDelete;