@@ -10,6 +10,8 @@ import { FormMessageBox } from '@/core/Form/FormMessageBox'
1010import { TextField } from '@/core/TextField/TextField'
1111import FriendlyCaptcha from './FriendlyCaptcha'
1212import { englishTextRegex , nameRegex } from './validations'
13+ import verifyCaptcha from '@/app/_actions/verifyCaptcha'
14+ import submitFormServerAction from '@/app/_actions/submitFormServerAction'
1315
1416type FormValues = {
1517 name : string
@@ -78,20 +80,36 @@ const OrderReportsForm = () => {
7880 } )
7981
8082 const onSubmit = async ( data : FormValues , event ?: BaseSyntheticEvent ) => {
83+
8184 if ( isFriendlyChallengeDone ) {
82- const res = await fetch ( '/api/forms/service-now-order-reports' , {
83- body : JSON . stringify ( {
84- data,
85- frcCaptchaSolution : ( event ?. target as any ) [ 'frc-captcha-response' ]
86- . value ,
87- } ) ,
88- headers : {
89- 'Content-Type' : 'application/json' ,
90- } ,
91- method : 'POST' ,
92- } )
93- setServerError ( res . status !== 200 )
94- setSuccessfullySubmitted ( res . status === 200 )
85+ const frcCaptchaSolution = ( event ?. target as any ) [ 'frc-captcha-response' ] . value
86+ const isCaptchaVerified = await verifyCaptcha ( frcCaptchaSolution )
87+
88+ if ( ! isCaptchaVerified ) {
89+ return
90+ }
91+
92+ let finalFormData = {
93+ "variables" : {
94+ "requested_for" : "tpawe" ,
95+ "external_emails" : data . email ,
96+ "cid" : "d1872741db26ea40977079e9bf961949" ,
97+ "name" : data . name ,
98+ "address" : data . address ,
99+ "zip" : data . zipcode ,
100+ "city" : data . city ,
101+ "country" : data . country ,
102+ "company" : data . company ,
103+ "reports" : data . reports
104+ }
105+ }
106+
107+ // Call the server action directly
108+ // CAT0012836 is CAT ID for Contact Equinor Form //
109+ const result = await submitFormServerAction ( JSON . stringify ( finalFormData ) , 'CAT0012841' )
110+
111+ setServerError ( result . status !== 200 )
112+ setSuccessfullySubmitted ( result . status === 200 )
95113 } else {
96114 //@ts -ignore: TODO: types
97115 setError ( 'root.notCompletedCaptcha' , {
0 commit comments