diff --git a/assets/src/backgroundsync-form_controller.js b/assets/src/backgroundsync-form_controller.js index 661014f..aaae0d8 100644 --- a/assets/src/backgroundsync-form_controller.js +++ b/assets/src/backgroundsync-form_controller.js @@ -5,39 +5,40 @@ import { Controller } from '@hotwired/stimulus'; /* stimulusFetch: 'lazy' */ export default class extends Controller { static values = { - params: { type: Array, default: { + params: { type: Object, default: { mode: 'cors', cache: 'no-cache', credentials: 'same-origin', redirect: 'follow', referrerPolicy: 'no-referrer' }}, - headers: { type: Array, default: [] }, + headers: { type: Object, default: {} }, redirection: { type: String, default: null }, }; async onSubmit(event) { event.preventDefault(); - const form = event.currentTarget; + const form = this.element; if (!form instanceof HTMLFormElement || !form.checkValidity()) { + console.error('Form is not valid', form, form.checkValidity()); return; } - const url = form.action; - const encType = form.encType ?? 'application/x-www-form-urlencoded'; - const method = form.method ?? 'POST'; - const params = this.paramsValue; - params.headers = this.headersValue; - params.headers['Content-Type'] = encType; + console.error(form.method); + const url = form.action; try { + const params = this.paramsValue; + params.headers = this.headersValue; + params.headers['Content-Type'] = form.encType ?? 'application/x-www-form-urlencoded'; params.body = new FormData(form); + params.method = form.method.toUpperCase(); await fetch(url, params); } catch (error) { + console.error('Error while sending form', error); // No need to do anything here } finally { - if (this.redirectionValue) { - window.location.href = this.redirectionValue; - } + console.log('finally', this.redirectionValue); + window.location.href = this.redirectionValue || url; } } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index cb09a87..ce425b9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -85,21 +85,6 @@ parameters: count: 1 path: src/Command/CreateScreenshotCommand.php - - - message: "#^Parameter \\#1 \\$files of method Symfony\\\\Component\\\\Filesystem\\\\Filesystem\\:\\:exists\\(\\) expects iterable\\|string, mixed given\\.$#" - count: 1 - path: src/Command/CreateServiceWorkerCommand.php - - - - message: "#^Parameter \\#1 \\$sourcePath of method Symfony\\\\Component\\\\AssetMapper\\\\AssetMapperInterface\\:\\:getAssetFromSourcePath\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Command/CreateServiceWorkerCommand.php - - - - message: "#^Parameter \\#2 \\$targetFile of method Symfony\\\\Component\\\\Filesystem\\\\Filesystem\\:\\:copy\\(\\) expects string, mixed given\\.$#" - count: 1 - path: src/Command/CreateServiceWorkerCommand.php - - message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$forceSyncFallback\\. Give it default value or assign it in the constructor\\.$#" count: 1 @@ -670,14 +655,6 @@ parameters: count: 1 path: src/Resources/config/definition/web_client.php - - - message: """ - #^Fetching class constant class of deprecated class SpomkyLabs\\\\PwaBundle\\\\Command\\\\CreateServiceWorkerCommand\\: - This command will be removed in the next major version\\. Create an empty file in assets/sw\\.js instead\\.$# - """ - count: 1 - path: src/Resources/config/services.php - - message: "#^Property SpomkyLabs\\\\PwaBundle\\\\Service\\\\ServiceWorkerCompiler\\:\\:\\$jsonOptions type has no value type specified in iterable type array\\.$#" count: 1