Merge pull request #905 from NagariaHussain/fix/image-upload
refactor: DRY up validate image file
This commit is contained in:
commit
fb644f5fbe
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<FileUploader
|
<FileUploader
|
||||||
@success="(file) => setUserImage(file.file_url)"
|
@success="(file) => setUserImage(file.file_url)"
|
||||||
:validateFile="validateFile"
|
:validateFile="validateIsImageFile"
|
||||||
>
|
>
|
||||||
<template v-slot="{ file, progress, error, uploading, openFileSelector }">
|
<template v-slot="{ file, progress, error, uploading, openFileSelector }">
|
||||||
<div class="flex flex-col items-center">
|
<div class="flex flex-col items-center">
|
||||||
@ -48,17 +48,11 @@
|
|||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { FileUploader } from 'frappe-ui'
|
import { FileUploader } from 'frappe-ui'
|
||||||
|
import { validateIsImageFile } from '@/utils';
|
||||||
|
|
||||||
const profile = defineModel()
|
const profile = defineModel()
|
||||||
|
|
||||||
function setUserImage(url) {
|
function setUserImage(url) {
|
||||||
profile.value.user_image = url
|
profile.value.user_image = url
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateFile(file) {
|
|
||||||
let extn = file.name.split('.').pop().toLowerCase()
|
|
||||||
if (!['png', 'jpg'].includes(extn)) {
|
|
||||||
return 'Only PNG and JPG images are allowed'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
<div class="border-b">
|
<div class="border-b">
|
||||||
<FileUploader
|
<FileUploader
|
||||||
@success="changeContactImage"
|
@success="changeContactImage"
|
||||||
:validateFile="validateFile"
|
:validateFile="validateIsImageFile"
|
||||||
>
|
>
|
||||||
<template #default="{ openFileSelector, error }">
|
<template #default="{ openFileSelector, error }">
|
||||||
<div class="flex flex-col items-start justify-start gap-4 p-5">
|
<div class="flex flex-col items-start justify-start gap-4 p-5">
|
||||||
@ -184,7 +184,7 @@ import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
|
|||||||
import CameraIcon from '@/components/Icons/CameraIcon.vue'
|
import CameraIcon from '@/components/Icons/CameraIcon.vue'
|
||||||
import DealsIcon from '@/components/Icons/DealsIcon.vue'
|
import DealsIcon from '@/components/Icons/DealsIcon.vue'
|
||||||
import DealsListView from '@/components/ListViews/DealsListView.vue'
|
import DealsListView from '@/components/ListViews/DealsListView.vue'
|
||||||
import { formatDate, timeAgo } from '@/utils'
|
import { formatDate, timeAgo, validateIsImageFile } from '@/utils'
|
||||||
import { showAddressModal, addressProps } from '@/composables/modals'
|
import { showAddressModal, addressProps } from '@/composables/modals'
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { getSettings } from '@/stores/settings'
|
import { getSettings } from '@/stores/settings'
|
||||||
@ -294,13 +294,6 @@ usePageMeta(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function validateFile(file) {
|
|
||||||
let extn = file.name.split('.').pop().toLowerCase()
|
|
||||||
if (!['png', 'jpg', 'jpeg'].includes(extn)) {
|
|
||||||
return __('Only PNG and JPG images are allowed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function changeContactImage(file) {
|
async function changeContactImage(file) {
|
||||||
await call('frappe.client.set_value', {
|
await call('frappe.client.set_value', {
|
||||||
doctype: 'Contact',
|
doctype: 'Contact',
|
||||||
|
|||||||
@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<FileUploader
|
<FileUploader
|
||||||
@success="(file) => updateField('image', file.file_url)"
|
@success="(file) => updateField('image', file.file_url)"
|
||||||
:validateFile="validateFile"
|
:validateFile="validateIsImageFile"
|
||||||
>
|
>
|
||||||
<template #default="{ openFileSelector, error }">
|
<template #default="{ openFileSelector, error }">
|
||||||
<div class="flex items-center justify-start gap-5 border-b p-5">
|
<div class="flex items-center justify-start gap-5 border-b p-5">
|
||||||
@ -344,7 +344,7 @@ import SidePanelLayout from '@/components/SidePanelLayout.vue'
|
|||||||
import FieldLayout from '@/components/FieldLayout/FieldLayout.vue'
|
import FieldLayout from '@/components/FieldLayout/FieldLayout.vue'
|
||||||
import SLASection from '@/components/SLASection.vue'
|
import SLASection from '@/components/SLASection.vue'
|
||||||
import CustomActions from '@/components/CustomActions.vue'
|
import CustomActions from '@/components/CustomActions.vue'
|
||||||
import { openWebsite, setupCustomizations, copyToClipboard } from '@/utils'
|
import { openWebsite, setupCustomizations, copyToClipboard, validateIsImageFile } from '@/utils'
|
||||||
import { showQuickEntryModal, quickEntryProps } from '@/composables/modals'
|
import { showQuickEntryModal, quickEntryProps } from '@/composables/modals'
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { getSettings } from '@/stores/settings'
|
import { getSettings } from '@/stores/settings'
|
||||||
@ -575,13 +575,6 @@ watch(tabs, (value) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function validateFile(file) {
|
|
||||||
let extn = file.name.split('.').pop().toLowerCase()
|
|
||||||
if (!['png', 'jpg', 'jpeg'].includes(extn)) {
|
|
||||||
return __('Only PNG and JPG images are allowed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const sections = createResource({
|
const sections = createResource({
|
||||||
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_sidepanel_sections',
|
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_sidepanel_sections',
|
||||||
cache: ['sidePanelSections', 'CRM Lead'],
|
cache: ['sidePanelSections', 'CRM Lead'],
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
</header>
|
</header>
|
||||||
</LayoutHeader>
|
</LayoutHeader>
|
||||||
<div v-if="contact.data" class="flex flex-col h-full overflow-hidden">
|
<div v-if="contact.data" class="flex flex-col h-full overflow-hidden">
|
||||||
<FileUploader @success="changeContactImage" :validateFile="validateFile">
|
<FileUploader @success="changeContactImage" :validateFile="validateIsImageFile">
|
||||||
<template #default="{ openFileSelector, error }">
|
<template #default="{ openFileSelector, error }">
|
||||||
<div class="flex flex-col items-start justify-start gap-4 p-4">
|
<div class="flex flex-col items-start justify-start gap-4 p-4">
|
||||||
<div class="flex gap-4 items-center">
|
<div class="flex gap-4 items-center">
|
||||||
@ -167,7 +167,7 @@ import PhoneIcon from '@/components/Icons/PhoneIcon.vue'
|
|||||||
import CameraIcon from '@/components/Icons/CameraIcon.vue'
|
import CameraIcon from '@/components/Icons/CameraIcon.vue'
|
||||||
import DealsIcon from '@/components/Icons/DealsIcon.vue'
|
import DealsIcon from '@/components/Icons/DealsIcon.vue'
|
||||||
import DealsListView from '@/components/ListViews/DealsListView.vue'
|
import DealsListView from '@/components/ListViews/DealsListView.vue'
|
||||||
import { formatDate, timeAgo } from '@/utils'
|
import { formatDate, timeAgo, validateIsImageFile } from '@/utils'
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { showAddressModal, addressProps } from '@/composables/modals'
|
import { showAddressModal, addressProps } from '@/composables/modals'
|
||||||
import { getSettings } from '@/stores/settings'
|
import { getSettings } from '@/stores/settings'
|
||||||
@ -266,13 +266,6 @@ usePageMeta(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function validateFile(file) {
|
|
||||||
let extn = file.name.split('.').pop().toLowerCase()
|
|
||||||
if (!['png', 'jpg', 'jpeg'].includes(extn)) {
|
|
||||||
return __('Only PNG and JPG images are allowed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function changeContactImage(file) {
|
async function changeContactImage(file) {
|
||||||
await call('frappe.client.set_value', {
|
await call('frappe.client.set_value', {
|
||||||
doctype: 'Contact',
|
doctype: 'Contact',
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
<div v-if="organization.doc" class="flex flex-col h-full overflow-hidden">
|
<div v-if="organization.doc" class="flex flex-col h-full overflow-hidden">
|
||||||
<FileUploader
|
<FileUploader
|
||||||
@success="changeOrganizationImage"
|
@success="changeOrganizationImage"
|
||||||
:validateFile="validateFile"
|
:validateFile="validateIsImageFile"
|
||||||
>
|
>
|
||||||
<template #default="{ openFileSelector, error }">
|
<template #default="{ openFileSelector, error }">
|
||||||
<div class="flex flex-col items-start justify-start gap-4 p-4">
|
<div class="flex flex-col items-start justify-start gap-4 p-4">
|
||||||
@ -164,7 +164,7 @@ import { globalStore } from '@/stores/global'
|
|||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { statusesStore } from '@/stores/statuses'
|
import { statusesStore } from '@/stores/statuses'
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { formatDate, timeAgo } from '@/utils'
|
import { formatDate, timeAgo, validateIsImageFile } from '@/utils'
|
||||||
import {
|
import {
|
||||||
Breadcrumbs,
|
Breadcrumbs,
|
||||||
Avatar,
|
Avatar,
|
||||||
@ -251,13 +251,6 @@ usePageMeta(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function validateFile(file) {
|
|
||||||
let extn = file.name.split('.').pop().toLowerCase()
|
|
||||||
if (!['png', 'jpg', 'jpeg'].includes(extn)) {
|
|
||||||
return __('Only PNG and JPG images are allowed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function changeOrganizationImage(file) {
|
async function changeOrganizationImage(file) {
|
||||||
await call('frappe.client.set_value', {
|
await call('frappe.client.set_value', {
|
||||||
doctype: 'CRM Organization',
|
doctype: 'CRM Organization',
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
<div class="border-b">
|
<div class="border-b">
|
||||||
<FileUploader
|
<FileUploader
|
||||||
@success="changeOrganizationImage"
|
@success="changeOrganizationImage"
|
||||||
:validateFile="validateFile"
|
:validateFile="validateIsImageFile"
|
||||||
>
|
>
|
||||||
<template #default="{ openFileSelector, error }">
|
<template #default="{ openFileSelector, error }">
|
||||||
<div class="flex flex-col items-start justify-start gap-4 p-5">
|
<div class="flex flex-col items-start justify-start gap-4 p-5">
|
||||||
@ -185,7 +185,7 @@ import { globalStore } from '@/stores/global'
|
|||||||
import { usersStore } from '@/stores/users'
|
import { usersStore } from '@/stores/users'
|
||||||
import { statusesStore } from '@/stores/statuses'
|
import { statusesStore } from '@/stores/statuses'
|
||||||
import { getView } from '@/utils/view'
|
import { getView } from '@/utils/view'
|
||||||
import { formatDate, timeAgo } from '@/utils'
|
import { formatDate, timeAgo, validateIsImageFile } from '@/utils'
|
||||||
import {
|
import {
|
||||||
Tooltip,
|
Tooltip,
|
||||||
Breadcrumbs,
|
Breadcrumbs,
|
||||||
@ -286,13 +286,6 @@ usePageMeta(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function validateFile(file) {
|
|
||||||
let extn = file.name.split('.').pop().toLowerCase()
|
|
||||||
if (!['png', 'jpg', 'jpeg'].includes(extn)) {
|
|
||||||
return __('Only PNG and JPG images are allowed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function changeOrganizationImage(file) {
|
async function changeOrganizationImage(file) {
|
||||||
await call('frappe.client.set_value', {
|
await call('frappe.client.set_value', {
|
||||||
doctype: 'CRM Organization',
|
doctype: 'CRM Organization',
|
||||||
|
|||||||
@ -394,6 +394,13 @@ export function isImage(extention) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function validateIsImageFile(file) {
|
||||||
|
const extn = file.name.split('.').pop().toLowerCase()
|
||||||
|
if (!isImage(extn)) {
|
||||||
|
return __('Only image files are allowed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getRandom(len = 4) {
|
export function getRandom(len = 4) {
|
||||||
let text = ''
|
let text = ''
|
||||||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user