Skip to content

Commit

Permalink
pass request and response to lifecycle hooks, lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Smef committed Jun 10, 2024
1 parent 189b637 commit 4765d85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions src/runtime/composables/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,21 @@ export default function useForm<TForm extends FormDataType>(
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 });
}
},
};
Expand All @@ -192,22 +192,22 @@ export default function useForm<TForm extends FormDataType>(
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/composables/usePrecognitionForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function validate(fieldName: string) {
onStart: () => {
this.validating = true;
},
onSuccess: async (response) => {
onSuccess: async () => {
this.clearErrors();
},
onError: (errors) => {
Expand All @@ -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<R> }): Promise<void> | void => {
Expand Down

0 comments on commit 4765d85

Please sign in to comment.