Skip to content

Commit

Permalink
Prevent file automatic reupload
Browse files Browse the repository at this point in the history
  • Loading branch information
nizetic committed May 9, 2024
1 parent 777b633 commit 96a1ef6
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/components/file-field/file-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const FileField = props => {
onError,
tooltip,
required = true,
file,
allowClear,
showError = true,
errorMessage,
Expand All @@ -50,23 +49,26 @@ const FileField = props => {
const [filename, setFilename] = useState('');

const onTextFieldClick = useCallback(() => {
document.getElementById(id).click();
}, [id]);
const onTextFieldKeyPress = useCallback(
e => {
if (e.key === 'Enter') {
document.getElementById(id).click();
}
},
[id]
);
fileInputRef.current.click();
}, []);

const onTextFieldKeyPress = useCallback(e => {
if (e.key === 'Enter') {
fileInputRef.current.click();
}
}, []);

const clearFile = useCallback(() => {
setFilename('');
if (fileInputRef.current) fileInputRef.current.value = '';
onFileSelect(null);
}, [onFileSelect]);

useEffect(() => {
clearFile();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const pickFile = useCallback(
e => {
const { files } = e.target;
Expand All @@ -83,6 +85,7 @@ const FileField = props => {
onError(t(errors.fileSizeExceeded));
return;
}

if (!fileTypes[fileType].includes(type)) {
clearFile();
onError(t(errors.fileTypeIncorrect, { type: fileType.toUpperCase() }));
Expand All @@ -95,13 +98,6 @@ const FileField = props => {
[fileType, onError, onFileSelect, setFilename, clearFile, t]
);

useEffect(() => {
if (file?.name) {
pickFile({ target: { files: [file] } });
}
// eslint-disable-next-line
}, []);

const message = useMemo(() => {
if (typeof errorMessage === 'string') return errorMessage;
if (typeof errorMessage === 'function') return errorMessage();
Expand Down

0 comments on commit 96a1ef6

Please sign in to comment.