Skip to content

Commit

Permalink
FIX BackgroundSync SC
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Mar 7, 2024
1 parent 2848140 commit d68307a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
25 changes: 13 additions & 12 deletions assets/src/backgroundsync-form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
23 changes: 0 additions & 23 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d68307a

Please sign in to comment.