Skip to content

Commit eda26b4

Browse files
committed
Career contact form server action integration #3478
1 parent 4b9beeb commit eda26b4

3 files changed

Lines changed: 39 additions & 18 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@
3232
"*.{js,ts,cjs,mjs,d.cts,d.mts,jsx,tsx,json,jsonc}": [
3333
"biome check --files-ignore-unknown=true --no-errors-on-unmatched"
3434
]
35-
}
35+
},
36+
"packageManager": "pnpm@10.24.0+sha512.01ff8ae71b4419903b65c60fb2dc9d34cf8bb6e06d03bde112ef38f7a34d6904c424ba66bea5cdcf12890230bf39f9580473140ed9c946fef328b6e5238a345a"
3637
}

web/app/_actions/submitFormServerAction.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//web lib actions equinorFormServerAction
22
'use server'
33

4-
import { ContactFormCatalogType } from '../../types'
5-
import { validateFormRequest } from '../../app/api/forms/validateFormRequest'
64
import { getAccessToken } from '../../lib/actions/getAccessToken'
75

6+
// ContactEquinor - CAT0012836
7+
// OrderReports - CAT0012841
8+
// CareersContactUs - CAT0012840
9+
// CareerFairs - CAT0012839
810
export default async function submitFormServerAction(formData: any, catelogNumber: string) {
911
const urlString = process.env.ACTION_BASE_URL_FOR_FORMS + '/' + catelogNumber;
1012

@@ -21,7 +23,7 @@ export default async function submitFormServerAction(formData: any, catelogNumbe
2123
})
2224

2325
const parsed = await response.json()
24-
console.log(response, parsed)
26+
console.log(response, parsed, formData)
2527
if (parsed.status === 'failure' || parsed.Status?.includes('Failure')) {
2628
console.error('Failed to create ticket in ServiceNow')
2729
return { status: 500 }

web/templates/forms/CareersContactForm.tsx

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { FormMessageBox } from '@/core/Form/FormMessageBox'
1111
import { Select } from '@/core/Select/Select'
1212
import { TextField } from '@/core/TextField/TextField'
1313
import FriendlyCaptcha from './FriendlyCaptcha'
14+
import verifyCaptcha from '@/app/_actions/verifyCaptcha'
15+
import submitFormServerAction from '@/app/_actions/submitFormServerAction'
1416
import {
1517
contentRegex,
1618
emailRegex,
@@ -29,6 +31,7 @@ type FormValues = {
2931
preferredLang: string
3032
candidateType: string
3133
supportingDocuments: string
34+
location: string
3235
}
3336

3437
const 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

Comments
 (0)