Skip to content

Commit

Permalink
Implement VAR for C24_WMDE_Desktop_EN_05
Browse files Browse the repository at this point in the history
VAR has a new main donation form with an address
checkbox.

Ticket: https://phabricator.wikimedia.org/T380360
  • Loading branch information
Abban committed Nov 22, 2024
1 parent 38ac67f commit 7390a86
Show file tree
Hide file tree
Showing 14 changed files with 597 additions and 21 deletions.
6 changes: 3 additions & 3 deletions banners/english/C24_WMDE_Desktop_EN_05/banner_var.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createVueApp } from '@src/createVueApp';

import './styles/styles.scss';
import './styles/styles_var.scss';

import BannerConductor from '@src/components/BannerConductor/FallbackBannerConductor.vue';
import Banner from './components/BannerVar.vue';
Expand All @@ -17,7 +17,7 @@ import DynamicTextPlugin from '@src/DynamicTextPlugin';
import { LocalImpressionCount } from '@src/utils/LocalImpressionCount';
import { LegacyTrackerWPORG } from '@src/tracking/LegacyTrackerWPORG';
import { Locales } from '@src/domain/Locales';
import messages from './messages';
import messages from './messages_var';
import { LocaleFactoryEn } from '@src/utils/LocaleFactory/LocaleFactoryEn';
import { createFormItems } from './form_items';
import { createFormActions } from '@src/createFormActions';
Expand Down Expand Up @@ -64,7 +64,7 @@ const currencyFormatter = localeFactory.getCurrencyFormatter();

app.provide( 'currencyFormatter', currencyFormatter );
app.provide( 'formItems', createFormItems( translator, currencyFormatter.euroAmount.bind( currencyFormatter ) ) );
app.provide( 'formActions', createFormActions( page.getTracking(), impressionCount, { locale: Locales.EN, afo: '1' } ) );
app.provide( 'formActions', createFormActions( page.getTracking(), impressionCount, { locale: Locales.EN } ) );
app.provide( 'tracker', tracker );
app.provide( 'timer', new WindowTimer() );

Expand Down
14 changes: 5 additions & 9 deletions banners/english/C24_WMDE_Desktop_EN_05/components/BannerVar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<MultiStepDonation :step-controllers="stepControllers" @form-interaction="formInteraction">

<template #[FormStepNames.MainDonationFormStep]="{ pageIndex, submit, isCurrent, previous }: any">
<MainDonationForm :page-index="pageIndex" @submit="submit" :is-current="isCurrent" @previous="previous">
<MainDonationFormAddressType :page-index="pageIndex" @submit="submit" :is-current="isCurrent" @previous="previous">
<template #label-payment-ppl>
<span class="wmde-banner-select-group-label with-logos paypal"><PayPalLogo/></span>
</template>
Expand All @@ -39,7 +39,7 @@
<MastercardLogo/>
</span>
</template>
</MainDonationForm>
</MainDonationFormAddressType>
</template>

<template #[FormStepNames.UpgradeToYearlyFormStep]="{ pageIndex, submit, isCurrent, previous }: any">
Expand Down Expand Up @@ -90,18 +90,13 @@ import FundsModal from '@src/components/UseOfFunds/FundsModal.vue';
import { UseOfFundsContent as useOfFundsContentInterface } from '@src/domain/UseOfFunds/UseOfFundsContent';
import UpgradeToYearlyButtonForm from '@src/components/DonationForm/Forms/UpgradeToYearlyButtonForm.vue';
import BannerSlides from '../content/BannerSlides.vue';
import MainDonationForm from '@src/components/DonationForm/Forms/MainDonationForm.vue';
import MultiStepDonation from '@src/components/DonationForm/MultiStepDonation.vue';
import BannerText from '../content/BannerText.vue';
import KeenSlider from '@src/components/Slider/KeenSlider.vue';
import FooterAlreadyDonated from '@src/components/Footer/FooterAlreadyDonated.vue';
import { useFormModel } from '@src/components/composables/useFormModel';
import {
createSubmittableMainDonationForm
} from '@src/components/DonationForm/StepControllers/SubmittableMainDonationForm';
import {
createSubmittableUpgradeToYearly
} from '@src/components/DonationForm/StepControllers/SubmittableUpgradeToYearly';
import { createSubmittableMainDonationForm } from '@src/components/DonationForm/StepControllers/SubmittableMainDonationForm';
import { createSubmittableUpgradeToYearly } from '@src/components/DonationForm/StepControllers/SubmittableUpgradeToYearly';
import { CloseChoices } from '@src/domain/CloseChoices';
import { CloseEvent } from '@src/tracking/events/CloseEvent';
import { TrackingFeatureName } from '@src/tracking/TrackingEvent';
Expand All @@ -112,6 +107,7 @@ import ProgressBar from '@src/components/ProgressBar/ProgressBarAlternative.vue'
import SoftClose from '@src/components/SoftClose/SoftClose.vue';
import WMDEFundsForwardingEN from '@src/components/UseOfFunds/Infographics/WMDEFundsForwardingEN.vue';
import { useBannerHider } from '@src/components/composables/useBannerHider';
import MainDonationFormAddressType from '@src/components/DonationForm/Forms/MainDonationFormDonationReceipt.vue';
enum ContentStates {
Main = 'wmde-banner-wrapper--main',
Expand Down
3 changes: 1 addition & 2 deletions banners/english/C24_WMDE_Desktop_EN_05/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const messages: TranslationMessages = {
...FallbackBanner,
'upgrade-to-yearly-copy': '<p>Every year we are dependent on the support of people like you. Yearly donations ' +
'help sustainably and enable long term development.</p>' +
'<p>No risks attached, you can tell us to stop at any time.</p>',
'cover-transaction-costs': 'I\'ll generously add {{transactionCosts}} to cover the transaction fees so you can keep 100% of my donation.'
'<p>No risks attached, you can tell us to stop at any time.</p>'
};

export default messages;
28 changes: 28 additions & 0 deletions banners/english/C24_WMDE_Desktop_EN_05/messages_var.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import CustomAmountFormEn from '@src/components/DonationForm/Forms/messages/CustomAmountForm.en';
import DynamicCampaignTextEn from '@src/utils/DynamicContent/messages/DynamicCampaignText.en';
import { TranslationMessages } from '@src/Translator';
import UpgradeToYearlyEn from '@src/components/DonationForm/Forms/messages/UpgradeToYearly.en';
import SoftCloseEn from '@src/components/SoftClose/messages/SoftClose.en';
import AddressFormEn from '@src/components/DonationForm/Forms/messages/AddressForm.en';
import FooterEn from '@src/components/Footer/messages/Footer.en';
import MainDonationFormEn from '@src/components/DonationForm/Forms/messages/MainDonationForm.en';
import AlreadyDonatedModalEn from '@src/components/AlreadyDonatedModal/translations/AlreadyDonatedModal.en';
import FallbackBanner from '@src/components/FallbackBanner/messages/FallbackBanner.en';

const messages: TranslationMessages = {
...CustomAmountFormEn,
...DynamicCampaignTextEn,
...UpgradeToYearlyEn,
...SoftCloseEn,
...AddressFormEn,
...FooterEn,
...MainDonationFormEn,
...AlreadyDonatedModalEn,
...FallbackBanner,
'upgrade-to-yearly-copy': '<p>Every year we are dependent on the support of people like you. Yearly donations ' +
'help sustainably and enable long term development.</p>' +
'<p>No risks attached, you can tell us to stop at any time.</p>',
'donation-receipt-checkbox-label': 'Please send me a tax deductible donation receipt to my postal address.'
};

export default messages;
60 changes: 60 additions & 0 deletions banners/english/C24_WMDE_Desktop_EN_05/styles/styles_var.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// This is the file where we import the theme-specific component styles
@use 'src/themes/Treedip/swatches/skin_vector-2022' with (
$slider: true,
$select-group-bubble: true,
$select-group-image-label: true,
$upgrade-to-yearly: true,
$fallback-banner: true,
$progress-bar: true,
$soft-close: true,
);
@use 'src/themes/Treedip/variables/breakpoints';
@use 'src/components/BannerConductor/banner-transition';
@use 'Banner';
@use 'MainBanner' with (
$banner-height: 355px,
$form-width: 300px
);
@use 'src/themes/UseOfFunds/swatches/skin_vector-2022' as uof-vector-2022;
@use 'src/themes/UseOfFunds/UseOfFunds';
@use 'src/themes/Treedip/defaults';
@use 'src/themes/Treedip/ButtonClose/ButtonClose' with (
$padding: 4px,
$top: 12px,
$right: 8px,
$margin: -4.5px
);
@use 'src/themes/Treedip/ProgressBar/ProgressBarAlternative' with (
$progress-bar-margin: 0 15px
);
@use 'src/themes/Treedip/DonationForm/DonationForm';
@use 'src/themes/Treedip/DonationForm/MultiStepDonation';
@use 'src/themes/Treedip/DonationForm/BubbleForm/SelectGroupBubble';
@use 'src/themes/Treedip/DonationForm/BubbleForm/SelectGroupRadioBubbles' with (
$height: 34px,
$font-size: 14px
);
@use 'src/themes/Treedip/DonationForm/BubbleForm/SelectCustomAmountRadioBubble' with (
$height: 34px,
$font-size: 14px
);
@use 'src/themes/Treedip/DonationForm/BubbleForm/SelectGroupBubbleImageLabel';
@use 'src/themes/Treedip/DonationForm/SubComponents/SmsBox';
@use 'src/themes/Treedip/DonationForm/Forms/MainDonationFormDonationReceipt' with (
$padding: 14px 0 0
);
@use 'src/themes/Treedip/DonationForm/Forms/UpgradeToYearlyButtonForm';
@use 'src/themes/Treedip/DonationForm/Forms/CustomAmountForm';
@use 'src/themes/Treedip/Footer/FooterAlreadyDonated' with (
$right-column-width: 300px
);
@use 'src/themes/Treedip/Footer/SelectionInput';
@use 'src/themes/Treedip/Message/Message' with (
$font-sizes: ( 1400px: 15px, 1600px: 16px, 1800px: 18px )
);
@use 'src/themes/Treedip/Slider/KeenSlider';
@use 'src/themes/Treedip/SoftClose/SoftClose';
@use 'FallbackBanner';
@use 'src/themes/Fijitiv/FallbackBanner/FallbackButton';
@use 'src/themes/Fijitiv/FallbackBanner/LargeFooter';
@use 'src/themes/Fijitiv/FallbackBanner/SmallFooter';
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@mixin layout {
&-sub-form-donation {
.wmde-banner-form-field-group {
border: 0;
margin: 0;
display: block;

&-legend {
width: 100%;
position: relative;
padding: 0;
}
}
}

.wmde-banner-form-donation-receipt-checkbox {
display: inline-block;
cursor: pointer;
position: relative;
padding: 0 0 10px 24px;

input[ type='checkbox' ] {
display: block;
float: left;
height: 16px;
margin: 0 0 0 -24px;
transition: background 0.15s ease-out;
width: 16px;
}
}
}
176 changes: 176 additions & 0 deletions src/components/DonationForm/Forms/MainDonationFormDonationReceipt.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
<template>
<form
method="post"
class="wmde-banner-sub-form wmde-banner-sub-form-donation"
@submit.prevent="validate"
>
<fieldset class="wmde-banner-form-field-group">
<legend class="wmde-banner-form-field-group-legend">{{ $translate( 'intervals-header' ) }}</legend>
<SelectGroup
:field-name="'select-interval'"
:selectionItems="formItems.intervals"
:isValid="isValidOrUnset( intervalValidity )"
:errorMessage="$translate( 'no-interval-message' )"
v-model:inputValue="interval"
:disabledOptions="disabledIntervals"
/>
</fieldset>

<fieldset class="wmde-banner-form-field-group">
<legend class="wmde-banner-form-field-group-legend">{{ $translate( 'amounts-header' ) }}</legend>
<SelectGroup
fieldName="select-amount"
:selectionItems="formItems.amounts"
:isValid="isValidOrUnset( amountValidity )"
:errorMessage="$translate( amountValidityMessageKey( amountValidity ) )"
v-model:inputValue="selectedAmount"
>
<SelectCustomAmount
fieldName="select-amount"
v-model:inputValue="customAmount"
@focus="clearSelectedAmount"
@blur="formatCustomAmount"
:placeholder="$translate( customAmountPlaceholderKey )"
/>
</SelectGroup>
</fieldset>

<fieldset class="wmde-banner-form-field-group">
<legend class="wmde-banner-form-field-group-legend">{{ $translate( 'payments-header' ) }}</legend>
<SelectGroup
:field-name="'select-payment-method'"
:selectionItems="formItems.paymentMethods"
:isValid="isValidOrUnset( paymentMethodValidity )"
:errorMessage="$translate( 'no-payment-type-message' )"
v-model:inputValue="paymentMethod"
:disabledOptions="disabledPaymentMethods"
>
<template #select-group-label="{ label, slotName }: any">
<slot :name="'label-' + slotName" :label="label"/>
</template>
<SmsBox>
<template #sms-icon>
<slot name="sms-icon"/>
</template>
</SmsBox>
</SelectGroup>
</fieldset>

<div class="wmde-banner-form-donation-receipt-checkbox" v-if="showReceiptCheckbox">
<input
class="wmde-banner-form-field-checkbox"
type="checkbox"
value="person"
id="wmde-banner-form-donation-receipt"
v-model="receiptNeeded"
>
<label for="wmde-banner-form-donation-receipt">
{{ $translate( 'donation-receipt-checkbox-label' ) }}
</label>
</div>

<div class="wmde-banner-form-button-container">
<slot name="button">
<MainDonationFormButtonMultiStep/>
</slot>
<button v-if="!isFormValid && showErrorScrollLink" class="wmde-banner-form-button-error">
{{ $translate( 'global-error' ) }}
</button>
</div>
</form>
</template>

<script lang="ts">
// All form components must have names
export default {
name: 'MainDonationFormDonationReceipt'
};
</script>
<script setup lang="ts">
import { computed, inject, onMounted, ref, watch } from 'vue';
import SelectGroup from '@src/components/DonationForm/SubComponents/SelectGroup.vue';
import { DonationFormItems } from '@src/utils/FormItemsBuilder/DonationFormItems';
import SelectCustomAmount from '@src/components/DonationForm/SubComponents/SelectCustomAmount.vue';
import SmsBox from '@src/components/DonationForm/SubComponents/SmsBox.vue';
import { useFormModel } from '@src/components/composables/useFormModel';
import { newDonationFormValidator } from '@src/validation/DonationFormValidator';
import { amountValidityMessageKey } from '@src/utils/amountValidityMessageKey';
import { isValidOrUnset } from '@src/components/DonationForm/Forms/isValidOrUnset';
import { Currency } from '@src/utils/DynamicContent/formatters/Currency';
import MainDonationFormButtonMultiStep from '@src/components/DonationForm/Forms/MainDonationFormButtonMultiStep.vue';
import { AddressTypes } from '@src/utils/FormItemsBuilder/fields/AddressTypes';
import { PaymentMethods } from '@src/utils/FormItemsBuilder/fields/PaymentMethods';
interface Props {
showErrorScrollLink?: boolean;
customAmountPlaceholderKey?: string;
}
withDefaults( defineProps<Props>(), {
showErrorScrollLink: false,
customAmountPlaceholderKey: 'custom-amount-placeholder'
} );
const emit = defineEmits( [ 'submit' ] );
const currencyFormatter = inject<Currency>( 'currencyFormatter' );
const formItems = inject<DonationFormItems>( 'formItems' );
const formModel = useFormModel();
const validator = newDonationFormValidator( formModel );
const showReceiptCheckbox = computed<boolean>( () => {
if ( interval.value === '' ) {
return false;
}
if ( paymentMethod.value === '' || paymentMethod.value === PaymentMethods.DIRECT_DEBIT.value ) {
return false;
}
if ( numericAmount.value === 0 ) {
return false;
}
return true;
} );
const receiptNeeded = ref<boolean>( false );
const isFormValid = ref<boolean>( true );
const validate = (): void => {
isFormValid.value = validator.validate();
if ( isFormValid.value ) {
emit( 'submit' );
}
};
const {
interval, intervalValidity, disabledIntervals,
selectedAmount, customAmount, numericAmount, amountValidity,
paymentMethod, paymentMethodValidity, disabledPaymentMethods,
addressType
} = formModel;
const clearSelectedAmount = (): void => {
selectedAmount.value = '';
};
const formatCustomAmount = (): void => {
if ( customAmount.value !== '' ) {
customAmount.value = currencyFormatter.customAmountInput( numericAmount.value );
}
};
watch( receiptNeeded, ( newValue: boolean ) => {
addressType.value = newValue ? '' : AddressTypes.ANONYMOUS.value;
} );
watch( [ interval, paymentMethod, numericAmount ], () => {
if ( !showReceiptCheckbox.value ) {
receiptNeeded.value = false;
}
} );
onMounted( () => {
addressType.value = AddressTypes.ANONYMOUS.value;
} );
</script>
Loading

0 comments on commit 7390a86

Please sign in to comment.