Image: fix table cell always deleting last image

This commit is contained in:
Sidney Alcantara
2022-10-05 16:38:08 +11:00
parent 18fe50e0da
commit 4f7f5e3d4f

View File

@@ -126,9 +126,8 @@ export default function Image_({
[value]
);
const handleDelete = (ref: string) => () => {
const handleDelete = (index: number) => () => {
const newValue = [...value];
const index = findIndex(newValue, ["ref", ref]);
const toBeDeleted = newValue.splice(index, 1);
toBeDeleted.length && deleteUpload(toBeDeleted[0]);
onSubmit(newValue);
@@ -184,7 +183,7 @@ export default function Image_({
>
<Grid container spacing={0.5} wrap="nowrap">
{Array.isArray(value) &&
value.map((file: FileValue) => (
value.map((file: FileValue, i) => (
<Grid item key={file.downloadURL}>
{disabled ? (
<Tooltip title="Open">
@@ -225,7 +224,7 @@ export default function Image_({
body: "This image cannot be recovered after",
confirm: "Delete",
confirmColor: "error",
handleConfirm: handleDelete(file.ref),
handleConfirm: handleDelete(i),
});
}}
>