Skip to content

Commit

Permalink
Implemented: state & countries dropdown accessibility and lat-long up…
Browse files Browse the repository at this point in the history
…dation (#20)
  • Loading branch information
amansinghbais committed Nov 22, 2023
1 parent aa9bf61 commit abf6695
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 24 deletions.
28 changes: 23 additions & 5 deletions src/components/FacilityAddressModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
</ion-item>
<ion-item>
<ion-label>{{ translate("Country") }}</ion-label>
<ion-input v-model="postalAddress.country" slot="end" />
<ion-select interface="popover" :placeholder="translate('Select')" @ionChange="updateState($event)" v-model="postalAddress.countryGeoId">
<ion-select-option v-for="(country, index) in countries" :key="index" :value="country.geoId">{{ country.geoName }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item>
<ion-label>{{ translate("State") }}</ion-label>
<ion-input v-model="postalAddress.state" slot="end" />
<ion-select interface="popover" :placeholder="translate('Select')" v-model="postalAddress.stateGeoId">
<ion-select-option v-for="(state, index) in states" :key="index" :value="state.geoId">{{ state.geoName }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item>
<ion-label>{{ translate("Zipcode") }}</ion-label>
Expand All @@ -56,6 +60,8 @@ import {
IonInput,
IonItem,
IonLabel,
IonSelect,
IonSelectOption,
IonText,
IonTitle,
IonToolbar,
Expand Down Expand Up @@ -83,16 +89,23 @@ export default defineComponent({
IonInput,
IonItem,
IonLabel,
IonSelect,
IonSelectOption,
IonText,
IonTitle,
IonToolbar
},
computed: {
...mapGetters({
postalAddress: 'facility/getPostalAddress'
postalAddress: 'facility/getPostalAddress',
countries: 'util/getCountries',
states: 'util/getStates'
})
},
props: ['facilityId'],
async mounted() {
await this.store.dispatch('util/fetchCountries', { countryGeoId: this.postalAddress?.countryGeoId })
},
methods: {
closeModal() {
modalController.dismiss()
Expand All @@ -109,10 +122,12 @@ export default defineComponent({
address1: this.postalAddress.address1,
address2: this.postalAddress.address2,
city: this.postalAddress.city,
country: this.postalAddress.country,
countryGeoId: this.postalAddress.countryGeoId,
countryGeoName: this.postalAddress.countryGeoName,
facilityId: this.facilityId,
postalCode: this.postalAddress.postalCode,
state: this.postalAddress.state
stateGeoName: this.postalAddress.stateGeoName,
stateProvinceGeoId: this.postalAddress.stateGeoId
}
try {
Expand All @@ -133,6 +148,9 @@ export default defineComponent({
logger.error(err)
}
modalController.dismiss()
},
updateState(ev: CustomEvent) {
this.store.dispatch('util/fetchStates', { geoId: ev.detail.value })
}
},
setup() {
Expand Down
17 changes: 8 additions & 9 deletions src/components/FacilityGeoPointModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default defineComponent({
throw resp.data
}
} catch(err) {
showToast(translate("Invalid Zipcode, GeoPoints can't be generated."))
showToast(translate("Failed to generate latitude & Longitude."))
logger.error(err)
}
},
Expand All @@ -124,25 +124,24 @@ export default defineComponent({
const payload = {
address1: this.geoPoint.address1,
city: this.geoPoint.city,
contactMechId: this.geoPoint.contactMechId,
facilityId: this.facilityId,
latitude: this.geoPoint.latitude,
longitude: this.geoPoint.latitude
longitude: this.geoPoint.longitude,
postalCode: this.geoPoint.postalCode
}
try {
if(this.postalAddress.latitude) {
resp = await FacilityService.updateFacilityPostalAddress({...payload, contactMechId: this.geoPoint.contactMechId})
} else {
resp = await FacilityService.createFacilityPostalAddress(payload)
}
resp = await FacilityService.updateFacilityPostalAddress({...payload})
if(!hasError(resp)) {
showToast(translate("Facility geoPoint updated successfully."))
showToast(translate("Facility latitude & longitude updated successfully."))
await this.store.dispatch('facility/fetchFacilityContactDetails', { facilityId: this.facilityId })
} else {
throw resp.data
}
} catch(err) {
showToast(translate("Failed to update facility geoPoint."))
showToast(translate("Failed to update facility latitude & longitude."))
logger.error(err)
}
modalController.dismiss()
Expand Down
6 changes: 3 additions & 3 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"Facility": "Facility",
"Facility address updated successfully.": "Facility address updated successfully.",
"Facility details": "Facility details",
"Facility geoPoint updated successfully.": "Facility geoPoint updated successfully.",
"Facility latitude & longitude updated successfully.": "Facility latitude & longitude updated successfully.",
"Facility ID": "Facility ID",
"Facility location created successfully": "Facility location created successfully",
"Facility location updated successfully": "Facility location updated successfully",
Expand All @@ -50,7 +50,8 @@
"Failed to find the facility locations": "Failed to find the facility locations",
"Failed to remove facility location": "Failed to remove facility location",
"Failed to update facility address.": "Failed to update facility address.",
"Failed to update facility geoPoint.": "Failed to update facility geoPoint.",
"Failed to generate latitude & Longitude.": "Failed to generate latitude & Longitude.",
"Failed to update facility latitude & longitude.": "Failed to update facility latitude & longitude.",
"Failed to update facility location": "Failed to update facility location",
"Fetching TimeZones": "Fetching TimeZones",
"Find Facilities": "Find Facilities",
Expand All @@ -65,7 +66,6 @@
"Groups": "Groups",
"Identification": "Identification",
"Instance Url": "Instance Url",
"Invalid Zipcode, GeoPoints can't be generated.": "Invalid Zipcode, GeoPoints can't be generated.",
"Language": "Language",
"Latitude": "Latitude",
"Latitude & Longitude": "Latitude & Longitude",
Expand Down
20 changes: 20 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,30 @@ const fetchLocationTypes = async (payload: any): Promise<any> => {
})
}

const fetchCountries = async (payload: any): Promise<any> => {
return api({
url: "performFind",
method: "POST",
data: payload,
cache: true
})
}

const fetchStates = async (payload: any): Promise<any> => {
return api({
url: "performFind",
method: "POST",
data: payload,
cache: true
})
}

export const UtilService = {
fetchCountries,
fetchFacilityTypes,
fetchLocationTypes,
fetchProductStores,
fetchStates,
generateLatLong
}

8 changes: 5 additions & 3 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const actions: ActionTree<FacilityState, RootState> = {
entityName: "FacilityContactDetailByPurpose",
orderBy: 'fromDate DESC',
filterByDate: 'Y',
fieldList: ['address1', 'address2', 'city', 'contactMechId', 'countryGeoName', 'latitude', 'longitude', 'postalCode', 'stateGeoName'],
fieldList: ['address1', 'address2', 'city', 'contactMechId', 'countryGeoId', 'countryGeoName', 'latitude', 'longitude', 'postalCode', 'stateGeoId', 'stateGeoName'],
viewSize: 1
}

Expand All @@ -183,11 +183,13 @@ const actions: ActionTree<FacilityState, RootState> = {
address2: contactInfo.address2,
city: contactInfo.city,
contactMechId: contactInfo.contactMechId,
country: contactInfo.countryGeoName,
countryGeoId: contactInfo.countryGeoId,
countryGeoName: contactInfo.countryGeoName,
latitude: contactInfo.latitude,
longitude: contactInfo.longitude,
postalCode: contactInfo.postalCode,
state: contactInfo.stateGeoName
stateGeoId: contactInfo.stateGeoId,
stateGeoName: contactInfo.stateGeoName
}
} else {
throw resp.data
Expand Down
2 changes: 2 additions & 0 deletions src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ export default interface UtilState {
productStores: any[];
facilityTypes: object;
locationTypes: object;
countries: any[];
states: any[];
}
54 changes: 54 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,60 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_LOCATION_TYPES_UPDATED, locationTypes)
},

async fetchCountries({ commit, dispatch }, payload) {
let countries = [] as any

const params = {
inputFields: {
geoIdTo: "DBIC"
},
entityName: 'GeoAssocAndGeoFrom',
noConditionFind: 'Y',
} as any

try {
const resp = await UtilService.fetchCountries(params)

if(!hasError(resp)) {
countries = resp.data.docs
dispatch('fetchStates', { geoId: payload.countryGeoId ? payload.countryGeoId : 'USA'})
} else {
throw resp.data
}
} catch(err) {
logger.error(err)
}

commit(types.UTIL_COUNTRIES_UPDATED, countries)
},

async fetchStates({ commit, dispatch }, payload) {

Check warning on line 129 in src/store/modules/util/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (16.x)

'dispatch' is defined but never used
let states = [] as any

const params = {
inputFields: {
geoIdFrom: payload.geoId
},
entityName: 'GeoAssocAndGeoTo',
noConditionFind: 'Y',
viewSize: 100
} as any

try {
const resp = await UtilService.fetchStates(params)

if(!hasError(resp)) {
states = resp.data.docs
} else {
throw resp.data
}
} catch(err) {
logger.error(err)
}

commit(types.UTIL_STATES_UPDATED, states)
},

clearUtilState({ commit }) {
commit(types.UTIL_PRODUCT_STORES_UPDATED, [])
commit(types.UTIL_FACILITY_TYPES_UPDATED, [])
Expand Down
6 changes: 6 additions & 0 deletions src/store/modules/util/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const getters: GetterTree<UtilState, RootState> = {
},
getLocationTypes(state) {
return state.locationTypes
},
getCountries(state) {
return state.countries
},
getStates(state) {
return state.states
}
}
export default getters;
4 changes: 3 additions & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const utilModule: Module<UtilState, RootState> = {
state: {
productStores: [],
facilityTypes: {},
locationTypes: {}
locationTypes: {},
countries: [],
states: []
},
getters,
actions,
Expand Down
4 changes: 3 additions & 1 deletion src/store/modules/util/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const SN_UTIL = 'util'
export const UTIL_PRODUCT_STORES_UPDATED = SN_UTIL + '/PRODUCT_STORES_UPDATED'
export const UTIL_FACILITY_TYPES_UPDATED = SN_UTIL + '/FACILITY_TYPES_UPDATED'
export const UTIL_LOCATION_TYPES_UPDATED = SN_UTIL + '/LOCATION_TYPES_UPDATED'
export const UTIL_LOCATION_TYPES_UPDATED = SN_UTIL + '/LOCATION_TYPES_UPDATED'
export const UTIL_COUNTRIES_UPDATED = SN_UTIL + '/COUNTRIES_UPDATED'
export const UTIL_STATES_UPDATED = SN_UTIL + '/STATES_UPDATED'
6 changes: 6 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const mutations: MutationTree<UtilState> = {
},
[types.UTIL_LOCATION_TYPES_UPDATED](state, payload) {
state.locationTypes = payload
},
[types.UTIL_COUNTRIES_UPDATED](state, payload) {
state.countries = payload
},
[types.UTIL_STATES_UPDATED](state, payload) {
state.states = payload
}
}
export default mutations;
5 changes: 3 additions & 2 deletions src/views/FacilityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<h3>{{ postalAddress.address1 }}</h3>
<h3>{{ postalAddress.address2 }}</h3>
<p class="ion-text-wrap">{{ postalAddress.postalCode ? `${postalAddress.city}, ${postalAddress.postalCode}` : postalAddress.city }}</p>
<p class="ion-text-wrap">{{ postalAddress.country ? `${postalAddress.state}, ${postalAddress.country}` : postalAddress.state }}</p>
<p class="ion-text-wrap">{{ postalAddress.countryGeoName ? `${postalAddress.stateGeoName}, ${postalAddress.countryGeoName}` : postalAddress.stateGeoName }}</p>
</ion-label>
</ion-item>
<ion-button fill="clear" @click="openAddressModal">{{ translate("Edit") }}</ion-button>
Expand Down Expand Up @@ -507,7 +507,8 @@ export default defineComponent({
},
async openGeoPointModal() {
const addGeoPointModal = await modalController.create({
component: FacilityGeoPointModal
component: FacilityGeoPointModal,
componentProps: { facilityId: this.facilityId }
})
addGeoPointModal.present()
Expand Down

0 comments on commit abf6695

Please sign in to comment.