From 980cfdb07dcb9499684e2f378f4f77d07761c047 Mon Sep 17 00:00:00 2001 From: Dave Brudner Date: Wed, 29 Jan 2020 19:40:26 -0600 Subject: [PATCH] Updates demo for useCheckoutPricing#singleInputs --- demo/public/index.html | 5 +- demo/src/checkout-pricing.js | 103 ++++++++++++++++++++++++++++++++--- 2 files changed, 100 insertions(+), 8 deletions(-) diff --git a/demo/public/index.html b/demo/public/index.html index f7c62ce..1c2214c 100644 --- a/demo/public/index.html +++ b/demo/public/index.html @@ -23,7 +23,7 @@ margin: 20px 0; padding: 0; } - h2 { + h2, h3 { color: #555; padding: 0; margin: 0; @@ -31,6 +31,9 @@ font-weight: 400; margin-bottom: 0.5em; } + h3 { + font-size: 1em; + } p { font-size: 0.8em; } diff --git a/demo/src/checkout-pricing.js b/demo/src/checkout-pricing.js index fd52358..e1e3c8d 100644 --- a/demo/src/checkout-pricing.js +++ b/demo/src/checkout-pricing.js @@ -15,24 +15,43 @@ function CheckoutPricingForm () { const [recurlyError, setRecurlyError] = useState(null); const [plan, setPlan] = useState(''); const [quantity, setQuantity] = useState(''); + const [coupon, setCoupon] = useState(''); + const [giftCard, setGiftCard] = useState(''); + const [currency, setCurrency] = useState(''); + const [billingCountry, setBillingCountry] = useState(''); + const [billingPostalCode, setBillingPostalCode] = useState(''); + const [billingVatNumber, setBillingVatNumber] = useState(''); + const [shippingCountry, setShippingCountry] = useState(''); + const [shippingPostalCode, setShippingPostalCode] = useState(''); + const [shippingVatNumber, setShippingVatNumber] = useState(''); const [{ price, loading }, setPricing] = useCheckoutPricing({}, setRecurlyError); + const showPrice = price && price.now && !recurlyError function updatePlan (e) { const plan = e.target.value; setRecurlyError(null); setPlan(plan); - setPricing(prev => ({ ...prev, subscriptions: [{ plan, quantity }] })); }; function updateQuantity (e) { const quantity = e.target.value; setRecurlyError(null); - setQuantity(() => quantity); - setPricing(prev => ({ ...prev, subscriptions: [{ plan, quantity }] })); + setQuantity(quantity); + }; + + function handleSubmit (e) { + e.preventDefault(); + const address = { + billingCountry, + billingPostalCode, + billingVatNumber, + }; + setRecurlyError(null); + setPricing({ subscriptions: [{ plan, quantity }], coupon, giftCard, address }); }; return ( -
+
setCoupon(e.target.value)} + placeholder="Coupon" + /> + setGiftCard(e.target.value)} + placeholder="Gift card" + /> + setCurrency(e.target.value)} + placeholder="Currency" + />
+
+

Billing address

+ setBillingCountry(e.target.value)} + placeholder="Country" + /> + setBillingPostalCode(e.target.value)} + placeholder="Postal code" + /> + setBillingVatNumber(e.target.value)} + placeholder="Vat number" + /> +
+
+

Shipping address

+ setShippingCountry(e.target.value)} + placeholder="Country" + /> + setShippingPostalCode(e.target.value)} + placeholder="Postal code" + /> + setShippingVatNumber(e.target.value)} + placeholder="Vat number" + /> +
+
+ {recurlyError ? {recurlyError.message} : ''} + {showPrice ? ( + + {"Subtotal: "} + + ${price.now.subtotal} + + + ) : null}
+ +
); };