-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This fixes validation and field names to make sure the form submits to the application correctly. https://phabricator.wikimedia.org/T345528
- Loading branch information
Showing
14 changed files
with
149 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
src/components/pages/donation_form/DonationReceipt/NameFields.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/components/pages/donation_form/DonationReceipt/useAddressFormEventHandlers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Store } from 'vuex'; | ||
import { trackFormSubmission } from '@src/tracking'; | ||
import { action } from '@src/store/util'; | ||
import { NS_ADDRESS, NS_BANKDATA, NS_PAYMENT } from '@src/store/namespaces'; | ||
import { validateAddress, validateAddressType, validateEmail } from '@src/store/address/actionTypes'; | ||
import { AddressTypeModel } from '@src/view_models/AddressTypeModel'; | ||
import { markEmptyValuesAsInvalid } from '@src/store/bankdata/actionTypes'; | ||
import { waitForServerValidationToFinish } from '@src/wait_for_server_validation'; | ||
import { discardInitialization } from '@src/store/payment/actionTypes'; | ||
import { ComputedRef } from 'vue'; | ||
|
||
const scrollToFirstError = () => { | ||
document.getElementsByClassName( 'help is-danger' )[ 0 ] | ||
.scrollIntoView( { behavior: 'smooth', block: 'center', inline: 'nearest' } ); | ||
}; | ||
|
||
type ReturnType = { | ||
submit: ( e: Event ) => Promise<void>, | ||
previousPage: () => void, | ||
} | ||
|
||
export function useAddressFormEventHandlers( | ||
store: Store<any>, | ||
emit: ( eventName: string ) => void, | ||
isDirectDebit: ComputedRef<any>, | ||
validateAddressUrl: string, | ||
validateEmailUrl: string | ||
): ReturnType { | ||
const submit = async ( e: Event ) => { | ||
e.preventDefault(); | ||
|
||
await store.dispatch( action( NS_ADDRESS, validateAddressType ), { | ||
type: store.state.address.addressType, | ||
disallowed: [ AddressTypeModel.UNSET ], | ||
} ); | ||
await store.dispatch( action( NS_ADDRESS, validateAddress ), validateAddressUrl ); | ||
await store.dispatch( action( NS_ADDRESS, validateEmail ), validateEmailUrl ); | ||
|
||
if ( isDirectDebit.value ) { | ||
await store.dispatch( action( NS_BANKDATA, markEmptyValuesAsInvalid ) ); | ||
} | ||
|
||
// We need to wait for the asynchronous bank data validation, that might still be going on | ||
await waitForServerValidationToFinish( store ); | ||
|
||
if ( !store.getters[ NS_ADDRESS + '/requiredFieldsAreValid' ] ) { | ||
scrollToFirstError(); | ||
return; | ||
} | ||
|
||
if ( isDirectDebit.value && !store.getters[ NS_BANKDATA + '/bankDataIsValid' ] ) { | ||
scrollToFirstError(); | ||
return; | ||
} | ||
|
||
const form = e.target as HTMLFormElement; | ||
|
||
trackFormSubmission( form ); | ||
form.submit(); | ||
}; | ||
|
||
const previousPage = async () => { | ||
await store.dispatch( action( NS_PAYMENT, discardInitialization ) ); | ||
emit( 'previous-page' ); | ||
}; | ||
|
||
return { | ||
submit, | ||
previousPage, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/components/pages/donation_form/DonationReceipt/useAddressTypeFromReceiptSetter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ComputedRef, Ref, ref, watch } from 'vue'; | ||
import { Store } from 'vuex'; | ||
import { action } from '@src/store/util'; | ||
import { NS_ADDRESS } from '@src/store/namespaces'; | ||
import { setAddressType as setAddressTypeActionType } from '@src/store/address/actionTypes'; | ||
import { AddressTypeModel } from '@src/view_models/AddressTypeModel'; | ||
|
||
export function useAddressTypeFromReceiptSetter( receiptModel: Ref<boolean | null>, addressType: ComputedRef<number>, store: Store<any> ): void { | ||
const lastAddressType = ref<number>( addressType.value ); | ||
|
||
if ( !receiptModel.value ) { | ||
store.dispatch( action( NS_ADDRESS, setAddressTypeActionType ), AddressTypeModel.EMAIL ); | ||
} else if ( ![ AddressTypeModel.PERSON, AddressTypeModel.COMPANY_WITH_CONTACT ].includes( addressType.value ) ) { | ||
store.dispatch( action( NS_ADDRESS, setAddressTypeActionType ), AddressTypeModel.UNSET ); | ||
} | ||
|
||
const setAddressTypeFromReceipt = ( receipt: boolean | null ): void => { | ||
if ( !receipt ) { | ||
lastAddressType.value = addressType.value; | ||
store.dispatch( action( NS_ADDRESS, setAddressTypeActionType ), AddressTypeModel.EMAIL ); | ||
} else { | ||
store.dispatch( action( NS_ADDRESS, setAddressTypeActionType ), lastAddressType.value ); | ||
lastAddressType.value = AddressTypeModel.UNSET; | ||
} | ||
}; | ||
|
||
watch( receiptModel, setAddressTypeFromReceipt ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
> | ||
<input | ||
v-model="inputModel" | ||
:value="inputModel" | ||
type="checkbox" | ||
ref="inputRef" | ||
:name="name" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters