Skip to content

Commit a514c21

Browse files
committed
Order reports form integrated with server actions #3478
1 parent eda26b4 commit a514c21

1 file changed

Lines changed: 31 additions & 13 deletions

File tree

web/templates/forms/OrderReportsForm.tsx

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { FormMessageBox } from '@/core/Form/FormMessageBox'
1010
import { TextField } from '@/core/TextField/TextField'
1111
import FriendlyCaptcha from './FriendlyCaptcha'
1212
import { englishTextRegex, nameRegex } from './validations'
13+
import verifyCaptcha from '@/app/_actions/verifyCaptcha'
14+
import submitFormServerAction from '@/app/_actions/submitFormServerAction'
1315

1416
type 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

Comments
 (0)