Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert membership confirmation to composition API #296

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ global._paq = {
};

config.global.plugins = [ createI18n( { legacy: false, missingWarn: false, fallbackWarn: false } ) ];
config.global.mocks = {
t: ( key: string ) => key,
n: ( key: string ) => key,
};

jest.mock( 'vue-i18n', () => {
return {
...jest.requireActual( 'vue-i18n' ),
useI18n: jest.fn().mockReturnValue( {
t: ( key: string, params?: Object ) => JSON.stringify( { key, ...params } ),
n: ( amount: string, params?: Object ) => JSON.stringify( { amount, ...params } ),
} ),
};
} );
11 changes: 11 additions & 0 deletions src/Domain/Membership/MembershipAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface MembershipAddress {
fullName: string;
salutation: string;
title: string;
email: string;
streetAddress: string;
postalCode: string;
city: string;
countryCode: string;
applicantType: 'person'|'firma';
}
7 changes: 7 additions & 0 deletions src/Domain/Membership/MembershipApplication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface MembershipApplication {
paymentIntervalInMonths: string|number;
membershipFee: string|number;
membershipType: 'active'|'sustaining';
paymentType: string;
incentives: string[];
}
12 changes: 12 additions & 0 deletions src/Domain/Membership/MembershipApplicationConfirmationData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Salutation } from '@src/view_models/Salutation';
import { MembershipApplication } from '@src/Domain/Membership/MembershipApplication';
import { MembershipAddress } from '@src/Domain/Membership/MembershipAddress';

export interface MembershipApplicationConfirmationData {
piwik: {
membershipApplicationConfirmationGoalId: number;
};
salutations: Array<Salutation>;
membershipApplication: MembershipApplication;
address: MembershipAddress;
}
38 changes: 14 additions & 24 deletions src/components/pages/MembershipConfirmation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
:address="confirmationData.address"
:membershipApplication="confirmationData.membershipApplication"
:salutations="salutations"
:address-is-invalid="false"
>
<template #title>
<h1>{{ $t( 'membership_confirmation_thanks_text' ) }}</h1>
</template>

<template #content>
<p v-if="hasIncentives">{{ $t( 'membership_confirmation_success_text_incentive' ) }}</p>
<p v-if="!hasIncentives">{{ $t( 'membership_confirmation_success_text' ) }}</p>
<p v-else>{{ $t( 'membership_confirmation_success_text' ) }}</p>
<p v-if="showBankTransferContent">{{ $t( 'membership_confirmation_success_text_bank_transfer' ) }}</p>
</template>
</MembershipSummary>
Expand All @@ -27,32 +28,21 @@
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
<script setup lang="ts">
import MembershipSummary from '@src/components/shared/MembershipSummary.vue';
import SummaryLinks from '@src/components/pages/membership_confirmation/SummaryLinks.vue';
import MembershipConfirmationBannerNotifier
from '@src/components/pages/membership_confirmation/MembershipConfirmationBannerNotifier.vue';
import { Salutation } from '@src/view_models/Salutation';
import { MembershipApplicationConfirmationData } from '@src/Domain/Membership/MembershipApplicationConfirmationData';

interface Props {
confirmationData: MembershipApplicationConfirmationData;
salutations: Salutation[];
}

const props = defineProps<Props>();
const hasIncentives = props.confirmationData.membershipApplication.incentives?.length > 0;
const showBankTransferContent = props.confirmationData.membershipApplication.paymentType === 'UEB';

export default defineComponent( {
name: 'MembershipConfirmation',
components: {
MembershipConfirmationBannerNotifier,
MembershipSummary,
SummaryLinks,
},
props: [
'confirmationData',
'salutations',
],
computed: {
hasIncentives(): boolean {
return this.confirmationData.membershipApplication.incentives !== undefined
&& this.confirmationData.membershipApplication.incentives.length > 0;
},
showBankTransferContent(): boolean {
return this.$props.confirmationData.membershipApplication.paymentType === 'UEB';
},
},
} );
</script>
102 changes: 35 additions & 67 deletions src/components/pages/MembershipForm.vue
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
<template>
<form name="laika-membership" ref="form" :action="`/apply-for-membership?${trackingParams}`" method="post">
<form name="laika-membership" ref="form" :action="`/apply-for-membership?${campaignParams}`" method="post">
<keep-alive>
<component
ref="currentPage"
:is="currentFormComponent"
v-on:next-page="changePageIndex( 1 )"
v-on:previous-page="changePageIndex( -1 )"
v-bind="currentProperties">
</component>
<PaymentPage
v-if="currentPageIndex === 0"
@next-page="goToAddressPage"
:validate-fee-url="validateFeeUrl"
:payment-amounts="paymentAmounts"
:validate-legacy-bank-data-url="validateLegacyBankDataUrl"
:payment-intervals="paymentIntervals"
:payment-types="paymentTypes"
:validate-bank-data-url="validateBankDataUrl"
:show-membership-type-option="showMembershipTypeOption"
/>
<AddressPage
v-else
@previous-page="goToPaymentPage"
:campaign-values="campaignValues"
:validate-email-url="validateEmailUrl"
:validate-address-url="validateAddressUrl"
:address-validation-patterns="addressValidationPatterns"
:countries="countries"
:date-of-birth-validation-pattern="dateOfBirthValidationPattern"
:salutations="salutations"
:tracking-data="trackingData"
/>
</keep-alive>
</form>
</template>

<script setup lang="ts">
import { Component, computed, ref, watch } from 'vue';
import { inject, ref, watch } from 'vue';
import { Country } from '@src/view_models/Country';
import { CampaignValues } from '@src/view_models/CampaignValues';
import { AddressValidation } from '@src/view_models/Validation';
import { TrackingData } from '@src/view_models/TrackingData';
import { Salutation } from '@src/view_models/Salutation';
import PaymentPage from '@src/components/pages/membership_form/subpages/PaymentPage.vue';
import AddressPage from '@src/components/pages/membership_form/subpages/AddressPage.vue';
import { QUERY_STRING_INJECTION_KEY } from '@src/util/createCampaignQueryString';

interface Props {
validateAddressUrl: string;
Expand All @@ -38,70 +55,21 @@ interface Props {
dateOfBirthValidationPattern: String,
campaignValues: CampaignValues;
trackingData: TrackingData
startPageIndex?: number;
}

const props = withDefaults( defineProps<Props>(), {
startPageIndex: 0,
} );

const currentPageIndex = ref<number>( props.startPageIndex );
const pages = [ PaymentPage, AddressPage ];

const trackingParams = computed( (): string => {
const params = new URLSearchParams( window.location.search );
const campaign = params.get( 'piwik_campaign' );
const kwd = params.get( 'piwik_kwd' );
if ( kwd && campaign ) {
return `piwik_campaign=${campaign}&piwik_kwd=${kwd}`;
}
return '';
} );
defineProps<Props>();
const currentPageIndex = ref<number>( 0 );
const campaignParams = inject<string>( QUERY_STRING_INJECTION_KEY, '' );

const currentFormComponent = computed( (): Component => {
return pages[ currentPageIndex.value ];
} );

const currentProperties = computed( (): object => {
if ( currentFormComponent.value === AddressPage ) {
return {
validateAddressUrl: props.validateAddressUrl,
validateEmailUrl: props.validateEmailUrl,
validateFeeUrl: props.validateFeeUrl,
countries: props.countries,
salutations: props.salutations,
addressValidationPatterns: props.addressValidationPatterns,
dateOfBirthValidationPattern: props.dateOfBirthValidationPattern,
trackingData: props.trackingData,
campaignValues: props.campaignValues,
};
}
return {
showMembershipTypeOption: props.showMembershipTypeOption,
validateFeeUrl: props.validateFeeUrl,
paymentAmounts: props.paymentAmounts,
paymentIntervals: props.paymentIntervals,
paymentTypes: props.paymentTypes,
validateBankDataUrl: props.validateBankDataUrl,
validateLegacyBankDataUrl: props.validateLegacyBankDataUrl,
salutations: props.salutations,
};
} );

const scrollToTop = (): void => {
window.scrollTo( 0, 0 );
const goToAddressPage = () => {
currentPageIndex.value = 1;
};
const goToPaymentPage = () => {
currentPageIndex.value = 0;
};

watch( currentPageIndex, () => {
scrollToTop();
window.scrollTo( 0, 0 );
} );

function changePageIndex( indexChange: number ): void {
const newIndex = currentPageIndex.value + indexChange;
if ( newIndex >= 0 && newIndex < pages.length ) {
currentPageIndex.value = newIndex;
scrollToTop();
}
}

</script>
Loading
Loading