Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: support to add,update and display an address and latitude, longitude for a facility (#20) #22

Merged
merged 21 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
24dbbf3
Implemented: action, service and state for fetching facility contact …
amansinghbais Nov 20, 2023
12ee9f7
Improved: added support to fetch and display facility contact informa…
amansinghbais Nov 20, 2023
7915e74
Implemented: services for adding and updating address, generating lat…
amansinghbais Nov 21, 2023
b0a41c6
Improved: code for generating geopoints, methods name (#20)
amansinghbais Nov 21, 2023
1c9a328
Improved: code syntax, removed unused mutations, alphabetical entries…
amansinghbais Nov 21, 2023
6196d88
Implemented: logic to add/update geoPoints, disable lat&long buttons …
amansinghbais Nov 21, 2023
f229af1
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais Nov 21, 2023
ce5af3d
Improved: code for unused getter, error message, rendering postalCode…
amansinghbais Nov 21, 2023
aa9bf61
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais Nov 21, 2023
abf6695
Implemented: state & countries dropdown accessibility and lat-long up…
amansinghbais Nov 22, 2023
bb7d313
Implemented: cacheing for states to avoid multiple api calls (#20)
amansinghbais Nov 22, 2023
eb5aaa3
Improved: code to add keyboard accessibility to form modals (#20)
amansinghbais Nov 22, 2023
77733d7
Improved: code to fetch only required fields from api (#20)
amansinghbais Nov 22, 2023
bf87bfe
Improved: geoPoint modal variable name (#20)
amansinghbais Nov 22, 2023
3935f50
Improved: ion-select looping logic, states type, payload entries (#20)
amansinghbais Nov 23, 2023
cf64836
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais Nov 23, 2023
58d7029
Improved: code to showToast and return when we save modal without cha…
amansinghbais Nov 23, 2023
348fa5a
Improved: payload mapping reduced for optimized code(#20)
amansinghbais Nov 28, 2023
6a351ef
Improved: added translation to placeholder (#20)
amansinghbais Nov 28, 2023
e47b178
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais Nov 28, 2023
125231e
Improved: added facilityId in payload for updating lat-long (#20)
amansinghbais Nov 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 0 additions & 96 deletions src/components/AddAddressModal.vue

This file was deleted.

88 changes: 0 additions & 88 deletions src/components/AddGeoPointModal.vue

This file was deleted.

169 changes: 169 additions & 0 deletions src/components/FacilityAddressModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<template>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button @click="closeModal()">
<ion-icon slot="icon-only" :icon="closeOutline" />
</ion-button>
</ion-buttons>
<ion-title>{{ translate("Address") }}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
<form @keyup.enter="saveAddress">
<ion-item>
<ion-label>{{ translate("Address line 1") }} <ion-text color="danger">*</ion-text></ion-label>
<ion-input v-model="address.address1" slot="end" />
</ion-item>
<ion-item class="ion-margin-bottom">
<ion-label>{{ translate("Address line 2") }}</ion-label>
<ion-input v-model="address.address2" slot="end" />
</ion-item>
<ion-item>
<ion-label>{{ translate("City") }} <ion-text color="danger">*</ion-text></ion-label>
<ion-input v-model="address.city" slot="end" />
</ion-item>
<ion-item @keyup.enter.stop>
<ion-label>{{ translate("Country") }}</ion-label>
<ion-select interface="popover" :placeholder="translate('Select')" @ionChange="updateState($event)" v-model="address.countryGeoId">
<ion-select-option v-for="country in countries" :key="country.geoId" :value="country.geoId">{{ country.geoName }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item @keyup.enter.stop>
<ion-label>{{ translate("State") }}</ion-label>
<ion-select interface="popover" :placeholder="translate('Select')" v-model="address.stateProvinceGeoId">
<ion-select-option v-for="state in states[address.countryGeoId]" :key="state.geoId" :value="state.geoId">{{ state.geoName }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item>
<ion-label>{{ translate("Zipcode") }}</ion-label>
<ion-input v-model="address.postalCode" slot="end" />
</ion-item>
</form>
</ion-content>

<ion-fab vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button @click="saveAddress">
<ion-icon :icon="saveOutline" />
</ion-fab-button>
</ion-fab>
</template>

<script lang="ts">
import {
IonButton,
IonButtons,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonInput,
IonItem,
IonLabel,
IonSelect,
IonSelectOption,
IonText,
IonTitle,
IonToolbar,
modalController
} from "@ionic/vue";
import { defineComponent } from "vue";
import { mapGetters, useStore } from "vuex";
import { closeOutline, saveOutline } from "ionicons/icons";
import { translate } from '@hotwax/dxp-components'
import { FacilityService } from '@/services/FacilityService';
import { hasError } from "@/adapter";
import logger from "@/logger";
import { showToast } from "@/utils";

export default defineComponent({
name: "FacilityAddressModal",
components: {
IonButton,
IonButtons,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonInput,
IonItem,
IonLabel,
IonSelect,
IonSelectOption,
IonText,
IonTitle,
IonToolbar
},
computed: {
...mapGetters({
postalAddress: 'facility/getPostalAddress',
countries: 'util/getCountries',
states: 'util/getStates'
})
},
data() {
return {
address: {} as any
}
},
props: ['facilityId'],
async mounted() {
this.address = JSON.parse(JSON.stringify(this.postalAddress))
await this.store.dispatch('util/fetchCountries', { countryGeoId: this.address?.countryGeoId })
},
methods: {
closeModal() {
modalController.dismiss()
},
async saveAddress() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only call saveAddress if there are changes in the address

const isAddressUpdated = Object.entries(this.postalAddress).filter(([addressKey, addressValue]) => this.address[addressKey] !== addressValue).length
if(!isAddressUpdated) {
showToast(translate("Please fill all the required fields"))
return;
}

let resp;

if(!this.address?.address1 || !this.address?.city) {
showToast("Please fill all the required fields.")
return
}

try {
if(this.address.contactMechId) {
resp = await FacilityService.updateFacilityPostalAddress({...this.address, facilityId: this.facilityId })
} else {
resp = await FacilityService.createFacilityPostalAddress(this.address)
}

if(!hasError(resp)) {
showToast(translate("Facility address updated successfully."))
await this.store.dispatch('facility/fetchFacilityContactDetails', { facilityId: this.facilityId })
} else {
throw resp.data
}
} catch(err) {
showToast(translate("Failed to update facility address."))
logger.error(err)
}
modalController.dismiss()
},
updateState(ev: CustomEvent) {
this.store.dispatch('util/fetchStates', { geoId: ev.detail.value })
}
},
setup() {
const store = useStore()

return {
closeOutline,
saveOutline,
store,
translate
};
},
});
</script>
Loading
Loading