File size: 1,846 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, CompactCard, Gridicon } from '@automattic/components';
import { useTranslate } from 'i18n-calypso';
import { useDispatch } from 'react-redux';
import { useLocalizedMoment } from 'calypso/components/localized-moment';
import useDeleteAppPasswordMutation from 'calypso/data/application-passwords/use-delete-app-password-mutation';
import { recordGoogleEvent } from 'calypso/state/analytics/actions';
import { errorNotice, successNotice } from 'calypso/state/notices/actions';
import './style.scss';

function ApplicationPasswordsItem( { password } ) {
	const dispatch = useDispatch();
	const moment = useLocalizedMoment();
	const translate = useTranslate();

	const { deleteAppPassword } = useDeleteAppPasswordMutation( {
		onSuccess() {
			dispatch(
				successNotice( translate( 'Application password successfully deleted.' ), {
					duration: 2000,
				} )
			);
		},
		onError() {
			dispatch(
				errorNotice(
					translate( 'The application password was not successfully deleted. Please try again.' ),
					{
						duration: 8000,
					}
				)
			);
		},
	} );

	return (
		<li>
			<CompactCard className="application-password-item">
				<div className="application-password-item__details">
					<h2 className="application-password-item__name">{ password.name }</h2>
					<p className="application-password-item__generated">
						{ translate( 'Generated on %s', {
							args: moment( password.generated ).format( 'lll' ),
						} ) }
					</p>
				</div>
				<Button
					compact
					className="application-password-item__revoke"
					onClick={ () => {
						dispatch( recordGoogleEvent( 'Me', 'Clicked on Remove Application Password Button' ) );
						deleteAppPassword( password.ID );
					} }
				>
					<Gridicon icon="trash" />
				</Button>
			</CompactCard>
		</li>
	);
}

export default ApplicationPasswordsItem;