@@ -6,15 +6,17 @@ import { Textarea } from '../base/textarea'
6
6
import Button from '../base/button'
7
7
import { cn } from '../../utils'
8
8
import { Loader2Icon } from 'lucide-react'
9
- import { getHubSpotFormUrl } from '../../utils/externalUrls'
9
+
10
10
import {
11
11
FormField ,
12
12
FromErrors ,
13
13
checkErrors ,
14
14
defaultValues ,
15
15
emptyValues ,
16
+ refreshStudioCSRFToken ,
16
17
teamSize
17
18
} from './utils'
19
+ import { studioContactUsApi } from '../../utils/externalUrls'
18
20
19
21
const ErrorMessage = ( {
20
22
name,
@@ -114,68 +116,31 @@ const RequestAQuoteForm = ({
114
116
}
115
117
116
118
try {
117
- const formId = `50ebdb54-825e-436f-9afc-6c6fa4b2d865`
118
- /**
119
- * NOTE: For Testing, simply call getHubSpotFormUrl() i.e without parameters
120
- * it defaults to test form id
121
- */
122
- const response = await fetch ( getHubSpotFormUrl ( { formId } ) , {
119
+ const csrfToken = await refreshStudioCSRFToken ( )
120
+ const response = await fetch ( studioContactUsApi , {
123
121
method : `POST` ,
124
122
headers : {
125
- 'Content-Type' : `application/json`
123
+ 'Content-Type' : `application/json` ,
124
+ 'X-CsrfToken' : csrfToken
126
125
} ,
126
+ credentials : `include` ,
127
+ mode : `cors` ,
127
128
body : JSON . stringify ( {
128
- fields : [
129
- {
130
- objectTypeId : `0-1` ,
131
- name : `full_name` ,
132
- value : values . name
133
- } ,
134
- {
135
- objectTypeId : `0-1` ,
136
- name : `company` ,
137
- value : values . company
138
- } ,
139
- {
140
- objectTypeId : `0-1` ,
141
- name : `email` ,
142
- value : values . email
143
- } ,
144
- {
145
- objectTypeId : `0-1` ,
146
- name : `team_size` ,
147
- value : values . teamSize
148
- } ,
149
- {
150
- objectTypeId : `0-1` ,
151
- name : `area_of_interest` ,
152
- value : values . areaOfInterest
153
- } ,
154
- {
155
- objectTypeId : `0-1` ,
156
- name : `phone` ,
157
- value : values . phone
158
- } ,
159
- {
160
- objectTypeId : `0-1` ,
161
- name : `message` ,
162
- value : values . message
163
- } ,
164
- {
165
- objectTypeId : `0-1` ,
166
- name : `purpose` ,
167
- value : values . purpose
168
- }
169
- ] ,
170
- context : {
171
- pageName : `Platinum Services (Request a Quote)` ,
172
- pageUri : `https://dvc.org/support`
173
- }
129
+ area_of_interest : values . areaOfInterest ,
130
+ company : values . company ,
131
+ email : values . email ,
132
+ info : values . message ,
133
+ name : values . name ,
134
+ phone : values . phone ,
135
+ purpose : values . purpose ,
136
+ site : window . location . href ,
137
+ team_size : values . teamSize
174
138
} ) ,
175
139
signal : newAbortController . signal
176
140
} )
141
+ if ( ! response . ok ) throw new Error ( response . statusText )
177
142
const data = await response . json ( )
178
- if ( data . status === ` error` ) throw new Error ( data )
143
+ if ( data . error ) throw new Error ( data . error )
179
144
180
145
setSubmitting ( false )
181
146
setValues ( defaultValues )
0 commit comments