import { Button, Theme, withStyles, WithStyles } from '@material-ui/core'; import { ApolloClient } from 'apollo-client'; import gql from 'graphql-tag'; import * as React from 'react'; import { withApollo, WithApolloClient } from 'react-apollo'; import { useQuery } from 'react-apollo-hooks'; import { Field } from 'react-final-form'; import { Link, RouteComponentProps } from 'react-router-dom'; import Form from '../../components/Form'; import Input from '../../components/form/TextField'; import { CheckActivationCode, CheckActivationCodeVariables } from '../../graphql'; import { requestJSON } from '../../util/http'; import { required } from '../../util/validation'; import Loading from '../pages/Loading'; import AccountPage from './AccountPage'; const checkActivationCodeQuery = gql` query CheckActivationCode($code: String!) { checkActivationCode(code: $code) } `; const styles = (theme: Theme) => ({ submit: { width: '100%', marginTop: theme.spacing(4), }, google: { width: '100%', marginTop: theme.spacing(4), background: theme.palette.common.white, }, errorMessage: { marginTop: theme.spacing(6), }, }); interface Props extends WithStyles, RouteComponentProps<{ code: string }>, WithApolloClient<{}> {} const activate = (client: ApolloClient, code: string, callback: any) => async ({ name, password, }: { name: string; password: string; }) => { await requestJSON('/auth/activate', 'post', { name, password, code, }); await client.reFetchObservableQueries(); callback(); }; const ConfirmReset: React.FC = ({ classes, client, match, history }) => { const { code } = match.params; const { data, loading } = useQuery(checkActivationCodeQuery, { variables: { code, }, }); if (loading) { return ; } return ( Signing in? } > {data!.checkActivationCode &&
{data!.checkActivationCode}
} {!data!.checkActivationCode && (
history.push('/'))}> {({ handleSubmit, submitting }) => ( )} )}
); }; export default withApollo(withStyles(styles)(ConfirmReset));