Merge branch 'beta' into feature/Address-view-refactor
gitea/hedera-web/pipeline/pr-beta This commit looks good
Details
gitea/hedera-web/pipeline/pr-beta This commit looks good
Details
This commit is contained in:
commit
73feb098fe
|
@ -0,0 +1,66 @@
|
|||
<script setup>
|
||||
import { onMounted, inject } from 'vue';
|
||||
|
||||
const $props = defineProps({
|
||||
autoLoad: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
filter: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
where: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
sortBy: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
limit: {
|
||||
type: [String, Number],
|
||||
default: ''
|
||||
},
|
||||
params: {
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['onFetch']);
|
||||
const api = inject('api');
|
||||
|
||||
defineExpose({ fetch });
|
||||
|
||||
onMounted(async () => {
|
||||
if ($props.autoLoad) {
|
||||
await fetch();
|
||||
}
|
||||
});
|
||||
|
||||
async function fetch(fetchFilter = {}) {
|
||||
try {
|
||||
const filter = { ...fetchFilter, ...$props.filter }; // eslint-disable-line vue/no-dupe-keys
|
||||
if ($props.where && !fetchFilter.where) filter.where = $props.where;
|
||||
if ($props.sortBy) filter.order = $props.sortBy;
|
||||
if ($props.limit) filter.limit = $props.limit;
|
||||
|
||||
const { data } = await api.get($props.url, {
|
||||
params: { filter: JSON.stringify(filter), ...$props.params }
|
||||
});
|
||||
|
||||
emit('onFetch', data);
|
||||
return data;
|
||||
} catch (e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<template></template>
|
||||
</template>
|
|
@ -5,6 +5,7 @@ import { useRouter } from 'vue-router';
|
|||
|
||||
import CardList from 'src/components/ui/CardList.vue';
|
||||
import VnList from 'src/components/ui/VnList.vue';
|
||||
import FetchData from 'src/components/common/FetchData.vue';
|
||||
|
||||
import useNotify from 'src/composables/useNotify.js';
|
||||
import { useVnConfirm } from 'src/composables/useVnConfirm.js';
|
||||
|
@ -21,6 +22,7 @@ const { openConfirmationModal } = useVnConfirm();
|
|||
const appStore = useAppStore();
|
||||
const userStore = useUserStore();
|
||||
const { isHeaderMounted } = storeToRefs(appStore);
|
||||
const fetchAddressesRef = ref(null);
|
||||
|
||||
const addresses = ref([]);
|
||||
const defaultAddress = ref(null);
|
||||
|
@ -41,19 +43,6 @@ const getDefaultAddress = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
const getActiveAddresses = async () => {
|
||||
try {
|
||||
addresses.value = await jApi.query(
|
||||
`SELECT a.id, a.nickname, p.name province, a.postalCode, a.city, a.street, a.isActive
|
||||
FROM myAddress a
|
||||
LEFT JOIN vn.province p ON p.id = a.provinceFk
|
||||
WHERE a.isActive`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error getting active addresses:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const changeDefaultAddress = async () => {
|
||||
if (!clientId.value) return;
|
||||
await jApi.execQuery(
|
||||
|
@ -77,7 +66,7 @@ async function removeAddress(address) {
|
|||
isActive: false
|
||||
}
|
||||
);
|
||||
getActiveAddresses();
|
||||
fetchAddressesRef.value.fetch();
|
||||
notify(t('dataSaved'), 'positive');
|
||||
} catch (error) {
|
||||
console.error('Error removing address:', error);
|
||||
|
@ -86,11 +75,28 @@ async function removeAddress(address) {
|
|||
|
||||
onMounted(async () => {
|
||||
getDefaultAddress();
|
||||
getActiveAddresses();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FetchData
|
||||
v-if="userStore?.user?.id"
|
||||
ref="fetchAddressesRef"
|
||||
url="Addresses"
|
||||
:filter="{
|
||||
where: { clientFk: userStore.user.id, isActive: true },
|
||||
fields: [
|
||||
'id',
|
||||
'nickname',
|
||||
'postalCode',
|
||||
'city',
|
||||
'street',
|
||||
'isActive'
|
||||
]
|
||||
}"
|
||||
auto-load
|
||||
@on-fetch="data => (addresses = data)"
|
||||
/>
|
||||
<Teleport v-if="isHeaderMounted" to="#actions">
|
||||
<QBtn
|
||||
:label="t('addAddress')"
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
<script setup>
|
||||
import { ref, onMounted, inject } from 'vue';
|
||||
const jApi = inject('jApi');
|
||||
const api = inject('api');
|
||||
const news = ref([]);
|
||||
const showPreview = ref(false);
|
||||
const selectedImageSrc = ref('');
|
||||
|
||||
const fetchData = async () => {
|
||||
news.value = await jApi.query(
|
||||
`SELECT title, text, image, id
|
||||
FROM news
|
||||
ORDER BY priority, created DESC`
|
||||
);
|
||||
const newsResponse = await api.get('News');
|
||||
|
||||
news.value = newsResponse.data;
|
||||
};
|
||||
|
||||
const showImagePreview = src => {
|
||||
|
|
|
@ -32,7 +32,10 @@ export const useAppStore = defineStore('hedera', {
|
|||
}),
|
||||
actions: {
|
||||
async getMenuLinks() {
|
||||
const sections = await jApi.query('SELECT * FROM myMenu');
|
||||
const { data: sections } = await api.get('MyMenus');
|
||||
|
||||
if (!sections) return;
|
||||
|
||||
const sectionMap = new Map();
|
||||
for (const section of sections) {
|
||||
sectionMap.set(section.id, section);
|
||||
|
|
|
@ -248,11 +248,10 @@ export const useUserStore = defineStore('user', () => {
|
|||
|
||||
const fetchUser = async (userType = 'user') => {
|
||||
try {
|
||||
const userData = await jApi.getObject(
|
||||
'SELECT id, nickname, name, lang FROM account.myUser'
|
||||
);
|
||||
if (userType === 'user') mainUser.value = userData;
|
||||
else supplantedUser.value = userData;
|
||||
const userData = await api.get('VnUsers/getCurrentUserData');
|
||||
|
||||
if (userType === 'user') mainUser.value = userData.data;
|
||||
else supplantedUser.value = userData.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching user: ', error);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue