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/singup to ts

kruzhambus0f9429b83b56
diff --git a/src/pages/Auth/Signin/Signin.container.jsx b/src/pages/Auth/Signin/Signin.container.jsx
deleted file mode 100644
index 8d7e8d2d8..000000000
--- a/src/pages/Auth/Signin/Signin.container.jsx
+++ /dev/null
@@ -1,22 +0,0 @@
-import { connect } from 'react-redux'
-
-import { authActions } from 'redux/reducers/auth'
-import { errorsActions } from 'redux/reducers/errors'
-import UIActions from 'redux/reducers/ui'
-import Signin from './Signin'
-
-const mapDispatchToProps = (dispatch) => ({
- login: (data, callback) => {
- dispatch(authActions.loginAsync(data, callback))
- },
- loginSuccess: (user) => {
- dispatch(authActions.loginSuccessful(user))
- dispatch(UIActions.loadProjects())
- dispatch(UIActions.loadSharedProjects())
- },
- loginFailed: (error) => {
- dispatch(errorsActions.loginFailed(error))
- },
-})
-
-export default connect(null, mapDispatchToProps)(Signin)
diff --git a/src/pages/Auth/Signin/Signin.container.tsx b/src/pages/Auth/Signin/Signin.container.tsx
new file mode 100644
index 000000000..005e3db81
--- /dev/null
+++ b/src/pages/Auth/Signin/Signin.container.tsx
@@ -0,0 +1,29 @@
+import { connect } from 'react-redux'
+
+import sagaActions from 'redux/sagas/actions'
+import { authActions } from 'redux/reducers/auth'
+import { errorsActions } from 'redux/reducers/errors'
+import { AppDispatch } from 'redux/store'
+import { IUser } from 'redux/models/IUser'
+import Signin from './Signin'
+
+const mapDispatchToProps = (dispatch: AppDispatch) => ({
+ login: (data: {
+ email: string,
+ password: string,
+ }, callback: () => void) => {
+ dispatch(sagaActions.loginAsync(data, callback))
+ },
+ loginSuccess: (user: IUser) => {
+ dispatch(authActions.loginSuccessful(user))
+ dispatch(sagaActions.loadProjects())
+ dispatch(sagaActions.loadSharedProjects())
+ },
+ loginFailed: (error: string) => {
+ dispatch(errorsActions.loginFailed({
+ message: error,
+ }))
+ },
+})
+
+export default connect(null, mapDispatchToProps)(Signin)
diff --git a/src/pages/Auth/Signin/Signin.jsx b/src/pages/Auth/Signin/Signin.tsx
similarity index 80%
rename from src/pages/Auth/Signin/Signin.jsx
rename to src/pages/Auth/Signin/Signin.tsx
index 50bd63046..234d7bc2b 100644
--- a/src/pages/Auth/Signin/Signin.jsx
+++ b/src/pages/Auth/Signin/Signin.tsx
@@ -16,27 +16,50 @@ import {
isValidEmail, isValidPassword, MIN_PASSWORD_CHARS,
} from 'utils/validator'
import { isSelfhosted } from 'redux/constants'
+import { IUser } from 'redux/models/IUser'
import { submit2FA } from 'api'
import { setAccessToken } from 'utils/accessToken'
import { setRefreshToken } from 'utils/refreshToken'
-const Signin = ({ login, loginSuccess, loginFailed }) => {
- const { t } = useTranslation('common')
- const [form, setForm] = useState({
+const Signin = ({ login, loginSuccess, loginFailed }: {
+ login: (data: {
+ email: string,
+ password: string,
+ dontRemember: boolean
+ }, callback: (result: boolean, twoFARequired: boolean) => void) => void,
+ loginSuccess: (user: IUser) => void,
+ loginFailed: (error: string) => void,
+}): JSX.Element => {
+ const { t }: {
+ t: (key: string, optinions?: {
+ [key: string]: string | number,
+ }) => string,
+ } = useTranslation('common')
+ const [form, setForm] = useState<{
+ email: string,
+ password: string,
+ dontRemember: boolean,
+ }>({
email: '',
password: '',
dontRemember: false,
})
- const [validated, setValidated] = useState(false)
- const [errors, setErrors] = useState({})
- const [beenSubmitted, setBeenSubmitted] = useState(false)
- const [isLoading, setIsLoading] = useState(false)
- const [isTwoFARequired, setIsTwoFARequired] = useState(false)
- const [twoFACode, setTwoFACode] = useState('')
- const [twoFACodeError, setTwoFACodeError] = useState(null)
+ const [validated, setValidated] = useState<boolean>(false)
+ const [errors, setErrors] = useState<{
+ email?: string,
+ password?: string,
+ }>({})
+ const [beenSubmitted, setBeenSubmitted] = useState<boolean>(false)
+ const [isLoading, setIsLoading] = useState<boolean>(false)
+ const [isTwoFARequired, setIsTwoFARequired] = useState<boolean>(false)
+ const [twoFACode, setTwoFACode] = useState<string>('')
+ const [twoFACodeError, setTwoFACodeError] = useState<string | null>(null)
const validate = () => {
- const allErrors = {}
+ const allErrors = {} as {
+ email?: string,
+ password?: string,
+ }
if (!isValidEmail(form.email)) {
allErrors.email = t('auth.common.badEmailError')
@@ -56,13 +79,17 @@ const Signin = ({ login, loginSuccess, loginFailed }) => {
validate()
}, [form]) // eslint-disable-line
- const handle2FAInput = event => {
+ const handle2FAInput = (event: React.ChangeEvent<HTMLInputElement>) => {
const { target: { value } } = event
setTwoFACode(value)
setTwoFACodeError(null)
}
- const onSubmit = data => {
+ const onSubmit = (data: {
+ email: string,
+ password: string,
+ dontRemember: boolean
+ }) => {
if (!isLoading) {
setIsLoading(true)
login(data, (result, twoFARequired) => {
@@ -74,7 +101,7 @@ const Signin = ({ login, loginSuccess, loginFailed }) => {
}
}
- const _submit2FA = async (e) => {
+ const _submit2FA = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
e.stopPropagation()
@@ -99,7 +126,9 @@ const Signin = ({ login, loginSuccess, loginFailed }) => {
}
}
- const handleInput = ({ target }) => {
+ const handleInput = ({ target }: {
+ target: HTMLInputElement,
+ }) => {
const value = target.type === 'checkbox' ? target.checked : target.value
setForm(oldForm => ({
@@ -108,7 +137,7 @@ const Signin = ({ login, loginSuccess, loginFailed }) => {
}))
}
- const handleSubmit = e => {
+ const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
e.stopPropagation()
setBeenSubmitted(true)
@@ -143,6 +172,7 @@ const Signin = ({ login, loginSuccess, loginFailed }) => {
<div className='whitespace-pre-line text-sm text-gray-600 dark:text-gray-400'>
{!isSelfhosted && (
<Trans
+ // @ts-ignore
t={t}
i18nKey='auth.signin.2faUnavailable'
components={{
diff --git a/src/pages/Auth/Signin/index.jsx b/src/pages/Auth/Signin/index.tsx
similarity index 100%
rename from src/pages/Auth/Signin/index.jsx
rename to src/pages/Auth/Signin/index.tsx