<commit_before>import React from 'react';
import PropTypes from 'prop-types';
import { useMutation } from 'react-apollo-hooks';
import { Redirect } from 'react-router-dom';

import { AcceptClickwrapAgreement } from './mutations.gql';
import { ClickwrapAgreementQuery } from './queries.gql';
import useQuerySuspended from '../useQuerySuspended';
import ErrorDisplay from '../ErrorDisplay';
import useAsyncFunction from '../useAsyncFunction';
import parseCmsContent from '../parseCmsContent';

function ClickwrapAgreement({ history }) {
  const { data, error } = useQuerySuspended(ClickwrapAgreementQuery);
  const [acceptMutate] = useMutation(AcceptClickwrapAgreement);
  const [accept, acceptError, acceptInProgress] = useAsyncFunction(acceptMutate);

  const acceptClicked = async () => {
    await accept();
    history.push('/my_profile/setup');
  };

  if (error) {
    return <ErrorDisplay graphqlError={error} />;
  }

  if (!data.myProfile || data.myProfile.accepted_clickwrap_agreement) {
    return <Redirect to="/" />;
  }

  const { convention } = data;

  return (
    <>
      <p className="my-4"><commit_msg>Hard-reset the session if we detect something is wrong in the clickwrap flow<commit_after>import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { useMutation, useApolloClient } from 'react-apollo-hooks';
import { Redirect } from 'react-router-dom';

import { AcceptClickwrapAgreement } from './mutations.gql';
import { ClickwrapAgreementQuery } from './queries.gql';
import useQuerySuspended from '../useQuerySuspended';
import ErrorDisplay from '../ErrorDisplay';
import useAsyncFunction from '../useAsyncFunction';
import parseCmsContent from '../parseCmsContent';
import AuthenticationModalContext from '../Authentication/AuthenticationModalContext';
import AuthenticityTokensContext from '../AuthenticityTokensContext';

function ClickwrapAgreement({ history }) {
  const { data, error } = useQuerySuspended(ClickwrapAgreementQuery);
  const [acceptMutate] = useMutation(AcceptClickwrapAgreement);
  const [accept, acceptError, acceptInProgress] = useAsyncFunction(acceptMutate);
  const authenticationModal = useContext(AuthenticationModalContext);
  const { refresh } = useContext(AuthenticityTokensContext);
  const apolloClient = useApolloClient();

  const acceptClicked = async () => {
    try {
      await accept();
      history.push('/my_profile/setup');
    } catch (err) {
      await refresh();
      await apolloClient.resetStore();
      throw err;
    }
  };

  if (error) {
    return <ErrorDisplay graphqlError={error} />;
  }

  if (!data.myProfile) {
    if (!authenticationModal.visible) {
      authenticationModal.open({ currentView: 'signIn' });
    }
    return <></>;
  }

  if (data.myProfile.accepted_clickwrap_agreement) {
    return <Redirect to="/" />;
  }

  const { convention } = data;

  return (
    <>
      <p className="my-4">
{'fraction_non_alphanumeric': 0.12692439274717757, 'fraction_numerical': 0.0006842285323297981, 'mean_word_length': 4.485928705440901, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5820401', 'n_tokens_mistral': 854, 'n_tokens_neox': 830, 'n_words': 202}