react-code-dataset / wp-calypso /client /landing /stepper /hooks /use-resend-email-verification.ts
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
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,
} )
);
}
};
}