| 1 |
<template> |
| 2 |
<div class="wpfnl-template-preview-wrapper"> |
| 3 |
<div class="wpfnl-template-steps-wrapper"> |
| 4 |
<div v-for="step in displaySteps" class="wpfnl-template-step" :class="activeStep.ID === step.ID ? 'active' : ''" @click="setActiveStep(step)"> |
| 5 |
<span> |
| 6 |
<figure> |
| 7 |
<img :src="step.featured_image" :alt="step.title"> |
| 8 |
</figure> |
| 9 |
</span> |
| 10 |
|
| 11 |
<p>{{ step.step_type }}</p> |
| 12 |
</div> |
| 13 |
</div> |
| 14 |
|
| 15 |
<div class="wpfnl-template-step-preview" :class="view"> |
| 16 |
<div class="speaker-mike"> |
| 17 |
<span class="large-speaker"></span> |
| 18 |
<span class="small-speaker"></span> |
| 19 |
</div> |
| 20 |
|
| 21 |
<div class="wpfnl-template-iframe-wrapper"> |
| 22 |
<iframe v-if="!shouldShowImagePreview(activeStep)" :src="activeStep?.link" width="100%" height="600px" @load="iframeLoaded"></iframe> |
| 23 |
<div v-if="!shouldShowImagePreview(activeStep)" class="wpfnl-loader-wrapper" :class="isLoading ? 'active' : ''"> |
| 24 |
<span class="wpfnl-loader"></span> |
| 25 |
</div> |
| 26 |
|
| 27 |
<div v-if="shouldShowImagePreview(activeStep)" class="wpfnl-preview-checkout-placeholder"> |
| 28 |
<img :src="getStepImageForView(activeStep)" :alt="activeStep?.title"> |
| 29 |
</div> |
| 30 |
</div> |
| 31 |
</div> |
| 32 |
</div> |
| 33 |
</template> |
| 34 |
|
| 35 |
<script> |
| 36 |
export default { |
| 37 |
name: 'TemplatePreview', |
| 38 |
props: { |
| 39 |
template:{ |
| 40 |
type: Object, |
| 41 |
default: { |
| 42 |
steps: [], |
| 43 |
} |
| 44 |
}, |
| 45 |
view: { |
| 46 |
type: String, |
| 47 |
default: 'desktop' |
| 48 |
} |
| 49 |
}, |
| 50 |
data() { |
| 51 |
return { |
| 52 |
activeStep: {}, |
| 53 |
isLoading: true, |
| 54 |
isStoreCheckout: window.template_library_object.isStoreCheckout || false, |
| 55 |
} |
| 56 |
}, |
| 57 |
computed: { |
| 58 |
displaySteps() { |
| 59 |
if (!this.template || !this.template.steps) return []; |
| 60 |
|
| 61 |
// Filter for Store Checkout - only show one checkout and one thankyou |
| 62 |
if (this.isStoreCheckout) { |
| 63 |
let filtered = []; |
| 64 |
let hasCheckout = false; |
| 65 |
let hasThankyou = false; |
| 66 |
|
| 67 |
this.template.steps.forEach(step => { |
| 68 |
if (step.step_type === 'checkout' && !hasCheckout) { |
| 69 |
filtered.push(step); |
| 70 |
hasCheckout = true; |
| 71 |
} else if (step.step_type === 'thankyou' && !hasThankyou) { |
| 72 |
filtered.push(step); |
| 73 |
hasThankyou = true; |
| 74 |
} |
| 75 |
}); |
| 76 |
|
| 77 |
return filtered; |
| 78 |
} |
| 79 |
|
| 80 |
return this.template.steps; |
| 81 |
} |
| 82 |
}, |
| 83 |
mounted() { |
| 84 |
if (this.displaySteps && this.displaySteps.length > 0) { |
| 85 |
this.activeStep = this.displaySteps[0]; |
| 86 |
} else { |
| 87 |
this.activeStep = {}; |
| 88 |
} |
| 89 |
}, |
| 90 |
methods: { |
| 91 |
getStepImageForView(step) { |
| 92 |
if (!step) { |
| 93 |
return ''; |
| 94 |
} |
| 95 |
|
| 96 |
if (this.view === 'desktop') { |
| 97 |
return step.desktop_view_image || ''; |
| 98 |
} |
| 99 |
|
| 100 |
if (this.view === 'tablet') { |
| 101 |
return step.tablet_view_image || ''; |
| 102 |
} |
| 103 |
|
| 104 |
if (this.view === 'mobile') { |
| 105 |
return step.mobile_view_image || ''; |
| 106 |
} |
| 107 |
|
| 108 |
return ''; |
| 109 |
}, |
| 110 |
shouldShowImagePreview(step) { |
| 111 |
const stepType = step?.step_type; |
| 112 |
if (stepType !== 'checkout' && stepType !== 'thankyou') { |
| 113 |
return false; |
| 114 |
} |
| 115 |
|
| 116 |
return !!this.getStepImageForView(step); |
| 117 |
}, |
| 118 |
setActiveStep(step) { |
| 119 |
this.activeStep = step; |
| 120 |
this.isLoading = true; // Show loader when a new step is selected |
| 121 |
}, |
| 122 |
iframeLoaded() { |
| 123 |
this.isLoading = false; // Hide loader when iframe has loaded |
| 124 |
}, |
| 125 |
} |
| 126 |
} |
| 127 |
</script> |