11import { FormattedMessage } from '@edx/frontend-platform/i18n' ;
2+ import { logError } from '@edx/frontend-platform/logging' ;
23import { AppContext } from '@edx/frontend-platform/react' ;
34import { zodResolver } from '@hookform/resolvers/zod' ;
45import {
@@ -14,7 +15,7 @@ import { useForm } from 'react-hook-form';
1415import { useLocation , useNavigate } from 'react-router-dom' ;
1516import { z } from 'zod' ;
1617
17- import { useFormValidationConstraints } from '@/components/app/data' ;
18+ import { useFormValidationConstraints , useRecaptchaSubmission } from '@/components/app/data' ;
1819import {
1920 useCreateCheckoutIntentMutation ,
2021 useLoginMutation ,
@@ -42,6 +43,7 @@ import '../Stepper/Steps/css/PriceAlert.css';
4243const PlanDetailsPage = ( ) => {
4344 const location = useLocation ( ) ;
4445 const queryClient = useQueryClient ( ) ;
46+
4547 const { data : formValidationConstraints } = useFormValidationConstraints ( ) ;
4648 const planDetailsFormData = useCheckoutFormStore ( ( state ) => state . formData [ DataStoreKey . PlanDetails ] ) ;
4749 const setFormData = useCheckoutFormStore ( ( state ) => state . setFormData ) ;
@@ -52,7 +54,7 @@ const PlanDetailsPage = () => {
5254 buttonMessage : stepperActionButtonMessage ,
5355 formSchema,
5456 } = useCurrentPageDetails ( ) ;
55-
57+ const { executeWithFallback } = useRecaptchaSubmission ( 'submit' ) ;
5658 const planDetailsSchema = useMemo ( ( ) => (
5759 formSchema ( formValidationConstraints , planDetailsFormData . stripePriceId )
5860 ) , [ formSchema , formValidationConstraints , planDetailsFormData . stripePriceId ] ) ;
@@ -169,14 +171,29 @@ const PlanDetailsPage = () => {
169171 password : data . password ,
170172 } ) ;
171173 } ,
172- [ SubmitCallbacks . PlanDetailsRegister ] : ( data : PlanDetailsRegisterPageData ) => {
173- registerMutation . mutate ( {
174+ [ SubmitCallbacks . PlanDetailsRegister ] : async ( data : PlanDetailsRegisterPageData ) => {
175+ let recaptchaToken : string | null = null ;
176+ try {
177+ recaptchaToken = await executeWithFallback ( ) ;
178+ } catch ( err : any ) {
179+ logError ( err . message ) ;
180+ }
181+
182+ let registerMutationPayload : BaseRegistrationCreateRequestSchema = {
174183 name : data . fullName ,
175184 email : data . adminEmail ,
176185 username : data . username ,
177186 password : data . password ,
178187 country : data . country ,
179- } ) ;
188+ } ;
189+
190+ if ( recaptchaToken ) {
191+ registerMutationPayload = {
192+ ...registerMutationPayload ,
193+ captchaToken : recaptchaToken ,
194+ } as RegistrationCreateRecaptchaRequestSchema ;
195+ }
196+ registerMutation . mutate ( registerMutationPayload ) ;
180197 } ,
181198 } ;
182199
0 commit comments