diff --git a/next-env.d.ts b/next-env.d.ts index 9bc3dd46b..c6643fda1 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,6 +1,3 @@ /// /// /// - -// NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/pages/verify.tsx b/pages/verify.tsx new file mode 100644 index 000000000..f16702e18 --- /dev/null +++ b/pages/verify.tsx @@ -0,0 +1,34 @@ +import { useRouter } from 'next/router' +import { useEffect } from 'react' +import { Layout } from 'src/components/common' +import LoadingCommon from 'src/components/common/LoadingCommon/LoadingCommon' +import { useVerifyCustomer } from 'src/components/hooks' + +export default function VerifyCustomer() { + const router = useRouter() + const { error, loading, verify } = useVerifyCustomer() + + useEffect(() => { + const { token } = router.query + console.log("token: ", token) + if (token) { + verify({ token: token.toString() }) + } + }, []) + + return ( +
+ { + loading ? <> + + Verifing your account .... + :
+ {error?.message} +
+ } +
+ ) +} + + +VerifyCustomer.Layout = Layout diff --git a/src/components/common/ModalAuthenticate/components/FormRegister/FormRegister.tsx b/src/components/common/ModalAuthenticate/components/FormRegister/FormRegister.tsx index 66ec1f8a4..afcfd259c 100644 --- a/src/components/common/ModalAuthenticate/components/FormRegister/FormRegister.tsx +++ b/src/components/common/ModalAuthenticate/components/FormRegister/FormRegister.tsx @@ -1,10 +1,11 @@ -import React, { useEffect, useRef } from 'react' -import { ButtonCommon, Inputcommon, InputPassword } from 'src/components/common' -import s from '../FormAuthen.module.scss' -import styles from './FormRegister.module.scss' -import SocialAuthen from '../SocialAuthen/SocialAuthen' import classNames from 'classnames' +import React, { useEffect, useRef, useState } from 'react' +import { ButtonCommon, Inputcommon, InputPassword } from 'src/components/common' import { CustomInputCommon } from 'src/utils/type.utils' +import { useSignup } from '../../../../hooks' +import s from '../FormAuthen.module.scss' +import SocialAuthen from '../SocialAuthen/SocialAuthen' +import styles from './FormRegister.module.scss' interface Props { isHide: boolean, @@ -13,6 +14,10 @@ interface Props { const FormRegister = ({ onSwitch, isHide }: Props) => { const emailRef = useRef(null) + const { loading, signup, error } = useSignup() + const [email, setEmail] = useState('') + const [password, setPassword] = useState('') + useEffect(() => { if (!isHide) { @@ -20,6 +25,18 @@ const FormRegister = ({ onSwitch, isHide }: Props) => { } }, [isHide]) + const onSignup = () => { + // TODO: validate fields + signup({ email, password }) + } + + + useEffect(() => { + if (error) { + alert(error.message) + } + }, [error]) + return (
{ })}>
- - + setEmail(val.toString())} + /> + setPassword(val.toString())} + /> +
Must contain 8 characters with at least 1 uppercase and 1 lowercase letter and either 1 number or 1 special character.
- Create Account + + Create Account +
diff --git a/src/components/hooks/index.ts b/src/components/hooks/index.ts index cf83feb42..4a25fd98e 100644 --- a/src/components/hooks/index.ts +++ b/src/components/hooks/index.ts @@ -1 +1,3 @@ export { default as useModalCommon } from './useModalCommon' +export { default as useVerifyCustomer } from './useVerifyCustomer' +export { default as useSignup } from './useSignup' diff --git a/src/components/hooks/useSignup.tsx b/src/components/hooks/useSignup.tsx index b06781e88..91a5fe186 100644 --- a/src/components/hooks/useSignup.tsx +++ b/src/components/hooks/useSignup.tsx @@ -22,8 +22,8 @@ const query = gql` interface SignupInput { email: string - firstName: string - lastName: string + firstName?: string + lastName?: string password: string } diff --git a/src/components/hooks/useVerifyCustomer.tsx b/src/components/hooks/useVerifyCustomer.tsx new file mode 100644 index 000000000..edd789d13 --- /dev/null +++ b/src/components/hooks/useVerifyCustomer.tsx @@ -0,0 +1,43 @@ +import { LoginMutation } from '@framework/schema' +import { useState } from 'react' +import { CommonError } from 'src/domains/interfaces/CommonError' +import rawFetcher from 'src/utils/rawFetcher' +import { VERIFY_CUSTOMER_ACCOUNT } from '../../graphql/mutation' +import useActiveCustomer from './useActiveCustomer' + +interface VerifyInput { + token: string + password?: string +} + +const useVerifyCustomer = () => { + const [loading, setLoading] = useState(false) + const [error, setError] = useState(null) + // const { mutate } = useActiveCustomer() + + const verify = (options: VerifyInput) => { + setError(null) + setLoading(true) + rawFetcher({ + query: VERIFY_CUSTOMER_ACCOUNT, + variables: options, + }) + .then(({ data, headers }) => { + console.log("data: ", data) + // if (data.login.__typename !== 'CurrentUser') { + // throw CommonError.create(data.login.message, data.login.errorCode) + // } + // const authToken = headers.get('vendure-auth-token') + // if (authToken != null) { + // localStorage.setItem('token', authToken) + // return mutate() + // } + }) + .catch(setError) + .finally(() => setLoading(false)) + } + + return { loading, verify, error } +} + +export default useVerifyCustomer diff --git a/src/graphql/mutation/index.ts b/src/graphql/mutation/index.ts new file mode 100644 index 000000000..7ea0d4f82 --- /dev/null +++ b/src/graphql/mutation/index.ts @@ -0,0 +1 @@ +export * from './user.mutation' diff --git a/src/graphql/mutation/user.mutation.ts b/src/graphql/mutation/user.mutation.ts new file mode 100644 index 000000000..a48074ef0 --- /dev/null +++ b/src/graphql/mutation/user.mutation.ts @@ -0,0 +1,16 @@ +import { gql } from 'graphql-request' + + +export const VERIFY_CUSTOMER_ACCOUNT = gql` +mutation verifyCustomerAccount(token: String!, password: String) { + verifyCustomerAccount( token: $token, password: $password) { + ...on CurrentUser { + id + identifier + } + ...ErrorResult + } +} +` + + diff --git a/src/graphql/query/index.ts b/src/graphql/query/index.ts new file mode 100644 index 000000000..47c53bc6d --- /dev/null +++ b/src/graphql/query/index.ts @@ -0,0 +1 @@ +// export * from './user.mutation' diff --git a/src/graphql/query/user.query.ts b/src/graphql/query/user.query.ts new file mode 100644 index 000000000..e9e7409b4 --- /dev/null +++ b/src/graphql/query/user.query.ts @@ -0,0 +1 @@ +// query here \ No newline at end of file