From 67035fbc7e63af0566b77cb82e8364e1a1bf1ff6 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 2 Mar 2023 19:39:02 +0200 Subject: [PATCH] 1.0.1 - Added useTuitioClient default options --- README.md | 3 ++- package-lock.json | 4 ++-- package.json | 2 +- src/hooks/useTuitioClient.ts | 14 ++++++++++---- tests/hooks/useTuitioClient.test.ts | 8 +------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 583980a..d119245 100644 --- a/README.md +++ b/README.md @@ -34,4 +34,5 @@ All tests in the package can be executed by running: `npm test`. ## Changelog -1.0.0 - Package initialization +1.0.0 - Package initialization +1.0.1 - Added useTuitioClient default options diff --git a/package-lock.json b/package-lock.json index fc8a59d..07a9110 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@flare/tuitio-client-react", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@flare/tuitio-client-react", - "version": "1.0.0", + "version": "1.0.1", "license": "MIT", "dependencies": { "@flare/tuitio-client": "^1.0.4" diff --git a/package.json b/package.json index c5e984d..e9959a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@flare/tuitio-client-react", - "version": "1.0.0", + "version": "1.0.1", "description": "Tuitio client react is an npm package written in typescript that facilitates the integration of a react application with Tuitio.", "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", diff --git a/src/hooks/useTuitioClient.ts b/src/hooks/useTuitioClient.ts index a3ffa7a..7c2420a 100644 --- a/src/hooks/useTuitioClient.ts +++ b/src/hooks/useTuitioClient.ts @@ -4,12 +4,18 @@ import { TuitioClient, invalidate } from "@flare/tuitio-client"; import type { TuitioAuthenticationResult } from "@flare/tuitio-client"; export type TuitioClientHookOptions = { - onLoginSuccess: (result: TuitioAuthenticationResult, userName: string) => void; - onLoginFailed: (result: TuitioAuthenticationResult, userName: string) => void; - onLoginError: (error: any) => void; + onLoginSuccess?: (result: TuitioAuthenticationResult, userName: string) => void; + onLoginFailed?: (result: TuitioAuthenticationResult, userName: string) => void; + onLoginError?: (error: any) => void; }; -const useTuitioClient = (options: TuitioClientHookOptions) => { +const defaultOptions: TuitioClientHookOptions = { + onLoginSuccess: undefined, + onLoginFailed: undefined, + onLoginError: undefined +}; + +const useTuitioClient = (options: TuitioClientHookOptions = defaultOptions) => { const state = useContext(TuitioContext); const dispatchActions = useContext(TuitioDispatchContext); diff --git a/tests/hooks/useTuitioClient.test.ts b/tests/hooks/useTuitioClient.test.ts index 38e934b..39e0587 100644 --- a/tests/hooks/useTuitioClient.test.ts +++ b/tests/hooks/useTuitioClient.test.ts @@ -102,13 +102,7 @@ describe("useTuitioClient", () => { }); it("should call invalidate when logout is called", () => { - const { result } = renderHook(() => - useTuitioClient({ - onLoginSuccess: jest.fn(), - onLoginFailed: jest.fn(), - onLoginError: jest.fn() - }) - ); + const { result } = renderHook(() => useTuitioClient()); act(() => { result.current.logout();