refactor cart to use submittedOrder values on order-confirmation page

This commit is contained in:
Katie Kroell 2024-04-12 15:15:16 -04:00
parent 5e3fe33414
commit 4c6cd78e62

View file

@ -59,7 +59,7 @@
<div class="py-1 d-flex justify-content-between align-items-center"> <div class="py-1 d-flex justify-content-between align-items-center">
<span>{{ item?.name ?? '' }}</span> <span>{{ item?.name ?? '' }}</span>
<textLink <textLink
v-if="!readOnly || !showAsPaid" v-if="!readOnly"
linkType="text" linkType="text"
text="Remove" text="Remove"
href="javascript:void(0)" href="javascript:void(0)"
@ -196,36 +196,20 @@ export default {
computed: { computed: {
deductible() { deductible() {
// Note: added as computed so it can be used in the template. // Note: added as computed so it can be used in the template.
if (this.submittedOrder) { return this.submittedOrder ? this.submittedOrder.currentDeductible : useMainStore().order.currentDeductible;
return this.submittedOrder.currentDeductible;
}
return useMainStore().order.currentDeductible;
}, },
showDeductibleCartItem() { showDeductibleCartItem() {
if (this.submittedOrder) { return !this.isNoComp && !this.isITAC;
return this.submittedOrder.policy.noCoverage === false && this.submittedOrder.policy.isITAC === false; },
} lineItems() {
return !useMainStore().isNoComp && !useMainStore().isITAC; return this.submittedOrder ? this.submittedOrder.lineItems : useMainStore().lineItems;
}, },
recycleFeeLineItem() { recycleFeeLineItem() {
if (this.submittedOrder) { return this.lineItems.supportingItems
return this.submittedOrder.lineItems.supportingItems
?.find((lineItem) => lineItem.partNumber === partNumberStrings.RECYCLE_FEE);
}
return useMainStore().lineItems.supportingItems
?.find((lineItem) => lineItem.partNumber === partNumberStrings.RECYCLE_FEE); ?.find((lineItem) => lineItem.partNumber === partNumberStrings.RECYCLE_FEE);
}, },
baseServiceLineItems() { baseServiceLineItems() {
if (this.submittedOrder) { const { supportingItems, glassParts, otherParts } = this.lineItems;
const { supportingItems, glassParts, otherParts } = this.submittedOrder.lineItems;
const parts = [
...(supportingItems ?? []),
...(glassParts ?? []),
...(otherParts ?? [])
];
return parts.filter((part) => part !== this.recycleFeeLineItem);
}
const { supportingItems, glassParts, otherParts } = useMainStore().lineItems;
const parts = [ const parts = [
...(supportingItems ?? []), ...(supportingItems ?? []),
...(glassParts ?? []), ...(glassParts ?? []),
@ -236,29 +220,21 @@ export default {
baseServicePrice() { baseServicePrice() {
return getPriceOfLineItems(this.baseServiceLineItems) ?? 0; return getPriceOfLineItems(this.baseServiceLineItems) ?? 0;
}, },
isVerified() {
return this.submittedOrder ? this.submittedOrder.payment.isVerified : useMainStore().isVerifiedCoverageStatus;
},
isUnverified() { isUnverified() {
if (this.submittedOrder) { return !this.isNoComp && !this.isITAC
return this.submittedOrder.policy.noCoverage === false && this.submittedOrder.policy.isITAC === false && (this.deductible == null || this.isUnverified);
&& (this.submittedOrder.currentDeductible == null || this.submittedOrder.payment.isVerified === false); },
} return !useMainStore().isNoComp && !useMainStore().isITAC isITAC() {
&& (this.deductible == null || !useMainStore().isVerifiedCoverageStatus); return this.submittedOrder ? this.submittedOrder.policy.isITAC : useMainStore().isITAC;
},
isNoComp() {
return this.submittedOrder ? this.submittedOrder.policy.noCoverage : useMainStore().isNoComp;
}, },
subTotal() { subTotal() {
if (this.submittedOrder) { const { supportingItems, glassParts, otherParts, vaps, mobileFee } = this.lineItems;
const { supportingItems, glassParts, otherParts, vaps, mobileFee } = this.submittedOrder.lineItems;
const allLineItems = [
...(supportingItems ?? []),
...(glassParts ?? []),
...(otherParts ?? []),
...(vaps ?? []),
mobileFee
];
return this.submittedOrder.policy.noCoverage === false && this.submittedOrder.policy.isITAC === false
? this.deductible + getPriceOfLineItems([...this.feeLineItems, ...(vaps ?? [])])
: getPriceOfLineItems(allLineItems);
}
const { supportingItems, glassParts, otherParts, vaps, mobileFee } = useMainStore().lineItems;
const allLineItems = [ const allLineItems = [
...(supportingItems ?? []), ...(supportingItems ?? []),
...(glassParts ?? []), ...(glassParts ?? []),
@ -266,23 +242,12 @@ export default {
...(vaps ?? []), ...(vaps ?? []),
mobileFee mobileFee
]; ];
return !useMainStore().isNoComp && !useMainStore().isITAC return !this.isNoComp && !this.isITAC
? this.deductible + getPriceOfLineItems([...this.feeLineItems, ...(vaps ?? [])]) ? this.deductible + getPriceOfLineItems([...this.feeLineItems, ...(vaps ?? [])])
: getPriceOfLineItems(allLineItems); : getPriceOfLineItems(allLineItems);
}, },
feeLineItems() { feeLineItems() {
if (this.submittedOrder) { const { mobileFee } = this.lineItems;
const { mobileFee } = this.submittedOrder.lineItems;
const result = [];
if (mobileFee) {
result.push(mobileFee);
}
if (this.recycleFeeLineItem) {
result.push(this.recycleFeeLineItem);
}
return result;
}
const { mobileFee } = useMainStore().lineItems;
const result = []; const result = [];
if (mobileFee) { if (mobileFee) {
result.push(mobileFee); result.push(mobileFee);
@ -299,21 +264,8 @@ export default {
let result = 0; let result = 0;
if (this.submittedOrder) { if (this.isVerified) {
if (this.submittedOrder.payment.insuranceCoverage.isVerified) { if (this.isITAC || this.isNoComp) {
if (this.submittedOrder.policy.isITAC || this.submittedOrder.policy.noCoverage) {
result += sumTax(this.baseServiceLineItems);
} else {
// deductible-case need to show tax for Recycle Fee
result += this.recycleFeeLineItem?.salesTax ?? 0;
}
}
result += sumTax(this.submittedOrder.lineItems.vaps ?? []);
return result;
}
if (useMainStore().payment.insuranceCoverage.isVerified) {
if (useMainStore().isITAC || useMainStore().isNoComp) {
result += sumTax(this.baseServiceLineItems); result += sumTax(this.baseServiceLineItems);
} else { } else {
// deductible-case need to show tax for Recycle Fee // deductible-case need to show tax for Recycle Fee
@ -321,7 +273,7 @@ export default {
} }
} }
result += sumTax(useMainStore().lineItems.vaps ?? []); result += sumTax(this.lineItems.vaps ?? []);
return result; return result;
}, },
@ -331,20 +283,7 @@ export default {
: this.subTotal + this.salesTax; : this.subTotal + this.salesTax;
}, },
availableLineItems() { availableLineItems() {
if (this.submittedOrder) { const { supportingItems, glassParts, otherParts, mobileFee } = this.lineItems;
const { supportingItems, glassParts, otherParts, mobileFee } = this.submittedOrder.lineItems;
const result = [
...(supportingItems ?? []),
...(glassParts ?? []),
...(otherParts ?? []),
...(this.availableVaps ?? [])
];
if (mobileFee) {
result.push(mobileFee);
}
return result;
}
const { supportingItems, glassParts, otherParts, mobileFee } = useMainStore().lineItems;
const result = [ const result = [
...(supportingItems ?? []), ...(supportingItems ?? []),
...(glassParts ?? []), ...(glassParts ?? []),
@ -356,19 +295,12 @@ export default {
} }
return result; return result;
}, },
vehicleDamage() {
return this.submittedOrder ? this.submittedOrder.damage : useMainStore().damage;
},
servicePackageTier() { servicePackageTier() {
if (this.submittedOrder) { const { glassToReplace, isRepair } = this.vehicleDamage;
const { glassToReplace, isRepair } = this.submittedOrder.damage; const { vaps } = this.lineItems;
const { vaps } = this.submittedOrder.lineItems;
return getHighestFullySatisfiedTier(
glassToReplace ?? [],
this.availableLineItems,
isRepair,
vaps ?? []
);
}
const { glassToReplace, isRepair } = useMainStore().damage;
const { vaps } = useMainStore().lineItems;
return getHighestFullySatisfiedTier( return getHighestFullySatisfiedTier(
glassToReplace ?? [], glassToReplace ?? [],
this.availableLineItems, this.availableLineItems,
@ -377,7 +309,7 @@ export default {
); );
}, },
partTypesInServicePackage() { partTypesInServicePackage() {
const { glassToReplace, isRepair } = useMainStore().damage; const { glassToReplace, isRepair } = this.vehicleDamage;
return getPackageContents( return getPackageContents(
glassToReplace ?? [], glassToReplace ?? [],
this.availableLineItems, this.availableLineItems,
@ -399,7 +331,7 @@ export default {
return items; return items;
}, },
nonServicePackageCartItems() { nonServicePackageCartItems() {
const vapPartTypesInOrder = Array.from(new Set(useMainStore().lineItems.vaps?.map((vap) => vap.partType) ?? [])); const vapPartTypesInOrder = Array.from(new Set(this.lineItems.vaps?.map((vap) => vap.partType) ?? []));
const vapPartTypesInOrderButNotPackage = vapPartTypesInOrder const vapPartTypesInOrderButNotPackage = vapPartTypesInOrder
.filter((partType) => !this.partTypesInServicePackage.includes(partType)) .filter((partType) => !this.partTypesInServicePackage.includes(partType))
?? []; ?? [];
@ -455,16 +387,10 @@ export default {
return this.getCmsContent(this.widget.salesTax, widgetFields.TEXT_BLOCK_WIDGET.TEXT); return this.getCmsContent(this.widget.salesTax, widgetFields.TEXT_BLOCK_WIDGET.TEXT);
}, },
servicePackageNames() { servicePackageNames() {
const test = this.getCmsContent( return this.getCmsContent(
this.widget.servicePackage, this.widget.servicePackage,
widgetFields.INPUT_QUESTION_WIDGET.ANSWERS widgetFields.INPUT_QUESTION_WIDGET.ANSWERS
); );
console.log(test);
return test;
// return this.getCmsContent(
// this.widget.servicePackage,
// widgetFields.INPUT_QUESTION_WIDGET.ANSWERS
// );
}, },
servicePackageLabelWidget() { servicePackageLabelWidget() {
if (!this.servicePackageNames) { if (!this.servicePackageNames) {
@ -486,7 +412,7 @@ export default {
: null; : null;
}, },
mobileFeeCartItem() { mobileFeeCartItem() {
const mobileFeeLineItem = useMainStore().lineItems.mobileFee; const mobileFeeLineItem = this.lineItems.mobileFee;
return mobileFeeLineItem return mobileFeeLineItem
? this.getCartItem( ? this.getCartItem(
this.getCmsContent(this.widget.mobileFee, widgetFields.TEXT_BLOCK_WIDGET.TEXT), this.getCmsContent(this.widget.mobileFee, widgetFields.TEXT_BLOCK_WIDGET.TEXT),
@ -505,16 +431,9 @@ export default {
this.isExpanded = !this.isExpanded; this.isExpanded = !this.isExpanded;
}, },
getDisplayed(amount) { getDisplayed(amount) {
if (this.submittedOrder) {
return this.isUnverified
&& this.submittedOrder.policy.noCoverage === false
&& this.submittedOrder.policy.isITAC === false
? VERIFYING_COVERAGE
: formatAmountInDollars(amount);
}
return this.isUnverified return this.isUnverified
&& !useMainStore().isNoComp && !this.isNoComp
&& !useMainStore().isITAC && !this.isITAC
? VERIFYING_COVERAGE ? VERIFYING_COVERAGE
: formatAmountInDollars(amount); : formatAmountInDollars(amount);
}, },
@ -537,14 +456,8 @@ export default {
return cartItem; return cartItem;
}, },
getCartItemForVapsPart(partType) { getCartItemForVapsPart(partType) {
if (this.submittedOrder) {
const label = this.getCmsContentForVapsType(partType);
const lineItems = this.submittedOrder.lineItems.vaps
?.filter((vapsLineItem) => vapsLineItem.partType === partType) ?? [];
return this.getCartItem(label, lineItems, cartItemType.VAP, partType);
}
const label = this.getCmsContentForVapsType(partType); const label = this.getCmsContentForVapsType(partType);
const lineItems = useMainStore().lineItems.vaps const lineItems = this.lineItems.vaps
?.filter((vapsLineItem) => vapsLineItem.partType === partType) ?? []; ?.filter((vapsLineItem) => vapsLineItem.partType === partType) ?? [];
return this.getCartItem(label, lineItems, cartItemType.VAP, partType); return this.getCartItem(label, lineItems, cartItemType.VAP, partType);
}, },