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

100% Statements 26/26
86.36% Branches 19/22
100% Functions 1/1
100% Lines 26/26

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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 1071x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x   28x 36x 36x 36x 36x   36x   36x                                                                   26x                 15x                 8x                 4x                 3x                   2x      
import { Typography } from "@mui/material";
import StyledLink from "components/StyledLink";
import { Trans, useTranslation } from "i18n";
import { AUTH, GLOBAL } from "i18n/namespaces";
import { missionRoute, tosRoute } from "routes";
import useSignupPageInfo from "utils/useSignupPageInfo";
 
import { useIsNativeEmbed } from "../../../utils/nativeLink";
import { useAuthContext } from "../AuthProvider";
import AccountForm from "./AccountForm";
import BasicForm from "./BasicForm";
import CommunityGuidelinesForm from "./CommunityGuidelinesForm";
import MotivationsForm from "./MotivationsForm";
import ResendVerificationEmailForm from "./ResendVerificationEmailForm";
 
export default function SignupFormContent({ inviteCode }: { inviteCode?: string }) {
  const { t } = useTranslation([AUTH, GLOBAL]);
  const { authState } = useAuthContext();
  const state = authState.flowState;
  const isNativeEmbed = useIsNativeEmbed();
 
  const { signupInfo } = useSignupPageInfo();
 
  if (!state || state.needBasic) {
    return (
      <>
        <Typography gutterBottom sx={{ fontSize: "1.4rem", fontWeight: "bold" }}>
          {t("landing:signup_header")}
        </Typography>
        <Typography gutterBottom sx={{ marginBottom: 2 }}>
          <Trans
            i18nKey={isNativeEmbed ? "landing:signup_description_no_link2" : "landing:signup_description2"}
            values={{
              // Number(...) returns NaN on bad input, and || treats it as false
              count: Number(signupInfo?.userCount) || 65000,
            }}
            components={isNativeEmbed ? {} : { aboutLink: <StyledLink href={missionRoute} /> }}
          />
        </Typography>
        <BasicForm inviteCode={inviteCode} submitText={t("global:create_account")} />
        <Typography variant="caption">
          <Trans
            i18nKey="auth:basic_sign_up_form.sign_up_agreement_explainer"
            components={{
              tosLink: (
                <StyledLink
                  href={tosRoute}
                  target={isNativeEmbed ? undefined : "_blank"}
                  variant="caption"
                  sx={{ fontWeight: 700 }}
                />
              ),
            }}
          />
        </Typography>
      </>
    );
  } else if (state.needAccount) {
    return (
      <>
        <Typography variant="h2" gutterBottom>
          {t("auth:account_form.header")}
        </Typography>
        <AccountForm />
      </>
    );
  } else if (state.needAcceptCommunityGuidelines) {
    return (
      <>
        <Typography variant="h2" gutterBottom>
          {t("auth:community_guidelines_form.header")}
        </Typography>
        <CommunityGuidelinesForm />
      </>
    );
  } else if (state.needMotivations) {
    return (
      <>
        <Typography variant="h2" gutterBottom>
          {t("auth:motivations_form.header")}
        </Typography>
        <MotivationsForm />
      </>
    );
  } else if (state.needVerifyEmail) {
    return (
      <>
        <Typography variant="h2" gutterBottom>
          {t("auth:sign_up_need_verification_title")}
        </Typography>
        <ResendVerificationEmailForm />
      </>
    );
  } else if (state.authRes) {
    return (
      <>
        <Typography variant="h2" gutterBottom>
          {t("auth:sign_up_completed_title")}
        </Typography>
        <Typography variant="body1">{t("auth:sign_up_confirmed_prompt")}</Typography>
      </>
    );
  } else {
    throw Error(t("auth:unhandled_sign_up_state"));
  }
}