Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

pages/auth/SingUp

kruzhambus1ca3dbe8e825
diff --git a/src/pages/Auth/Signup/BasicSignup.jsx b/src/pages/Auth/Signup/BasicSignup.tsx
similarity index 74%
rename from src/pages/Auth/Signup/BasicSignup.jsx
rename to src/pages/Auth/Signup/BasicSignup.tsx
index ef4c070a2..2f92754b7 100644
--- a/src/pages/Auth/Signup/BasicSignup.jsx
+++ b/src/pages/Auth/Signup/BasicSignup.tsx
@@ -1,6 +1,5 @@
import React, { memo, useState, useEffect } from 'react'
-import { useDispatch } from 'react-redux'
-import { authActions } from 'redux/reducers/auth'
+import sagaActions from 'redux/sagas/actions'
import { useTranslation, Trans } from 'react-i18next'
import _size from 'lodash/size'
import _keys from 'lodash/keys'
@@ -15,12 +14,24 @@ import {
} from 'utils/validator'
import { HAVE_I_BEEN_PWNED_URL } from 'redux/constants'
import { trackCustom } from 'utils/analytics'
+import { useAppDispatch } from 'redux/store'
import _omit from 'lodash/omit'
-const BasicSignup = () => {
- const { t } = useTranslation('common')
- const dispatch = useDispatch()
- const [form, setForm] = useState({
+const BasicSignup = (): JSX.Element => {
+ const { t }: {
+ t: (key: string, optinions?: {
+ [key: string]: string | number,
+ }) => string,
+ } = useTranslation('common')
+ const dispatch = useAppDispatch()
+ const [form, setForm] = useState<{
+ email: string,
+ password: string,
+ repeat: string,
+ tos: boolean,
+ dontRemember: boolean,
+ checkIfLeaked: boolean,
+ }>({
email: '',
password: '',
repeat: '',
@@ -28,15 +39,27 @@ const BasicSignup = () => {
dontRemember: false,
checkIfLeaked: true,
})
- const [validated, setValidated] = useState(false)
- const [errors, setErrors] = useState({})
- const [beenSubmitted, setBeenSubmitted] = useState(false)
- const [isLoading, setIsLoading] = useState(false)
-
- const onSubmit = (data) => {
+ const [validated, setValidated] = useState<boolean>(false)
+ const [errors, setErrors] = useState<{
+ email?: string,
+ password?: string,
+ repeat?: string,
+ tos?: string,
+ }>({})
+ const [beenSubmitted, setBeenSubmitted] = useState<boolean>(false)
+ const [isLoading, setIsLoading] = useState<boolean>(false)
+
+ const onSubmit = (data: {
+ email: string,
+ password: string,
+ repeat: string,
+ tos: boolean,
+ dontRemember: boolean,
+ checkIfLeaked: boolean,
+ }) => {
if (!isLoading) {
setIsLoading(true)
- dispatch(authActions.signupAsync(_omit(data, 'tos'), t, (result) => {
+ dispatch(sagaActions.signupAsync(_omit(data, 'tos'), t, (result) => {
if (result) {
trackCustom('SIGNUP_BASIC')
} else {
@@ -47,7 +70,11 @@ const BasicSignup = () => {
}
const validate = () => {
- const allErrors = {}
+ const allErrors = {} as {
+ email?: string,
+ password?: string,
+ repeat?: string,
+ }
if (!isValidEmail(form.email)) {
allErrors.email = t('auth.common.badEmailError')
@@ -75,7 +102,7 @@ const BasicSignup = () => {
validate()
}, [form]) // eslint-disable-line
- const handleInput = (event) => {
+ const handleInput = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target } = event
const value = target.type === 'checkbox' ? target.checked : target.value
@@ -85,7 +112,7 @@ const BasicSignup = () => {
}))
}
- const handleSubmit = e => {
+ const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
e.stopPropagation()
setBeenSubmitted(true)
@@ -138,6 +165,7 @@ const BasicSignup = () => {
className='ml-2'
text={(
<Trans
+ // @ts-ignore
t={t}
i18nKey='auth.common.checkLeakedPasswordDesc'
components={{
diff --git a/src/pages/Auth/Signup/Signup.container.jsx b/src/pages/Auth/Signup/Signup.container.jsx
deleted file mode 100644
index b0f9b9a8a..000000000
--- a/src/pages/Auth/Signup/Signup.container.jsx
+++ /dev/null
@@ -1,11 +0,0 @@
-import { connect } from 'react-redux'
-import { authActions } from 'redux/reducers/auth'
-import Signup from './Signup'
-
-const mapDispatchToProps = (dispatch) => ({
- signup: (data, t, callback) => {
- dispatch(authActions.signupAsync(data, t, callback))
- },
-})
-
-export default connect(null, mapDispatchToProps)(Signup)
diff --git a/src/pages/Auth/Signup/Signup.container.tsx b/src/pages/Auth/Signup/Signup.container.tsx
new file mode 100644
index 000000000..836427595
--- /dev/null
+++ b/src/pages/Auth/Signup/Signup.container.tsx
@@ -0,0 +1,20 @@
+import { connect } from 'react-redux'
+import { AppDispatch } from 'redux/store'
+import sagaActions from 'redux/sagas/actions'
+import Signup from './Signup'
+
+const mapDispatchToProps = (dispatch: AppDispatch) => ({
+ signup: (data: {
+ email: string,
+ password: string,
+ repeat: string,
+ dontRemember: boolean,
+ checkIfLeaked: boolean,
+ }, t: (key: string, optinions?: {
+ [key: string]: string | number,
+ }) => string, callback: (res: any) => void) => {
+ dispatch(sagaActions.signupAsync(data, t, callback))
+ },
+})
+
+export default connect(null, mapDispatchToProps)(Signup)
diff --git a/src/pages/Auth/Signup/Signup.jsx b/src/pages/Auth/Signup/Signup.tsx
similarity index 81%
rename from src/pages/Auth/Signup/Signup.jsx
rename to src/pages/Auth/Signup/Signup.tsx
index e688bbde6..cf63cd65f 100644
--- a/src/pages/Auth/Signup/Signup.jsx
+++ b/src/pages/Auth/Signup/Signup.tsx
@@ -20,9 +20,30 @@ import { HAVE_I_BEEN_PWNED_URL, TRIAL_DAYS } from 'redux/constants'
import { trackCustom } from 'utils/analytics'
import _omit from 'lodash/omit'
-const Signup = ({ signup }) => {
- const { t } = useTranslation('common')
- const [form, setForm] = useState({
+const Signup = ({ signup }: {
+ signup: (data: {
+ email: string,
+ password: string,
+ repeat: string,
+ dontRemember: boolean,
+ checkIfLeaked: boolean,
+ }, t: (key: string, optinions?: {
+ [key: string]: string | number,
+ }) => string, callback: (res: any) => void) => void,
+}): JSX.Element => {
+ const { t }: {
+ t: (key: string, optinions?: {
+ [key: string]: string | number,
+ }) => string,
+ } = useTranslation('common')
+ const [form, setForm] = useState<{
+ email: string,
+ password: string,
+ repeat: string,
+ tos: boolean,
+ dontRemember: boolean,
+ checkIfLeaked: boolean,
+ }>({
email: '',
password: '',
repeat: '',
@@ -30,13 +51,23 @@ const Signup = ({ signup }) => {
dontRemember: false,
checkIfLeaked: true,
})
- const [validated, setValidated] = useState(false)
- const [errors, setErrors] = useState({})
- const [beenSubmitted, setBeenSubmitted] = useState(false)
- const [isLoading, setIsLoading] = useState(false)
+ const [validated, setValidated] = useState<boolean>(false)
+ const [errors, setErrors] = useState<{
+ email?: string,
+ password?: string,
+ repeat?: string,
+ tos?: string,
+ }>({})
+ const [beenSubmitted, setBeenSubmitted] = useState<boolean>(false)
+ const [isLoading, setIsLoading] = useState<boolean>(false)
const validate = () => {
- const allErrors = {}
+ const allErrors = {} as {
+ email?: string,
+ password?: string,
+ repeat?: string,
+ tos?: string,
+ }
if (!isValidEmail(form.email)) {
allErrors.email = t('auth.common.badEmailError')
@@ -68,7 +99,14 @@ const Signup = ({ signup }) => {
validate()
}, [form]) // eslint-disable-line
- const onSubmit = data => {
+ const onSubmit = (data: {
+ email: string,
+ password: string,
+ repeat: string,
+ tos: boolean,
+ dontRemember: boolean,
+ checkIfLeaked: boolean,
+ }) => {
if (!isLoading) {
setIsLoading(true)
signup(_omit(data, 'tos'), t, (result) => {
@@ -81,7 +119,7 @@ const Signup = ({ signup }) => {
}
}
- const handleInput = event => {
+ const handleInput = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target } = event
const value = target.type === 'checkbox' ? target.checked : target.value
@@ -91,7 +129,7 @@ const Signup = ({ signup }) => {
}))
}
- const handleSubmit = e => {
+ const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
e.stopPropagation()
setBeenSubmitted(true)
@@ -156,6 +194,7 @@ const Signup = ({ signup }) => {
label={(
<span>
<Trans
+ // @ts-ignore
t={t}
i18nKey='auth.signup.tos'
components={{
@@ -180,6 +219,7 @@ const Signup = ({ signup }) => {
className='ml-2'
text={(
<Trans
+ // @ts-ignore
t={t}
i18nKey='auth.common.checkLeakedPasswordDesc'
components={{
diff --git a/src/pages/Auth/Signup/index.jsx b/src/pages/Auth/Signup/index.tsx
similarity index 100%
rename from src/pages/Auth/Signup/index.jsx
rename to src/pages/Auth/Signup/index.tsx
diff --git a/src/redux/sagas/actions/index.ts b/src/redux/sagas/actions/index.ts
index 73e4a5b04..263c69b2a 100644
--- a/src/redux/sagas/actions/index.ts
+++ b/src/redux/sagas/actions/index.ts
@@ -44,7 +44,7 @@ const loginAsync = (credentials: {
const signupAsync = (data: {
email: string,
password: string,
-}, t?: (string: string) => {}, callback = () => { }) => ({
+}, t?: (string: string) => {}, callback = (res: any) => { }) => ({
type: types.SIGNUP_ASYNC,
payload: {
data, callback, t,