Commit b5b85c4f authored by peterh-gr's avatar peterh-gr
Browse files

Added redirect URL field to donate page

We want to be able to redirect to a different thank you page for some
donate pages. It will default to /donate-thank-you, but otherwise you
can put in any full URL.

Issue #48274
parent 5e95fb17
......@@ -83,3 +83,5 @@ tshirt_perk_monthly_label: T-Shirt
tshirt_perk_monthly_image: /static/images/donate/t-shirt-take-back-internet.png
---
image: /static/images/donate/donate-header.png
---
success_redirect_url:
......@@ -40,6 +40,10 @@ type = markdown
label = Header Image (centered)
type = string
[fields.success_redirect_url]
label = URL to redirect to after donation completed successfully
type = url
[fields.single_one]
label = Single Price 1 (in US cents)
type = integer
......
......@@ -16,7 +16,7 @@ import {LoadingDialogReactPages} from './loading_dialog_react_pages';
import {FrequencySelector} from './frequency_selector';
export function _GivingForm(props) {
const {stripe, frequencyOptions, pricesOnButtons, donateProccessorBaseUrl, perks, initialSelectedPrices, defaultFrequencyForBoth} = props;
const {stripe, frequencyOptions, pricesOnButtons, donateProccessorBaseUrl, perks, initialSelectedPrices, defaultFrequencyForBoth, successRedirectUrl} = props;
const [frequency, setFrequency] = useState((frequencyOptions == 'both')? defaultFrequencyForBoth : frequencyOptions);
const displayPerkSelection = displayPerkSelections[frequency];
const [noPerk, setNoPerk] = useState(true);
......@@ -42,6 +42,11 @@ export function _GivingForm(props) {
'region': null,
});
let normalizedSuccessRedirectUrl = successRedirectUrl.trim();
if (normalizedSuccessRedirectUrl == '') {
normalizedSuccessRedirectUrl = '/donate-thank-you';
}
const priceOtherRef = useRef(null);
const appContext = useContext(AppContext);
......@@ -281,7 +286,7 @@ export function _GivingForm(props) {
setLoading(false);
newErrors.push(new NamedError('stripeError', errorMessage));
} else {
window.location.href = '/donate-thank-you';
window.location.href = normalizedSuccessRedirectUrl;
}
} else if ('error' in tokenCreated) {
const errorMessage = tokenCreated['error'].message;
......@@ -456,6 +461,7 @@ export function _GivingForm(props) {
addError={addError}
displayPerkSelection={displayPerkSelection}
donateProccessorBaseUrl={donateProccessorBaseUrl}
successRedirectUrl={normalizedSuccessRedirectUrl}
/>
</div>
<GivingErrorContainer errors={errors} />
......
......@@ -14,7 +14,7 @@ import {StripeCreditCardForm} from './stripe_credit_card_form';
import {DonationInformation} from './donation_information';
export function GivingInfoForm(props) {
const {paymentMethod, mailingListOptIn, onMailingListOptInCheckboxChange, selectedPerk, perkOption, perkOptionProperties, shirtFits, sweatshirtSizes, frequency, selectedPrice, noPerk, selectedPerkFriendlyName, requiredFields, errors, textFields, priceOtherRef, formData, countryChanged, regionChanged, onInputFieldChange, fitsAndSizes, updateFitsAndSizes, stripeSubmitHandle, stripe, isValidEmail, validateRequiredFieldsAndDonationAmount, preparePerkData, prepareFieldsData, createBillingAgreement, onStripeFieldChange, addError, displayPerkSelection, donateProccessorBaseUrl} = props;
const {paymentMethod, mailingListOptIn, onMailingListOptInCheckboxChange, selectedPerk, perkOption, perkOptionProperties, shirtFits, sweatshirtSizes, frequency, selectedPrice, noPerk, selectedPerkFriendlyName, requiredFields, errors, textFields, priceOtherRef, formData, countryChanged, regionChanged, onInputFieldChange, fitsAndSizes, updateFitsAndSizes, stripeSubmitHandle, stripe, isValidEmail, validateRequiredFieldsAndDonationAmount, preparePerkData, prepareFieldsData, createBillingAgreement, onStripeFieldChange, addError, displayPerkSelection, donateProccessorBaseUrl, successRedirectUrl} = props;
const donationInformation = () => {
if (displayPerkSelection) {
......@@ -141,6 +141,7 @@ export function GivingInfoForm(props) {
createBillingAgreement={createBillingAgreement}
addError={addError}
donateProccessorBaseUrl={donateProccessorBaseUrl}
successRedirectUrl={successRedirectUrl}
/>
</React.Fragment>
);
......
......@@ -5,7 +5,7 @@ import {NamedError} from './named_error';
import {LoadingDialogReactPages} from './loading_dialog_react_pages';
export function PayPalButton(props) {
const {paymentMethod, amount, perk, frequency, formData, noPerkCheckbox, fitsAndSizes, perkOption, requiredFields, addError, givingFormError, textFields, priceOtherRef, isValidEmail, validateRequiredFieldsAndDonationAmount, preparePerkData, prepareFieldsData, createBillingAgreement, donateProccessorBaseUrl} = props;
const {paymentMethod, amount, perk, frequency, formData, noPerkCheckbox, fitsAndSizes, perkOption, requiredFields, addError, givingFormError, textFields, priceOtherRef, isValidEmail, validateRequiredFieldsAndDonationAmount, preparePerkData, prepareFieldsData, createBillingAgreement, donateProccessorBaseUrl, successRedirectUrl} = props;
const PayPalButton = paypal.Buttons.driver('react', {React, ReactDOM});
......@@ -49,7 +49,7 @@ export function PayPalButton(props) {
toggleLoading(false);
throw new Error(errorMessage);
} else {
document.location = '/donate-thank-you';
document.location = successRedirectUrl;
}
}
};
......
......@@ -131,7 +131,8 @@
'single': parseInt(`{{ this.single_three }}`),
'monthly': parseInt(`{{ this.monthly_three }}`),
},
'donateProccessorBaseUrl': `{{ bag('donate', envvars('ENV'), 'donateProccessorBaseUrl') }}`
'donateProccessorBaseUrl': `{{ bag('donate', envvars('ENV'), 'donateProccessorBaseUrl') }}`,
'successRedirectUrl': `{{ this.success_redirect_url }}`,
},
}
];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment