File size: 1,047 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
import { useTranslate } from 'i18n-calypso';
import {
	ResendEmailVerificationBody,
	useSendEmailVerification,
} from 'calypso/landing/stepper/hooks/use-send-email-verification';
import { useDispatch } from 'calypso/state';
import { successNotice, errorNotice } from 'calypso/state/notices/actions';

export function useResendEmailVerification(
	body: ResendEmailVerificationBody
): () => Promise< void > {
	const resendEmailNotice = 'resend-verification-email';
	const dispatch = useDispatch();
	const resendEmail = useSendEmailVerification( body );
	const translate = useTranslate();

	return async () => {
		try {
			const result = await resendEmail();
			if ( result.success ) {
				dispatch(
					successNotice( translate( 'Verification email resent. Please check your inbox.' ), {
						id: resendEmailNotice,
						duration: 4000,
					} )
				);
				return;
			}
		} catch ( Error ) {
			dispatch(
				errorNotice( translate( "Couldn't resend verification email. Please try again." ), {
					id: resendEmailNotice,
				} )
			);
		}
	};
}