mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
22 lines
761 B
JavaScript
22 lines
761 B
JavaScript
import { Controller } from "stimulus";
|
|
|
|
export default class extends Controller {
|
|
async remove() {
|
|
const attachmentRemovalParameterKey = this.element.id; // e.g. 'remove_logo'
|
|
const action = this.element.closest("form").action;
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content');
|
|
const formData = new FormData();
|
|
formData.append(`enterprise[${attachmentRemovalParameterKey}]`, "1")
|
|
const response = await fetch(action, {
|
|
method: 'PATCH',
|
|
headers: {
|
|
Accept: 'text/vnd.turbo-stream.html',
|
|
'X-CSRF-Token': csrfToken,
|
|
},
|
|
body: formData
|
|
});
|
|
const responseTurboStream = await response.text();
|
|
Turbo.renderStreamMessage(responseTurboStream);
|
|
}
|
|
}
|