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

kruzhambus9de3edcd28ab
diff --git a/src/api/index.ts b/src/api/index.ts
index f1dfaf398..8c7149d49 100644
--- a/src/api/index.ts
+++ b/src/api/index.ts
@@ -159,7 +159,9 @@ export const changeUserDetails = (data: IUser) =>
throw new Error(errorsArray)
})
-export const forgotPassword = (email: string) =>
+export const forgotPassword = (email: {
+ email: string
+}) =>
api
.post('v1/auth/reset-password', email)
.then((response) => response.data)
diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx
deleted file mode 100644
index ff6a7f38b..000000000
--- a/src/pages/Auth/ForgotPassword/ForgotPassword.container.jsx
+++ /dev/null
@@ -1,15 +0,0 @@
-import { connect } from 'react-redux'
-import { errorsActions } from 'redux/reducers/errors'
-import { alertsActions } from 'redux/reducers/alerts'
-import ForgotPassword from './ForgotPassword'
-
-const mapDispatchToProps = (dispatch) => ({
- createNewPasswordFailed: (e) => {
- dispatch(errorsActions.createNewPasswordFailed(e.toString()))
- },
- newPassword: (message) => {
- dispatch(alertsActions.newPassword(message))
- },
-})
-
-export default connect(null, mapDispatchToProps)(ForgotPassword)
diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.container.tsx b/src/pages/Auth/ForgotPassword/ForgotPassword.container.tsx
new file mode 100644
index 000000000..3f81d9023
--- /dev/null
+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.container.tsx
@@ -0,0 +1,20 @@
+import { connect } from 'react-redux'
+import { errorsActions } from 'redux/reducers/errors'
+import { alertsActions } from 'redux/reducers/alerts'
+import { AppDispatch } from 'redux/store'
+import ForgotPassword from './ForgotPassword'
+
+const mapDispatchToProps = (dispatch: AppDispatch) => ({
+ createNewPasswordFailed: (e: string) => {
+ dispatch(errorsActions.createNewPasswordFailed({
+ message: e,
+ }))
+ },
+ newPassword: (message: string) => {
+ dispatch(alertsActions.newPassword({
+ message,
+ }))
+ },
+})
+
+export default connect(null, mapDispatchToProps)(ForgotPassword)
diff --git a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx b/src/pages/Auth/ForgotPassword/ForgotPassword.tsx
similarity index 77%
rename from src/pages/Auth/ForgotPassword/ForgotPassword.jsx
rename to src/pages/Auth/ForgotPassword/ForgotPassword.tsx
index 892c7b4ef..ea64ffa54 100644
--- a/src/pages/Auth/ForgotPassword/ForgotPassword.jsx
+++ b/src/pages/Auth/ForgotPassword/ForgotPassword.tsx
@@ -14,19 +14,30 @@ import { isValidEmail } from 'utils/validator'
const ForgotPassword = ({
createNewPasswordFailed, newPassword,
-}) => {
- const { t } = useTranslation('common')
+}: {
+ createNewPasswordFailed: (e: string) => void,
+ newPassword: (message: string) => void,
+}): JSX.Element => {
+ const { t }: {
+ t: (key: string) => string,
+ } = useTranslation('common')
const history = useHistory()
- const [form, setForm] = useState({
+ const [form, setForm] = useState<{
+ email: string,
+ }>({
email: '',
})
- 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,
+ }>({})
+ const [beenSubmitted, setBeenSubmitted] = useState<boolean>(false)
+ const [isLoading, setIsLoading] = useState<boolean>(false)
const validate = () => {
- const allErrors = {}
+ const allErrors = {} as {
+ email?: string,
+ }
if (!isValidEmail(form.email)) {
allErrors.email = t('auth.common.badEmailError')
@@ -42,7 +53,9 @@ const ForgotPassword = ({
validate()
}, [form]) // eslint-disable-line
- const onSubmit = async (data) => {
+ const onSubmit = async (data: {
+ email: string,
+ }) => {
if (!isLoading) {
setIsLoading(true)
@@ -51,7 +64,7 @@ const ForgotPassword = ({
newPassword(t('auth.forgot.sent'))
history.push(routes.main)
- } catch (e) {
+ } catch (e: any) {
createNewPasswordFailed(e.toString())
} finally {
setIsLoading(false)
@@ -59,7 +72,9 @@ const ForgotPassword = ({
}
}
- const handleInput = ({ target }) => {
+ const handleInput = ({ target }: {
+ target: HTMLInputElement,
+ }) => {
const value = target.type === 'checkbox' ? target.checked : target.value
setForm(oldForm => ({
@@ -68,7 +83,7 @@ const ForgotPassword = ({
}))
}
- const handleSubmit = e => {
+ const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
e.stopPropagation()
setBeenSubmitted(true)
diff --git a/src/pages/Auth/ForgotPassword/index.jsx b/src/pages/Auth/ForgotPassword/index.tsx
similarity index 100%
rename from src/pages/Auth/ForgotPassword/index.jsx
rename to src/pages/Auth/ForgotPassword/index.tsx