diff --git a/package.json b/package.json index 1f362c5..7ea890d 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,22 @@ { "name": "memed-react", - "version": "2.0.5", + "version": "3.0.5", "description": "React library to integrate with memed", "main": "lib/index.js", "repository": "git@github.com:jonatassales/memed-react.git", "homepage": "https://memed-react-refs.vercel.app/", "author": "Jonatas Sales ", "license": "MIT", - "keywords": ["memed", "react memed", "memed integracao"], + "keywords": [ + "memed", + "react memed", + "memed integracao" + ], "scripts": { "build": "tsc", "lint": "eslint --ext .ts,.tsx ./src" }, - "peerDependencies": { + "peerDependencies": { "react": "16.8.x || 17.x" }, "devDependencies": { @@ -38,4 +42,4 @@ "pre-commit": "yarn prettier --check ./src && yarn lint && yarn build" } } -} +} \ No newline at end of file diff --git a/src/actions/setupOptions.ts b/src/actions/setupOptions.ts index 72afd00..59ed3a3 100644 --- a/src/actions/setupOptions.ts +++ b/src/actions/setupOptions.ts @@ -6,7 +6,8 @@ export default function setupOptions(options: ModuleOptions): void { throw MdHubNotInitializedError } - const { onPrescriptionPrinted } = options + const { onPrescriptionPrinted, onPrescriptionExcluded } = options window.MdHub.event.add('prescricaoImpressa', onPrescriptionPrinted) + window.MdHub.event.add('prescricaoExcluida', onPrescriptionExcluded) } diff --git a/src/domain/MdHub.ts b/src/domain/MdHub.ts index 477b1b5..1dd82bd 100644 --- a/src/domain/MdHub.ts +++ b/src/domain/MdHub.ts @@ -13,6 +13,6 @@ export interface MdHub { } module: Module event: { - add(name: string, handler: (...args: unknown[]) => void): void + add(name: string, handler: (...args: T[]) => void): void } } diff --git a/src/domain/ModuleOptions.ts b/src/domain/ModuleOptions.ts index 102d3ae..df0182e 100644 --- a/src/domain/ModuleOptions.ts +++ b/src/domain/ModuleOptions.ts @@ -1,3 +1,4 @@ export interface ModuleOptions { onPrescriptionPrinted: (prescriptionData: unknown) => void + onPrescriptionExcluded: (prescriptionId: number) => void } diff --git a/src/errors/PrescriptionExcludedNotFunctionError.ts b/src/errors/PrescriptionExcludedNotFunctionError.ts new file mode 100644 index 0000000..c30f997 --- /dev/null +++ b/src/errors/PrescriptionExcludedNotFunctionError.ts @@ -0,0 +1 @@ +export default new Error('onPrescriptionExcluded must be a function.') diff --git a/src/errors/index.ts b/src/errors/index.ts index 413b9da..63cf6b7 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -2,3 +2,4 @@ export { default as MdHubNotInitializedError } from './MdHubNotInitializedError' export { default as MdSinapsePrescricaoNotInitializedError } from './MdSinapsePrescricaoNotInitializedError' export { default as ProviderNotPlacedError } from './ProviderNotPlacedError' export { default as PrescriptionPrintedNotFunctionError } from './PrescriptionPrintedNotFunctionError' +export { default as PrescriptionExcludedNotFunctionError } from './PrescriptionExcludedNotFunctionError' diff --git a/src/hooks/useMemed.ts b/src/hooks/useMemed.ts index 70846e2..426038c 100644 --- a/src/hooks/useMemed.ts +++ b/src/hooks/useMemed.ts @@ -1,6 +1,10 @@ import React from 'react' -import { ProviderNotPlacedError, PrescriptionPrintedNotFunctionError } from '../errors' +import { + ProviderNotPlacedError, + PrescriptionPrintedNotFunctionError, + PrescriptionExcludedNotFunctionError +} from '../errors' import { ModuleOptions } from '../domain' import MemedContext, { MemedContextValue } from '../contexts/MemedContext' @@ -14,7 +18,7 @@ export default function useMemed(options?: ModuleOptions): MemedContextValue { React.useEffect(() => { if (options && !optionsSet) { - const { onPrescriptionPrinted } = options + const { onPrescriptionPrinted, onPrescriptionExcluded } = options /** * I had to do this because of non-ts-implementations using the lib @@ -23,7 +27,10 @@ export default function useMemed(options?: ModuleOptions): MemedContextValue { // @ts-ignore if (typeof onPrescriptionPrinted !== 'function') { throw PrescriptionPrintedNotFunctionError + } else if (typeof onPrescriptionExcluded !== 'function') { + throw PrescriptionExcludedNotFunctionError } + memed.setOptions(options) setOptionsSet(true) } diff --git a/tsconfig.json b/tsconfig.json index ac5bd64..7eaed66 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,10 @@ "baseUrl": "./", "target": "ES2018", "module": "esnext", - "lib": ["ES2018", "DOM"], + "lib": [ + "ES2018", + "DOM" + ], "declaration": true, "composite": false, "downlevelIteration": true, @@ -23,4 +26,4 @@ "exclude": [ "lib/**" ] -} +} \ No newline at end of file