File size: 1,338 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
import {
	__experimentalHStack as HStack,
	__experimentalText as Text,
	__experimentalVStack as VStack,
	Button,
	Modal,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useState } from 'react';
import { restoreDatabasePassword } from '../../data/site-hosting';

interface ResetPasswordModalProps {
	siteId: number;
	onClose: () => void;
	onSuccess: () => void;
	onError: () => void;
}

export default function ResetPasswordModal( {
	siteId,
	onClose,
	onSuccess,
	onError,
}: ResetPasswordModalProps ) {
	const [ isRestoring, setIsRestoring ] = useState( false );

	const handleRestore = () => {
		setIsRestoring( true );
		restoreDatabasePassword( siteId )
			.then( () => {
				setIsRestoring( false );
				onSuccess();
			} )
			.catch( () => {
				setIsRestoring( false );
				onError();
			} );
	};

	return (
		<Modal title={ __( 'Restore database password' ) } onRequestClose={ onClose }>
			<VStack spacing={ 6 }>
				<Text>
					{ __( 'Are you sure you want to restore the default password of your database?' ) }
				</Text>
				<HStack justify="flex-end" spacing={ 2 }>
					<Button onClick={ onClose }>{ __( 'Cancel' ) }</Button>
					<Button variant="primary" isBusy={ isRestoring } onClick={ handleRestore }>
						{ __( 'Restore' ) }
					</Button>
				</HStack>
			</VStack>
		</Modal>
	);
}