Skip to content

Commit

Permalink
[react] Fix typings for QuilttButton onLoad handler (#313)
Browse files Browse the repository at this point in the history
* [react] Fix typings for QuilttButton onLoad handler

* Add changeset

* Fixes from code review
  • Loading branch information
zubairaziz authored Dec 24, 2024
1 parent de5d43e commit 3b789c9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changeset/olive-scissors-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@quiltt/react": patch
"@quiltt/core": patch
"@quiltt/react-native": patch
---

Update typings for QuilttButton onLoad handler
42 changes: 34 additions & 8 deletions packages/react/src/components/QuilttButton.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import type { PropsWithChildren } from 'react'
import type { MouseEvent, PropsWithChildren } from 'react'

import type { ConnectorSDKCallbacks } from '@quiltt/core'

import { useQuilttConnector } from '../hooks/useQuilttConnector'
import type { AnyTag, PropsOf } from '../types'

// Base button props without callback-specific properties
type BaseQuilttButtonProps<T extends AnyTag> = {
as?: T
connectorId: string
connectionId?: string // For Reconnect Mode
institution?: string // For Connect Mode
// Override the native onClick handler
onClick?: (event: MouseEvent<HTMLElement>) => void
}

// Separate SDK callback types
type QuilttCallbackProps = Omit<ConnectorSDKCallbacks, 'onLoad'> & {
// Separate the SDK onLoad from the HTML onLoad to avoid conflicts
onLoad?: ConnectorSDKCallbacks['onLoad'] // Handles SDK initialization
onHtmlLoad?: React.ReactEventHandler<HTMLElement> // Handles DOM element load
}

// Combined type for the full component
type QuilttButtonProps<T extends AnyTag> = PropsWithChildren<
{
as?: T
connectorId: string
connectionId?: string // For Reconnect Mode
institution?: string // For Connect Mode
} & ConnectorSDKCallbacks
BaseQuilttButtonProps<T> & QuilttCallbackProps
>

export const QuilttButton = <T extends AnyTag = 'button'>({
Expand All @@ -26,6 +39,8 @@ export const QuilttButton = <T extends AnyTag = 'button'>({
onExitSuccess,
onExitAbort,
onExitError,
onClick,
onHtmlLoad,
children,
...props
}: QuilttButtonProps<T> & PropsOf<T>) => {
Expand All @@ -43,8 +58,19 @@ export const QuilttButton = <T extends AnyTag = 'button'>({

const Button = as || 'button'

const handleClick = (event: MouseEvent<HTMLElement>) => {
// Call the user's onClick handler first to allow for:
// 1. Pre-open validation
// 2. Preventing opening via event.preventDefault()
// 3. Setting up state before connector opens
if (onClick) onClick(event)

// Then open the Quiltt connector
open()
}

return (
<Button onClick={open} quiltt-connection={connectionId} {...props}>
<Button onClick={handleClick} onLoad={onHtmlLoad} quiltt-connection={connectionId} {...props}>
{children}
</Button>
)
Expand Down
2 changes: 1 addition & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"tasks": {
"build": {
"dependsOn": ["prebuild", "^build"],
"outputs": ["dist/**", ".next/**"]
"outputs": ["dist/**", ".next/**", "ios/**", "android/**"]
},
"clean": {
"cache": false,
Expand Down

0 comments on commit 3b789c9

Please sign in to comment.