refactor: updated the validateFile function in utils and reused it

This commit is contained in:
Joedeep Singh
2025-07-04 13:22:25 +00:00
parent 5f04607a44
commit d71f1c7f9a
4 changed files with 28 additions and 33 deletions

View File

@@ -497,10 +497,13 @@ export function singularize(word) {
)
}
export const validateFile = (file) => {
let extension = file.name.split('.').pop().toLowerCase()
if (!['jpg', 'jpeg', 'png', 'webp'].includes(extension)) {
return __('Only image file is allowed.')
export const validateFile = (file, showToast = true) => {
if (!file.type.startsWith('image/')) {
const errorMessage = __('Only image file is allowed.')
if (showToast) {
toast.error(errorMessage)
}
return errorMessage
}
}