{"size": 2026, "ext": "js", "max_stars_repo_path": "pages/auth/signup/email/validate.js", "max_stars_repo_name": "Architected/next-js-sample-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "pages/auth/signup/email/validate.js", "max_issues_repo_name": "Architected/next-js-sample-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "pages/auth/signup/email/validate.js", "max_forks_repo_name": "Architected/next-js-sample-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.0133333333, "max_line_length": 77, "alphanum_fraction": 0.6372161895}
import React, { useContext, useEffect, useState } from 'react';
import { useRouter } from 'next/router';
import { Store } from '../../../../state/storeProvider';
import EmailValidate from '../../../../components/auth/signup/emailValidate';
import { urlConstants } from '../../../../helper/urlConstants';
import { iamService } from '../../../../service/defaultServices.js';
import * as authActionType from 'architected-client/constants/iam.js';

function SignUpEmailValidate() {
  const router = useRouter();
  const { state, dispatch } = useContext(Store);
  const [resendInProgress, setResendInProgress] = useState(false);
  const {
    authState,
    callInProgress,
    errorMessage,
    warningMessage,
    successMessage,
    bearerToken,
  } = state['auth'];

  useEffect(() => {
    let isMounted = true;
    dispatch({ type: authActionType.INIT_DEFAULT_LAYOUT });

    if (authState == null || bearerToken == null) {
      router.push('/');
    } else if (authState && authState.signupScope === 'FULL') {
      router.push(urlConstants.get('PAGE_FILE_LIST'));
    }

    return () => {
      isMounted = false;
    };
  }, []);

  const submitHandler = async ({ code }) => {
    if (!resendInProgress) {
      const responseData = await iamService.signUpValidateEmail(
        code,
        bearerToken.tokenValue,
        dispatch
      );

      if (responseData && !responseData.inError) {
        router.push(urlConstants.get('SIGNUP_COMPLETE'));
      }
    }
  };

  const resendHandler = async () => {
    setResendInProgress(true);
    const responseData = await iamService.signUpVerifyEmail(
      bearerToken.tokenValue,
      dispatch
    );
    setResendInProgress(false);
  };

  return (
    <>
      <EmailValidate
        submitHandler={submitHandler}
        isLoading={callInProgress}
        errorMessage={errorMessage}
        warningMessage={warningMessage}
        successMessage={successMessage}
        resendHandler={resendHandler}
      />
    </>
  );
}

export default SignUpEmailValidate;
