Skip to content
Open
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
12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <jonatasvsales@gmail.com>",
"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": {
Expand All @@ -38,4 +42,4 @@
"pre-commit": "yarn prettier --check ./src && yarn lint && yarn build"
}
}
}
}
3 changes: 2 additions & 1 deletion src/actions/setupOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion src/domain/MdHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export interface MdHub {
}
module: Module
event: {
add(name: string, handler: (...args: unknown[]) => void): void
add<T = unknown>(name: string, handler: (...args: T[]) => void): void
}
}
1 change: 1 addition & 0 deletions src/domain/ModuleOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface ModuleOptions {
onPrescriptionPrinted: (prescriptionData: unknown) => void
onPrescriptionExcluded: (prescriptionId: number) => void
}
1 change: 1 addition & 0 deletions src/errors/PrescriptionExcludedNotFunctionError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default new Error('onPrescriptionExcluded must be a function.')
1 change: 1 addition & 0 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
11 changes: 9 additions & 2 deletions src/hooks/useMemed.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand All @@ -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)
}
Expand Down
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"baseUrl": "./",
"target": "ES2018",
"module": "esnext",
"lib": ["ES2018", "DOM"],
"lib": [
"ES2018",
"DOM"
],
"declaration": true,
"composite": false,
"downlevelIteration": true,
Expand All @@ -23,4 +26,4 @@
"exclude": [
"lib/**"
]
}
}