CSR-1391 better looking payment buttons
This commit is contained in:
parent
da764e57cf
commit
4d9c1a88de
2 changed files with 90 additions and 70 deletions
|
|
@ -1,74 +1,73 @@
|
|||
<template>
|
||||
<baseInputButton v-bind="$props" @update:modelValue="handleClick">
|
||||
<div class="button-content d-flex flex-row py-3 px-4">
|
||||
<img
|
||||
v-if="shouldDisplaySideImage"
|
||||
:id="buttonImageId"
|
||||
class="ms-auto order-3"
|
||||
:src="buttonImage"
|
||||
:alt="altText" />
|
||||
<div class="order-2">
|
||||
<p class="m-0">
|
||||
<span v-for="token in tokens" :key="token">
|
||||
<span v-if="isInlineImageToken(token)">
|
||||
<img
|
||||
v-if="hasImage"
|
||||
:src="buttonImage"
|
||||
:alt="getInlineAltText(token)" />
|
||||
<span v-else> {{ getInlineAltText(token) }}</span>
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ token }}
|
||||
</span>
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</baseInputButton>
|
||||
<button
|
||||
type="button"
|
||||
class="btn d-flex align-items-center justify-content-center py-3 px-4 delay"
|
||||
@click="handleClick">
|
||||
<!-- <span class="m-0">{{ buttonLabelText }}</span> -->
|
||||
<span v-for="token in tokens" :key="token">
|
||||
<span v-if="isInlineImageToken(token)">
|
||||
<img
|
||||
v-if="hasImage"
|
||||
class="ms-2"
|
||||
:src="buttonImage"
|
||||
:alt="getInlineAltText(token)" />
|
||||
<span v-else> {{ getInlineAltText(token) }}</span>
|
||||
</span>
|
||||
<span v-else>
|
||||
{{ token }}
|
||||
</span>
|
||||
</span>
|
||||
</button>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import baseInputButton from "@/digital-components/base-input-button/base-input-button";
|
||||
import inputButtonWrapperMixin from "@/mixins/input-button-wrapper-mixin";
|
||||
import { splitCopyOnCMSPlaceHolder } from "@/helpers/cms-content-helper";
|
||||
|
||||
const INLINE_IMAGE_TOKEN = "custom:inlineImage";
|
||||
|
||||
function isInlineImageToken(token) {
|
||||
return token.includes(INLINE_IMAGE_TOKEN);
|
||||
}
|
||||
|
||||
function getInlineAltText(token) {
|
||||
let innerTokens = token.split(",");
|
||||
|
||||
return innerTokens[1] ?? "";
|
||||
}
|
||||
|
||||
export default {
|
||||
name: "payment-switch-button",
|
||||
mixins: [inputButtonWrapperMixin],
|
||||
props: {
|
||||
buttonText: String,
|
||||
buttonImage: String,
|
||||
buttonImageId: String,
|
||||
},
|
||||
methods: {
|
||||
isInlineImageToken,
|
||||
getInlineAltText,
|
||||
handleClick(newValue) {
|
||||
this.$emit("click-event", newValue);
|
||||
handleClick(clickValue) {
|
||||
this.pushEventToGA(
|
||||
this.$route.query[this.queryStrings.FMG_PAGE],
|
||||
this.GaActions.CLICKED,
|
||||
this.buttonText,
|
||||
true
|
||||
);
|
||||
this.$emit("click-event", clickValue);
|
||||
},
|
||||
isInlineImageToken(token) {
|
||||
return token.includes(INLINE_IMAGE_TOKEN);
|
||||
},
|
||||
getInlineAltText(token) {
|
||||
let innerTokens = token.split(",");
|
||||
|
||||
return innerTokens[1] ?? "";
|
||||
},
|
||||
},
|
||||
computed: {
|
||||
tokens() {
|
||||
return splitCopyOnCMSPlaceHolder(this.buttonLabel ?? "");
|
||||
return splitCopyOnCMSPlaceHolder(this.buttonText ?? "");
|
||||
},
|
||||
hasImage() {
|
||||
return !!this.buttonImage;
|
||||
},
|
||||
shouldDisplaySideImage() {
|
||||
return this.hasImage && this.tokens.every((token) => !isInlineImageToken(token));
|
||||
buttonLabelText() {
|
||||
return this.tokens[0];
|
||||
},
|
||||
},
|
||||
components: {
|
||||
baseInputButton,
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped></style>
|
||||
<style lang="scss" scoped>
|
||||
.btn {
|
||||
border: 1px solid $gray-600;
|
||||
border-radius: 8px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -2,24 +2,29 @@
|
|||
<div class="switch-payment-header pb-3">{{ switchPaymentHeaderText }}</div>
|
||||
<div class="switch-payment-button">
|
||||
<paymentSwitchButton
|
||||
v-if="paymentType !== 'cc'"
|
||||
buttonLabel="Credit or Debit"
|
||||
imageSrc="https://digitalconsumercms.dev.safelite.io/images/default-source/default-album/icons/credit-card-group.svg?sfvrsn=553dfb5b_0"
|
||||
@click-event="switchPaymentClick('cc')" />
|
||||
v-if="paymentType !== paymentTypes.cc"
|
||||
:buttonText="paymentMethodsInfo[paymentTypes.cc]?.buttonText"
|
||||
:buttonImage="paymentMethodsInfo[paymentTypes.cc]?.answerImageUrl"
|
||||
:buttonImageId="paymentMethodsInfo[paymentTypes.cc]?.imageId"
|
||||
@click-event="switchPaymentClick(paymentTypes.cc)" />
|
||||
</div>
|
||||
<div class="switch-button-separator py-3" v-if="paymentType !== 'cc'">or</div>
|
||||
<div class="switch-button-separator py-3" v-if="paymentType !== paymentTypes.cc">or</div>
|
||||
<div class="switch-payment-button">
|
||||
<paymentSwitchButton
|
||||
v-if="paymentType !== 'pp'"
|
||||
buttonLabel="PayPal"
|
||||
@click-event="switchPaymentClick('pp')" />
|
||||
v-if="paymentType !== paymentTypes.pp"
|
||||
:buttonText="paymentMethodsInfo[paymentTypes.pp]?.buttonText"
|
||||
:buttonImage="paymentMethodsInfo[paymentTypes.pp]?.answerImageUrl"
|
||||
:buttonImageId="paymentMethodsInfo[paymentTypes.pp]?.imageId"
|
||||
@click-event="switchPaymentClick(paymentTypes.pp)" />
|
||||
</div>
|
||||
<div class="switch-button-separator py-3" v-if="paymentType === 'cc'">or</div>
|
||||
<div class="switch-button-separator py-3" v-if="paymentType === paymentTypes.cc">or</div>
|
||||
<div class="switch-payment-button">
|
||||
<paymentSwitchButton
|
||||
v-if="paymentType !== 'ap'"
|
||||
buttonLabel="Afterpay"
|
||||
@click-event="switchPaymentClick('ap')" />
|
||||
v-if="paymentType !== paymentTypes.ap"
|
||||
:buttonText="paymentMethodsInfo[paymentTypes.ap]?.buttonText"
|
||||
:buttonImage="paymentMethodsInfo[paymentTypes.ap]?.answerImageUrl"
|
||||
:buttonImageId="paymentMethodsInfo[paymentTypes.ap]?.imageId"
|
||||
@click-event="switchPaymentClick(paymentTypes.ap)" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
@ -29,7 +34,13 @@ import paymentSwitchButton from "./payment-switch-button/payment-switch-button";
|
|||
export default {
|
||||
name: "paymentSwitch",
|
||||
data() {
|
||||
return {};
|
||||
return {
|
||||
paymentTypes: {
|
||||
cc: "cc",
|
||||
pp: "pp",
|
||||
ap: "ap",
|
||||
},
|
||||
};
|
||||
},
|
||||
props: {
|
||||
cmsWidgetName: String,
|
||||
|
|
@ -39,14 +50,24 @@ export default {
|
|||
switchPaymentHeaderText() {
|
||||
return this.getCmsContent(this.cmsWidgetName, "QuestionText");
|
||||
},
|
||||
ccButtonText() {
|
||||
return this.getCmsContent(this.cmsWidgetName, "QuestionText");
|
||||
paymentMethodAnswerData() {
|
||||
const rawData = this.getCmsContent(this.cmsWidgetName, "Answers");
|
||||
|
||||
if (!rawData) {
|
||||
return [];
|
||||
} else {
|
||||
return rawData;
|
||||
}
|
||||
},
|
||||
ppButtonText() {
|
||||
return this.getCmsContent(this.cmsWidgetName, "QuestionText");
|
||||
},
|
||||
apButtonText() {
|
||||
return this.getCmsContent(this.cmsWidgetName, "QuestionText");
|
||||
paymentMethodsInfo() {
|
||||
return this.paymentMethodAnswerData.reduce((accumulator, paymentMethod) => {
|
||||
accumulator[paymentMethod.Name] = {
|
||||
buttonText: paymentMethod.Text,
|
||||
answerImageUrl: paymentMethod.AnswerImageUrl,
|
||||
imageId: paymentMethod.ImageId,
|
||||
};
|
||||
return accumulator;
|
||||
}, {});
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
|
|
|||
Loading…
Reference in a new issue