Hide google signup and complete signup logic

This commit is contained in:
Hazem Krimi
2021-04-29 19:11:28 +01:00
parent e04b0d44dd
commit 06eefdb583
+31 -12
View File
@@ -2,15 +2,39 @@ import * as Yup from 'yup';
import { useFormik } from 'formik'; import { useFormik } from 'formik';
import { useState } from 'react'; import { useState } from 'react';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { Google, Signup as SignupIllustration, Logo } from '../../../assets'; import { useMutation } from '@apollo/client';
import { Signup as SignupIllustration, Logo } from '../../../assets';
import { Box, Button, Input, Link, Text, Alert } from '../../../components'; import { Box, Button, Input, Link, Text, Alert } from '../../../components';
import { theme } from '../../../themes'; import { theme } from '../../../themes';
import { Wrapper } from './styles'; import { Wrapper } from './styles';
import {
SignupMutation,
SignupMutationVariables,
} from '../../../graphql/types';
import { SIGNUP } from '../../../graphql/auth.api';
import { roleVar, tokenVar, userVar } from '../../../graphql/state';
const Signup = () => { const Signup = () => {
const history = useHistory(); const history = useHistory();
const [error, setError] = useState<string>(''); const [error, setError] = useState<string>('');
const [signup, { loading }] = useMutation<
SignupMutation,
SignupMutationVariables
>(SIGNUP, {
onCompleted({ signup: { token, user } }) {
roleVar('client');
tokenVar(token);
userVar(user);
localStorage.setItem('token', token);
history.push('/additional-info');
},
onError({ graphQLErrors }) {
setError(graphQLErrors[0]?.extensions?.info);
setTimeout(() => setError(''), 3000);
},
});
const form = useFormik({ const form = useFormik({
initialValues: { initialValues: {
email: '', email: '',
@@ -24,15 +48,8 @@ const Signup = () => {
.required('Password is required') .required('Password is required')
.min(6, 'Password is 6 characters minimum'), .min(6, 'Password is 6 characters minimum'),
}), }),
onSubmit: ({ email, password }, { resetForm }) => { onSubmit: ({ email, password }) => {
try { signup({ variables: { email, password } });
history.push(`/additional-info?email=${email}&password=${password}`);
} catch (err) {
setError(err.message);
setTimeout(() => setError(''), 3000);
} finally {
resetForm();
}
}, },
}); });
@@ -105,14 +122,16 @@ const Signup = () => {
type='submit' type='submit'
color='client' color='client'
text='Signup' text='Signup'
loading={loading}
disabled={loading}
/> />
<Button {/* <Button
variant='secondary-action' variant='secondary-action'
fullWidth fullWidth
color='client' color='client'
text='Signup with Google' text='Signup with Google'
iconLeft={<Google />} iconLeft={<Google />}
/> /> */}
</Box> </Box>
<Box display='flex' flexDirection='row'> <Box display='flex' flexDirection='row'>
<Box flexGrow='1'> <Box flexGrow='1'>