Skip to content

Commit

Permalink
xns name capture prop work
Browse files Browse the repository at this point in the history
adding intent, removing tracking instances, relying on userEvents.userClick in ButtonEx
  • Loading branch information
jonesmac committed Sep 18, 2024
1 parent df285fc commit e4f03a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { UserEventHandler } from '@xylabs/pixel'
import type { FlexBoxProps } from '@xylabs/react-flexbox'
import type { Mixpanel } from 'mixpanel-browser'
import type { ReactNode } from 'react'
import type { To } from 'react-router-dom'

Expand All @@ -12,11 +10,9 @@ export interface XnsNameCaptureBuyCallbacks {
* Trackers for user actions
*/
export interface XnsNameCaptureTrackingProps {
event?: string
funnel?: string
mixpanel?: Mixpanel
intent?: string
placement?: string
userEvents?: UserEventHandler<Record<string, unknown>>
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ export const XnsNameCapture: React.FC<XnsNameCaptureProps> = ({
children,
defaultXnsName,
errorUi = 'alert',
event = 'Click to Checkout',
funnel = 'xns',
mixpanel,
intent = 'unset',
mobileButtonText = 'Buy',
navigate,
onCaptureName: onCaptureNameProp,
Expand All @@ -31,7 +30,6 @@ export const XnsNameCapture: React.FC<XnsNameCaptureProps> = ({
routingError,
showSecondary = false,
to = '/xns/estimation',
userEvents,
...props
}) => {
const [xnsName, setXnsName] = useState<string>(() => defaultXnsName ?? '')
Expand All @@ -51,22 +49,17 @@ export const XnsNameCapture: React.FC<XnsNameCaptureProps> = ({

const onCaptureName = useCallback(async () => {
if (captureDisabled) return
mixpanel?.track(event, {
Funnel: funnel,
Placement: placement,
})
const formattedXnsName = `${xnsName}.xyo`
const helper = XnsNameHelper.fromString(formattedXnsName)
const [valid, errors] = await helper.validate()
if (valid) {
await userEvents?.userClick({ elementName: event, elementType: 'xns-cta' })
await onCaptureNameProp?.(xnsName)

navigateWithUsername(xnsName, paramsString, navigate, to)
} else {
setError(new Error(errors.join(', ')))
}
}, [event, funnel, mixpanel, paramsString, placement, to, userEvents, xnsName, onCaptureNameProp, navigate])
}, [paramsString, to, xnsName, onCaptureNameProp, navigate])

const onKeyDown: KeyboardEventHandler<HTMLDivElement> = useCallback(async (event) => {
if (event.key === 'Enter' && !captureDisabled) {
Expand All @@ -89,6 +82,9 @@ export const XnsNameCapture: React.FC<XnsNameCaptureProps> = ({
/>
<ButtonEx
disabled={captureDisabled}
funnel={funnel}
intent={intent}
placement={placement}
variant="contained"
color="success"
endIcon={<KeyboardArrowRightRounded />}
Expand Down

0 comments on commit e4f03a4

Please sign in to comment.