All files / app/features/auth/signup ResendVerificationEmailForm.tsx

68.18% Statements 15/22
33.33% Branches 2/6
20% Functions 1/5
68.18% Lines 15/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 63 64 65 661x 1x 1x 1x   1x 1x 1x 1x 1x   1x 1x 1x   1x   1x                                   1x                                                            
import { Typography } from "@material-ui/core";
import Alert from "components/Alert";
import StyledLink from "components/StyledLink";
import { useAuthContext } from "features/auth/AuthProvider";
import { RpcError } from "grpc-web";
import { Trans, useTranslation } from "i18n";
import { AUTH, GLOBAL } from "i18n/namespaces";
import { useState } from "react";
import { useMutation } from "react-query";
import { service } from "service";
 
export default function ResendVerificationEmailForm() {
  const { t } = useTranslation([AUTH, GLOBAL]);
  const { authActions, authState } = useAuthContext();
 
  const [resent, setResent] = useState<boolean>(false);
 
  const mutation = useMutation<void, RpcError>(
    async () => {
      const state = await service.auth.signupFlowResendVerificationEmail(
        authState.flowState!.flowToken
      );
      authActions.updateSignupState(state);
      setResent(true);
    },
    {
      onMutate() {
        authActions.clearError();
      },
      onSettled() {
        window.scroll({ top: 0, behavior: "smooth" });
      },
    }
  );
 
  return (
    <>
      {mutation.error && (
        <Alert severity="error">{mutation.error.message || ""}</Alert>
      )}
      <Typography variant="body1" gutterBottom>
        {t("auth:sign_up_completed_prompt")}
      </Typography>
      <Typography variant="body1">
        {!resent ? (
          <Trans i18nKey="auth:sign_up_resend_verification_email_help">
            Didn't receive the email? Click{" "}
            <StyledLink
              href="#"
              onClick={(e) => {
                e.preventDefault();
                mutation.mutateAsync();
              }}
            >
              here to resend the verification link
            </StyledLink>
            .
          </Trans>
        ) : (
          <>{t("auth:sign_up_resend_verification_done")}</>
        )}
      </Typography>
    </>
  );
}