-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Implemented: added support for gift card activation (#716)
- Loading branch information
Showing
10 changed files
with
502 additions
and
3 deletions.
There are no files selected for viewing
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,184 @@ | ||
<template> | ||
<ion-header> | ||
<ion-toolbar> | ||
<ion-buttons slot="start"> | ||
<ion-button @click="closeModal()"> | ||
<ion-icon slot="icon-only" :icon="closeOutline" /> | ||
</ion-button> | ||
</ion-buttons> | ||
<ion-title>{{ translate("Gift card activation") }}</ion-title> | ||
</ion-toolbar> | ||
</ion-header> | ||
|
||
<ion-content> | ||
<div v-if="isLoading" class="empty-state"> | ||
<ion-spinner name="crescent" /> | ||
<ion-label>{{ translate("Fetching gift card info.") }}</ion-label> | ||
</div> | ||
<ion-list v-else> | ||
<ion-item lines="none" v-if="!item.isGCActivated"> | ||
<ion-input :label="translate('Activation code')" :placeholder="translate('serial number')" :helper-text="translate('Scan or enter the unique code on the gift card')" v-model="activationCode" /> | ||
</ion-item> | ||
|
||
<ion-item v-else> | ||
<ion-icon :icon="cardOutline" slot="start" /> | ||
<ion-label>{{ item.gcInfo.cardNumber }}</ion-label> | ||
<ion-note slot="end">{{ getCreatedDateTime() }}</ion-note> | ||
</ion-item> | ||
|
||
<ion-item lines="none"> | ||
<ion-icon :icon="giftOutline" slot="start" /> | ||
<ion-label> | ||
{{ getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(item.productId)) ? getProductIdentificationValue(productIdentificationPref.primaryId, getProduct(item.productId)) : item.productName }} | ||
<p>{{ getProductIdentificationValue(productIdentificationPref.secondaryId, getProduct(item.productId)) }}</p> | ||
</ion-label> | ||
<ion-label slot="end">{{ formatCurrency(itemPriceInfo.unitPrice, itemPriceInfo.currencyUom) }}</ion-label> | ||
</ion-item> | ||
</ion-list> | ||
</ion-content> | ||
|
||
<ion-fab v-if="!item.isGCActivated" vertical="bottom" horizontal="end" slot="fixed"> | ||
<ion-fab-button @click="confirmSave()"> | ||
<ion-icon :icon="cardOutline" /> | ||
</ion-fab-button> | ||
</ion-fab> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { | ||
IonButton, | ||
IonButtons, | ||
IonContent, | ||
IonFab, | ||
IonFabButton, | ||
IonHeader, | ||
IonIcon, | ||
IonInput, | ||
IonItem, | ||
IonLabel, | ||
IonList, | ||
IonNote, | ||
IonSpinner, | ||
IonTitle, | ||
IonToolbar, | ||
alertController, | ||
modalController | ||
} from "@ionic/vue"; | ||
import { computed, defineComponent } from "vue"; | ||
import { mapGetters, useStore } from "vuex"; | ||
import { cardOutline, closeOutline, giftOutline, saveOutline } from "ionicons/icons"; | ||
import { getProductIdentificationValue, translate, useProductIdentificationStore } from '@hotwax/dxp-components' | ||
import { UtilService } from "@/services/UtilService"; | ||
import { formatCurrency, formatUtcDate, hasError, showToast } from '@/utils'; | ||
import logger from "@/logger"; | ||
import { DateTime } from 'luxon'; | ||
export default defineComponent({ | ||
name: "GiftCardActivationModal", | ||
components: { | ||
IonButton, | ||
IonButtons, | ||
IonContent, | ||
IonFab, | ||
IonFabButton, | ||
IonHeader, | ||
IonIcon, | ||
IonInput, | ||
IonItem, | ||
IonLabel, | ||
IonList, | ||
IonNote, | ||
IonSpinner, | ||
IonTitle, | ||
IonToolbar | ||
}, | ||
computed: { | ||
...mapGetters({ | ||
getProduct: 'product/getProduct', | ||
}), | ||
}, | ||
data() { | ||
return { | ||
isLoading: false, | ||
itemPriceInfo: {} as any, | ||
activationCode: "" | ||
} | ||
}, | ||
props: ["item"], | ||
async mounted() { | ||
this.isLoading = true; | ||
this.itemPriceInfo = await UtilService.fetchGiftCardItemPriceInfo({ orderId: this.item.orderId, orderItemSeqId: this.item.orderItemSeqId }) | ||
this.isLoading = false; | ||
}, | ||
methods: { | ||
closeModal(payload = {}) { | ||
modalController.dismiss({ dismissed: true, ...payload }) | ||
}, | ||
async confirmSave() { | ||
if(!this.activationCode.trim()) { | ||
showToast(translate("Please enter a activation code.")) | ||
return; | ||
} | ||
const alert = await alertController.create({ | ||
header: translate("Activate gift card"), | ||
message: translate("This gift card code will be activated. The customer may also receive a notification about this activation. Please verify all information is entered correctly. This cannot be edited after activation.", { space: "<br /><br />" }), | ||
buttons: [ | ||
{ | ||
text: translate("Cancel"), | ||
}, | ||
{ | ||
text: translate("Activate"), | ||
handler: async () => { | ||
await this.activateGitCard() | ||
} | ||
} | ||
], | ||
}); | ||
return alert.present(); | ||
}, | ||
async activateGitCard() { | ||
try { | ||
const resp = await UtilService.activateGiftCard({ | ||
orderId: this.item.orderId, | ||
orderItemSeqId: this.item.orderItemSeqId, | ||
amount: this.itemPriceInfo.unitPrice, | ||
typeEnumId: "GC_ACTIVATE", | ||
cardNumber: this.activationCode.trim() | ||
}) | ||
if(!hasError(resp)) { | ||
showToast(translate("Gift card activated successfully.")) | ||
this.closeModal({ isGCActivated: true, item: this.item }) | ||
} else { | ||
throw resp.data; | ||
} | ||
} catch(error: any) { | ||
showToast(translate("Failed to activate gift card.")) | ||
logger.error(error); | ||
} | ||
}, | ||
getCreatedDateTime() { | ||
return DateTime.fromMillis(this.item.gcInfo.fulfillmentDate).toFormat("dd MMMM yyyy t a ZZZZ"); | ||
} | ||
}, | ||
setup() { | ||
const store = useStore() | ||
const productIdentificationStore = useProductIdentificationStore(); | ||
let productIdentificationPref = computed(() => productIdentificationStore.getProductIdentificationPref) | ||
return { | ||
cardOutline, | ||
closeOutline, | ||
formatCurrency, | ||
formatUtcDate, | ||
getProductIdentificationValue, | ||
giftOutline, | ||
productIdentificationPref, | ||
saveOutline, | ||
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
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.