diff --git a/src/pages/04_property-managment/MainPage.vue b/src/pages/04_property-managment/MainPage.vue index 7bb547cf..aa913f85 100644 --- a/src/pages/04_property-managment/MainPage.vue +++ b/src/pages/04_property-managment/MainPage.vue @@ -14,19 +14,22 @@ import { FloatingActionButton, PaginationComponent } from 'src/components'; import PaginationPageSize from 'src/components/PaginationPageSize.vue'; import PropertyDialog from './PropertyDialog.vue'; import { Property } from 'src/stores/property/types'; -import { dialog } from 'src/stores/utils'; +import { dialog, toCamelCase } from 'src/stores/utils'; import CreateButton from 'src/components/AddButton.vue'; +import useOptionStore from 'stores/options'; -const { t } = useI18n(); +const { t, locale } = useI18n(); const $q = useQuasar(); const navigatorStore = useNavigator(); const propertyStore = useProperty(); +const optionStore = useOptionStore(); const { data: propertyData, page: propertyPage, pageSize: propertyPageSize, pageMax: propertyPageMax, } = storeToRefs(propertyStore); +const { globalOption } = storeToRefs(optionStore); const currPropertyData = ref(); const formProperty = ref({ @@ -146,6 +149,7 @@ async function fetchPropertyList(mobileFetch?: boolean) { function triggerDialog(type: 'add' | 'edit' | 'view') { if (type === 'add') { + resetForm(); pageState.addModal = true; pageState.isDrawerEdit = true; } @@ -271,6 +275,31 @@ async function submit() { }); } await fetchPropertyList($q.screen.xs); + + // assign new property to global option + const propList = propertyData.value.map((v) => { + return { + label: locale.value === 'eng' ? v.nameEN : v.name, + value: toCamelCase(v.nameEN), + type: v.type.type, + }; + }); + + const existingValues = new Set( + globalOption.value.propertiesField.map( + (item: { value: string }) => item.value, + ), + ); + const newProps = propList.filter((prop) => !existingValues.has(prop.value)); + if (newProps) { + globalOption.value.propertiesField.splice( + globalOption.value.propertiesField.length - 4, + 0, + ...newProps, + ); + } + + currPropertyData.value; resetForm(); }