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

100% Statements 27/27
50% Branches 1/2
100% Functions 3/3
100% Lines 27/27

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 66 67 682x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x   2x 10x 10x   10x 4x 4x 4x       3x               3x   1x         1x       4x     10x                 1x 1x                      
import { Typography } from "@material-ui/core";
import ContributorForm from "components/ContributorForm";
import StyledLink from "components/StyledLink";
import { useAuthContext } from "features/auth/AuthProvider";
import { Trans, useTranslation } from "i18n";
import { GLOBAL } from "i18n/namespaces";
import Sentry from "platform/sentry";
import { ContributorForm as ContributorFormPb } from "proto/auth_pb";
import TagManager from "react-gtm-module";
import { service } from "service";
import isGrpcError from "service/utils/isGrpcError";
import getRandomId from "utils/getRandomId";
 
export default function FeedbackForm() {
  const { t } = useTranslation(GLOBAL);
  const { authActions, authState } = useAuthContext();
 
  const handleSubmit = async (form: ContributorFormPb.AsObject) => {
    authActions.clearError();
    try {
      const res = await service.auth.signupFlowFeedback(
        authState.flowState!.flowToken,
        form
      );
      TagManager.dataLayer({
        dataLayer: {
          event: "sign_up",
          signupMethod: "email",
          userId: getRandomId(),
          "gtm.elementUrl": `${window.location.hostname}${window.location.pathname}`,
        },
      });
      authActions.updateSignupState(res);
    } catch (err) {
      Sentry.captureException(err, {
        tags: {
          component: "auth/signup/feedbackForm",
        },
      });
      authActions.authError(
        isGrpcError(err) ? err.message : t("error.fatal_message")
      );
    }
    window.scroll({ top: 0, behavior: "smooth" });
  };
 
  return (
    <>
      <Typography variant="h2">
        <Trans i18nKey="auth:feedback_form.skip_step_text">
          Not interested?{" "}
          <StyledLink
            variant="h2"
            href="#"
            onClick={(e) => {
              e.preventDefault();
              handleSubmit(new ContributorFormPb().toObject());
            }}
          >
            Skip this step
          </StyledLink>
        </Trans>
      </Typography>
      <ContributorForm processForm={handleSubmit} autofocus />
    </>
  );
}