Skip to content

Commit 45cee11

Browse files
committed
fix: handle multiple files when allow edit is turned off
1 parent 692968b commit 45cee11

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/components/FileUpload/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ export const FileUpload: FC<FileUploadProps> = ({
132132
}
133133
}, [files]);
134134

135+
useEffect(() => {
136+
if (!isDataEditable && files.length > 1) {
137+
setFiles([files[0]]);
138+
}
139+
}, [files, isDataEditable]);
140+
135141
const removeFile = useCallback((name: string) => {
136142
setFiles((prev) => prev.filter((file) => file.name !== name));
137143
}, [files]);

src/components/NFTMultipleData/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useAppDispatch, useAppSelector } from "@/store/hooks";
2-
import { FC, Fragment, useCallback, useMemo } from "react";
2+
import { FC, Fragment, useCallback, useEffect, useMemo } from "react";
33
import { addDataToMultipleData, setNFTMultipleData } from "@/features/nft/nftSlice";
44
import { FileUpload } from "../FileUpload";
55
import { Input } from "../Input";
@@ -51,6 +51,12 @@ export const NFTMultipleData: FC<NFTMultipleDataProps> = ({ isDataEditable }: NF
5151
}
5252
}, []);
5353

54+
useEffect(() => {
55+
if (!isDataEditable && nftMultipleData.length > 1) {
56+
dispatch(setNFTMultipleData([...nftMultipleData.slice(0, 1)]));
57+
}
58+
}, [isDataEditable, nftMultipleData]);
59+
5460
const renderContentData = useMemo(() => {
5561
if (!isDataEditable) {
5662
return (

0 commit comments

Comments
 (0)