Skip to content

Commit

Permalink
feat: Add remove file option to modal (#2750)
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr authored Feb 5, 2024
1 parent 5866eda commit 761f230
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ interface FileTaggingModalProps {
fileList: FileList;
setFileList: (value: React.SetStateAction<FileList>) => void;
setShowModal: (value: React.SetStateAction<boolean>) => void;
removeFile: (slot: FileUploadSlot) => void;
}

const ListHeader = styled(Box)(({ theme }) => ({
Expand All @@ -52,6 +53,7 @@ export const FileTaggingModal = ({
fileList,
setFileList,
setShowModal,
removeFile,
}: FileTaggingModalProps) => {
const [error, setError] = useState<string | undefined>();

Expand Down Expand Up @@ -95,7 +97,11 @@ export const FileTaggingModal = ({
</Box>
{uploadedFiles.map((slot) => (
<Box sx={{ mb: 4 }} key={`tags-per-file-container-${slot.id}`}>
<UploadedFileCard {...slot} key={slot.id} />
<UploadedFileCard
{...slot}
key={slot.id}
removeFile={() => removeFile(slot)}
/>
<SelectMultiple
uploadedFile={slot}
fileList={fileList}
Expand Down
27 changes: 13 additions & 14 deletions editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ function Component(props: Props) {
}
};

const removeFile = (slot: FileUploadSlot) => {
setSlots(slots.filter((currentSlot) => currentSlot.file !== slot.file));
setFileUploadStatus(`${slot.file.path} was deleted`);
const updatedFileList = removeSlots(
getTagsForSlot(slot.id, fileList),
slot,
fileList,
);
setFileList(updatedFileList);
};

return (
<Card
handleSubmit={props.hideDropZone ? props.handleSubmit : validateAndSubmit}
Expand Down Expand Up @@ -222,6 +233,7 @@ function Component(props: Props) {
fileList={fileList}
setFileList={setFileList}
setShowModal={setShowModal}
removeFile={removeFile}
/>
)}
{slots.map((slot) => {
Expand All @@ -231,20 +243,7 @@ function Component(props: Props) {
key={slot.id}
tags={getTagsForSlot(slot.id, fileList)}
onChange={onUploadedFileCardChange}
removeFile={() => {
setSlots(
slots.filter(
(currentSlot) => currentSlot.file !== slot.file,
),
);
setFileUploadStatus(`${slot.file.path} was deleted`);
const updatedFileList = removeSlots(
getTagsForSlot(slot.id, fileList),
slot,
fileList,
);
setFileList(updatedFileList);
}}
removeFile={() => removeFile(slot)}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ImagePreview from "components/ImagePreview";
import React from "react";

interface Props extends FileUploadSlot {
removeFile?: () => void;
removeFile: () => void;
onChange?: () => void;
tags?: string[];
}
Expand Down

0 comments on commit 761f230

Please sign in to comment.