Skip to content

Commit

Permalink
Improved: syntax and simplified if conditions (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
amansinghbais committed Nov 23, 2023
1 parent cceca14 commit 8e5e0f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
21 changes: 10 additions & 11 deletions src/components/AddStaffMemberModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
</ion-label>
<ion-select interface="popover" :placeholder="translate('Select')" :value="getPartyRoleTypeId(party.partyId)" @ion-change="updateSelectedParties($event, party.partyId)" required>
<ion-select-option v-for="(description, roleTypeId) in partyRoles" :key='roleTypeId' :value="roleTypeId">{{ description }}</ion-select-option>
</ion-select>
</ion-select>
</ion-item>
</div>
</ion-list>
</ion-content>

<ion-fab @click="saveParties" vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button>
<ion-fab vertical="bottom" horizontal="end" slot="fixed">
<ion-fab-button @click="saveParties">
<ion-icon :icon="saveOutline" />
</ion-fab-button>
</ion-fab>
Expand Down Expand Up @@ -98,7 +98,7 @@ export default defineComponent({
IonToolbar
},
props: ['facilityId', 'selectedParties'],
data () {
data() {
return {
parties: [],
queryString: '',
Expand Down Expand Up @@ -207,25 +207,24 @@ export default defineComponent({
let party = {} as any
const selectedRoleTypeId = event.detail.value
if(this.isPartySelected(selectedPartyId)) {
party = this.getParty(selectedPartyId)
if(party?.partyId) {
party = this.selectedPartyValues.find((party: any) => party.partyId === selectedPartyId)
this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId)
if(selectedRoleTypeId === '') {
this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId)
} else if(selectedPartyId !== party.roleTypeId) {
this.selectedPartyValues = this.selectedPartyValues.filter((party: any) => party.partyId !== selectedPartyId)
if(selectedRoleTypeId) {
this.selectedPartyValues.push({...party, roleTypeId: selectedRoleTypeId})
}
} else {
party = this.parties.find((party: any) => party.partyId === selectedPartyId)
this.selectedPartyValues.push({...party, roleTypeId: selectedRoleTypeId})
}
},
isPartySelected(partyId: string) {
getParty(partyId: string) {
return this.selectedPartyValues.find((party: any) => party.partyId === partyId)
},
getPartyRoleTypeId(partyId: string) {
return this.selectedPartyValues.find((party: any) => party.partyId === partyId) ? this.selectedPartyValues.find((party: any) => party.partyId === partyId).roleTypeId : ''
return this.getParty(partyId) ? this.getParty(partyId).roleTypeId : ''
}
},
async mounted() {
Expand Down
10 changes: 5 additions & 5 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const actions: ActionTree<UtilState, RootState> = {
return
}

const roles = {} as any
const partyRoles = {} as any
const params = {
inputFields: {
roleTypeGroupId: 'FACILITY_PARTY_ROLE'
Expand All @@ -118,19 +118,19 @@ const actions: ActionTree<UtilState, RootState> = {
try {
const resp = await UtilService.fetchPartyRoles(params)
if (!hasError(resp)) {
resp.data.docs.map((doc:any) => {
roles[doc.roleTypeId] = doc.description
resp.data.docs.map((role: any) => {
partyRoles[role.roleTypeId] = role.description
})

// pushing none explicitly to show on UI
roles[''] = 'none'
partyRoles[''] = 'none'
} else {
throw resp.data
}
} catch (error) {
logger.error(error)
}
commit(types.UTIL_PARTY_ROLES_UPDATED, roles)
commit(types.UTIL_PARTY_ROLES_UPDATED, partyRoles)
},

clearUtilState({ commit }) {
Expand Down

0 comments on commit 8e5e0f4

Please sign in to comment.