@@ -119,7 +119,7 @@ function PydanticFormContextProvider({
119119
120120 // fetch the form definition using SWR hook
121121 const {
122- data : apiErrorResp ,
122+ data : apiResponse ,
123123 isLoading : isLoadingSchema ,
124124 error,
125125 } = usePydanticForm ( formKey , formInputData , formProvider , metaData ) ;
@@ -170,14 +170,13 @@ function PydanticFormContextProvider({
170170
171171 rhfRef . current = rhf ;
172172
173- /* TODO: implement this
173+ /* TODO: Reimplement
174174 // prevent user from navigating away when there are unsaved changes
175175 const hasUnsavedData =
176176 !saveToLeavePageInCurrentState &&
177177 !isFullFilled &&
178178 rhf.formState.isDirty;
179179
180- /* TODO: implement this
181180 useLeavePageConfirm(
182181 hasUnsavedData,
183182 'Er zijn aanpassingen in het formulier. \nWeet je zeker dat je de pagina wilt verlaten?',
@@ -226,36 +225,43 @@ function PydanticFormContextProvider({
226225 } ) ;
227226
228227 if ( skipSuccessNotice ) {
229- onSuccess ( values , summaryData ) ;
228+ onSuccess ( values , summaryData , apiResponse || { } ) ;
230229 } else {
231230 setTimeout ( ( ) => {
232- onSuccess ?.( values , summaryData ) ;
233- } , 1500 ) ;
231+ onSuccess ?.( values , summaryData , apiResponse || { } ) ;
232+ } , 1500 ) ; // Delay to allow notice to show first
234233 }
235- } , [ isFullFilled , skipSuccessNotice , onSuccess , rhf , formData ] ) ;
234+ } , [
235+ isFullFilled ,
236+ skipSuccessNotice ,
237+ onSuccess ,
238+ rhf ,
239+ formData ,
240+ apiResponse ,
241+ ] ) ;
236242
237243 // a useeffect for whenever the error response updates
238244 // sometimes we need to update the form,
239245 // some we need to update the errors
240246 useEffect ( ( ) => {
241- if ( apiErrorResp ?. success ) {
247+ if ( apiResponse ?. success ) {
242248 setIsFullFilled ( true ) ;
243249 return ;
244250 }
245251
246252 // when we receive a form from the JSON, we fully reset the scheme
247- if ( apiErrorResp ?. form ) {
248- setRawSchema ( apiErrorResp . form ) ;
253+ if ( apiResponse ?. form ) {
254+ setRawSchema ( apiResponse . form ) ;
249255 setErrorDetails ( undefined ) ;
250256 }
251257
252258 // when we receive errors, we append to the scheme
253- if ( apiErrorResp ?. validation_errors ) {
254- setErrorDetails ( getErrorDetailsFromResponse ( apiErrorResp ) ) ;
259+ if ( apiResponse ?. validation_errors ) {
260+ setErrorDetails ( getErrorDetailsFromResponse ( apiResponse ) ) ;
255261 }
256262
257263 setIsSending ( false ) ;
258- } , [ apiErrorResp , onSuccess , rhf , skipSuccessNotice ] ) ;
264+ } , [ apiResponse , onSuccess , rhf , skipSuccessNotice ] ) ;
259265
260266 const resetFormData = useCallback ( ( ) => {
261267 if ( ! formData ) {
@@ -320,7 +326,7 @@ function PydanticFormContextProvider({
320326 [ resetFormData , rhf ] ,
321327 ) ;
322328
323- // with this we have the possiblity to have listeners for specific fields
329+ // with this we have the possibility to have listeners for specific fields
324330 // this could be used to trigger validations of related fields, casting changes to elsewhere, etc.
325331 useEffect ( ( ) => {
326332 let sub : Subscription ;
0 commit comments