File size: 1,434 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
import { useCallback } from 'react';
import useRemoveEmailForwardMutation from 'calypso/data/emails/use-remove-email-forward-mutation';
import useResendVerifyEmailForwardMutation from 'calypso/data/emails/use-resend-verify-email-forward-mutation';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import type { Mailbox } from 'calypso/data/emails/types';

export function useRemove( { mailbox }: { mailbox: Mailbox } ) {
	const { mutate: removeEmailForward } = useRemoveEmailForwardMutation( mailbox.domain );

	return useCallback(
		( mailbox: string, domain: string, destination: string ) => {
			recordTracksEvent( 'calypso_email_management_email_forwarding_delete_click', {
				destination,
				domain_name: domain,
				mailbox: mailbox,
			} );

			removeEmailForward( {
				mailbox: mailbox,
				destination,
				domain,
			} );
		},
		[ removeEmailForward ]
	);
}

export function useResend( { mailbox }: { mailbox: Mailbox } ) {
	const { mutate: resendVerificationEmail } = useResendVerifyEmailForwardMutation( mailbox.domain );

	return useCallback(
		( mailbox: string, domain: string, destination: string ) => {
			recordTracksEvent(
				'calypso_email_management_email_forwarding_resend_verification_email_click',
				{
					destination,
					domain_name: domain,
					mailbox: mailbox,
				}
			);

			resendVerificationEmail( { mailbox, destination, domain } );
		},
		[ resendVerificationEmail ]
	);
}