-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented: functionality to product store card on facility details page (#10) #14
Merged
Merged
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7b8ee92
Implemented: service and actions for fetching all product Stores and …
amansinghbais 1450c40
Implemented: api and code for adding and removing product stores from…
amansinghbais 7ce2c03
Improved: code for unlink functionality, and translation entries (#10)
amansinghbais d4eed57
Improved: method name, props entry order (#10)
amansinghbais 7f39d25
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais aada1d4
Improved: popover component name, conditions in getProductStores acti…
amansinghbais 6a35e72
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais d0e9a70
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais eb969c2
Improved: code for adding support for make primary functionality (#10)
amansinghbais 12aea73
Implemented: make primary functionality (#10)
amansinghbais ebf0d9f
Improved: api payload for createFacilityGroup (#10)
amansinghbais 094ffde
Improved: make primary functionality based on productStoreId and resp…
amansinghbais 66d4e9a
Improved: code for refetching primaryMember on unlink event, disabled…
amansinghbais d7844a1
Improved: reverted unuseful changes (#10)
amansinghbais c8af8b5
Improved: code for correct argument type, alphabetical ordering (#10)
amansinghbais 6d2b474
Improved: save action for selectProductStoreModal to be performed fro…
amansinghbais 0ab2d61
Improved: code to get store detail from util getter (#10)
amansinghbais ff26676
Reverted: unwanted space in getter (#10)
amansinghbais 719b0e4
Implemented: feature to toggle functionality from popover (#10)
amansinghbais 05f582c
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais b40fc29
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
amansinghbais 349912f
Improved: code to disable selectProductStore modal when nothing selec…
amansinghbais 057e4b6
Improved: variable name, toast message and api error handling (#10)
amansinghbais 68819c3
Improved: alphabetical ordering in imports (#10)
amansinghbais c301ab1
Improved: method name for removing primary status, and added comments…
amansinghbais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
<template> | ||
<ion-content> | ||
<ion-list> | ||
<ion-list-header>{{ getProductStore(currentProductStore.productStoreId).storeName }}</ion-list-header> | ||
<ion-item button @click="makePrimary()"> | ||
{{ translate("Primary") }} | ||
<ion-icon slot="end" :color="primaryMember.facilityGroupId === currentProductStore.productStoreId ? 'warning' : ''" :icon="primaryMember.facilityGroupId === currentProductStore.productStoreId ? star : starOutline" /> | ||
</ion-item> | ||
<ion-item button lines="none" @click="removeStoreFromFacility()"> | ||
{{ translate("Unlink") }} | ||
<ion-icon slot="end" :icon="removeCircleOutline" /> | ||
</ion-item> | ||
</ion-list> | ||
</ion-content> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { | ||
IonContent, | ||
IonList, | ||
IonListHeader, | ||
IonIcon, | ||
IonItem, | ||
popoverController | ||
} from "@ionic/vue"; | ||
import { defineComponent } from "vue"; | ||
import { removeCircleOutline, star, starOutline } from "ionicons/icons"; | ||
import { translate } from "@hotwax/dxp-components"; | ||
import { mapGetters, useStore } from "vuex"; | ||
import { FacilityService } from "@/services/FacilityService"; | ||
import { DateTime } from "luxon"; | ||
import { hasError } from "@/adapter"; | ||
import { showToast } from "@/utils"; | ||
import logger from "@/logger"; | ||
|
||
export default defineComponent({ | ||
name: "ProductStorePopover", | ||
components: { | ||
IonContent, | ||
IonList, | ||
IonListHeader, | ||
IonIcon, | ||
IonItem | ||
}, | ||
props: ['currentProductStore', 'facilityId', 'primaryMember'], | ||
computed: { | ||
...mapGetters({ | ||
facilityProductStores: 'facility/getFacilityProductStores', | ||
productStores: 'util/getProductStores', | ||
getProductStore: 'util/getProductStore' | ||
}) | ||
}, | ||
methods: { | ||
async removeStoreFromFacility() { | ||
try { | ||
const resp = await FacilityService.updateProductStoreFacility({ | ||
facilityId: this.facilityId, | ||
productStoreId: this.currentProductStore.productStoreId, | ||
fromDate: this.currentProductStore.fromDate, | ||
thruDate: DateTime.now().toMillis() | ||
}) | ||
|
||
if(!hasError(resp)) { | ||
showToast(translate('Store unlinked successfully.')) | ||
|
||
// Removing store from primary Member group if primary. | ||
if(this.currentProductStore.productStoreId === this.primaryMember.facilityGroupId){ | ||
await this.removeProductFromPrimaryMember() | ||
} | ||
|
||
// refetching product stores with updated roles | ||
await this.store.dispatch('facility/getFacilityProductStores', { facilityId: this.facilityId }) | ||
} else { | ||
throw resp.data | ||
} | ||
} catch(err) { | ||
logger.error(err) | ||
showToast(translate('Store unlink failed.')) | ||
} | ||
popoverController.dismiss() | ||
}, | ||
async makePrimary() { | ||
const productStoreId = this.currentProductStore.productStoreId | ||
if(this.primaryMember.facilityGroupId === productStoreId) { | ||
this.removeProductFromPrimaryMember() | ||
popoverController.dismiss() | ||
return; | ||
} | ||
|
||
let resp; | ||
let facilityGroupId; | ||
|
||
facilityGroupId = await this.fetchFacilityGroup(productStoreId) | ||
|
||
if(!facilityGroupId) { | ||
facilityGroupId = await this.createFacilityGroup(productStoreId) | ||
} | ||
|
||
if(facilityGroupId) { | ||
try { | ||
resp = await FacilityService.addFacilityToGroup({ | ||
facilityId: this.facilityId, | ||
facilityGroupId: facilityGroupId | ||
}) | ||
|
||
if(!hasError(resp)) { | ||
// Remove old primary store | ||
if(this.primaryMember.facilityGroupId) { | ||
await this.removeProductFromPrimaryMember() | ||
} | ||
} else { | ||
throw resp.data | ||
} | ||
} catch(err) { | ||
showToast(translate("Failed to make product store primary.")) | ||
logger.error(err) | ||
} | ||
} else { | ||
showToast(translate("Failed to make product store primary.")) | ||
} | ||
popoverController.dismiss() | ||
}, | ||
async fetchFacilityGroup(productStoreId: string) { | ||
let facilityGroupId; | ||
let resp; | ||
try { | ||
resp = await FacilityService.fetchFacilityGroup({ | ||
inputFields: { | ||
facilityGroupId: productStoreId | ||
}, | ||
entityName: 'FacilityGroup', | ||
viewSize: 100 | ||
}) | ||
|
||
if(!hasError(resp)) { | ||
facilityGroupId = resp.data.docs[0].facilityGroupId | ||
} else { | ||
throw resp.data | ||
} | ||
} catch(err) { | ||
logger.error(err) | ||
} | ||
return facilityGroupId | ||
}, | ||
async createFacilityGroup(productStoreId: string) { | ||
let facilityGroupId; | ||
try { | ||
const resp = await FacilityService.createFacilityGroup({ | ||
facilityGroupTypeId: 'FEATURING', | ||
facilityGroupName: this.getProductStore(productStoreId).storeName, | ||
facilityGroupId: productStoreId | ||
}) | ||
|
||
if(!hasError(resp)) { | ||
facilityGroupId = resp.data.facilityGroupId | ||
} else { | ||
throw resp.data | ||
} | ||
} catch(err) { | ||
logger.error(err) | ||
} | ||
|
||
return facilityGroupId | ||
}, | ||
async removeProductFromPrimaryMember() { | ||
let resp; | ||
try { | ||
resp = await FacilityService.updateFacilityToGroup({ | ||
"facilityId": this.facilityId, | ||
"facilityGroupId": this.primaryMember.facilityGroupId, | ||
"fromDate": this.primaryMember.fromDate, | ||
"thruDate": DateTime.now().toMillis() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle case when having error in the resp. |
||
}) | ||
|
||
if(hasError(resp)) { | ||
throw resp.data | ||
} | ||
} catch (err) { | ||
logger.error(err) | ||
} | ||
} | ||
}, | ||
setup() { | ||
const store = useStore(); | ||
|
||
return { | ||
removeCircleOutline, | ||
star, | ||
starOutline, | ||
store, | ||
translate | ||
}; | ||
} | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrange imports in alphabetical order.