1
1
import { createFileRoute , useNavigate } from "@tanstack/react-router" ;
2
- import { components } from "../../../../api.gen" ;
3
2
import { $api } from "../../../../stores/api" ;
4
3
import { useQueryClient } from "@tanstack/react-query" ;
5
- import { Button , TextInput , useForm } from "@quassel/ui" ;
6
- import { useEffect } from "react" ;
7
-
8
- type FormValues = components [ "schemas" ] [ "CarerMutationDto" ] ;
4
+ import { CarerForm } from "../../../../components/CarerForm" ;
5
+ import { components } from "../../../../api.gen" ;
9
6
10
7
function AdministrationCarersEdit ( ) {
11
8
const p = Route . useParams ( ) ;
12
9
const q = useQueryClient ( ) ;
13
- const { data, isSuccess } = $api . useSuspenseQuery ( "get" , "/carers/{id}" , { params : { path : { id : p . id } } } ) ;
10
+ const { data } = $api . useSuspenseQuery ( "get" , "/carers/{id}" , { params : { path : { id : p . id } } } ) ;
14
11
const n = useNavigate ( ) ;
15
12
const editCarerMutation = $api . useMutation ( "patch" , "/carers/{id}" , {
16
13
onSuccess : ( ) => {
@@ -22,34 +19,15 @@ function AdministrationCarersEdit() {
22
19
n ( { to : "/administration/carers" } ) ;
23
20
} ,
24
21
} ) ;
25
- const f = useForm < FormValues > ( {
26
- initialValues : {
27
- name : "" ,
28
- } ,
29
- } ) ;
30
- const handleSubmit = ( values : FormValues ) => {
22
+
23
+ const handleSubmit = ( values : components [ "schemas" ] [ "CarerMutationDto" ] ) => {
31
24
editCarerMutation . mutate ( {
32
25
body : { ...values } ,
33
26
params : { path : { id : p . id } } ,
34
27
} ) ;
35
28
} ;
36
29
37
- useEffect ( ( ) => {
38
- f . setValues ( { ...data , participant : data . participant ?. id } ) ;
39
- f . resetDirty ( ) ;
40
- } , [ isSuccess , data ] ) ;
41
-
42
- return (
43
- < >
44
- < form autoComplete = "off" onSubmit = { f . onSubmit ( handleSubmit ) } >
45
- < TextInput label = "Name" type = "name" { ...f . getInputProps ( "name" ) } />
46
-
47
- < Button type = "submit" fullWidth mt = "xl" loading = { editCarerMutation . isPending } >
48
- Change
49
- </ Button >
50
- </ form >
51
- </ >
52
- ) ;
30
+ return < CarerForm carer = { data } onSave = { handleSubmit } loading = { editCarerMutation . isPending } /> ;
53
31
}
54
32
55
33
export const Route = createFileRoute ( "/_auth/administration/carers/edit/$id" ) ( {
0 commit comments