@@ -21,15 +21,18 @@ import clsx from "classnames"
2121import useValidateEvent from "./useValidateEvent"
2222import Loadable from "@/components/Loadable"
2323import Typography from "@mui/material/Typography"
24+ import Grid from "@mui/material/Grid"
25+ import Switch from "@mui/material/Switch"
2426import { PAB , PlainButton } from "@/components/Buttons"
2527import { Check , Warning , Error as ErrorIcon } from "@mui/icons-material"
2628import PrettyJson from "@/components/PrettyJson"
2729import usePayload from "./usePayload"
2830import { ValidationMessage } from "../types"
2931import Spinner from "@/components/Spinner"
30- import { EventCtx , Label , UseEuEndpointCtx } from ".."
32+ import { EventCtx , Label } from ".."
3133import { Card } from "@mui/material"
3234import { green , red } from "@mui/material/colors"
35+ import WithHelpText from "@/components/WithHelpText"
3336
3437const PREFIX = 'ValidateEvent' ;
3538
@@ -47,6 +50,7 @@ interface TemplateProps {
4750 sent ?: boolean
4851 payloadErrors ?: string | undefined
4952 useTextBox ?: boolean
53+ useEuEndpoint : boolean
5054}
5155
5256export interface ValidateEventProps {
@@ -68,7 +72,8 @@ const classes = {
6872 heading : `${ PREFIX } -heading` ,
6973 payload : `${ PREFIX } -payload` ,
7074 form : `${ PREFIX } -form` ,
71- buttonRow : `${ PREFIX } -buttonRow`
75+ buttonRow : `${ PREFIX } -buttonRow` ,
76+ endpointSwitch : `${ PREFIX } -endpointSwitch` ,
7277} ;
7378
7479const Root = styled ( 'div' ) ( (
@@ -80,6 +85,10 @@ const Root = styled('div')((
8085 padding : theme . spacing ( 2 ) ,
8186 } ,
8287
88+ [ `& .${ classes . endpointSwitch } ` ] : {
89+ marginBottom : theme . spacing ( 2 ) ,
90+ } ,
91+
8392 [ `& .${ classes . payloadTitle } ` ] : {
8493 margin : theme . spacing ( 1 , 0 ) ,
8594 } ,
@@ -166,11 +175,11 @@ const Template: React.FC<TemplateProps> = ({
166175 error,
167176 valid,
168177 payloadErrors,
169- useTextBox
178+ useTextBox,
179+ useEuEndpoint,
170180} ) => {
171181
172182 const { instanceId, api_secret } = useContext ( EventCtx ) !
173- const useEuEndpoint = useContext ( UseEuEndpointCtx )
174183 const payload = usePayload ( )
175184 return (
176185 < Card
@@ -271,82 +280,118 @@ const Template: React.FC<TemplateProps> = ({
271280}
272281
273282const ValidateEvent : React . FC < ValidateEventProps > = ( { formatPayload, payloadErrors, useTextBox} ) => {
274- const request = useValidateEvent ( )
283+ const [ useEuEndpoint , setUseEuEndpoint ] = React . useState ( false )
284+ const request = useValidateEvent ( useEuEndpoint )
275285
276286 return (
277- < Loadable
278- request = { request }
279- renderNotStarted = { ( { validateEvent } ) => (
280- < Template
281- heading = "This event has not been validated"
282- headingIcon = { < Warning /> }
283- body = {
284- < Root >
285- < Typography >
286- Update the event using the controls above.
287- </ Typography >
288- < Typography >
289- When you're done editing the event, click "Validate Event" to
290- check if the event is valid.
291- </ Typography >
292- </ Root >
293- }
294- validateEvent = { ( ) => {
287+ < div className = { classes . form } >
288+ < WithHelpText
289+ notched
290+ shrink
291+ label = "server endpoint"
292+ className = { classes . endpointSwitch }
293+ helpText = "Collect data in the European Union. If enabled, the https://region1.google-analytics.com endpoint will be used to validate and send events."
294+ >
295+ < Grid component = "label" container alignItems = "center" spacing = { 1 } >
296+ < Grid item > Default</ Grid >
297+ < Grid item >
298+ < Switch
299+ data-testid = "use-eu-endpoint"
300+ checked = { useEuEndpoint }
301+ onChange = { e => {
302+ setUseEuEndpoint ( e . target . checked )
303+ } }
304+ name = "use-eu-endpoint"
305+ color = "primary"
306+ />
307+ </ Grid >
308+ < Grid item > EU</ Grid >
309+ </ Grid >
310+ </ WithHelpText >
311+ < Loadable
312+ request = { request }
313+ renderNotStarted = { ( { validateEvent } ) => (
314+ < Template
315+ useEuEndpoint = { useEuEndpoint }
316+ heading = "This event has not been validated"
317+ headingIcon = { < Warning /> }
318+ body = {
319+ < Root >
320+ < Typography >
321+ Update the event using the controls above.
322+ </ Typography >
323+ < Typography >
324+ When you're done editing the event, click "Validate Event" to
325+ check if the event is valid.
326+ </ Typography >
327+ </ Root >
328+ }
329+ validateEvent = { ( ) => {
295330 if ( formatPayload ) {
296331 formatPayload ( )
297332 }
298333
299334 validateEvent ( )
300- }
301- }
302- />
303- ) }
304- renderInProgress = { ( ) => (
305- < Template heading = "Validating" body = { < Spinner ellipses /> } />
306- ) }
307- renderFailed = { ( { validationMessages, validateEvent} ) => (
308- < Template
309- error
310- headingIcon = { < ErrorIcon /> }
311- heading = "Event is invalid"
312- body = ""
313- validateEvent = { ( ) => {
335+ } }
336+ />
337+ ) }
338+ renderInProgress = { ( ) => (
339+ < Template
340+ useEuEndpoint = { useEuEndpoint }
341+ heading = "Validating"
342+ body = { < Spinner ellipses /> }
343+ />
344+ ) }
345+ renderFailed = { ( { validationMessages, validateEvent } ) => (
346+ < Template
347+ useEuEndpoint = { useEuEndpoint }
348+ error
349+ headingIcon = { < ErrorIcon /> }
350+ heading = "Event is invalid"
351+ body = ""
352+ validateEvent = { ( ) => {
314353 if ( formatPayload ) {
315354 formatPayload ( )
316355 }
317356
318357 validateEvent ( )
358+ } }
359+ validationMessages = { validationMessages }
360+ payloadErrors = { payloadErrors }
361+ useTextBox = { useTextBox }
362+ />
363+ ) }
364+ renderSuccessful = { ( {
365+ sendToGA,
366+ copyPayload,
367+ copySharableLink,
368+ sent,
369+ } ) => (
370+ < Template
371+ useEuEndpoint = { useEuEndpoint }
372+ sent = { sent }
373+ valid
374+ heading = "Event is valid"
375+ headingIcon = { < Check /> }
376+ sendToGA = { sendToGA }
377+ copyPayload = { copyPayload }
378+ copySharableLink = { copySharableLink }
379+ body = {
380+ < >
381+ < Typography >
382+ Use the controls below to copy the event payload or share it
383+ with coworkers.
384+ </ Typography >
385+ < Typography >
386+ You can also send the event to Google Analytics and watch it in
387+ action in the Real Time view.
388+ </ Typography >
389+ </ >
319390 }
320- }
321- validationMessages = { validationMessages }
322- payloadErrors = { payloadErrors }
323- useTextBox = { useTextBox }
324- />
325- ) }
326- renderSuccessful = { ( { sendToGA, copyPayload, copySharableLink, sent} ) => (
327- < Template
328- sent = { sent }
329- valid
330- heading = "Event is valid"
331- headingIcon = { < Check /> }
332- sendToGA = { sendToGA }
333- copyPayload = { copyPayload }
334- copySharableLink = { copySharableLink }
335- body = {
336- < >
337- < Typography >
338- Use the controls below to copy the event payload or share it
339- with coworkers.
340- </ Typography >
341- < Typography >
342- You can also send the event to Google Analytics and watch it in
343- action in the Real Time view.
344- </ Typography >
345- </ >
346- }
347- />
348- ) }
349- />
391+ />
392+ ) }
393+ />
394+ </ div >
350395 ) ;
351396}
352397
0 commit comments