diff --git a/src/fmg-components/donation-block/donation-block.vue b/src/fmg-components/donation-block/donation-block.vue index 1dead20e0..d895e801b 100644 --- a/src/fmg-components/donation-block/donation-block.vue +++ b/src/fmg-components/donation-block/donation-block.vue @@ -1,65 +1,70 @@ @@ -71,6 +76,8 @@ export default { props: { cmsWidgetName: String, modelValue: String, + showDonationSuccess: Boolean, + showDonationError: Boolean, }, computed: { DonationHeadline() { @@ -106,11 +113,17 @@ export default { }, }, }, - data() { - return { - donationSuccess: true, - donationError: true, - }; + // data() { + // return { + // donationSuccess: true, + // donationError: true, + // }; + // }, + methods: { + handleDonationAction(submitEvent) { + console.log("running handleDonationAction(), submitEvent.target.elements.amount.value: ", submitEvent.target.elements.amount.value) + this.selectedValue = submitEvent.target.elements.amount.value; + } }, components: { textLink, diff --git a/src/layouts/confirmation/confirmation.vue b/src/layouts/confirmation/confirmation.vue index 13767b70a..d5993595f 100644 --- a/src/layouts/confirmation/confirmation.vue +++ b/src/layouts/confirmation/confirmation.vue @@ -68,7 +68,9 @@ + :donationValues="donationValues" + :showDonationSuccess="showDonationSuccess" + :showDonationError="showDonationError" />

donationAmount: {{ donationAmount }}

@@ -239,7 +241,10 @@ export default { vaps: [], submittedOrder: null, shouldHideRecalibration: null, - donationAmount: null, + donationAmount: 0, + showDonationSuccess: null, + showDonationError: null, + }; }, computed: { @@ -513,21 +518,55 @@ export default { forwardButtonAction() { window.location.assign(location.protocol + "//" + location.host); }, - async addDonation(amount) { + async addDonation(amount, plateTemp) { // try to call API to add donation to order - // TODO - change the following to check the response from the call - const donationResponse = await baseMixin.methods.dispatchStoreAction( - storeActions.ADD_DONATION_TO_SUBMITTED_ORDER, - amount, + // TEMP DUMMY CALL TO SIMULATE SUCCESS OR ERROR FROM API CALL + // TO BE REPLACED BY REAL CALL LATER + const donationResponse = await this.dispatchStoreActionWithLogging( + storeActions.LOOKUP_VIN_BY_PLATE, + { licensePlate: plateTemp, licenseState: "OH" }, + "test", false - ); + ).catch((error) => { + // this.$refs.navbar.removeLoader(); + console.error("Error!!! error: ", error) + return error; + }); + + console.log("ran addDonation()... (*fake call*) donationResponse: ", donationResponse) + + if (donationResponse?.status == "200") { + this.showDonationSuccess = true; + this.showDonationError = false; + const donationResponse = await baseMixin.methods.dispatchStoreAction( + storeActions.ADD_DONATION_TO_SUBMITTED_ORDER, + amount, + false + ); + } else { + this.showDonationError = true; + this.showDonationSuccess = false; + const donationResponse = await baseMixin.methods.dispatchStoreAction( + storeActions.ADD_DONATION_TO_SUBMITTED_ORDER, + 0, + false + ); + } + }, }, watch: { donationAmount(newValue) { console.log("WATCHED donationAmount changed: ", newValue); - this.addDonation(newValue); + + // this.addDonation(newValue); + // TODO - when backend code is final, then remove the below and restore the line above + if (newValue == 5) { + this.addDonation(newValue, "FAILING_PLATE"); // throws error + } else { + this.addDonation(newValue, "2fast"); // should give successful response + } }, }, components: { diff --git a/src/store/index.js b/src/store/index.js index 1691c8080..6a27116e1 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3158,22 +3158,32 @@ export const actions = { addDonationToSubmittedOrder(context, donationAmount) { console.log("running addDonationToSubmittedOrder()... donationAmount: ", donationAmount); - + const submittedOrder = deepClone(baseMixin.methods.getSubmittedOrder()); + + if (donationAmount > 0) { + console.log("running addDonationToSubmittedOrder()... adding donation to supportingItems in session storage ") + submittedOrder.lineItems.supportingItems.push({ + partNumber: "DONATION", + description: null, + partType: "DONATION", + isInsurable: false, + isChildPart: false, + laborAmount: 0, + sellingPrice: donationAmount, + kitPrice: 0, + salesTax: null, + id: "donation-" + donationAmount, + }); + } else { + // filter out all donations + console.log("running addDonationToSubmittedOrder()... removing all donation items in supportingItems in session storage ") - submittedOrder.lineItems.supportingItems.push({ - partNumber: "DONATION", - description: null, - partType: "DONATION", - isInsurable: false, - isChildPart: false, - laborAmount: 0, - sellingPrice: donationAmount, - kitPrice: 0, - salesTax: null, - id: "donation-" + donationAmount, - }); - + const nonDonationItems = submittedOrder.lineItems.supportingItems.filter(item => { + return item.partType !== "DONATION"; + }); + submittedOrder.lineItems.supportingItems = nonDonationItems; + } // set to local storage window.sessionStorage.setItem("submittedOrder", JSON.stringify(submittedOrder)); },