@@ -2,7 +2,7 @@ import { FormProvider, useForm } from 'react-hook-form';
2
2
import styles from './TaskForm.module.scss' ;
3
3
import { ColorPicker , TextField } from '@/components/FormRHF' ;
4
4
import { useMainButton } from '@/hooks/useMainButton' ;
5
- import { categorySchema } from '@/schema' ;
5
+ import { categorySchema , taskSchema } from '@/schema' ;
6
6
import { generateRandomHexColor } from '@/utils' ;
7
7
import {
8
8
useCategory ,
@@ -13,32 +13,32 @@ import { useTranslation } from '@/hooks/useTranslation';
13
13
import { useClosingBehaviour } from '@/hooks/useClosingBehaviour' ;
14
14
import { IFormType } from '@/types' ;
15
15
import { useRouter } from '@/hooks/useRouter' ;
16
- import { useMemo } from 'react' ;
17
16
import { yupResolver } from '@hookform/resolvers/yup' ;
17
+ import { useCreateTask , useEditTask , useTask } from '@/hooks/api/task' ;
18
18
19
19
interface IProps {
20
20
type : IFormType ;
21
21
}
22
22
23
23
const TaskForm = ( { type } : IProps ) => {
24
24
const {
25
- query : { id } ,
25
+ query : { todoListId , taskId } ,
26
26
} = useRouter ( ) ;
27
27
28
- const { data : category , isLoading } = useCategory ( id as string ) ;
29
-
30
- const randomHexColor = useMemo ( generateRandomHexColor , [ ] ) ;
28
+ const { data : task , isLoading } = useTask ( {
29
+ todoListId : todoListId as string ,
30
+ taskId : taskId as string ,
31
+ } ) ;
31
32
32
33
const methods = useForm ( {
33
- resolver : yupResolver ( categorySchema ) ,
34
- values : {
35
- title : category ?. title ?? '' ,
36
- color : category ?. color ?? randomHexColor ,
37
- } ,
34
+ resolver : yupResolver ( taskSchema ) ,
35
+ // values: {
36
+
37
+ // },
38
38
} ) ;
39
39
40
- const { mutate : create , isLoading : isCreateLoading } = useCreateCategory ( ) ;
41
- const { mutate : edit , isLoading : isEditLoading } = useEditCategory ( ) ;
40
+ const { mutate : create , isLoading : isCreateLoading } = useCreateTask ( ) ;
41
+ const { mutate : edit , isLoading : isEditLoading } = useEditTask ( ) ;
42
42
43
43
const { t } = useTranslation ( ) ;
44
44
@@ -51,8 +51,8 @@ const TaskForm = ({ type }: IProps) => {
51
51
if ( type === 'create' ) {
52
52
create ( data ) ;
53
53
} else {
54
- if ( ! category ?. id ) return ;
55
- edit ( { ...data , id : category . id } ) ;
54
+ if ( ! task ?. id ) return ;
55
+ edit ( { ...data , id : task . id } ) ;
56
56
}
57
57
} ) ;
58
58
@@ -74,8 +74,7 @@ const TaskForm = ({ type }: IProps) => {
74
74
< h1 > { t ( 'new_category' ) } </ h1 >
75
75
< FormProvider { ...methods } >
76
76
< form >
77
- < TextField name = 'title' label = 'Category name' />
78
- < ColorPicker name = 'color' label = 'Color' />
77
+ < TextField name = 'title' label = { t ( 'task_name' ) } />
79
78
</ form >
80
79
</ FormProvider >
81
80
</ div >
0 commit comments