Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[react] Fix typings for QuilttButton onLoad handler #313

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
zubairaziz marked this conversation as resolved.
Show resolved Hide resolved
...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()
}
zubairaziz marked this conversation as resolved.
Show resolved Hide resolved

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
Loading