Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted ResetPassword component from jsx to tsx #2688

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useMemo } from 'react'
import { FC, useEffect, useMemo } from 'react'
import { useTranslation } from 'react-i18next'

import useForm from '~/hooks/use-form'
Expand All @@ -19,14 +19,20 @@ import TitleWithDescription from '~/components/title-with-description/TitleWithD
import LoginDialog from '~/containers/guest-home-page/login-dialog/LoginDialog'
import { styles } from '~/containers/guest-home-page/reset-password/ResetPassword.styles'

import { ButtonVariantEnum, SizeEnum } from '~/types'
import { ButtonVariantEnum, SizeEnum, NewPassword } from '~/types'
import { confirmPassword, password } from '~/utils/validations/login'
import { snackbarVariants } from '~/constants'
import imgSuccess from '~/assets/img/email-confirmation-modals/success-icon.svg'
import { openAlert } from '~/redux/features/snackbarSlice'
import { getErrorKey } from '~/utils/get-error-key'
import { Component } from '~/context/modal-context'

const ResetPassword = ({ resetToken, openModal }) => {
interface ResetPasswordProps {
resetToken: string
openModal: (component: Component, delayToClose?: number) => void
}

const ResetPassword: FC<ResetPasswordProps> = ({ resetToken, openModal }) => {
const { t } = useTranslation()
const dispatch = useAppDispatch()

Expand Down Expand Up @@ -57,7 +63,7 @@ const ResetPassword = ({ resetToken, openModal }) => {
loading,
fetchData: sendResetPassword
} = useAxios({
service: (newPassword) =>
service: (newPassword: NewPassword) =>
AuthService.resetPassword(resetToken, newPassword),
fetchOnMount: false,
defaultResponse: null
Expand All @@ -76,13 +82,13 @@ const ResetPassword = ({ resetToken, openModal }) => {
}
}, [error, openModal, response, dispatch, successNotification])

const { handleSubmit, handleInputChange, handleBlur, errors, data } = useForm(
{
onSubmit: () => sendResetPassword({ password: data.password }),
const { handleSubmit, handleInputChange, handleBlur, errors, data } =
useForm<NewPassword>({
onSubmit: async (): Promise<void> =>
sendResetPassword({ password: data.password }),
initialValues: { password: '', confirmPassword: '' },
validations: { password, confirmPassword }
}
)
})

const { inputVisibility: passwordVisibility, showInputText: showPassword } =
useInputVisibility(errors.password)
Expand All @@ -107,7 +113,6 @@ const ResetPassword = ({ resetToken, openModal }) => {
onBlur={handleBlur('password')}
onChange={handleInputChange('password')}
required
size='large'
sx={{ mb: '5px' }}
type={showPassword ? 'text' : 'password'}
value={data.password}
Expand All @@ -120,7 +125,6 @@ const ResetPassword = ({ resetToken, openModal }) => {
onBlur={handleBlur('confirmPassword')}
onChange={handleInputChange('confirmPassword')}
required
size='large'
type={showConfirmPassword ? 'text' : 'password'}
value={data.confirmPassword}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/services/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const AuthService = {
},
resetPassword: (
resetToken: string,
newPassword: string
newPassword: { password: string }
): Promise<AxiosResponse> => {
const confirmUrl = createUrlPath(URLs.auth.resetPassword, resetToken)
return axiosClient.patch(confirmUrl, newPassword)
Expand Down
9 changes: 9 additions & 0 deletions src/types/user/user-interfaces/user.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ export interface ChangePasswordParams {
confirmPassword: string
}

export interface NewPassword {
confirmPassword?: string
password: string
}

export interface SendResetPasswordPayload {
password: string
}

export interface SignupResponse {
userId: string
userEmail: string
Expand Down
Loading