@@ -22,13 +22,13 @@ import { MoteurDeLiens } from '../../MoteurDeLiens.ts';
22
22
import { useMutation , useQuery } from '@tanstack/react-query' ;
23
23
import {
24
24
CorpsDemandeDevenirAidant ,
25
+ entiteEnFonctionDuTypeAidant ,
25
26
ReponseDemandeInitiee ,
26
27
} from '../devenir-aidant/DevenirAidant.ts' ;
27
28
import { constructeurParametresAPI } from '../../../fournisseurs/api/ConstructeurParametresAPI.ts' ;
28
29
import { useMACAPI } from '../../../fournisseurs/api/useMACAPI.ts' ;
29
30
import { useNavigationMAC } from '../../../fournisseurs/hooks.ts' ;
30
31
import { FormulaireDevenirAidant } from '../devenir-aidant/formulaire-devenir-aidant/FormulaireDevenirAidant.tsx' ;
31
- import { CorpsMutationDemandeDevenirAidant } from '../devenir-aidant/formulaire-devenir-aidant/CapteurFormulaireDevenirAidant.tsx' ;
32
32
import { TypographieH5 } from '../../../composants/communs/typographie/TypographieH5/TypographieH5.tsx' ;
33
33
import { Toast } from '../../../composants/communs/Toasts/Toast.tsx' ;
34
34
import Button from '../../../composants/atomes/Button/Button.tsx' ;
@@ -74,7 +74,7 @@ export const EcranDemandeDevenirAidant = () => {
74
74
isError : mutationEnErreur ,
75
75
} = useMutation ( {
76
76
mutationKey : [ 'demander-a-devenir-aidant' ] ,
77
- mutationFn : ( corpsMutation : CorpsMutationDemandeDevenirAidant ) => {
77
+ mutationFn : ( corpsMutation : CorpsDemandeDevenirAidant ) => {
78
78
const actionSoumettre = new MoteurDeLiens (
79
79
navigationMAC . etat
80
80
) . trouveEtRenvoie ( 'envoyer-demande-devenir-aidant' ) ;
@@ -84,6 +84,8 @@ export const EcranDemandeDevenirAidant = () => {
84
84
'Une erreur est survenue lors de la demande devenir aidant'
85
85
) ;
86
86
87
+ console . log ( { corpsMutation } ) ;
88
+ return Promise . resolve ( ) ;
87
89
return macAPI . execute < void , void , CorpsDemandeDevenirAidant > (
88
90
constructeurParametresAPI < CorpsDemandeDevenirAidant > ( )
89
91
. url ( actionSoumettre . url )
@@ -100,6 +102,7 @@ export const EcranDemandeDevenirAidant = () => {
100
102
101
103
const surClickChoixUtilisation = useCallback ( ( choix : Utilisation ) => {
102
104
envoie ( choixUtilisationFaite ( choix ) ) ;
105
+ window . scrollTo ( { top : 0 } ) ;
103
106
} , [ ] ) ;
104
107
105
108
const surClickChoixTypeAidant = useCallback (
@@ -110,10 +113,21 @@ export const EcranDemandeDevenirAidant = () => {
110
113
entite,
111
114
} )
112
115
) ;
116
+ window . scrollTo ( { top : 0 } ) ;
113
117
} ,
114
118
[ ]
115
119
) ;
116
120
121
+ const surSignatureCharteAidant = useCallback ( ( ) => {
122
+ envoie ( signeCharteAidant ( ) ) ;
123
+ window . scrollTo ( { top : 0 } ) ;
124
+ } , [ ] ) ;
125
+
126
+ const surClickEtapePrecedente = useCallback ( ( ) => {
127
+ envoie ( retourEtapePrecedente ( ) ) ;
128
+ window . scrollTo ( { top : 0 } ) ;
129
+ } , [ ] ) ;
130
+
117
131
const etapes : Map < Etape , React . ReactElement > = new Map ( [
118
132
[
119
133
'choixUtilisation' ,
@@ -128,15 +142,15 @@ export const EcranDemandeDevenirAidant = () => {
128
142
key = "choixTypeAidant"
129
143
typeAidant = { etatEtapeCourante . demande ?. type }
130
144
surClick = { surClickChoixTypeAidant }
131
- precedent = { ( ) => envoie ( retourEtapePrecedente ( ) ) }
145
+ precedent = { surClickEtapePrecedente }
132
146
/> ,
133
147
] ,
134
148
[
135
149
'signatureCharteAidant' ,
136
150
< SignatureCharteAidant
137
151
key = "signatureCharteAidant"
138
- signeCharteAidant = { ( ) => envoie ( signeCharteAidant ( ) ) }
139
- precedent = { ( ) => envoie ( retourEtapePrecedente ( ) ) }
152
+ signeCharteAidant = { surSignatureCharteAidant }
153
+ precedent = { surClickEtapePrecedente }
140
154
/> ,
141
155
] ,
142
156
[ 'signatureCGUs' , < SignatureCGU key = "signatureCGUs" /> ] ,
@@ -169,33 +183,48 @@ export const EcranDemandeDevenirAidant = () => {
169
183
</ FormulaireDevenirAidant . AvantPropos >
170
184
< FormulaireDevenirAidant . Formulaire
171
185
referentielDepartements = { referentielDepartements }
172
- surSoumission = { ( formulaire ) =>
186
+ surSoumission = { ( formulaire ) => {
187
+ const { typeAidant, entite : entiteDuFormulaire } =
188
+ etatEtapeCourante . demande ! . type ;
189
+
190
+ const entiteCorrespondante =
191
+ entiteEnFonctionDuTypeAidant . get ( typeAidant ) ;
192
+
173
193
mutate ( {
174
194
...formulaire ,
175
- typeAidant : etatEtapeCourante . demande ?. type . typeAidant ,
176
- entite : etatEtapeCourante . demande ?. type . entite ,
177
- } )
178
- }
195
+ signatureCharte : etatEtapeCourante . demande ! . signatureCharte ,
196
+ ...( entiteCorrespondante && {
197
+ entite : entiteCorrespondante (
198
+ entiteDuFormulaire ?. nom ,
199
+ entiteDuFormulaire ?. siret
200
+ ) ,
201
+ } ) ,
202
+ } ) ;
203
+ } }
179
204
devientValide = { ( estFormulaireValide ) => {
180
205
setEstValide ( estFormulaireValide ) ;
181
206
} }
182
207
>
183
- < Button
184
- type = "submit"
185
- key = "envoyer-demande-devenir-aidant"
186
- className = "fr-btn bouton-mac bouton-mac-primaire"
187
- onClick = { ( ) => envoie ( retourEtapePrecedente ( ) ) }
188
- >
189
- Précédent
190
- </ Button >
191
- < Button
192
- type = "submit"
193
- key = "envoyer-demande-devenir-aidant"
194
- className = "fr-btn bouton-mac bouton-mac-primaire"
195
- disabled = { ! estValide }
196
- >
197
- Envoyer
198
- </ Button >
208
+ < div className = "actions" >
209
+ < Button
210
+ type = "submit"
211
+ variant = "secondary"
212
+ key = "envoyer-demande-devenir-aidant"
213
+ onClick = { surClickEtapePrecedente }
214
+ >
215
+ < i className = "fr-icon-arrow-left-line" > </ i >
216
+ < span > Précédent</ span >
217
+ </ Button >
218
+ < Button
219
+ type = "submit"
220
+ key = "envoyer-demande-devenir-aidant"
221
+ className = "fr-btn bouton-mac bouton-mac-primaire"
222
+ disabled = { ! estValide }
223
+ >
224
+ Envoyer
225
+ < span className = "fr-icon-check-line" aria-hidden = "true" > </ span >
226
+ </ Button >
227
+ </ div >
199
228
</ FormulaireDevenirAidant . Formulaire >
200
229
201
230
{ mutationEnErreur ? (
0 commit comments