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

kruzhambus3757f4435540
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.container.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.container.jsx
deleted file mode 100644
index 11c1ff44c..000000000
--- a/src/pages/Auth/CreateNewPassword/CreateNewPassword.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 CreateNewPassword from './CreateNewPassword'
-
-const mapDispatchToProps = (dispatch) => ({
- createNewPasswordFailed: (e) => {
- dispatch(errorsActions.createNewPasswordFailed(e.toString()))
- },
- newPassword: (message) => {
- dispatch(alertsActions.newPassword(message))
- },
-})
-
-export default connect(null, mapDispatchToProps)(CreateNewPassword)
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.container.tsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.container.tsx
new file mode 100644
index 000000000..6bec5f3f2
--- /dev/null
+++ b/src/pages/Auth/CreateNewPassword/CreateNewPassword.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 CreateNewPassword from './CreateNewPassword'
+
+const mapDispatchToProps = (dispatch: AppDispatch) => ({
+ createNewPasswordFailed: (e: string) => {
+ dispatch(errorsActions.createNewPasswordFailed({
+ message: e,
+ }))
+ },
+ newPassword: (message: string) => {
+ dispatch(alertsActions.newPassword({
+ message,
+ }))
+ },
+})
+
+export default connect(null, mapDispatchToProps)(CreateNewPassword)
diff --git a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx b/src/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
similarity index 78%
rename from src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
rename to src/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
index 1375b09d2..600f87d7c 100644
--- a/src/pages/Auth/CreateNewPassword/CreateNewPassword.jsx
+++ b/src/pages/Auth/CreateNewPassword/CreateNewPassword.tsx
@@ -13,23 +13,41 @@ import Input from 'ui/Input'
import Button from 'ui/Button'
import { isValidPassword, MIN_PASSWORD_CHARS, MAX_PASSWORD_CHARS } from 'utils/validator'
+interface FormSubmitData {
+ password: string,
+ repeat: string,
+}
+
const CreateNewPassword = ({
createNewPasswordFailed, newPassword,
-}) => {
- const { t } = useTranslation('common')
+}: {
+ createNewPasswordFailed: (e: string) => void,
+ newPassword: (message: string) => void,
+}): JSX.Element => {
+ const { t }: {
+ t: (key: string, options?: { [key: string]: string | number }) => string,
+ } = useTranslation('common')
const history = useHistory()
- const { id } = useParams()
- const [form, setForm] = useState({
+ const { id }: {
+ id: string,
+ } = useParams()
+ const [form, setForm] = useState<FormSubmitData>({
password: '',
repeat: '',
})
- 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<{
+ password?: string,
+ repeat?: string,
+ }>({})
+ const [beenSubmitted, setBeenSubmitted] = useState<boolean>(false)
+ const [isLoading, setIsLoading] = useState<boolean>(false)
const validate = () => {
- const allErrors = {}
+ const allErrors = {} as {
+ password?: string,
+ repeat?: string,
+ }
if (!isValidPassword(form.password)) {
allErrors.password = t('auth.common.xCharsError', { amount: MIN_PASSWORD_CHARS })
@@ -53,7 +71,7 @@ const CreateNewPassword = ({
validate()
}, [form]) // eslint-disable-line
- const onSubmit = async (data) => {
+ const onSubmit = async (data: FormSubmitData) => {
if (!isLoading) {
setIsLoading(true)
try {
@@ -62,7 +80,7 @@ const CreateNewPassword = ({
newPassword(t('auth.recovery.updated'))
history.push(routes.signin)
- } catch (e) {
+ } catch (e: any) {
createNewPasswordFailed(e.toString())
} finally {
setIsLoading(false)
@@ -70,7 +88,9 @@ const CreateNewPassword = ({
}
}
- const handleInput = ({ target }) => {
+ const handleInput = ({ target }: {
+ target: HTMLInputElement,
+ }) => {
const value = target.type === 'checkbox' ? target.checked : target.value
setForm(oldForm => ({
@@ -79,7 +99,7 @@ const CreateNewPassword = ({
}))
}
- const handleSubmit = e => {
+ const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()
e.stopPropagation()
setBeenSubmitted(true)
diff --git a/src/pages/Auth/CreateNewPassword/index.jsx b/src/pages/Auth/CreateNewPassword/index.tsx
similarity index 100%
rename from src/pages/Auth/CreateNewPassword/index.jsx
rename to src/pages/Auth/CreateNewPassword/index.tsx
diff --git a/src/redux/reducers/alerts.ts b/src/redux/reducers/alerts.ts
index 3408c2484..a0f9a0ff6 100644
--- a/src/redux/reducers/alerts.ts
+++ b/src/redux/reducers/alerts.ts
@@ -11,9 +11,9 @@ const initialState: IInitialState = {
type: 'info',
}
-const alertsCreate = (state: IInitialState, { payload }: PayloadAction<{ message: string, type: string }>) => {
+const alertsCreate = (state: IInitialState, { payload }: PayloadAction<{ message: string, type?: string }>) => {
state.message = payload.message
- state.type = payload.type
+ state.type = payload.type || 'info'
}
const alertsSlice = createSlice({
diff --git a/src/ui/Button.tsx b/src/ui/Button.tsx
index a8c899faa..f0459e9b9 100644
--- a/src/ui/Button.tsx
+++ b/src/ui/Button.tsx
@@ -11,7 +11,7 @@ const Button = ({
text, children, primary, secondary, danger, onClick, white, small, regular, large, giant, type, className, loading, semiSmall, semiDanger, noBorder, focus,
}: {
text?: string,
- children?: JSX.Element,
+ children?: JSX.Element | string,
primary?: boolean,
secondary?: boolean,
danger?: boolean,
diff --git a/src/ui/Input.tsx b/src/ui/Input.tsx
index 9f72a622f..dedadb410 100644
--- a/src/ui/Input.tsx
+++ b/src/ui/Input.tsx
@@ -16,7 +16,7 @@ const Input = ({
name?: string,
className?: string,
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void,
- error?: string | null,
+ error?: string | null | boolean,
value?: string | number,
disabled?: boolean,
onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void,