Skip to content

Commit 53bb339

Browse files
authored
Merge pull request #66 from Dialogue-Bot/DIAL-42-implement-test-your-bot
Dial 42 implement test your bot
2 parents 8c66e45 + 8b7fc5d commit 53bb339

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1490
-121
lines changed

client/src/apis/auth.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ENDPOINTS } from '@/constants'
22
import http_client from '@/lib/http-client'
3-
import { TForgotPass } from '@/lib/schema/forgot-pass'
43
import { TLogin } from '@/lib/schema/login'
4+
import { TForgotPass } from '@/lib/schema/mail'
55
import { TRegister } from '@/lib/schema/register'
66
import { TSetPass } from '@/lib/schema/set-pass'
77
import { TBaseResponse, TToken } from '@/types/share'
@@ -45,6 +45,13 @@ class Auth {
4545
logout(): Promise<TBaseResponse<null>> {
4646
return http_client.post(ENDPOINTS.AUTH.LOGOUT)
4747
}
48+
49+
requestVerifyAccount(email: string): Promise<TBaseResponse<null>> {
50+
return http_client.post(ENDPOINTS.AUTH.REQUEST_VERIFY_ACCOUNT, { email })
51+
}
52+
verifyAccount(token: string): Promise<TBaseResponse<null>> {
53+
return http_client.post(ENDPOINTS.AUTH.VERIFY_ACCOUNT, { token })
54+
}
4855
}
4956

5057
export const auth = new Auth()

client/src/components/forms/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export * from './card'
22
export * from './change-pass'
3-
export * from './forgot-pass'
43
export * from './general-setting'
54
export * from './login'
5+
export * from './mail'
66
export * from './register'
77
export * from './set-pass'
88
export * from './setting-mail'

client/src/components/forms/intent.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from '@/lib/schema/intent-input'
55
import { TIntentInput } from '@/types/intent'
66
import { zodResolver } from '@hookform/resolvers/zod'
7+
import { createId } from '@paralleldrive/cuid2'
78
import _ from 'lodash'
89
import { Minus, Plus } from 'lucide-react'
910
import { useCallback } from 'react'
@@ -38,14 +39,13 @@ const IntentForm = ({ defaultValues, id = 'intent-form', onSubmit }: Props) => {
3839
const form = useForm<TIntentInputForm>({
3940
defaultValues: {
4041
trainType: 'manual',
42+
referenceId: createId(),
4143
...defaultValues,
4244
},
4345
resolver: zodResolver(schema),
4446
mode: 'onChange',
4547
})
4648

47-
console.log(form.formState.errors)
48-
4949
const watchTrainType = form.watch('trainType')
5050
const trainDescriptionWatch = useWatch({
5151
control: form.control,
@@ -369,6 +369,7 @@ const IntentForm = ({ defaultValues, id = 'intent-form', onSubmit }: Props) => {
369369
<Input
370370
{...field}
371371
placeholder={t('referenceId.placeholder')}
372+
disabled
372373
/>
373374
</FormControl>
374375
<FormMessage />

client/src/components/forms/forgot-pass.tsx renamed to client/src/components/forms/mail.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { useErrorsLngChange } from '@/hooks/use-errors-lng-change'
2-
import { TForgotPass, useForgotPassSchema } from '@/lib/schema/forgot-pass'
2+
import { TEmail, useMailSchema } from '@/lib/schema/mail'
33
import { zodResolver } from '@hookform/resolvers/zod'
44
import { useForm } from 'react-hook-form'
55
import { useTranslation } from 'react-i18next'
66
import {
7-
Button,
87
Form,
98
FormControl,
109
FormField,
@@ -15,29 +14,39 @@ import {
1514
} from '../ui'
1615

1716
type Props = {
18-
loading?: boolean
19-
onSubmit?: (data: TForgotPass) => void
17+
onSubmit?: (data: TEmail) => void
18+
id?: string
19+
defaultValues?: TEmail
2020
}
2121

22-
export const ForgotPassForm = ({ loading, onSubmit }: Props) => {
22+
export const MailForm = ({
23+
onSubmit,
24+
id = 'mail-form',
25+
defaultValues,
26+
}: Props) => {
2327
const { t } = useTranslation(['set_pass', 'forms'])
2428

25-
const schema = useForgotPassSchema()
29+
const schema = useMailSchema()
2630

27-
const form = useForm<TForgotPass>({
31+
const form = useForm<TEmail>({
2832
resolver: zodResolver(schema),
2933
mode: 'onChange',
34+
defaultValues,
3035
})
3136

32-
const handleSubmit = (data: TForgotPass) => {
37+
const handleSubmit = (data: TEmail) => {
3338
onSubmit?.(data)
3439
}
3540

3641
useErrorsLngChange(form)
3742

3843
return (
3944
<Form {...form}>
40-
<form className='space-y-3' onSubmit={form.handleSubmit(handleSubmit)}>
45+
<form
46+
className='space-y-3'
47+
onSubmit={form.handleSubmit(handleSubmit)}
48+
id={id}
49+
>
4150
<FormField
4251
control={form.control}
4352
name='email'
@@ -62,14 +71,9 @@ export const ForgotPassForm = ({ loading, onSubmit }: Props) => {
6271
)
6372
}}
6473
/>
65-
<Button className='w-full' type='submit' loading={loading}>
66-
{t('btn_submit', {
67-
ns: 'set_pass',
68-
})}
69-
</Button>
7074
</form>
7175
</Form>
7276
)
7377
}
7478

75-
export default ForgotPassForm
79+
export default MailForm

client/src/components/ui/multiple-lelect.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { cn } from '@/lib/utils'
12
import { CaretSortIcon } from '@radix-ui/react-icons'
3+
import { CheckIcon, X } from 'lucide-react'
24
import { memo, useCallback, useMemo, useState } from 'react'
3-
import { Popover, PopoverContent, PopoverTrigger } from './popover'
4-
import { cn } from '@/lib/utils'
55
import { Badge } from './badge'
6-
import { CheckIcon, X } from 'lucide-react'
6+
import { Popover, PopoverContent, PopoverTrigger } from './popover'
77

88
export type TOption = {
99
label: string
@@ -72,7 +72,7 @@ export const MultipleSelect = memo(
7272
return (
7373
<Popover>
7474
<PopoverTrigger asChild>
75-
<div className='flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 cursor-pointer focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none select-none gap-1'>
75+
<div className='flex min-h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 cursor-pointer focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none select-none gap-1 flex-wrap'>
7676
{selectedWithLabel && selectedWithLabel.length ? (
7777
selectedWithLabel?.map((item) => (
7878
<Badge

client/src/constants/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export const ENDPOINTS = {
1212
RESET_PASSWORD: '/auth/reset-password',
1313
WITH_ID_TOKEN: '/auth/with-id-token',
1414
LOGOUT: '/auth/logout',
15+
VERIFY_ACCOUNT: '/auth/verify-account',
16+
REQUEST_VERIFY_ACCOUNT: '/auth/request-verify-account',
1517
},
1618
UPLOAD: {
1719
SINGLE: '/upload/single',
@@ -53,6 +55,8 @@ export const ROUTES = {
5355
REGISTER: '/register',
5456
FORGOT_PASS: '/forgot-password',
5557
RESET_PASS: '/set-password',
58+
REQUEST_VERIFY_ACCOUNT: '/request-verify-account',
59+
VERIFY_ACCOUNT: '/verify-account',
5660
},
5761
PUBLIC: {
5862
LANDING_PAGE: '/',

client/src/hooks/auth/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from './use-login-with-id-token'
44
export * from './use-login-with-provider'
55
export * from './use-logout'
66
export * from './use-register'
7+
export * from './use-req-verify-account'
78
export * from './use-set-pass'

client/src/hooks/auth/use-forgot-pass.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { auth } from '@/apis/auth'
2-
import { TForgotPass } from '@/lib/schema/forgot-pass'
2+
import { TEmail } from '@/lib/schema/mail'
33
import { useMutation } from '@tanstack/react-query'
44
import { useTranslation } from 'react-i18next'
55
import { toast } from 'sonner'
66

77
export const useForgotPass = () => {
88
const { t } = useTranslation('common')
99
return useMutation({
10-
mutationFn: (data: TForgotPass) => {
10+
mutationFn: (data: TEmail) => {
1111
return auth.forgotPassword(data)
1212
},
1313
onSuccess(data) {

client/src/hooks/auth/use-login.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { auth } from '@/apis/auth'
22
import { TLogin } from '@/lib/schema/login'
33
import { useMutation } from '@tanstack/react-query'
44
import { useTranslation } from 'react-i18next'
5-
import { useSearchParams } from 'react-router-dom'
5+
import { useNavigate, useSearchParams } from 'react-router-dom'
66
import { toast } from 'sonner'
77

88
export const useLogin = () => {
99
const { t } = useTranslation('common')
1010
const [search] = useSearchParams()
11+
const navigate = useNavigate()
1112
return useMutation({
1213
mutationFn: (data: TLogin) => {
1314
return auth.login(data)
@@ -18,6 +19,10 @@ export const useLogin = () => {
1819
onError(err: any) {
1920
console.log(err)
2021
toast.error(err?.response?.data?.message || t('api_error'))
22+
23+
if (err?.response?.data?.errorKey === 'EMAIL_NOT_VERIFIED') {
24+
navigate('/request-verify-account')
25+
}
2126
},
2227
})
2328
}

client/src/hooks/auth/use-register.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { auth } from '@/apis/auth'
2+
import { ROUTES } from '@/constants'
23
import { TRegister } from '@/lib/schema/register'
34
import { useMutation } from '@tanstack/react-query'
45
import { useTranslation } from 'react-i18next'
@@ -12,9 +13,11 @@ export const useRegister = () => {
1213
mutationFn: (data: TRegister) => {
1314
return auth.register(data)
1415
},
15-
onSuccess(data) {
16+
onSuccess(data, variables) {
1617
toast.success(data.message)
17-
navigate('/login')
18+
navigate(
19+
`${ROUTES.AUTH.REQUEST_VERIFY_ACCOUNT}?send=true&email=${variables.email}`,
20+
)
1821
},
1922
onError(err: any) {
2023
toast.error(err?.response?.data?.message || t('api_error'))

0 commit comments

Comments
 (0)