From 4765d85eebd97031d35bff6a3ea8bc35921671d9 Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Mon, 10 Jun 2024 14:57:17 -0400 Subject: [PATCH] pass request and response to lifecycle hooks, lint fixes --- src/runtime/composables/useForm.ts | 22 +++++++++---------- .../composables/usePrecognitionForm.ts | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/runtime/composables/useForm.ts b/src/runtime/composables/useForm.ts index 1f9e485..7c34d13 100644 --- a/src/runtime/composables/useForm.ts +++ b/src/runtime/composables/useForm.ts @@ -161,21 +161,21 @@ export default function useForm( this.isDirty = false; return onSuccess; }, - onError: (errors) => { + onError: ({ request, options, response, errors }) => { this.processing = false; this.progress = null; this.clearErrors().setError(errors); if (options.onError) { - return options.onError(errors); + return options.onError({ request, options, response, errors }); } }, - onFinish: (visit) => { + onFinish: ({ request, options, response }) => { this.processing = false; this.progress = null; if (options.onFinish) { - return options.onFinish(visit); + return options.onFinish({ request, options, response }); } }, }; @@ -192,22 +192,22 @@ export default function useForm( method: method, body: data, onRequest: async ({ request, options }) => { - await _options.onStart(); + await _options.onStart({ request, options }); }, - onResponse: async ({ response }) => { + onResponse: async ({ request, options, response }) => { // onResponse is always called, even if there was an errors // return early so we don't execute both this and onResponseError if (!response.ok) { return; } - await _options.onSuccess(response); - await _options.onFinish(); + await _options.onSuccess({ request, options, response }); + await _options.onFinish({ request, options, response }); }, - async onResponseError({ response }) { + async onResponseError({ request, options, response }) { console.log("onResponseError"); const errors = response._data.data?.errors; - await _options.onError(errors); - await _options.onFinish(); + await _options.onError({ request, options, response, errors }); + await _options.onFinish({ request, options, response }); }, }); } catch (e) { diff --git a/src/runtime/composables/usePrecognitionForm.ts b/src/runtime/composables/usePrecognitionForm.ts index 3c7904c..ea1b490 100644 --- a/src/runtime/composables/usePrecognitionForm.ts +++ b/src/runtime/composables/usePrecognitionForm.ts @@ -40,7 +40,7 @@ async function validate(fieldName: string) { onStart: () => { this.validating = true; }, - onSuccess: async (response) => { + onSuccess: async () => { this.clearErrors(); }, onError: (errors) => { @@ -61,7 +61,7 @@ async function validate(fieldName: string) { "Precognition-Validate-Only": validateOnly, }, body: onlyFieldsToValidate, - onRequest: async ({ request, options }) => { + onRequest: async () => { await defaultOptions.onStart(); }, onResponse: async (context: FetchContext & { response: FetchResponse }): Promise | void => {