1
1
"use client" ;
2
2
import Input from "@codegouvfr/react-dsfr/Input" ;
3
3
import { zodResolver } from "@hookform/resolvers/zod" ;
4
+ import { useMutation } from "@tanstack/react-query" ;
4
5
import { useRouter } from "next/navigation" ;
5
6
import { useForm } from "react-hook-form" ;
6
7
import { z } from "zod" ;
7
8
8
9
import { FormButtons } from "@/components/form/form-footer/FormButtons" ;
10
+ import { useGraphQlClient } from "@/components/graphql/graphql-client/GraphqlClient" ;
9
11
import { graphqlErrorToast , successToast } from "@/components/toast/toast" ;
10
12
13
+ import { graphql } from "@/graphql/generated" ;
14
+
15
+ const createCommanditaireVaeCollectiveMutation = graphql ( `
16
+ mutation vaeCollective_createCommanditaireVaeCollective(
17
+ $raisonSociale: String!
18
+ $gestionnaireEmail: String!
19
+ $gestionnaireFirstname: String!
20
+ $gestionnaireLastname: String!
21
+ ) {
22
+ vaeCollective_createCommanditaireVaeCollective(
23
+ raisonSociale: $raisonSociale
24
+ gestionnaireEmail: $gestionnaireEmail
25
+ gestionnaireFirstname: $gestionnaireFirstname
26
+ gestionnaireLastname: $gestionnaireLastname
27
+ ) {
28
+ id
29
+ }
30
+ }
31
+ ` ) ;
32
+
11
33
const structureVaeCollectiveSchema = z . object ( {
12
34
raisonSociale : z . string ( ) . min ( 1 , "Merci de remplir ce champ" ) ,
13
35
gestionnaireEmail : z . string ( ) . min ( 1 , "Merci de remplir ce champ" ) ,
@@ -21,6 +43,17 @@ type StructureVaeCollectiveFormValues = z.infer<
21
43
22
44
export default function AddStructureVaeCollectivePage ( ) {
23
45
const router = useRouter ( ) ;
46
+ const { graphqlClient } = useGraphQlClient ( ) ;
47
+ const { mutateAsync : createCommanditaireVaeCollective } = useMutation ( {
48
+ mutationFn : ( params : {
49
+ raisonSociale : string ;
50
+ gestionnaireEmail : string ;
51
+ gestionnaireFirstname : string ;
52
+ gestionnaireLastname : string ;
53
+ } ) =>
54
+ graphqlClient . request ( createCommanditaireVaeCollectiveMutation , params ) ,
55
+ } ) ;
56
+
24
57
const { register, handleSubmit, formState, reset } =
25
58
useForm < StructureVaeCollectiveFormValues > ( {
26
59
resolver : zodResolver ( structureVaeCollectiveSchema ) ,
@@ -34,7 +67,7 @@ export default function AddStructureVaeCollectivePage() {
34
67
35
68
const onSubmit = async ( data : StructureVaeCollectiveFormValues ) => {
36
69
try {
37
- console . log ( { data } ) ;
70
+ await createCommanditaireVaeCollective ( data ) ;
38
71
successToast ( "Structure de VAE collective créée avec succès" ) ;
39
72
router . push ( `/structures-vae-collective` ) ;
40
73
} catch ( error ) {
0 commit comments