Skip to content

Commit

Permalink
moved out the rest of UI related functions from impl to platform
Browse files Browse the repository at this point in the history
  • Loading branch information
vygandas committed Dec 24, 2023
1 parent b582cac commit 5066531
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 89 deletions.
47 changes: 19 additions & 28 deletions apps/platform/src/views/auth/passwordReset.view.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import { usePasswordResetRequestForm } from '@isomera/impl'
import {
pages,
useHandleErrorHook,
usePasswordResetRequestForm
} from '@isomera/impl'
import { toast } from 'react-toastify'
import { useNavigate } from 'react-router-dom'

export const PasswordResetView = () => {
// const navigate = useNavigate()
// const location = useLocation()
const navigate = useNavigate()
const { handleError } = useHandleErrorHook()

// const from = (location.state?.from.pathname as string) || '/profile'
const onSuccess = () => {
toast.success(
"If there was such user registered with email, then you'll receive confirmation code."
)
navigate(pages.passwordResetRequestConfirmation.path)
}

const onSuccess = (message: string) => {
toast.success(message)
const onError = (error?: unknown) => {
if (error) {
handleError(error, { view: 'login' })
}
}

const {
Expand All @@ -19,28 +31,7 @@ export const PasswordResetView = () => {
touched,
handleSubmit,
isSubmitting
} = usePasswordResetRequestForm(onSuccess)

// useEffect(() => {
// if (isSuccess) {
// toast.success('You successfully logged in')
// navigate(from)
// }
// if (isError) {
// if (Array.isArray((error as any).data.error)) {
// ;(error as any).data.error.forEach((el: any) =>
// toast.error(el.message, {
// position: 'top-right'
// })
// )
// } else {
// toast.error((error as any).data.message, {
// position: 'top-right'
// })
// }
// }
// // eslint-disable-next-line react-hooks/exhaustive-deps
// }, [isLoading])
} = usePasswordResetRequestForm({ onSuccess, onError })

return (
<form onSubmit={handleSubmit}>
Expand Down
26 changes: 20 additions & 6 deletions apps/platform/src/views/auth/passwordResetConfirm.view.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { usePasswordResetPerformForm } from '@isomera/impl'
import {
pages,
useHandleErrorHook,
usePasswordResetPerformForm
} from '@isomera/impl'
import { toast } from 'react-toastify'
import { useNavigate } from 'react-router-dom'

export const PasswordResetConfirmView = () => {
const onSuccess = (message: string) => {
toast.success(message)
const { handleError } = useHandleErrorHook()
const navigate = useNavigate()

const onSuccess = () => {
toast.success(
'Password changed successfully. Please log in with your new password.'
)
navigate(pages.login.path)
}

const onError = (message: string) => {
toast.error(message)
const onError = (error?: unknown) => {
toast.error('Password change failed. Please try again.')
if (error) {
handleError(error, { view: 'login' })
}
}

const {
Expand All @@ -18,7 +32,7 @@ export const PasswordResetConfirmView = () => {
touched,
handleSubmit,
isSubmitting
} = usePasswordResetPerformForm(onSuccess, onError)
} = usePasswordResetPerformForm({ onSuccess, onError })

return (
<form onSubmit={handleSubmit}>
Expand Down
26 changes: 20 additions & 6 deletions apps/platform/src/views/auth/verificationCode.view.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
import { useConfirmCodePerformForm } from '@isomera/impl'
import {
pages,
useConfirmCodePerformForm,
useHandleErrorHook
} from '@isomera/impl'
import { toast } from 'react-toastify'
import { useNavigate } from 'react-router-dom'

export const VerificationCodeView = () => {
const onSuccess = (message: string) => {
toast.success(message)
const navigate = useNavigate()
const { handleError } = useHandleErrorHook()

const onSuccess = () => {
toast.success(
'Activate user successfully. Please log in with your account.'
)
navigate(pages.login.path)
}

const onError = (message: string) => {
toast.error(message)
const onError = (error?: unknown) => {
toast.error('Activate user failed. Please try again.')
if (error) {
handleError(error, { view: 'login' })
}
}

const {
Expand All @@ -18,7 +32,7 @@ export const VerificationCodeView = () => {
touched,
handleSubmit,
isSubmitting
} = useConfirmCodePerformForm(onSuccess, onError)
} = useConfirmCodePerformForm({ onSuccess, onError })

return (
<form onSubmit={handleSubmit}>
Expand Down
26 changes: 9 additions & 17 deletions libs/impl/src/hooks/auth/useConfirmCodePerformForm.hook.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { useFormik } from 'formik'

import { useNavigate } from 'react-router-dom'

import { pages } from '../../constants/pages'
import { ConfirmationCodeDto, formikValidate } from '@isomera/dtos'
import { useHandleErrorHook } from '../error/useHandleError.hook'
import { Pure, StatusType } from '@isomera/interfaces'
import { userConfirmCodePerformHook } from './useConfirmCodePerform.hook'

Expand All @@ -13,27 +8,24 @@ const initialValues: Pure<ConfirmationCodeDto> = {
email: ''
}

export const useConfirmCodePerformForm = (
onSuccess: (arg0: string) => void,
onError: (arg0: string) => void
) => {
interface Options {
onSuccess?: () => void
onError?: (error?: unknown) => void
}

export const useConfirmCodePerformForm = (options: Options) => {
const { performReset } = userConfirmCodePerformHook()
const { handleError } = useHandleErrorHook()
const navigate = useNavigate()

const onSubmit = async (values: typeof initialValues) => {
try {
const result = await performReset(values)
if (result.status === StatusType.OK) {
onSuccess(
'Activate user successfully. Please log in with your account.'
)
options.onSuccess && options.onSuccess()
} else {
onError('Activate user failed. Please try again.')
options.onError && options.onError()
}
navigate(pages.login.path)
} catch (error) {
handleError(error, { view: 'login' })
options.onError && options.onError(error)
}
}

Expand Down
26 changes: 9 additions & 17 deletions libs/impl/src/hooks/auth/usePasswordResetPerformForm.hook.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { useFormik } from 'formik'

import { useNavigate } from 'react-router-dom'

import { pages } from '../../constants/pages'
import { formikValidate, ResetPasswordRequestDto } from '@isomera/dtos'
import { useHandleErrorHook } from '../error/useHandleError.hook'
import { Pure, StatusType } from '@isomera/interfaces'
import { usePasswordResetPerformHook } from './usePasswordResetPerform.hook'

Expand All @@ -13,27 +8,24 @@ const initialValues: Pure<ResetPasswordRequestDto> = {
passwordResetCode: ''
}

export const usePasswordResetPerformForm = (
onSuccess: (arg0: string) => void,
onError: (arg0: string) => void
) => {
interface Options {
onSuccess: () => void
onError: (error?: unknown) => void
}

export const usePasswordResetPerformForm = (options: Options) => {
const { performReset } = usePasswordResetPerformHook()
const { handleError } = useHandleErrorHook()
const navigate = useNavigate()

const onSubmit = async (values: typeof initialValues) => {
try {
const result = await performReset(values)
if (result.status === StatusType.OK) {
onSuccess(
'Password changed successfully. Please log in with your new password.'
)
options.onSuccess && options.onSuccess()
} else {
onError('Password change failed. Please try again.')
options.onError && options.onError()
}
navigate(pages.login.path)
} catch (error) {
handleError(error, { view: 'login' })
options.onError && options.onError(error)
}
}

Expand Down
23 changes: 8 additions & 15 deletions libs/impl/src/hooks/auth/usePasswordResetRequestForm.hook.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { useFormik } from 'formik'

import { useNavigate } from 'react-router-dom'

import { pages } from '../../constants/pages'
import { formikValidate } from '@isomera/dtos'
import { useHandleErrorHook } from '../error/useHandleError.hook'
import { Pure } from '@isomera/interfaces'
import { usePasswordResetRequestHook } from './usePasswordResetRequest.hook'
import { ForgotPasswordResetRequestDto } from '@isomera/dtos'
Expand All @@ -13,22 +8,20 @@ const initialValues: Pure<ForgotPasswordResetRequestDto> = {
email: ''
}

export const usePasswordResetRequestForm = (
onSuccess: (arg0: string) => void
) => {
interface Options {
onSuccess?: () => void
onError?: (error?: unknown) => void
}

export const usePasswordResetRequestForm = (options: Options) => {
const { requestReset } = usePasswordResetRequestHook()
const { handleError } = useHandleErrorHook()
const navigate = useNavigate()

const onSubmit = async (values: typeof initialValues) => {
try {
await requestReset(values)
onSuccess(
`If there was such user registered with email ${values.email}, then you'll receive confirmation code.`
)
navigate(pages.passwordResetRequestConfirmation.path)
options.onSuccess && options.onSuccess()
} catch (error) {
handleError(error, { view: 'login' })
options.onError && options.onError(error)
}
}

Expand Down

2 comments on commit 5066531

@vercel
Copy link

@vercel vercel bot commented on 5066531 Dec 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

isomera-platform – ./

isomera-platform-cortip.vercel.app
isomera.vercel.app
isomera-platform-git-main-cortip.vercel.app
app.isomera.org

@vercel
Copy link

@vercel vercel bot commented on 5066531 Dec 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.