This commit is contained in:
seb
2026-09-18 06:44:12 +02:00
parent d5ade4923d
commit a537c2f72d
8 changed files with 308 additions and 31 deletions

View File

@@ -369,7 +369,7 @@ export const deliveryEditorAutomat = new Automat(initialState, {
updateAttachment(payload) {
const { id, ...fields } = payload || {};
const current = deliveryEditorAutomat.state.attachments ?? [];
const idx = current.findIndex((a) => a.id === id);
const idx = current.findIndex((a) => a.id === id || String(a.id) === String(id));
if (idx !== -1) {
const next = [...current];
next[idx] = { ...next[idx], ...fields };
@@ -377,14 +377,20 @@ export const deliveryEditorAutomat = new Automat(initialState, {
}
},
removeAttachment(idOrIndex) {
removeAttachment(idOrPayload) {
const current = deliveryEditorAutomat.state.attachments ?? [];
const targetId =
typeof idOrPayload === 'object' && idOrPayload !== null
? (idOrPayload.id ?? idOrPayload.fileId)
: idOrPayload;
const hasMatch = current.some((a) => a.id === targetId || String(a.id) === String(targetId));
let next;
if (typeof idOrIndex === 'number') {
next = current.filter((_, idx) => idx !== idOrIndex);
if (hasMatch) {
next = current.filter((a) => a.id !== targetId && String(a.id) !== String(targetId));
} else if (typeof idOrPayload === 'number' && idOrPayload >= 0 && idOrPayload < current.length) {
next = current.filter((_, idx) => idx !== idOrPayload);
} else {
const id = typeof idOrIndex === 'string' ? idOrIndex : idOrIndex?.id;
next = current.filter((a) => a.id !== id);
next = current.filter((a) => a.id !== targetId && String(a.id) !== String(targetId));
}
deliveryEditorAutomat.setState({ attachments: next, files: next });
},