add: limit size
This commit is contained in:
@@ -18,6 +18,7 @@ interface DocumentOperationProps {
|
|||||||
onUploadSuccess?: () => void;
|
onUploadSuccess?: () => void;
|
||||||
page?: string;
|
page?: string;
|
||||||
access?: string;
|
access?: string;
|
||||||
|
limitSize?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildAcceptString = (extensions: string[]): string => {
|
const buildAcceptString = (extensions: string[]): string => {
|
||||||
@@ -44,6 +45,7 @@ export const DocumentOperation = ({
|
|||||||
onUploadSuccess,
|
onUploadSuccess,
|
||||||
page = "",
|
page = "",
|
||||||
access = "",
|
access = "",
|
||||||
|
limitSize,
|
||||||
}: DocumentOperationProps) => {
|
}: DocumentOperationProps) => {
|
||||||
const { openBackdrop, closeBackdrop } = useBackdropStore();
|
const { openBackdrop, closeBackdrop } = useBackdropStore();
|
||||||
const showToast = useToast();
|
const showToast = useToast();
|
||||||
@@ -153,6 +155,11 @@ export const DocumentOperation = ({
|
|||||||
fileInputRef.current.value = "";
|
fileInputRef.current.value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (limitSize && file.size > limitSize * 1024 * 1024) {
|
||||||
|
showToast(`حداکثر حجم فایل ${limitSize} مگابایت است`, "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
openBackdrop();
|
openBackdrop();
|
||||||
try {
|
try {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -212,7 +219,7 @@ export const DocumentOperation = ({
|
|||||||
) : (
|
) : (
|
||||||
<ArrowUpTrayIcon className="w-4 h-4" />
|
<ArrowUpTrayIcon className="w-4 h-4" />
|
||||||
)}
|
)}
|
||||||
<span>{uploadedFileName ? "آپلود شده" : "آپلود"}</span>
|
<span>آپلود</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user