diff --git a/src/composables/useOpenURL.js b/src/composables/useOpenURL.js new file mode 100644 index 000000000..008774c20 --- /dev/null +++ b/src/composables/useOpenURL.js @@ -0,0 +1,8 @@ +import { openURL } from 'quasar'; +const defaultWindowFeatures = { + noopener: true, + noreferrer: true, +}; +export default function (url, windowFeatures = defaultWindowFeatures, fn = undefined) { + openURL(url, fn, windowFeatures); +} diff --git a/src/pages/Customer/Card/CustomerDescriptorMenu.vue b/src/pages/Customer/Card/CustomerDescriptorMenu.vue index 5ef217a31..aeaeaef57 100644 --- a/src/pages/Customer/Card/CustomerDescriptorMenu.vue +++ b/src/pages/Customer/Card/CustomerDescriptorMenu.vue @@ -6,8 +6,8 @@ import axios from 'axios'; import { useQuasar } from 'quasar'; import useNotify from 'src/composables/useNotify'; - import VnSmsDialog from 'src/components/common/VnSmsDialog.vue'; +import useOpenURL from 'src/composables/useOpenURL'; const $props = defineProps({ customer: { @@ -15,7 +15,6 @@ const $props = defineProps({ required: true, }, }); - const { notify } = useNotify(); const { t } = useI18n(); const quasar = useQuasar(); @@ -41,48 +40,37 @@ const sendSms = async (payload) => { } }; -const openTicketCreateForm = () => { +const openCreateForm = (type) => { const query = { table: { clientFk: $props.customer.id, }, createForm: { - clientId: $props.customer.id, addressId: $props.customer.defaultAddressFk, }, }; - openWindow('ticket', query); -}; -const openOrderCreateForm = () => { - const query = { - table: { - clientFk: $props.customer.id, - }, - createForm: { - clientFk: $props.customer.id, - addressId: $props.customer.defaultAddressFk, - }, + const clientFk = { + ticket: 'clientId', + order: 'clientFk', }; - openWindow('order', query); -}; + const key = clientFk[type]; + if (!key) return; + query.createForm[key] = $props.customer.id; -const openWindow = (type, { createForm, table }) => { - window.open( - `/#/${type}/list?createForm=${JSON.stringify(createForm)}&table=${JSON.stringify( - table - )}`, - '_blank' - ); + const params = Object.entries(query) + .map(([key, value]) => `${key}=${JSON.stringify(value)}`) + .join('&'); + useOpenURL(`/#/${type}/list?${params}`); };