|
| 1 | +<template> |
| 2 | + <div class="wmde-banner-wrapper" :class="contentState"> |
| 3 | + <MiniBanner |
| 4 | + @close="() => onClose( 'MiniBanner', CloseChoices.Close )" |
| 5 | + @show-full-page-banner="onshowFullPageBanner" |
| 6 | + @show-full-page-banner-preselected="onshowFullPageBannerPreselected" |
| 7 | + @showFundsModal="onShowFundsModal( 'MiniBanner' )" |
| 8 | + @already-donated-clicked="onClose( 'MiniBanner', CloseChoices.AlreadyDonated )" |
| 9 | + > |
| 10 | + <template #banner-slides> |
| 11 | + <KeenSlider :with-navigation="false" :play="slideshowShouldPlay" :interval="7000"> |
| 12 | + |
| 13 | + <template #slides="{ currentSlide }: any"> |
| 14 | + <BannerSlides :currentSlide="currentSlide" :play-live-text="contentState === ContentStates.Mini"> |
| 15 | + <template #progress><ProgressBar amount-to-show-on-right="TARGET"/></template> |
| 16 | + </BannerSlides> |
| 17 | + </template> |
| 18 | + |
| 19 | + </KeenSlider> |
| 20 | + </template> |
| 21 | + </MiniBanner> |
| 22 | + |
| 23 | + <FullPageBanner |
| 24 | + @showFundsModal="onShowFundsModal( 'FullPageBanner' )" |
| 25 | + @close="() => onClose( 'FullPageBanner', CloseChoices.Hide )" |
| 26 | + > |
| 27 | + <template #banner-text> |
| 28 | + <BannerText :play-live-text="contentState === ContentStates.FullPage"/> |
| 29 | + </template> |
| 30 | + |
| 31 | + <template #progress> |
| 32 | + <ProgressBar amount-to-show-on-right="TARGET"/> |
| 33 | + </template> |
| 34 | + |
| 35 | + <template #donation-form="{ formInteraction }: any"> |
| 36 | + <MultiStepDonation |
| 37 | + :step-controllers="stepControllers" |
| 38 | + @form-interaction="formInteraction" |
| 39 | + :page-scroller="pageScroller" |
| 40 | + :submit-callback="onSubmit" |
| 41 | + > |
| 42 | + |
| 43 | + <template #[FormStepNames.MainDonationFormStep]="{ pageIndex, submit, isCurrent, previous }: any"> |
| 44 | + <MainDonationForm |
| 45 | + :page-index="pageIndex" |
| 46 | + @submit="submit" |
| 47 | + :is-current="isCurrent" |
| 48 | + @previous="previous" |
| 49 | + :dynamic-amounts="amountOptionsForForm" |
| 50 | + > |
| 51 | + |
| 52 | + <template #button> |
| 53 | + <MainDonationFormButton/> |
| 54 | + </template> |
| 55 | + |
| 56 | + </MainDonationForm> |
| 57 | + </template> |
| 58 | + |
| 59 | + <template #[FormStepNames.UpgradeToYearlyFormStep]="{ pageIndex, submit, isCurrent, previous }: any"> |
| 60 | + <UpgradeToYearlyButtonForm |
| 61 | + :page-index="pageIndex" |
| 62 | + @submit="submit" |
| 63 | + :is-current="isCurrent" |
| 64 | + @previous="previous" |
| 65 | + > |
| 66 | + <template #back> |
| 67 | + <ChevronLeftIcon/> |
| 68 | + {{ $translate( 'back-button' ) }} |
| 69 | + </template> |
| 70 | + </UpgradeToYearlyButtonForm> |
| 71 | + </template> |
| 72 | + |
| 73 | + </MultiStepDonation> |
| 74 | + </template> |
| 75 | + |
| 76 | + <template #footer> |
| 77 | + <BannerFooter :show-funds-link="false"/> |
| 78 | + </template> |
| 79 | + </FullPageBanner> |
| 80 | + |
| 81 | + <FundsModal |
| 82 | + :content="useOfFundsContent" |
| 83 | + :visible="isFundsModalVisible" |
| 84 | + @hide="onHideFundsModal" |
| 85 | + @callToAction="onFundsModalCallToAction" |
| 86 | + /> |
| 87 | + </div> |
| 88 | +</template> |
| 89 | + |
| 90 | +<script setup lang="ts"> |
| 91 | +import { BannerStates } from '@src/components/BannerConductor/StateMachine/BannerStates'; |
| 92 | +import { computed, inject, ref, watch } from 'vue'; |
| 93 | +import FullPageBanner from './FullPageBanner.vue'; |
| 94 | +import MiniBanner from './MiniBanner.vue'; |
| 95 | +import FundsModal from '@src/components/UseOfFunds/UseOfFundsModal.vue'; |
| 96 | +import { UseOfFundsContent as useOfFundsContentInterface } from '@src/domain/UseOfFunds/UseOfFundsContent'; |
| 97 | +import { PageScroller } from '@src/utils/PageScroller/PageScroller'; |
| 98 | +import MainDonationForm from '@src/components/DonationForm/Forms/MainDonationForm.vue'; |
| 99 | +import MultiStepDonation from '@src/components/DonationForm/MultiStepDonation.vue'; |
| 100 | +import BannerText from '../content/BannerText.vue'; |
| 101 | +import BannerSlides from '../content/BannerSlides.vue'; |
| 102 | +import BannerFooter from '@src/components/Footer/BannerFooter.vue'; |
| 103 | +import KeenSlider from '@src/components/Slider/KeenSlider.vue'; |
| 104 | +import { Tracker } from '@src/tracking/Tracker'; |
| 105 | +import { MobileMiniBannerExpandedEvent } from '@src/tracking/events/MobileMiniBannerExpandedEvent'; |
| 106 | +import { useFormModel } from '@src/components/composables/useFormModel'; |
| 107 | +import UpgradeToYearlyButtonForm from '@src/components/DonationForm/Forms/UpgradeToYearlyButtonForm.vue'; |
| 108 | +import ChevronLeftIcon from '@src/components/Icons/ChevronLeftIcon.vue'; |
| 109 | +import { CloseChoices } from '@src/domain/CloseChoices'; |
| 110 | +import { CloseEvent } from '@src/tracking/events/CloseEvent'; |
| 111 | +import { TrackingFeatureName } from '@src/tracking/TrackingEvent'; |
| 112 | +import { |
| 113 | + createSubmittableMainDonationForm |
| 114 | +} from '@src/components/DonationForm/StepControllers/SubmittableMainDonationForm'; |
| 115 | +import { |
| 116 | + createSubmittableUpgradeToYearly |
| 117 | +} from '@src/components/DonationForm/StepControllers/SubmittableUpgradeToYearly'; |
| 118 | +import MainDonationFormButton |
| 119 | + from '@src/components/DonationForm/SubComponents/SubmitButtons/MainDonationFormButton.vue'; |
| 120 | +import { LocalCloseTracker } from '@src/utils/LocalCloseTracker'; |
| 121 | +import { BannerSubmitOnReturnEvent } from '@src/tracking/events/BannerSubmitOnReturnEvent'; |
| 122 | +import { FormItem } from '@src/utils/FormItemsBuilder/FormItem'; |
| 123 | +import FormItemsBuilder from '@src/utils/FormItemsBuilder/FormItemsBuilder'; |
| 124 | +import { Translator } from '@src/Translator'; |
| 125 | +import { Currency } from '@src/utils/DynamicContent/formatters/Currency'; |
| 126 | +import { UseOfFundsShownEvent } from '@src/tracking/events/UseOfFundsShownEvent'; |
| 127 | +import ProgressBar from '@src/components/ProgressBar/ProgressBar.vue'; |
| 128 | +
|
| 129 | +enum ContentStates { |
| 130 | + Mini = 'wmde-banner-wrapper--mini', |
| 131 | + FullPage = 'wmde-banner-wrapper--full-page' |
| 132 | +} |
| 133 | +
|
| 134 | +enum FormStepNames { |
| 135 | + MainDonationFormStep = 'MainDonationForm', |
| 136 | + UpgradeToYearlyFormStep = 'UpgradeToYearlyForm' |
| 137 | +} |
| 138 | +
|
| 139 | +interface Props { |
| 140 | + bannerState: BannerStates; |
| 141 | + useOfFundsContent: useOfFundsContentInterface; |
| 142 | + pageScroller: PageScroller; |
| 143 | + localCloseTracker: LocalCloseTracker; |
| 144 | +} |
| 145 | +
|
| 146 | +const props = defineProps<Props>(); |
| 147 | +const emit = defineEmits( [ 'bannerClosed', 'bannerContentChanged', 'modalOpened', 'modalClosed' ] ); |
| 148 | +
|
| 149 | +const tracker = inject<Tracker>( 'tracker' ); |
| 150 | +
|
| 151 | +const isFundsModalVisible = ref<boolean>( false ); |
| 152 | +const slideShowStopped = ref<boolean>( false ); |
| 153 | +const slideshowShouldPlay = computed( () => props.bannerState === BannerStates.Visible && !slideShowStopped.value ); |
| 154 | +const contentState = ref<ContentStates>( ContentStates.Mini ); |
| 155 | +const formModel = useFormModel(); |
| 156 | +const stepControllers = [ |
| 157 | + createSubmittableMainDonationForm( formModel, FormStepNames.UpgradeToYearlyFormStep ), |
| 158 | + createSubmittableUpgradeToYearly( formModel, FormStepNames.MainDonationFormStep, FormStepNames.MainDonationFormStep ) |
| 159 | +]; |
| 160 | +
|
| 161 | +const localTranslator = inject<Translator>( 'translator' ); |
| 162 | +const currencyFormatter = inject<Currency>( 'currencyFormatter' ); |
| 163 | +
|
| 164 | +const localFormItemsBuilder = new FormItemsBuilder( localTranslator, currencyFormatter.euroAmount.bind( currencyFormatter ) ); |
| 165 | +const amountOptionsFive = localFormItemsBuilder.setAmounts( 5, 15, 25, 50, 100 ).getItems().amounts; |
| 166 | +const amountOptionsTen = localFormItemsBuilder.setAmounts( 10, 15, 25, 50, 100 ).getItems().amounts; |
| 167 | +const amountOptionsForForm = ref<FormItem[]>( amountOptionsTen ); |
| 168 | +
|
| 169 | +watch( contentState, async () => { |
| 170 | + emit( 'bannerContentChanged' ); |
| 171 | +} ); |
| 172 | +
|
| 173 | +function onClose( feature: TrackingFeatureName, userChoice: CloseChoices ): void { |
| 174 | + emit( 'bannerClosed', new CloseEvent( feature, userChoice ) ); |
| 175 | + emit( 'modalClosed' ); |
| 176 | +} |
| 177 | +
|
| 178 | +const onSubmit = (): void => { |
| 179 | + const closeChoice = props.localCloseTracker.getItem(); |
| 180 | + if ( closeChoice !== '' ) { |
| 181 | + tracker.trackEvent( new BannerSubmitOnReturnEvent( closeChoice ) ); |
| 182 | + } |
| 183 | +}; |
| 184 | +
|
| 185 | +function onshowFullPageBanner(): void { |
| 186 | + slideShowStopped.value = true; |
| 187 | + contentState.value = ContentStates.FullPage; |
| 188 | + emit( 'modalOpened' ); |
| 189 | +
|
| 190 | + amountOptionsForForm.value = amountOptionsFive; |
| 191 | +
|
| 192 | + tracker.trackEvent( new MobileMiniBannerExpandedEvent() ); |
| 193 | +} |
| 194 | +
|
| 195 | +function onshowFullPageBannerPreselected(): void { |
| 196 | + slideShowStopped.value = true; |
| 197 | +
|
| 198 | + amountOptionsForForm.value = amountOptionsTen; |
| 199 | +
|
| 200 | + formModel.selectedAmount.value = '10'; |
| 201 | + contentState.value = ContentStates.FullPage; |
| 202 | + tracker.trackEvent( new MobileMiniBannerExpandedEvent( 'preselected' ) ); |
| 203 | +} |
| 204 | +
|
| 205 | +const onHideFundsModal = (): void => { |
| 206 | + isFundsModalVisible.value = false; |
| 207 | +
|
| 208 | + if ( contentState.value === ContentStates.Mini ) { |
| 209 | + emit( 'modalClosed' ); |
| 210 | + } |
| 211 | +
|
| 212 | + if ( contentState.value === ContentStates.FullPage ) { |
| 213 | + props.pageScroller.scrollIntoView( '.wmde-banner-form' ); |
| 214 | + } |
| 215 | +}; |
| 216 | +
|
| 217 | +const onShowFundsModal = ( feature: TrackingFeatureName ): void => { |
| 218 | + isFundsModalVisible.value = true; |
| 219 | + tracker.trackEvent( new UseOfFundsShownEvent( feature ) ); |
| 220 | +
|
| 221 | + if ( contentState.value === ContentStates.Mini ) { |
| 222 | + emit( 'modalOpened' ); |
| 223 | + } |
| 224 | +}; |
| 225 | +
|
| 226 | +const onFundsModalCallToAction = (): void => { |
| 227 | + isFundsModalVisible.value = false; |
| 228 | +
|
| 229 | + if ( contentState.value === ContentStates.Mini ) { |
| 230 | + onshowFullPageBanner(); |
| 231 | + } |
| 232 | +
|
| 233 | + props.pageScroller.scrollIntoView( '.wmde-banner-form' ); |
| 234 | +}; |
| 235 | +
|
| 236 | +</script> |
0 commit comments