Skip to content

Commit

Permalink
Merge pull request #213 from amansinghbais/208-change-group-type
Browse files Browse the repository at this point in the history
Implemented: support for updating group type of a facility group (#208)
  • Loading branch information
ymaheshwari1 authored Mar 7, 2024
2 parents 29da01c + bf2c1e3 commit f6ba597
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/FacilityGroupActionsPopover.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<ion-item button @click="updateGroupDescriptionModal()">
{{ group?.description ? translate("Edit description") : translate("Add description") }}
</ion-item>
<ion-item button @click="updateGroupTypeModal()">
{{ translate("Select type") }}
</ion-item>
<ion-item button @click="deleteFacilityGroup()" lines="none">
{{ translate("Delete") }}
</ion-item>
Expand All @@ -34,7 +37,8 @@ import { FacilityService } from "@/services/FacilityService";
import { hasError } from "@/adapter";
import { mapGetters, useStore } from "vuex";
import logger from "@/logger";
import FacilityGroupDescriptionModal from "./FacilityGroupDescriptionModal.vue";
import FacilityGroupDescriptionModal from "@/components/FacilityGroupDescriptionModal.vue";
import GroupTypeModal from "@/components/GroupTypeModal.vue";
export default defineComponent({
name: "FacilityGroupActionsPopover",
Expand Down Expand Up @@ -131,6 +135,15 @@ export default defineComponent({
}
});
})
},
async updateGroupTypeModal() {
const updateGroupTypeModal = await modalController.create({
component: GroupTypeModal,
componentProps: { facilityGroup: this.group }
})
await popoverController.dismiss()
updateGroupTypeModal.present()
}
},
setup() {
Expand Down
139 changes: 139 additions & 0 deletions src/components/GroupTypeModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<template>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button @click="closeModal()">
<ion-icon :icon="closeOutline" slot="icon-only" />
</ion-button>
</ion-buttons>
<ion-title>{{ translate("Group type") }}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
<form @keyup.enter="saveGroupType()" class="ion-margin-top">
<!-- Empty state -->
<div class="empty-state" v-if="!facilityGroupTypes.length">
<p>{{ translate("No group types found")}}</p>
</div>

<div v-else>
<ion-radio-group v-model="facilityGroupValue.facilityGroupTypeId">
<ion-item :key="groupType.facilityGroupTypeId" v-for="groupType in facilityGroupTypes">
<ion-label>
{{ groupType.description ? groupType.description : groupType.facilityGroupTypeId }}
<p>{{ groupType.facilityGroupTypeId }}</p>
</ion-label>
<ion-radio :value="groupType.facilityGroupTypeId" slot="end" />
</ion-item>
</ion-radio-group>
</div>
</form>

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

<script lang="ts">
import {
IonButtons,
IonButton,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonItem,
IonIcon,
IonLabel,
IonRadioGroup,
IonRadio,
IonTitle,
IonToolbar,
modalController,
} from "@ionic/vue";
import { defineComponent } from "vue";
import { closeOutline, saveOutline } from "ionicons/icons";
import { translate } from "@hotwax/dxp-components";
import { mapGetters, useStore } from "vuex";
import { FacilityService } from "@/services/FacilityService";
import { hasError } from "@/adapter";
import logger from "@/logger";
import { showToast } from "@/utils";
export default defineComponent({
name: "GroupTypeModal",
components: {
IonButtons,
IonButton,
IonContent,
IonFab,
IonFabButton,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonRadioGroup,
IonRadio,
IonTitle,
IonToolbar
},
data() {
return {
facilityGroupValue: JSON.parse(JSON.stringify(this.facilityGroup))
}
},
props: ["facilityGroup"],
computed: {
...mapGetters({
facilityGroupTypes: "util/getFacilityGroupTypes",
groups: "facility/getFacilityGroups",
})
},
methods: {
closeModal() {
modalController.dismiss()
},
async saveGroupType() {
try {
const resp = await FacilityService.updateFacilityGroup({
facilityGroupId: this.facilityGroupValue.facilityGroupId,
facilityGroupTypeId: this.facilityGroupValue.facilityGroupTypeId
})
if(!hasError(resp)) {
showToast(translate("Facility group type updated successfully."))
const currentGroup = this.groups.find((group: any) => group.facilityGroupId === this.facilityGroupValue.facilityGroupId)
currentGroup.facilityGroupTypeId = this.facilityGroupValue.facilityGroupTypeId
await this.store.dispatch('facility/updateFacilityGroups', this.groups)
modalController.dismiss()
} else {
throw resp.data;
}
} catch(err) {
showToast(translate("Failed to update facility group type."))
logger.error(err)
}
}
},
setup() {
const store = useStore();
return {
closeOutline,
saveOutline,
translate,
store
};
}
});
</script>

<style scoped>
ion-content {
--padding-bottom: 80px;
}
</style>
5 changes: 5 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"Facility External ID": "Facility External ID",
"Facility external ID updated.": "Facility external ID updated.",
"Facility group deleted.": "Facility group deleted.",
"Facility group type updated successfully.": "Facility group type updated successfully.",
"Facility ID": "Facility ID",
"Facility latitude and longitude removed successfully.": "Facility latitude and longitude removed successfully.",
"Facility latitude and longitude updated successfully.": "Facility latitude and longitude updated successfully.",
Expand Down Expand Up @@ -146,6 +147,7 @@
"Failed to remove shopify mapping": "Failed to remove shopify mapping",
"Failed to rename facility group.": "Failed to rename facility group.",
"Failed to rename parking.": "Failed to rename parking.",
"Failed to update facility group type.": "Failed to update facility group type.",
"Failed to update some groups for facility": "Failed to update some groups for facility",
"Facility type updated": "Facility type updated",
"Failed to unarchive parking.": "Failed to unarchive parking.",
Expand Down Expand Up @@ -178,6 +180,7 @@
"Go to OMS": "Go to OMS",
"Group": "Group",
"Group associated to system group types.": "Group associated to system group types.",
"Group type": "Group type",
"Group unlinked from facility": "Group unlinked from facility",
"groups": "{count} groups",
"Groups": "Groups",
Expand Down Expand Up @@ -226,6 +229,7 @@
"No facility found": "No facility found",
"No fulfillment capacity": "No fulfillment capacity",
"No groups found": "No groups found",
"No group types found": "No group types found",
"no longer sells on": "{facilityName} no longer sells on {facilityGroupId}.",
"No party found": "No party found",
"No records found": "No records found",
Expand Down Expand Up @@ -311,6 +315,7 @@
"Search groups": "Search groups",
"Search time zones": "Search time zones",
"Select time zone": "Select time zone",
"Select type": "Select type",
"Select product stores": "Select product stores",
"Select which channels this facility publishes inventory too.": "Select which channels this facility publishes inventory too.",
"Select your preferred language.": "Select your preferred language.",
Expand Down

0 comments on commit f6ba597

Please sign in to comment.