-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from sonjoydatta/master
Refactor TypeScript interfaces updated version and updated docs
- Loading branch information
Showing
9 changed files
with
2,060 additions
and
804 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
es2021: true, | ||
}, | ||
extends: ['eslint:recommended', 'plugin:react/recommended', 'plugin:@typescript-eslint/recommended'], | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
ecmaFeatures: { | ||
jsx: true, | ||
}, | ||
ecmaVersion: 12, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['react', '@typescript-eslint'], | ||
rules: { | ||
indent: ['error', 'tab'], | ||
'linebreak-style': ['error', 'crlf'], | ||
quotes: ['error', 'single'], | ||
semi: ['error', 'always'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,6 @@ typings/ | |
|
||
# generate output | ||
dist | ||
|
||
# components | ||
Example.tsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "react-bkash", | ||
"version": "1.0.3", | ||
"version": "1.0.5", | ||
"description": "A React Component for Accepting Bkash Payments using React", | ||
"author": "Shahriar Shojib <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -17,8 +17,12 @@ | |
}, | ||
"devDependencies": { | ||
"@types/react": "^17.0.5", | ||
"@typescript-eslint/eslint-plugin": "^4.24.0", | ||
"@typescript-eslint/parser": "^4.24.0", | ||
"babel-core": "^6.26.3", | ||
"babel-runtime": "^6.26.0", | ||
"eslint": "^7.27.0", | ||
"eslint-plugin-react": "^7.23.2", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"rollup": "^2.48.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,32 @@ | ||
import React, { ReactElement } from 'react'; | ||
import { useEffect, useState, FC, PropsWithChildren, cloneElement } from 'react'; | ||
import { createBkashButton, initBkash, triggerBkash } from './utils/initBkash'; | ||
import { IProps } from './utils/interfaces'; | ||
import { loadScript } from './utils/loadScript'; | ||
import React, { ReactElement, useEffect, useState, FC, cloneElement } from 'react'; | ||
import { initBkash, triggerBkash, loadDeps, IProps } from './utils'; | ||
|
||
const BkashButton: FC<IProps> = (props): JSX.Element | null => { | ||
const [isLoaded, setLoaded] = useState(false); | ||
const { | ||
onSuccess, | ||
onClose, | ||
children, | ||
config: { amount, bkashScriptURL, createPaymentURL, executePaymentURL, additionalHeaders }, | ||
} = props; | ||
|
||
const BkashButton: FC<PropsWithChildren<IProps>> = ({ | ||
onSuccess, | ||
onClose, | ||
children, | ||
config: { amount, bkashScriptURL, createPaymentURL, executePaymentURL, additionalHeaders }, | ||
}): JSX.Element => { | ||
const [isLoaded, setIsLoaded] = useState(false); | ||
useEffect(() => { | ||
async function main() { | ||
if (!isLoaded) { | ||
await loadScript('https://code.jquery.com/jquery-3.3.1.min.js', 'jquery'); | ||
createBkashButton(); | ||
await loadScript(bkashScriptURL, 'bkashScript'); | ||
await loadDeps(bkashScriptURL); | ||
initBkash(amount, createPaymentURL, executePaymentURL, onSuccess, onClose, additionalHeaders); | ||
setIsLoaded(true); | ||
setLoaded(true); | ||
} | ||
} | ||
main(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
if (isLoaded) { | ||
return <div onClick={triggerBkash}>{cloneElement(children as ReactElement, { onClick: triggerBkash })}</div>; | ||
} | ||
|
||
return <></>; | ||
return null; | ||
}; | ||
|
||
export default BkashButton; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './initBkash'; | ||
export * from './interfaces'; | ||
export * from './loadScript'; | ||
export * from './loadDeps'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { createBkashButton } from './initBkash'; | ||
import { loadScript } from './loadScript'; | ||
|
||
export const loadDeps = async (bkashScriptURL: string) => { | ||
if (!document.querySelector('#jquery')) { | ||
await loadScript('https://code.jquery.com/jquery-3.3.1.min.js', 'jquery'); | ||
} | ||
createBkashButton(); | ||
|
||
if (!document.querySelector('#jquery')) { | ||
await loadScript(bkashScriptURL, 'bkashScript'); | ||
} | ||
}; |
Oops, something went wrong.