Skip to content

Commit

Permalink
Merge pull request #63 from ymaheshwari1/fix/regenerate-latLng
Browse files Browse the repository at this point in the history
Fixed: logic to not make api call for checking postalCode when closing the modal without changing latLng
  • Loading branch information
ravilodhi authored Dec 4, 2023
2 parents c3e5507 + eaa7a89 commit f225250
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
9 changes: 6 additions & 3 deletions src/components/FacilityGeoPointModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default defineComponent({
try {
const resp = await UtilService.generateLatLong(payload)
if(!hasError(resp)) {
if(!hasError(resp) && resp.data.response.docs.length > 0) {
const result = resp.data.response.docs[0]
this.geoPoint.latitude = result.latitude
this.geoPoint.longitude = result.longitude
Expand All @@ -133,12 +133,15 @@ export default defineComponent({
return;
}
let resp;
let resp, geoPoints = '';
try {
// passing old postalCode from here, as we don't allow user to update postalCode from this modal,
// and the user can only update the latLon from here
resp = await FacilityService.updateFacilityPostalAddress({...this.geoPoint, postalCode: this.postalAddress.postalCode, facilityId: this.facilityId})
if(!hasError(resp)) {
geoPoints = this.geoPoint
showToast(translate("Facility latitude and longitude updated successfully."))
await this.store.dispatch('facility/fetchFacilityContactDetails', { facilityId: this.facilityId })
} else {
Expand All @@ -148,7 +151,7 @@ export default defineComponent({
showToast(translate("Failed to update facility latitude and longitude."))
logger.error(err)
}
modalController.dismiss()
modalController.dismiss({ geoPoints })
}
},
setup() {
Expand Down
8 changes: 4 additions & 4 deletions src/components/GeoPointPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default defineComponent({
props: ['facilityId', 'isRegenerationRequired'],
methods: {
async regenerateLatitudeAndLongitude() {
let resp;
let resp, generatedLatLong;
try {
resp = await UtilService.generateLatLong({
Expand All @@ -53,8 +53,8 @@ export default defineComponent({
}
})
if(!hasError(resp)) {
const generatedLatLong = resp.data.response.docs[0]
if(!hasError(resp) && resp.data.response.docs.length > 0) {
generatedLatLong = resp.data.response.docs[0]
if(generatedLatLong.latitude && generatedLatLong.longitude) {
resp = await FacilityService.updateFacilityPostalAddress({
Expand All @@ -79,7 +79,7 @@ export default defineComponent({
logger.error(err);
}
popoverController.dismiss()
popoverController.dismiss({ generatedLatLong })
},
async removeLatitudeAndLongitude() {
let resp;
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@
"Store unlink failed.": "Store unlink failed.",
"Store unlinked successfully.": "Store unlinked successfully.",
"Successfully associated calendar to the facility.": "Successfully associated calendar to the facility.",
"Successfully created and associated calendar to the facility.": "Successfully created and associated calendar to the facility.",
"Successfully regenerated latitude and longitude for the facility.": "Successfully regenerated latitude and longitude for the facility.",
"Sunday": "Sunday",
"The timezone you select is used to ensure automations you schedule are always accurate to the time you select.": "The timezone you select is used to ensure automations you schedule are always accurate to the time you select.",
Expand Down
16 changes: 11 additions & 5 deletions src/views/FacilityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,12 @@ export default defineComponent({
showBackdrop: false
});
popover.onDidDismiss().then(async() => {
await this.fetchPostalCodeByGeoPoints()
popover.onDidDismiss().then(async(result) => {
if(result?.data?.generatedLatLong) {
// changing the value for the variable, as if the popover has returned some value, it simply
// means that the latLng are correct for current zipCode
this.isRegenerationRequired = false
}
})
return popover.present()
Expand Down Expand Up @@ -578,9 +582,11 @@ export default defineComponent({
componentProps: { facilityId: this.facilityId }
})
geoPointModal.onDidDismiss().then(async() => {
await this.fetchPostalCodeByGeoPoints()
} )
geoPointModal.onDidDismiss().then(async(result) => {
if(result.data?.geoPoints) {
await this.fetchPostalCodeByGeoPoints()
}
})
geoPointModal.present()
},
Expand Down

0 comments on commit f225250

Please sign in to comment.