@@ -3,6 +3,7 @@ import AppContext from '../../app-context';
33import CloseButton from '../common/close-button' ;
44import SiteTitleBackButton from '../common/site-title-back-button' ;
55import InputForm from '../common/input-form' ;
6+ import ActionButton from '../common/action-button' ;
67import LoadingPage from './loading-page' ;
78import { ReactComponent as CheckmarkIcon } from '../../images/icons/checkmark.svg' ;
89import { getAvailableProducts , getCurrencySymbol , formatNumber , getStripeAmount , isCookiesDisabled , getActiveInterval } from '../../utils/helpers' ;
@@ -61,7 +62,7 @@ function GiftProductCardPrice({product, selectedInterval}) {
6162 ) ;
6263}
6364
64- function GiftProductCard ( { product, selectedInterval, onPurchase , disabled } ) {
65+ function GiftProductCard ( { brandColor , product, selectedInterval, isDisabled , isPurchasing , onPurchase } ) {
6566 let productDescription = product . description ;
6667
6768 if ( ( ! product . benefits || ! product . benefits . length ) && ! productDescription ) {
@@ -84,14 +85,15 @@ function GiftProductCard({product, selectedInterval, onPurchase, disabled}) {
8485 < GiftProductCardBenefits product = { product } />
8586 </ div >
8687 < div className = 'gh-portal-btn-product' >
87- < button
88- data-test-button = 'purchase-gift'
89- className = 'gh-portal-btn'
90- disabled = { disabled }
91- onClick = { onPurchase }
92- >
93- Purchase gift
94- </ button >
88+ < ActionButton
89+ dataTestId = 'purchase-gift'
90+ label = 'Purchase gift'
91+ onClick = { e => onPurchase ( e , product ) }
92+ disabled = { isDisabled }
93+ isRunning = { isPurchasing }
94+ brandColor = { brandColor }
95+ style = { { width : '100%' } }
96+ />
9597 </ div >
9698 </ div >
9799 </ div >
@@ -132,10 +134,11 @@ function GiftPriceSwitch({selectedInterval, setSelectedInterval, products}) {
132134}
133135
134136const GiftPage = ( ) => {
135- const { site, member} = useContext ( AppContext ) ;
137+ const { site, member, brandColor , action , doAction } = useContext ( AppContext ) ;
136138 const [ email , setEmail ] = useState ( member ?. email || '' ) ;
137139 const [ emailError , setEmailError ] = useState ( '' ) ;
138140 const [ selectedInterval , setSelectedInterval ] = useState ( null ) ;
141+ const [ selectedProduct , setSelectedProduct ] = useState ( null ) ;
139142
140143 if ( ! site ) {
141144 return < LoadingPage /> ;
@@ -176,7 +179,8 @@ const GiftPage = () => {
176179
177180 const siteIcon = site . icon ;
178181 const siteTitle = site . title || '' ;
179- const disabled = isCookiesDisabled ( ) ;
182+ const isPurchasing = action === 'checkoutGift:running' ;
183+ const isDisabled = isCookiesDisabled ( ) || isPurchasing ;
180184
181185 const emailField = [ {
182186 type : 'email' ,
@@ -190,7 +194,7 @@ const GiftPage = () => {
190194 errorMessage : emailError
191195 } ] ;
192196
193- const handlePurchase = ( e ) => {
197+ const handlePurchase = ( e , product ) => {
194198 e . preventDefault ( ) ;
195199
196200 const errors = ValidateInputForm ( { fields : emailField } ) ;
@@ -201,7 +205,13 @@ const GiftPage = () => {
201205 }
202206
203207 setEmailError ( '' ) ;
204- // TODO: implement gift checkout using priceId and email
208+ setSelectedProduct ( product . id ) ;
209+
210+ doAction ( 'checkoutGift' , {
211+ tierId : product . id ,
212+ cadence : activeInterval ,
213+ email
214+ } ) ;
205215 } ;
206216
207217 return (
@@ -243,10 +253,12 @@ const GiftPage = () => {
243253 { products . map ( product => (
244254 < GiftProductCard
245255 key = { product . id }
256+ brandColor = { brandColor }
246257 product = { product }
247258 selectedInterval = { activeInterval }
259+ isDisabled = { isDisabled }
260+ isPurchasing = { isPurchasing && selectedProduct === product . id }
248261 onPurchase = { handlePurchase }
249- disabled = { disabled }
250262 />
251263 ) ) }
252264 </ div >
0 commit comments