@@ -11,6 +11,8 @@ import { FormMessageBox } from '@/core/Form/FormMessageBox'
1111import { Select } from '@/core/Select/Select'
1212import { TextField } from '@/core/TextField/TextField'
1313import FriendlyCaptcha from './FriendlyCaptcha'
14+ import verifyCaptcha from '@/app/_actions/verifyCaptcha'
15+ import submitFormServerAction from '@/app/_actions/submitFormServerAction'
1416import {
1517 contentRegex ,
1618 emailRegex ,
@@ -29,6 +31,7 @@ type FormValues = {
2931 preferredLang : string
3032 candidateType : string
3133 supportingDocuments : string
34+ location : string
3235}
3336
3437const CareersContactForm = ( ) => {
@@ -91,22 +94,37 @@ const CareersContactForm = () => {
9194 }
9295
9396 const onSubmit = async ( data : FormValues , event ?: BaseSyntheticEvent ) => {
97+
9498 data . preferredLang = locale
9599 if ( isFriendlyChallengeDone ) {
96- const res = await fetch ( '/api/forms/service-now-careers-contact' , {
97- body : JSON . stringify ( {
98- data,
99- frcCaptchaSolution : ( event ?. target as any ) [ 'frc-captcha-response' ]
100- . value ,
101- catalogType : getCatalogType ( data . category , data . candidateType ) ,
102- } ) ,
103- headers : {
104- 'Content-Type' : 'application/json' ,
105- } ,
106- method : 'POST' ,
107- } )
108- setSuccessfullySubmitted ( res . status === 200 )
109- setServerError ( res . status !== 200 )
100+ const frcCaptchaSolution = ( event ?. target as any ) [ 'frc-captcha-response' ] . value
101+ const isCaptchaVerified = await verifyCaptcha ( frcCaptchaSolution )
102+ const cid = getCatalogType ( data . category , data . candidateType )
103+ if ( ! isCaptchaVerified ) {
104+ return
105+ }
106+
107+ let finalFormData = {
108+ "variables" : {
109+ "requested_for" : "tpawe" ,
110+ "cid" : cid , //change
111+ "name" : data . name ,
112+ "phoneNumber" : data . phone ,
113+ "external_emails" : data . email ,
114+ "positionDetails" : data . positionId ,
115+ "location" : data . location ,
116+ "questions" : data . questions ,
117+ "supportingdocuments" : data . supportingDocuments ,
118+ "candidatetype" : data . candidateType ,
119+ "positiondetails" : data . positionId
120+ }
121+ }
122+
123+ // Call the server action directly
124+ const result = await submitFormServerAction ( JSON . stringify ( finalFormData ) , 'CAT0012840' )
125+
126+ setServerError ( result . status !== 200 )
127+ setSuccessfullySubmitted ( result . status === 200 )
110128 } else {
111129 //@ts -ignore: TODO: types
112130 setError ( 'root.notCompletedCaptcha' , {
0 commit comments