Skip to content

Commit

Permalink
Merge pull request #17 from ymaheshwari1/#16
Browse files Browse the repository at this point in the history
Implemented: support to update the fulfillment settings from details page(#16)
  • Loading branch information
ravilodhi authored Nov 21, 2023
2 parents 631c07c + 7e77074 commit 8f1f41a
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"Custom mapping": "Custom mapping",
"Country": "Country",
"Days to ship": "Days to ship",
"days to ship": "days to ship",
"Dismiss": "Dismiss",
"Edit": "Edit",
"Edit location": "Edit location",
Expand Down
51 changes: 40 additions & 11 deletions src/services/FacilityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ const fetchFacilities = async(query: any): Promise <any> => {
});
}

const fetchFacilityOnlineGroupInformation = async(facilityIds: Array<string>): Promise<any> => {
let facilitiesWithSellOnlineEnabled = []
const fetchFacilityGroupInformation = async(facilityIds: Array<string>): Promise<any> => {
let facilitiesGroupInformation = []

const params = {
inputFields: {
facilityId: facilityIds,
facilityId_op: "in",
facilityGroupTypeId: 'SHOPIFY_GROUP_FAC',
facilityGroupTypeId_op: 'equals'
facilityId_op: "in"
},
fieldList: ['facilityId', 'facilityGroupTypeId'],
fieldList: ['facilityId', 'facilityGroupId', 'facilityGroupTypeId', "fromDate"],
entityName: "FacilityGroupAndMember",
distinct: 'Y',
filterByDate: 'Y',
viewSize: facilityIds.length
viewSize: facilityIds.length * 10 // multiplying the id by 10, as one facility at max will be in 10 groups
}

try {
Expand All @@ -35,15 +33,28 @@ const fetchFacilityOnlineGroupInformation = async(facilityIds: Array<string>): P
}) as any;

if(!hasError(resp) && resp.data.count > 0) {
facilitiesWithSellOnlineEnabled = resp.data.docs.map((facility: any) => facility.facilityId)
facilitiesGroupInformation = resp.data.docs.reduce((facilityGroups: any, facilityGroup: any) => {

if(facilityGroups[facilityGroup.facilityId]) {
facilityGroups[facilityGroup.facilityId].push({
...facilityGroup
})
} else {
facilityGroups[facilityGroup.facilityId] = [{
...facilityGroup
}]
}

return facilityGroups
}, {})
} else {
throw resp.data;
}
} catch(err) {
logger.error(err)
}

return facilitiesWithSellOnlineEnabled;
return facilitiesGroupInformation;
}

const fetchFacilitiesOrderCount = async(facilityIds: Array<string>): Promise<any> => {
Expand Down Expand Up @@ -123,10 +134,28 @@ const updateFacility = async (payload: any): Promise<any> => {
})
}

const addFacilityToGroup = async (payload: any): Promise<any> => {
return api({
url: "service/addFacilityToGroup",
method: "post",
data: payload
})
}

const updateFacilityToGroup = async (payload: any): Promise<any> => {
return api({
url: "service/updateFacilityToGroup",
method: "post",
data: payload
})
}

export const FacilityService = {
fetchFacilityOnlineGroupInformation,
addFacilityToGroup,
fetchFacilityGroupInformation,
fetchFacilityOrderCounts,
fetchFacilitiesOrderCount,
fetchFacilities,
updateFacility
updateFacility,
updateFacilityToGroup
}
31 changes: 20 additions & 11 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ const actions: ActionTree<FacilityState, RootState> = {

if(!hasError(resp) && resp.data.count) {
facilities = resp.data.docs
if(payload.viewIndex && payload.viewIndex > 0) facilities = JSON.parse(JSON.stringify(state.facilities.list)).concat(resp.data.docs)
total = resp.data.count

// make api calls in parallel
const facilityOnlineGroupInformation = await FacilityService.fetchFacilityOnlineGroupInformation(facilities.map((facility: any) => facility.facilityId))
const facilitiesGroupInformation = await FacilityService.fetchFacilityGroupInformation(facilities.map((facility: any) => facility.facilityId))
const facilitiesOrderCount = await FacilityService.fetchFacilitiesOrderCount(facilities.map((facility: any) => facility.facilityId))

facilities.map((facility: any) => {
Expand All @@ -73,12 +72,18 @@ const actions: ActionTree<FacilityState, RootState> = {

facility.orderCount = facilitiesOrderCount[facility.facilityId] ? facilitiesOrderCount[facility.facilityId] : 0;

if(facilityOnlineGroupInformation.includes(facility.facilityId)) {
facility.sellOnline = true
} else {
facility.sellOnline = false
const facilityGroupInformation = facilitiesGroupInformation[facility.facilityId]

if(facilityGroupInformation.length) {
facility.groupInformation = facilityGroupInformation
facility.sellOnline = (facilityGroupInformation.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'FAC_GRP'))
facility.useOMSFulfillment = (facilityGroupInformation.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'OMS_FULFILLMENT'))
facility.generateShippingLabel = (facilityGroupInformation.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'AUTO_SHIPPING_LABEL'))
facility.allowPickup = (facilityGroupInformation.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'PICKUP'))
}
})

if(payload.viewIndex && payload.viewIndex > 0) facilities = JSON.parse(JSON.stringify(state.facilities.list)).concat(facilities)
} else {
throw resp.data
}
Expand Down Expand Up @@ -120,7 +125,7 @@ const actions: ActionTree<FacilityState, RootState> = {
if(!hasError(resp) && resp.data.count > 0) {
facility = resp.data.docs[0]

const [facilityOnlineGroupInformation, facilityOrderCount] = await Promise.all([FacilityService.fetchFacilityOnlineGroupInformation(facility.facilityId), FacilityService.fetchFacilitiesOrderCount(facility.facilityId)])
const [facilityGroupInformation, facilityOrderCount] = await Promise.all([FacilityService.fetchFacilityGroupInformation([facility.facilityId]), FacilityService.fetchFacilitiesOrderCount([facility.facilityId])])

const fulfillmentOrderLimit = facility.maximumOrderLimit
if (fulfillmentOrderLimit === 0) {
Expand All @@ -133,10 +138,14 @@ const actions: ActionTree<FacilityState, RootState> = {

facility.orderCount = facilityOrderCount[facility.facilityId] ? facilityOrderCount[facility.facilityId] : 0;

if(facilityOnlineGroupInformation.includes(facility.facilityId)) {
facility.sellOnline = true
} else {
facility.sellOnline = false
const facilityGroupInfo = facilityGroupInformation[facility.facilityId]

if(facilityGroupInfo.length) {
facility.groupInformation = facilityGroupInfo
facility.sellOnline = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'FAC_GRP'))
facility.useOMSFulfillment = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'OMS_FULFILLMENT'))
facility.generateShippingLabel = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'AUTO_SHIPPING_LABEL'))
facility.allowPickup = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'PICKUP'))
}
} else {
throw resp.data
Expand Down
89 changes: 82 additions & 7 deletions src/views/FacilityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,25 @@
</ion-card-header>
<ion-item>
<ion-label>{{ translate("Sell Inventory Online") }}</ion-label>
<ion-toggle :checked="true" slot="end" />
<ion-toggle :checked="current.sellOnline" slot="end" @click="updateFulfillmentSetting($event, 'FAC_GRP')"/>
</ion-item>
<ion-item>
<ion-label>{{ translate("Uses native fulfillment app") }}</ion-label>
<ion-toggle :checked="true" slot="end" />
<ion-toggle :checked="current.useOMSFulfillment" slot="end" @click="updateFulfillmentSetting($event, 'OMS_FULFILLMENT')"/>
</ion-item>
<ion-item>
<ion-label>{{ translate("Generate shipping labels") }}</ion-label>
<ion-toggle :checked="true" slot="end" />
<ion-toggle :checked="current.generateShippingLabel" slot="end" @click="updateFulfillmentSetting($event, 'AUTO_SHIPPING_LABEL')"/>
</ion-item>
<ion-item>
<ion-label>{{ translate("Allow pickup") }}</ion-label>
<ion-toggle :checked="true" slot="end" />
<ion-toggle :checked="current.allowPickup" slot="end" @click="updateFulfillmentSetting($event, 'PICKUP')"/>
</ion-item>
<ion-item lines="full">
<ion-label>{{ translate("Days to ship") }}</ion-label>
<ion-input :value="current.defaultDaysToShip" type="number" min="0" placeholder="0"/>
<ion-input v-model="defaultDaysToShip" type="number" min="0" :placeholder="translate('days to ship')"/>
</ion-item>
<ion-button fill="outline" expand="block">
<ion-button fill="outline" expand="block" @click="updateDefaultDaysToShip">
{{ translate("Update days to ship") }}
</ion-button>
</ion-card>
Expand Down Expand Up @@ -432,6 +432,7 @@ import { hasError } from '@/adapter';
import { showToast } from '@/utils';
import logger from '@/logger';
import ViewFacilityOrderCountModal from '@/components/ViewFacilityOrderCountModal.vue'
import { DateTime } from 'luxon';
export default defineComponent({
name: 'FacilityDetails',
Expand Down Expand Up @@ -465,7 +466,8 @@ export default defineComponent({
return {
isTimeModalOpen: false as boolean,
isLoading: true, // shows whether the facility information fetching is completed or not
segment: 'external-mappings'
segment: 'external-mappings',
defaultDaysToShip: '' // not assinging 0 by default as it will convey the user that the facility can ship same day, but actually defaultDays are not setup on the facility
}
},
computed: {
Expand All @@ -476,6 +478,7 @@ export default defineComponent({
props: ["facilityId"],
async ionViewWillEnter() {
await this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId })
this.defaultDaysToShip = this.current.defaultDaysToShip
this.isLoading = false
},
methods: {
Expand Down Expand Up @@ -587,6 +590,78 @@ export default defineComponent({
})
facilityOrderCountModal.present()
},
async addFacilityToGroup(facilityGroupId: string) {
let resp;
try {
resp = await FacilityService.addFacilityToGroup({
"facilityId": this.current.facilityId,
"facilityGroupId": facilityGroupId
})
if(!hasError(resp)) {
showToast(translate('Fulfillment setting updated successfully'))
} else {
throw resp.data
}
} catch (err) {
showToast(translate('Failed to update fulfillment setting'))
logger.error('Failed to update fulfillment setting', err)
}
},
async updateFulfillmentSetting(event: any, facilityGroupId: string) {
event.stopImmediatePropagation();
// Using `not` as the click event returns the current status of toggle, but on click we want to change the toggle status
const isChecked = !event.target.checked;
if(isChecked) {
this.addFacilityToGroup(facilityGroupId)
} else {
this.updateFacilityToGroup(facilityGroupId)
}
},
async updateFacilityToGroup(facilityGroupId: string) {
let resp;
const groupInformation = this.current.groupInformation.find((group: any) => group.facilityGroupId === facilityGroupId)
try {
resp = await FacilityService.updateFacilityToGroup({
"facilityId": this.current.facilityId,
"facilityGroupId": facilityGroupId,
"fromDate": groupInformation.fromDate,
"thruDate": DateTime.now().toMillis()
})
if (!hasError(resp)) {
showToast(translate('Fulfillment setting updated successfully'))
} else {
throw resp.data
}
} catch (err) {
showToast(translate('Failed to update fulfillment setting'))
logger.error('Failed to update fulfillment setting', err)
}
},
async updateDefaultDaysToShip() {
try {
const payload = {
facilityId: this.current.facilityId,
defaultDaysToShip: this.defaultDaysToShip
}
const resp = await FacilityService.updateFacility(payload)
if(!hasError(resp)) {
showToast(translate('Updated default days to ship'))
} else {
throw resp.data
}
} catch(err) {
logger.error('Failed to update default days to ship', err)
showToast(translate('Failed to update default days to ship'))
}
}
},
setup() {
Expand Down

0 comments on commit 8f1f41a

Please sign in to comment.